1use glam::IVec2;
2use thiserror::Error;
3
4use crate::{BodyId, GateType, LoopStateId};
5
6#[derive(Debug, Error, Clone, Copy, PartialEq, Eq)]
8#[error("translating coordinate {coordinate:?} by {offset:?} overflows i32")]
9pub struct CoordinateOverflowError {
10 pub coordinate: IVec2,
12 pub offset: IVec2,
14}
15
16#[derive(Debug, Error, Clone, PartialEq, Eq)]
18pub enum FlowError {
19 #[error("{0}")]
21 CoordinateOverflow(#[from] CoordinateOverflowError),
22 #[error("{0}")]
24 Composition(String),
25}
26
27#[derive(Debug, Error, Clone, PartialEq, Eq)]
30pub enum MeasurementFrameError {
31 #[error("operation measurement count {measurements} exceeds the u32 record range")]
33 MeasurementCountOutOfRange {
34 measurements: usize,
36 },
37 #[error(
39 "repeat frame with {measurements_per_iteration} measurements per iteration repeated {repetitions} times overflows the emitted measurement count"
40 )]
41 RepeatedMeasurementCountOverflow {
42 measurements_per_iteration: u32,
44 repetitions: u32,
46 },
47 #[error(
49 "emitted measurement count {emitted_count} plus repeated contribution {additional} overflows the emitted measurement count"
50 )]
51 EmittedMeasurementCountOverflow {
52 emitted_count: u32,
54 additional: u32,
56 },
57 #[error(
59 "repeat body measurement offset {offset} is outside measurements per iteration {measurements_per_iteration}"
60 )]
61 RepeatMeasurementOffsetOutOfRange {
62 offset: u32,
64 measurements_per_iteration: u32,
66 },
67 #[error("repeat body measurement offset overflowed")]
69 RepeatMeasurementOffsetOverflow,
70 #[error("measurement record lookback {lookback} exceeds backend limit {max}")]
72 RecordLookbackOutOfRange {
73 lookback: u32,
75 max: u32,
77 },
78}
79
80#[derive(Debug, Error, Clone, PartialEq, Eq)]
84pub enum CircuitError {
85 #[error("measurement id {0} is not allocated in this circuit")]
87 InvalidMeasurementId(u32),
88 #[error("invalid circuit body id {0:?}")]
90 InvalidCircuitBody(BodyId),
91 #[error("circuit body index {index} exceeds the u32 body-id range")]
93 BodyIdOutOfRange {
94 index: usize,
96 },
97 #[error("invalid loop detector state id {0:?}")]
99 InvalidLoopDetectorState(LoopStateId),
100 #[error("qubit at {0} not found in layout")]
102 QubitNotFoundInLayout(IVec2),
103 #[error("qubit index {index} is outside a {num_qubits}-qubit layout")]
105 QubitIndexOutOfRange {
106 index: usize,
108 num_qubits: usize,
110 },
111 #[error("{0}")]
113 MeasurementFrame(#[from] MeasurementFrameError),
114 #[error("{gate} requires paired targets, got {targets}")]
116 InvalidGateTargetCount {
117 gate: GateType,
119 targets: usize,
121 },
122 #[error("MPP product must have at least one non-identity Pauli target")]
124 EmptyPauliProduct,
125 #[error("flattening repeat blocks would overflow the u32 measurement id space")]
127 FlattenMeasurementIdOverflow,
128 #[error("flattening requires at least {observed} work units (limit {limit})")]
131 FlattenResourceLimit {
132 observed: usize,
134 limit: usize,
136 },
137}