use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Error, Debug)]
pub enum Error {
#[error("Qubit index {0} is out of bounds for {1} qubits.")]
QubitIndexOutOfBounds(usize, usize),
#[error("Number of qubits must be greater than zero, got {0}.")]
InvalidNumQubits(usize),
#[error("Two-qubit gate requires two different qubit indices, but got the same: {0}.")]
DuplicateQubitIndices(usize),
#[error(
"Impossible projection on qubit {qubit_index}: cannot project determined state |{}> onto|{}>.",
if *desired { 0 } else { 1 },
if *desired { 1 } else { 0 }
)]
ImpossibleProjection { qubit_index: usize, desired: bool },
#[error(
"The qubit counts of the two states must match for {}, got {} and {}.",
operation,
left,
right
)]
QubitCountMismatch {
operation: &'static str,
left: usize,
right: usize,
},
#[error("The length of the permutation ({0}) must match the number of qubits ({1}).")]
InvalidPermutationLength(usize, usize),
#[error("The provided permutation {0:?} is not a valid permutation of qubit indices.")]
InvalidPermutation(Vec<usize>),
#[error("The length of the qubit state ({0}) does not match the number of qubits ({1}).")]
InvalidQubitStateLength(usize, usize),
#[error("Cannot discard qubit {0} because it is not in a proper state")]
CannotDiscardQubit(usize),
#[error("QASM parsing error: {0}")]
QasmParsingError(String),
#[error("Pauli string parsing error: {0}")]
PauliStringParsingError(String),
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
}