pub struct QecProgram { /* private fields */ }Expand description
Native QEC program expressed as measurement-record operations.
Implementations§
Source§impl QecProgram
impl QecProgram
Sourcepub fn detector_error_model(&self) -> Result<DetectorErrorModel>
pub fn detector_error_model(&self) -> Result<DetectorErrorModel>
Derive the detector error model implied by the program’s Pauli-noise annotations, detectors, and observables.
Every annotation expands into its Pauli fault branches per fault site
(one branch per target for X_ERROR / Z_ERROR, three per target for
DEPOLARIZE1, fifteen per target pair for DEPOLARIZE2). Each branch
is propagated through the circuit to the set of detectors and
observables it flips. Mutually exclusive branches at one fault site
with the same symptom sum; independent fault sites (distinct targets
of one annotation included) with the same symptom compose as
p = p1(1-p2) + p2(1-p1). Faults that flip no detector and no
observable are omitted. Mechanisms are independent in the model, so
its joint statistics agree with the sampler to second order in the
branch probabilities.
§Errors
Requires the compiled Clifford path: non-Clifford gates and reuse of a measured qubit without reset are rejected.
§Examples
use prism_q::QecProgram;
let program = QecProgram::from_text(
"X_ERROR(0.05) 0 1 2
CX 0 3 1 3 1 4 2 4
M 3 4
DETECTOR rec[-2]
DETECTOR rec[-1]",
)?;
let model = program.detector_error_model()?;
assert_eq!(model.num_detectors(), 2);
assert_eq!(model.num_mechanisms(), 3);Source§impl QecProgram
impl QecProgram
pub fn new(num_qubits: usize) -> Self
pub fn with_options(num_qubits: usize, options: QecOptions) -> Self
Sourcepub fn from_ops(
num_qubits: usize,
options: QecOptions,
ops: Vec<QecOp>,
) -> Result<Self>
pub fn from_ops( num_qubits: usize, options: QecOptions, ops: Vec<QecOp>, ) -> Result<Self>
Create a program from operations, validating record references as operations are appended.
pub fn num_qubits(&self) -> usize
pub fn options(&self) -> QecOptions
pub fn set_options(&mut self, options: QecOptions)
pub fn ops(&self) -> &[QecOp]
Sourcepub fn num_measurements(&self) -> usize
pub fn num_measurements(&self) -> usize
Number of measurement records produced by the operation stream.
pub fn num_detectors(&self) -> usize
Sourcepub fn num_observables(&self) -> usize
pub fn num_observables(&self) -> usize
Observable slot count, max included index + 1.
Sourcepub fn num_expectation_values(&self) -> usize
pub fn num_expectation_values(&self) -> usize
Number of EXP_VAL ops.
Sourcepub fn expectation_value_ops(&self) -> Vec<(&[QecPauli], f64)>
pub fn expectation_value_ops(&self) -> Vec<(&[QecPauli], f64)>
The EXP_VAL ops in op order as (terms, coefficient).
pub fn push_op(&mut self, op: QecOp) -> Result<()>
pub fn push_gate(&mut self, gate: Gate, targets: &[usize]) -> Result<()>
pub fn reset(&mut self, basis: QecBasis, qubit: usize) -> Result<()>
Sourcepub fn measure(&mut self, basis: QecBasis, qubit: usize) -> Result<usize>
pub fn measure(&mut self, basis: QecBasis, qubit: usize) -> Result<usize>
Append a single-qubit measurement and return its record index.
Sourcepub fn measure_z(&mut self, qubit: usize) -> Result<usize>
pub fn measure_z(&mut self, qubit: usize) -> Result<usize>
Append a Z-basis measurement and return its record index.
Sourcepub fn measure_x(&mut self, qubit: usize) -> Result<usize>
pub fn measure_x(&mut self, qubit: usize) -> Result<usize>
Append an X-basis measurement and return its record index.
Sourcepub fn measure_pauli_product(&mut self, terms: &[QecPauli]) -> Result<usize>
pub fn measure_pauli_product(&mut self, terms: &[QecPauli]) -> Result<usize>
Append a Pauli-product measurement and return its record index.
Sourcepub fn detector(&mut self, records: &[QecRecordRef]) -> Result<usize>
pub fn detector(&mut self, records: &[QecRecordRef]) -> Result<usize>
Append a detector and return its detector index.
Sourcepub fn detector_with_coords(
&mut self,
records: &[QecRecordRef],
coords: &[f64],
) -> Result<usize>
pub fn detector_with_coords( &mut self, records: &[QecRecordRef], coords: &[f64], ) -> Result<usize>
Append a detector with coordinates and return its detector index.
pub fn observable_include( &mut self, observable: usize, records: &[QecRecordRef], ) -> Result<()>
pub fn expectation_value( &mut self, terms: &[QecPauli], coefficient: f64, ) -> Result<()>
pub fn postselect( &mut self, records: &[QecRecordRef], expected: bool, ) -> Result<()>
pub fn noise(&mut self, channel: QecNoise, targets: &[usize]) -> Result<()>
Sourcepub fn feedforward(
&mut self,
records: &[QecRecordRef],
expected: bool,
body: Vec<QecOp>,
) -> Result<()>
pub fn feedforward( &mut self, records: &[QecRecordRef], expected: bool, body: Vec<QecOp>, ) -> Result<()>
Append a feed-forward correction: body runs iff the parity over
records equals expected.
See QecOp::Feedforward for what the body admits.
Sourcepub fn detector_rows(&self) -> Result<Vec<Vec<usize>>>
pub fn detector_rows(&self) -> Result<Vec<Vec<usize>>>
Resolve detector rows to absolute measurement record indices.
Sourcepub fn observable_rows(&self) -> Result<Vec<Vec<usize>>>
pub fn observable_rows(&self) -> Result<Vec<Vec<usize>>>
Resolve observable rows to absolute measurement record indices.
Sourcepub fn postselection_rows(&self) -> Result<Vec<(Vec<usize>, bool)>>
pub fn postselection_rows(&self) -> Result<Vec<(Vec<usize>, bool)>>
Resolve postselection rows to absolute measurement record indices.
Sourcepub fn empty_result(&self) -> QecSampleResult
pub fn empty_result(&self) -> QecSampleResult
Create an empty result with the program’s current record shape.
Trait Implementations§
Source§impl Clone for QecProgram
impl Clone for QecProgram
Source§fn clone(&self) -> QecProgram
fn clone(&self) -> QecProgram
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for QecProgram
impl Debug for QecProgram
Source§impl PartialEq for QecProgram
impl PartialEq for QecProgram
impl StructuralPartialEq for QecProgram
Auto Trait Implementations§
impl Freeze for QecProgram
impl RefUnwindSafe for QecProgram
impl Send for QecProgram
impl Sync for QecProgram
impl Unpin for QecProgram
impl UnsafeUnpin for QecProgram
impl UnwindSafe for QecProgram
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T, U> Imply<T> for U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more