Skip to main content

bloq_graph/verify/
error.rs

1//! Typed failures from logical verification.
2
3use std::collections::BTreeMap;
4
5use glam::IVec3;
6
7/// An error raised while building, sampling, or contracting a logical ZX map.
8#[derive(Debug, thiserror::Error)]
9#[non_exhaustive]
10pub enum VerifyLogicalError {
11    /// The caller cancelled construction or analysis.
12    #[error("{0}")]
13    Cancelled(#[from] crate::ComputationCancelled),
14    /// Block-graph construction or validation failed.
15    #[error("{0}")]
16    Graph(#[from] crate::BlockGraphError),
17    /// ZX translation or manipulation failed.
18    #[error("{0}")]
19    ZX(#[from] crate::ZXError),
20    /// Output correction surfaces could not be solved.
21    #[error("{0}")]
22    OutputCorrection(#[from] crate::OutputCorrectionError),
23    /// A logical boundary position appears more than once.
24    #[error("logical boundary {0} is listed more than once")]
25    DuplicateBoundary(IVec3),
26    /// A requested logical boundary is not an open port.
27    #[error("logical boundary {0} is not an open port")]
28    InvalidBoundary(IVec3),
29    /// An open port is absent from the requested logical boundary order.
30    #[error("open port {0} is absent from the logical boundary order")]
31    MissingBoundary(IVec3),
32    /// A measurement-dependent branch lacks an assigned value.
33    #[error("measurement {0:?} has no supplied branch value")]
34    MissingMeasurementValue(String),
35    /// An external Boolean input lacks an assigned value.
36    #[error("external Boolean input {0:?} has no supplied branch value")]
37    MissingInputValue(String),
38    /// A feedback target has no wire carrying the requested Pauli frame.
39    #[error("feedback target {target} has no wire on which to insert {pauli}")]
40    FeedbackTargetWithoutWire {
41        /// Block receiving feedback.
42        target: IVec3,
43        /// Pauli correction being inserted.
44        pauli: crate::PauliBasis,
45    },
46    /// A measurement outcome cannot be represented as a native ZX phase.
47    #[error("measurement {0:?} has no native ZX phase representation")]
48    MeasurementPhaseUnavailable(String),
49    /// The symbolic phase count exceeds QuiZX's variable-ID range.
50    #[error("too many symbolic phases for QuiZX's u32 variable ids")]
51    TooManySymbols,
52    /// Actual and expected logical maps have different boundary arity.
53    #[error(
54        "expected map has {expected_inputs} input(s) and {expected_outputs} output(s), but the Bloq map has {actual_inputs} input(s) and {actual_outputs} output(s)"
55    )]
56    BoundaryArityMismatch {
57        /// Number of inputs in the Bloq map.
58        actual_inputs: usize,
59        /// Number of outputs in the Bloq map.
60        actual_outputs: usize,
61        /// Number of inputs in the expected map.
62        expected_inputs: usize,
63        /// Number of outputs in the expected map.
64        expected_outputs: usize,
65    },
66    /// The caller-supplied expected logical map is identically zero.
67    #[error("the caller-supplied expected ZX map is the zero map")]
68    ZeroExpectedMap,
69    /// One sampled branch differs from the expected map up to scalar.
70    #[error(
71        "sampled nonzero branch does not equal the expected ZX map up to scalar: {classical_state:?}"
72    )]
73    MapMismatch {
74        /// Classical assignment selecting the mismatched branch.
75        classical_state: BTreeMap<String, bool>,
76    },
77    /// Sampling found no accepted branch with a nonzero logical map.
78    #[error("no accepted nonzero branch was sampled in {samples} fuzz case(s)")]
79    NoVerifiedBranch {
80        /// Number of sampled classical assignments.
81        samples: usize,
82    },
83    /// Initial runtime-basis construction failed.
84    #[error("could not initialize the logical stabilizer basis")]
85    RuntimeBasisInitializationFailed {
86        /// Underlying runtime-basis failure.
87        #[source]
88        source: crate::RuntimeBasisError,
89    },
90    /// Applying one runtime selection to the basis failed.
91    #[error("runtime basis update failed at {pos}")]
92    RuntimeBasisUpdateFailed {
93        /// Selective-block position being updated.
94        pos: IVec3,
95        /// Underlying runtime-basis failure.
96        #[source]
97        source: crate::RuntimeBasisError,
98    },
99    /// Required logical-output correction surfaces are unavailable.
100    #[error("output correction surfaces are unavailable for {0:?}")]
101    OutputSurfaceUnavailable(Vec<IVec3>),
102}