microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
source/resource_estimator/src/system/error.rs
150lines ยท modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | use miette::Diagnostic; |
| 5 | use thiserror::Error; |
| 6 | |
| 7 | #[derive(Debug, Error, Diagnostic)] |
| 8 | pub enum IO { |
| 9 | /// Cannot open a filename that is passed by string |
| 10 | /// |
| 11 | /// โ
This does not contain user data and can be logged |
| 12 | /// ๐ We want this to be tracked as error and investigate |
| 13 | /// |
| 14 | /// Note that in the service, we are creating all filenames. |
| 15 | /// It's not relevant to log this data. |
| 16 | #[error("cannot open file: '{0}'")] |
| 17 | #[diagnostic(code("Qsc.Estimates.IOError.CannotOpenFile"))] |
| 18 | CannotOpenFile(String), |
| 19 | /// Captures various reasons that JSON cannot be parsed |
| 20 | /// |
| 21 | /// โ This may contain user data and cannot be logged |
| 22 | /// ๐งโ๐ป This indicates a user error |
| 23 | #[error("cannot parse JSON: '{0}'")] |
| 24 | #[diagnostic(code("Qsc.Estimates.IOError.CannotParseJSON"))] |
| 25 | CannotParseJSON(serde_json::error::Error), |
| 26 | } |
| 27 | |
| 28 | #[derive(Debug, Error, Diagnostic)] |
| 29 | pub enum TFactory { |
| 30 | /// Cannot compute the inverse binomial distribution |
| 31 | /// |
| 32 | /// โ
This does not contain user data and can be logged |
| 33 | /// ๐ We want this to be tracked as error and investigate |
| 34 | #[error("cannot compute inverse binomial distribution for n = {0}, p1 = {1}, and p2 = {2}")] |
| 35 | #[diagnostic(code("Qsc.Estimates.TFactoryError.CannotComputeInverseBinomial"))] |
| 36 | CannotComputeInverseBinomial(usize, f64, f64), |
| 37 | } |
| 38 | |
| 39 | #[derive(Debug, Error, Diagnostic)] |
| 40 | pub enum InvalidInput { |
| 41 | /// Fault-tolerance protocol is not compatible with instruction set |
| 42 | /// |
| 43 | /// โ
This does not contain user data and can be logged |
| 44 | /// ๐งโ๐ป This indicates a user error |
| 45 | #[error("fault tolerance protocol does not support gate type of qubit")] |
| 46 | #[diagnostic(code("Qsc.Estimates.InvalidInputError.InvalidFaultToleranceProtocol"))] |
| 47 | InvalidFaultToleranceProtocol, |
| 48 | /// Logical cycle is non-positive for some code distance value |
| 49 | /// |
| 50 | /// โ
This does not contain user data and can be logged |
| 51 | /// ๐งโ๐ป This indicates a user error |
| 52 | #[error("logicalCycleTime formula yields non-positive value for code distance = {0}")] |
| 53 | #[diagnostic(code("Qsc.Estimates.InvalidInputError.NonPositiveLogicalCycleTime"))] |
| 54 | NonPositiveLogicalCycleTime(u64), |
| 55 | /// Number of physical qubits per logial qubits is non-positive for some code distance value |
| 56 | /// |
| 57 | /// โ
This does not contain user data and can be logged |
| 58 | /// ๐งโ๐ป This indicates a user error |
| 59 | #[error( |
| 60 | "physicalQubitsPerLogicalQubit formula yields non-positive value for code distance = {0}" |
| 61 | )] |
| 62 | #[diagnostic(code("Qsc.Estimates.InvalidInputError.NonPositivePhysicalQubitsPerLogicalQubit"))] |
| 63 | NonPositivePhysicalQubitsPerLogicalQubit(u64), |
| 64 | /// Invalid error budget (<= 0.0 or >= 1.0) |
| 65 | /// |
| 66 | /// โ
This does not contain user data and can be logged |
| 67 | /// ๐งโ๐ป This indicates a user error |
| 68 | #[error("The error budget must be between 0.0 and 1.0, provided input was `{0}`")] |
| 69 | #[diagnostic(code("Qsc.Estimates.InvalidInputError.InvalidErrorBudget"))] |
| 70 | InvalidErrorBudget(f64), |
| 71 | /// Constraints provided for frontier estimation |
| 72 | /// (maximal time, maximal number of qubits, maximal number of T factories) |
| 73 | /// are not supported for frontier estimation. |
| 74 | /// |
| 75 | /// โ
This does not contain user data and can be logged |
| 76 | /// ๐งโ๐ป This indicates a user error |
| 77 | #[error("Unsupported constraints provided for Frontier Estimation.")] |
| 78 | #[diagnostic(code("Qsc.Estimates.InvalidInputError.ConstraintsProvidedForFrontierEstimation"))] |
| 79 | ConstraintsProvidedForFrontierEstimation, |
| 80 | } |
| 81 | |
| 82 | #[derive(Debug, Error, Diagnostic)] |
| 83 | pub enum Error { |
| 84 | /// Handles various types of I/O errors |
| 85 | /// |
| 86 | /// โ This may contain user data and cannot be logged |
| 87 | #[error(transparent)] |
| 88 | #[diagnostic(transparent)] |
| 89 | IO(IO), |
| 90 | /// An error that happens when evaluating an expression |
| 91 | /// |
| 92 | /// โ This may contain user data and cannot be logged |
| 93 | /// ๐งโ๐ป This indicates a user error |
| 94 | #[error("cannot evaluate expression: '{0}'")] |
| 95 | #[diagnostic(code("Qsc.Estimates.EvaluationError.CannotEvaluateExpression"))] |
| 96 | Evaluation(String), |
| 97 | /// Invalid value for some variable, allowed range is specified via lower |
| 98 | /// and upper bound |
| 99 | /// |
| 100 | /// โ
This does not contain user data and can be logged |
| 101 | /// ๐งโ๐ป This indicates a user error |
| 102 | #[error("invalid value for '{0}', expected value between {1} and {2}")] |
| 103 | #[diagnostic(code("Qsc.Estimates.InvalidValueError.InvalidValue"))] |
| 104 | InvalidValue(String, f64, f64), |
| 105 | /// Handles various types of invalid input |
| 106 | /// |
| 107 | /// โ
This does not contain user data and can be logged |
| 108 | /// (mostly user error, but check `InvalidInput` for more details) |
| 109 | #[error(transparent)] |
| 110 | #[diagnostic(transparent)] |
| 111 | InvalidInput(InvalidInput), |
| 112 | /// Handles various types of T-factory problems |
| 113 | /// |
| 114 | /// โ
This does not contain user data and can be logged |
| 115 | /// ๐งโ๐ป This indicates a user error |
| 116 | #[error(transparent)] |
| 117 | #[diagnostic(transparent)] |
| 118 | TFactory(TFactory), |
| 119 | /// Handles various errors from physical resource estimation |
| 120 | /// |
| 121 | /// โ
This does not contain user data and can be logged |
| 122 | /// ๐งโ๐ป This indicates a user error |
| 123 | #[error(transparent)] |
| 124 | #[diagnostic(transparent)] |
| 125 | Estimation(#[from] crate::estimates::Error), |
| 126 | } |
| 127 | |
| 128 | impl From<fasteval::Error> for Error { |
| 129 | fn from(error: fasteval::Error) -> Self { |
| 130 | Self::Evaluation(error.to_string()) |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | impl From<IO> for Error { |
| 135 | fn from(error: IO) -> Self { |
| 136 | Self::IO(error) |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | impl From<TFactory> for Error { |
| 141 | fn from(error: TFactory) -> Self { |
| 142 | Self::TFactory(error) |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | impl From<InvalidInput> for Error { |
| 147 | fn from(error: InvalidInput) -> Self { |
| 148 | Self::InvalidInput(error) |
| 149 | } |
| 150 | } |
| 151 | |