Skip to main content

QuantumCircuit

Struct QuantumCircuit 

pub struct QuantumCircuit { /* private fields */ }
Expand description

Validated native QuantumOp gate-list input, not a symbolic crate::PathSum. Verification converts gate lists to symbolic Path-sums internally and exposes the residual via the result.

Supported QASM 2/3 decimal angles are preserved as exact rational radian terms and supported pi factors remain symbolic in Angle. Rotation helpers take Angle values, not silently rounded f64. Unsupported QASM operations cause parsing errors.

§Example

use quprs::{rational::Angle, QuantumCircuit};
let angle = Angle::from_qasm_str("1.2345678901234567")
    .expect("supported exact angle");
let mut direct = QuantumCircuit::new(1);
direct.rz(0, angle)?;
let parsed = QuantumCircuit::from_qasm_str(
    "OPENQASM 3.0;\nqubit[1] q;\nrz(1.2345678901234567) q[0];\n"
)?;
assert_eq!(direct, parsed);

Implementations§

§

impl QuantumCircuit

pub fn new(num_qubits: usize) -> Self

Construct an empty circuit with a fixed register width.

pub fn from_ops(num_qubits: usize, ops: Vec<QuantumOp>) -> Result<Self>

Validate and adopt an owned operation list without reallocation.

Each operation is checked before the circuit can escape. The original allocation and exact Angle values are retained; validation is linear in gate count, but does not rebuild the operations Vec.

pub fn from_qasm_str(source: &str) -> Result<Self>

Strictly parse the supported OpenQASM 2/3 unitary subset.

pub fn from_qasm_file(path: impl AsRef<Path>) -> Result<Self>

Strictly parse an OpenQASM file; reject unsupported operations.

pub fn num_qubits(&self) -> usize

pub fn operations(&self) -> &[QuantumOp]

Borrow operations without cloning the existing source IR.

pub fn len(&self) -> usize

pub fn is_empty(&self) -> bool

pub fn push(&mut self, op: QuantumOp) -> Result<&mut Self>

Append an operation after bounds and distinct-operand validation.

pub fn h(&mut self, qubit: usize) -> Result<&mut Self>

pub fn x(&mut self, qubit: usize) -> Result<&mut Self>

pub fn y(&mut self, qubit: usize) -> Result<&mut Self>

pub fn z(&mut self, qubit: usize) -> Result<&mut Self>

pub fn cx(&mut self, control: usize, target: usize) -> Result<&mut Self>

pub fn cz(&mut self, control: usize, target: usize) -> Result<&mut Self>

pub fn rz(&mut self, qubit: usize, theta: Angle) -> Result<&mut Self>

The source Angle is preserved without conversion to f64.

pub fn rx(&mut self, qubit: usize, theta: Angle) -> Result<&mut Self>

pub fn ry(&mut self, qubit: usize, theta: Angle) -> Result<&mut Self>

Trait Implementations§

§

impl Clone for QuantumCircuit

§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for QuantumCircuit

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
§

impl Eq for QuantumCircuit

§

impl PartialEq for QuantumCircuit

§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
§

impl StructuralPartialEq for QuantumCircuit

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.