use symb_anafis::DiffError;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum ParameterError {
#[error(transparent)]
SymbolicError(#[from] DiffError),
#[error("Symbol not found: {0}")]
UndefinedSymbol(String),
#[error("Division by zero")]
DivisionByZero,
#[error("Domain error: {0}")]
DomainError(String),
#[error("Calculation resulted in NaN: {0}")]
NaN(String),
#[error("Parse error: {0}")]
ParseError(String),
}
#[derive(Debug, Error)]
pub enum EvalError {
#[error("Symbol not found: {0}")]
UndefinedSymbol(String),
#[error("Division by zero")]
DivisionByZero,
#[error("Domain error: {0}")]
DomainError(String),
#[error("Calculation resulted in NaN: {0}")]
NaN(String),
#[error("Maximum recursion depth exceeded during evaluation (depth limit: {0})")]
MaxRecursionDepthExceeded(usize),
}
#[derive(Debug, Error)]
pub enum DerivativeError {
#[error("Cannot differentiate expression: {0}")]
NonDifferentiable(String),
}
#[derive(Debug, Error)]
pub enum CircuitError {
#[error("Duplicate qubits found in circuit definition")]
DuplicateQubits,
#[error("Qubit {0} not found in circuit")]
QubitNotFound(u32),
#[error("Qubit count mismatch: expected {expected}, got {actual}")]
QubitCountMismatch {
expected: usize,
actual: usize,
},
#[error("Parameter count mismatch: expected {expected}, got {actual}")]
ParameterCountMismatch {
expected: usize,
actual: usize,
},
#[error("Invalid parameter: {0}")]
InvalidParameter(#[from] ParameterError),
#[error("Instruction has no matrix representation")]
NoMatrixRepresentation,
#[error("Failed to evaluate parameters: {0}")]
ParamEvaluationFailed(#[from] EvalError),
#[error("Operation is irreversible")]
IrreversibleOperation,
#[error("Operation cannot be controlled: {0}")]
InvalidControlOperation(String),
#[error("Symbolic parameter cannot be evaluated in this context")]
SymbolicParameterError,
#[error("Unresolved parameter in decomposition: {0}")]
UnresolvedParameter(String),
#[error("Parameter index {0} out of range")]
InvalidParameterIndex(u32),
#[error("Operation index {index} out of bounds for circuit with {len} operations")]
OperationIndexOutOfBounds {
index: usize,
len: usize,
},
#[error("classical value {index} is still used at {context}")]
ClassicalValueStillInUse {
index: u32,
context: String,
},
#[error("Invalid parameter value at index {0}: {1}")]
InvalidParameterValue(usize, f64),
#[error("Invalid control flow graph structure: {0}")]
InvalidControlFlow(String),
#[error("Invalid circuit DAG structure: {0}")]
InvalidDag(String),
#[error("{kind} {index} belongs to another circuit")]
ForeignClassicalHandle {
kind: &'static str,
index: u32,
},
#[error("classical value {index} is not available at {context}")]
UndefinedClassicalValue {
index: u32,
context: String,
},
#[error("classical value {index} has more than one definition: {first} and {second}")]
DuplicateClassicalValueDefinition {
index: u32,
first: String,
second: String,
},
#[error("classical value {index} escapes its defining control-flow region at {context}")]
ClassicalValueOutOfScope {
index: u32,
context: String,
},
#[error("{operation} must be the final operation in {context}")]
NonTerminalControlTransfer {
operation: &'static str,
context: String,
},
#[error("circuit contains control-flow operations; pass recurse=true for an estimated depth")]
ControlFlowPresent,
#[error("Invalid Operation: {0}")]
InvalidOperation(String),
}
#[derive(Debug, Error)]
pub enum CompileError {
#[error("error")]
Error,
}