#[derive(Debug, PartialEq)]
pub enum ExportError
{
ExportPeekInvalid(&'static str),
NoClassicalRegister,
IncompleteConditionRegister,
InvalidConditionalOp(String),
NotImplemented(&'static str, String),
CantCloseLoop,
RangeAlreadyOpen
}
impl ::std::fmt::Display for ExportError
{
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result
{
match *self
{
ExportError::ExportPeekInvalid(method) => {
write!(f, "Peeking into the quantum state is not a physical operation, and is not supported in {}", method)
},
ExportError::NoClassicalRegister => {
write!(f, "In cQasm, no classical registers can be specified. Measurements must be made to a classical bit with the same index as the qubit")
},
ExportError::IncompleteConditionRegister => {
write!(f, "OpenQasm can only perform conditional operations based on a complete classical register")
},
ExportError::InvalidConditionalOp(ref qasm) => {
write!(f, "Unable to find gate name or argument in \"{}\"", qasm)
},
ExportError::NotImplemented(method, ref desc) => {
write!(f, "Export to {} was not implemented for \"{}\"", method, desc)
},
ExportError::CantCloseLoop => {
write!(f, "Unable to close loop, because no loop is currently open")
},
ExportError::RangeAlreadyOpen => {
write!(f, "Trying to reserve range of bits, but a previous reservation is still open")
}
}
}
}
pub type ExportResult<T> = ::std::result::Result<T, ExportError>;
#[derive(Debug, PartialEq)]
pub enum ParseError
{
UnknownGate(String),
NoGateName(String),
InvalidNrArguments(usize, usize, String),
InvalidNrBits(usize, usize, String),
InvalidArgument(String),
NoBits(String),
InvalidBit(String),
TrailingText(String),
UnclosedParentheses(String),
}
impl ::std::fmt::Display for ParseError
{
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result
{
match *self
{
ParseError::UnknownGate(ref name) => {
write!(f, "Unknown gate \"{}\"", name)
},
ParseError::NoGateName(ref text) => {
write!(f, "Failed to find gate name in \"{}\"", text)
},
ParseError::InvalidNrArguments(actual, expected, ref name) => {
write!(f, "Expected {} arguments to \"{}\" gate, got {}", expected, name, actual)
},
ParseError::InvalidNrBits(actual, expected, ref name) => {
write!(f, "Expected {} bits for \"{}\" gate, got {}", expected, name, actual)
},
ParseError::InvalidArgument(ref text) => {
write!(f, "Failed to parse argument \"{}\"", text)
},
ParseError::NoBits(ref name) => {
write!(f, "Unable to find the bits gate {} operates on", name)
},
ParseError::InvalidBit(ref text) => {
write!(f, "Failed to parse bit number in \"{}\"", text)
},
ParseError::TrailingText(ref text) => {
write!(f, "Trailing text after gate description: \"{}\"", text)
},
ParseError::UnclosedParentheses(ref text) => {
write!(f, "Unclosed parentheses in expression: \"{}\"", text)
}
}
}
}
pub type ParseResult<T> = ::std::result::Result<T, ParseError>;
#[derive(Debug, PartialEq)]
pub enum Error
{
InvalidNrBits(usize, usize, String),
InvalidQBit(usize),
InvalidCBit(usize),
NotExecuted,
InternalError(String),
ExportError(ExportError),
ParseError(ParseError)
}
impl From<ExportError> for Error
{
fn from(err: ExportError) -> Self
{
Error::ExportError(err)
}
}
impl From<ParseError> for Error
{
fn from(err: ParseError) -> Self
{
Error::ParseError(err)
}
}
impl ::std::fmt::Display for Error
{
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result
{
match *self
{
Error::InvalidNrBits(actual, expected, ref desc) => {
write!(f, "Expected {} bits for \"{}\", got {}", expected, desc, actual)
},
Error::InvalidQBit(bit) => {
write!(f, "Invalid index {} for a quantum bit", bit)
},
Error::InvalidCBit(bit) => {
write!(f, "Invalid index {} for a classical bit", bit)
},
Error::NotExecuted => {
write!(f, "The circuit has not been executed yet")
},
Error::InternalError(ref err) => {
write!(f, "Internal error: {}", err)
},
Error::ExportError(ref err) => {
write!(f, "{}", err)
},
Error::ParseError(ref err) => {
write!(f, "{}", err)
}
}
}
}
pub type Result<T> = ::std::result::Result<T, Error>;