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
impl QuantumCircuit
pub fn from_ops(num_qubits: usize, ops: Vec<QuantumOp>) -> Result<Self>
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>
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>
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]
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>
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>
pub fn rz(&mut self, qubit: usize, theta: Angle) -> Result<&mut Self>
The source Angle is preserved without conversion to f64.