Skip to main content

cqlib_core/error_mitigation/
error.rs

1// This code is part of Cqlib.
2//
3// (C) Copyright China Telecom Quantum Group 2026
4//
5// This code is licensed under the Apache License, Version 2.0. You may
6// obtain a copy of this license in the LICENSE.txt file in the root directory
7// of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
8//
9// Any modifications or derivative works of this code must retain this
10// copyright notice, and modified files need to carry a notice indicating
11// that they have been altered from the originals.
12
13use thiserror::Error;
14
15use crate::circuit::CircuitError;
16use crate::qis::error::QisError;
17
18/// Shared errors raised by error-mitigation APIs.
19#[derive(Debug, Error)]
20pub enum ErrorMitigationError {
21    #[error(transparent)]
22    Circuit(#[from] CircuitError),
23
24    #[error(transparent)]
25    Qis(#[from] QisError),
26
27    #[error("virtual distillation requires at least 2 copies, got {0}")]
28    InvalidCopies(usize),
29
30    #[error("hamiltonian qubit count mismatch: expected {expected}, got {actual}")]
31    HamiltonianQubitCountMismatch { expected: usize, actual: usize },
32
33    #[error("virtual distillation denominator mean is zero")]
34    ZeroDenominatorMean,
35
36    #[error("fold level must be non-negative, got {0}")]
37    InvalidFoldLevel(i32),
38
39    #[error("run() must be completed before get_mitigated()")]
40    RunRequiredBeforeMitigation,
41
42    #[error("run() has already been completed for this ErrorMitigation instance")]
43    AlreadyRun,
44
45    #[error("get_mitigated() has already been completed for this ErrorMitigation instance")]
46    AlreadyMitigated,
47
48    #[error("run arguments do not match the configured mitigation method")]
49    RunArgsMethodMismatch,
50
51    #[error("processing arguments do not match the configured mitigation method")]
52    ProcessArgsMethodMismatch,
53
54    #[error("noisy results must not be empty")]
55    EmptyNoisyResults,
56
57    #[error("noisy results length mismatch: expected {expected}, got {actual}")]
58    NoisyResultsLengthMismatch { expected: usize, actual: usize },
59
60    #[error("polynomial degree {degree} must be smaller than number of data points {num_points}")]
61    InvalidPolynomialDegree { degree: usize, num_points: usize },
62
63    #[error("all noisy results must be positive for exponential extrapolation")]
64    NonPositiveNoisyResults,
65
66    #[error("exponential fit failed due to a singular linear-regression system")]
67    SingularExponentialFit,
68
69    #[error("polynomial fit failed due to a singular normal-equation matrix")]
70    SingularPolynomialFit,
71}