Skip to main content

oxicuda_quantum/
error.rs

1/// Errors produced by quantum simulation operations.
2#[derive(Debug, thiserror::Error)]
3pub enum QuantumError {
4    #[error("empty input")]
5    EmptyInput,
6
7    #[error("dimension mismatch: expected {expected}, got {got}")]
8    DimensionMismatch { expected: usize, got: usize },
9
10    #[error("invalid qubit count: {n}")]
11    InvalidQubitCount { n: usize },
12
13    #[error("qubit index {index} out of range for {n_qubits} qubits")]
14    QubitIndexOutOfRange { index: usize, n_qubits: usize },
15
16    #[error("state not normalized: norm = {norm}")]
17    NonNormalizedState { norm: f32 },
18
19    #[error("Hamiltonian is not Hermitian")]
20    NonHermitianHamiltonian,
21
22    #[error("Kraus operators not complete: residual = {residual}")]
23    KrausNotComplete { residual: f32 },
24
25    #[error("invalid parameter '{name}'")]
26    InvalidParameter { name: String },
27
28    #[error("invalid Pauli operator '{op}'")]
29    InvalidPauliOp { op: String },
30
31    #[error("incompatible ansatz configuration")]
32    IncompatibleAnsatz,
33
34    #[error("optimization diverged after {iter} iterations")]
35    OptimizationDiverged { iter: usize },
36
37    #[error("model not fitted (call fit() first)")]
38    NotFitted,
39
40    #[error("measurement failed")]
41    MeasurementFailed,
42
43    #[error("internal error: {msg}")]
44    Internal { msg: String },
45}
46
47pub type QuantumResult<T> = std::result::Result<T, QuantumError>;