LCOV - code coverage report
Current view: top level - src - lib.rs (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 2 3 66.7 %
Date: 2021-11-09 13:25:48 Functions: 4 14 28.6 %

          Line data    Source code
       1           1 : // Copyright © 2021 HQS Quantum Simulations GmbH. All Rights Reserved.
       2             : //
       3             : // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
       4             : // in compliance with the License. You may obtain a copy of the License at
       5             : //
       6             : //     http://www.apache.org/licenses/LICENSE-2.0
       7             : //
       8             : // Unless required by applicable law or agreed to in writing, software distributed under the
       9             : // License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
      10             : // express or implied. See the License for the specific language governing permissions and
      11             : // limitations under the License.
      12             : 
      13             : #![deny(missing_docs)]
      14             : #![warn(private_intra_doc_links)]
      15             : #![warn(missing_crate_level_docs)]
      16             : #![warn(missing_doc_code_examples)]
      17             : #![warn(private_doc_tests)]
      18             : #![deny(missing_debug_implementations)]
      19             : 
      20             : //! # roqoqo
      21             : //!
      22             : //! `Rust only Quantum Operation Quantum Operation` - the quantum computing toolkit by HQS Quantum Simulations.
      23             : //!
      24             : pub use qoqo_calculator::Calculator;
      25             : use qoqo_calculator::CalculatorError;
      26             : pub use qoqo_calculator::CalculatorFloat;
      27             : use thiserror::Error;
      28             : 
      29             : /// roqoqo version information, used for roqoqo import/export checks
      30             : pub const ROQOQO_VERSION: &str = env!("CARGO_PKG_VERSION");
      31             : 
      32             : /// Errors that can occur in roqoqo.
      33          80 : #[derive(Error, Debug, PartialEq)]
      34             : pub enum RoqoqoError {
      35             :     /// Error when values of alpha and beta lead to an invalid unitary matrix.
      36             :     #[error("Resulting gate matrix is not unitary. Please check values of alpha and beta: alpha_r: {alpha_r:?}, alpha_i: {alpha_i:?}, beta_r: {beta_r:?}, beta_i: {beta_i:?}, norm: {norm:?}.")]
      37             :     UnitaryMatrixErrror {
      38             :         /// Real part of diagonal element of (not) unitary matrix.
      39             :         alpha_r: f64,
      40             :         /// Imaginary part of diagonal element of (not) unitary matrix.
      41             :         alpha_i: f64,
      42             :         /// Real part of off-diagonal element of (not) unitary matrix.
      43             :         beta_r: f64,
      44             :         /// Real part of off-diagonal element of (not) unitary matrix.
      45             :         beta_i: f64,
      46             :         /// Norm of (not) unitary matrix.
      47             :         norm: f64,
      48             :     },
      49             :     /// Error when remapping qubits fails because qubit in operation is not in keys of HashMap/dict.
      50             :     #[error("Mapping of qubit {qubit:?} failed")]
      51             :     QubitMappingError {
      52             :         /// Qubit that can not be mapped.
      53             :         qubit: usize,
      54             :     },
      55             :     /// Custom error for failed conversion between enums with the TryFrom trait.
      56             :     #[error("Conversion from {start_type} to {end_type} failed")]
      57             :     ConversionError {
      58             :         /// Type from which should be converted.
      59             :         start_type: &'static str,
      60             :         /// Type into which should be converted.
      61             :         end_type: &'static str,
      62             :     },
      63             :     /// Error using try from  
      64             :     #[error("TryFrom conversion failed")]
      65             :     TryFromError,
      66             :     /// Custom error for failed multipliction of two gates acting on different qubits.
      67             :     #[error("Qubits {squbit} and {oqubit} incompatible. Gates acting on different qubits can not be multiplied.")]
      68             :     MultiplicationIncompatibleQubits {
      69             :         /// Self qubit of the operation on the left hand.
      70             :         squbit: usize,
      71             :         /// Other qubit of the operation on the right hand.
      72             :         oqubit: usize,
      73             :     },
      74             :     /// Error adding a PauliProduct involving qubits larger than number of qubit to measurement input.
      75             :     #[error("Pauli product involves qubit {pp_qubit} but number qubits is lower {number_qubits}.")]
      76             :     PauliProductExceedsQubits {
      77             :         /// Qubit involved in Pauli product.
      78             :         pp_qubit: usize,
      79             :         /// Number of qubits in measurement.
      80             :         number_qubits: usize,
      81             :     },
      82             :     /// Error when adding a new operator to expectation values.
      83             :     #[error(
      84             :         "Index of operator {index:?} exceeds Hilbert space dimension of {number_qubits} qubits."
      85             :     )]
      86             :     MismatchedOperatorDimension {
      87             :         /// Index not matching dimensions.
      88             :         index: (usize, usize),
      89             :         /// Number of qubits in measurement.
      90             :         number_qubits: usize,
      91             :     },
      92             :     /// Error when a complex register does not correspond to the expected dimension for cheated measurement.
      93             :     #[error(
      94             :         "Dimension of register {dim:?} exceeds Hilbert space dimension of {number_qubits} qubits."
      95             :     )]
      96             :     MismatchedRegisterDimension {
      97             :         /// Index not matching dimensions.
      98             :         dim: usize,
      99             :         /// Number of qubits in measurement.
     100             :         number_qubits: usize,
     101             :     },
     102             :     /// Error adding an expectation value, name of expectation value already take.
     103             :     #[error("Name {name} of expectation value already taken.")]
     104             :     ExpValUsedTwice {
     105             :         /// Name of the expecataion value missing.
     106             :         name: String,
     107             :     },
     108             :     /// Expected register is missing from the Output registers.
     109             :     #[error("OutputRegister {name} is missing.")]
     110             :     MissingRegister {
     111             :         /// Name of the missing register.
     112             :         name: String,
     113             :     },
     114             :     /// Error occured in basis rotation measurement.
     115             :     #[error("Error occured in basis rotation measurement. {msg}")]
     116             :     BasisRotationMeasurementError {
     117             :         /// Error message.
     118             :         msg: String,
     119             :     },
     120             :     /// Error serializing an internal roqoqo object
     121             :     #[error("An error occured serializing a roqoqo object: {msg} ")]
     122             :     SerializationError {
     123             :         /// Error message
     124             :         msg: String,
     125             :     },
     126             :     /// Generic error that does not fit in other error categories.
     127             :     #[error("An error occured in roqoqo: {msg} ")]
     128             :     GenericError {
     129             :         /// Generic error message
     130             :         msg: String,
     131             :     },
     132             :     // /// Rates matrix has negative eigenvalues, when they should be positive semi-definite.
     133             :     // #[error("Rates matrix has a negative eigenvalue: {value}")]
     134             :     // NegativeEigenvalue {
     135             :     //     /// Negative eigenvalue.
     136             :     //     value: f64,
     137             :     // },
     138             :     /// Transparent propagation of CalculatorError.
     139             :     #[error(transparent)]
     140             :     CalculatorError(#[from] CalculatorError),
     141             : }
     142             : 
     143             : /// Errors that can occur in roqoqo backends.
     144           0 : #[derive(Error, Debug, PartialEq)]
     145             : pub enum RoqoqoBackendError {
     146             :     /// Error operation not supported by backend
     147             :     #[error("Operation {hqslang} not supported by backend {hqslang}: ")]
     148             :     OperationNotInBackend {
     149             :         /// Name of the backend.
     150             :         backend: &'static str,
     151             :         /// hqslang name of the operation.
     152             :         hqslang: &'static str,
     153             :     },
     154             :     /// Error for backends missing authentification information.
     155             :     #[error("Backend authentification information is missing: {msg} ")]
     156             :     MissingAuthentification {
     157             :         /// Error msg
     158             :         msg: String,
     159             :     },
     160             :     /// Error when communicating with backend over the network.
     161             :     #[error("NetworkError communicating with: {msg} ")]
     162             :     NetworkError {
     163             :         /// Error msg
     164             :         msg: String,
     165             :     },
     166             :     /// Error when communicating with backend over the network.
     167             :     #[error("Backend timed out: {msg} ")]
     168             :     Timeout {
     169             :         /// Error msg
     170             :         msg: String,
     171             :     },
     172             :     /// Error when communicating with backend over the network.
     173             :     #[error("The file at this location already exists: {path} ")]
     174             :     FileAlreadyExists {
     175             :         /// Path of file to be created
     176             :         path: String,
     177             :     },
     178             :     /// Error when communicating with backend over the network.
     179             :     #[error("An error occured in the backend: {msg} ")]
     180             :     GenericError {
     181             :         /// Generic error message
     182             :         msg: String,
     183             :     },
     184             :     /// Transparent propagation of RoqoqoError.
     185             :     #[error(transparent)]
     186             :     RoqoqoError(#[from] RoqoqoError),
     187             :     /// Transparent propagation of CalculatorError.
     188             :     #[error(transparent)]
     189             :     CalculatorError(#[from] CalculatorError),
     190             : }
     191             : 
     192             : #[doc(hidden)]
     193             : mod circuit;
     194             : pub mod operations;
     195             : pub mod prelude;
     196             : pub use circuit::*;
     197             : pub mod backends;
     198             : pub mod devices;
     199             : pub mod measurements;
     200             : mod quantum_program;
     201             : pub mod registers;
     202             : pub use quantum_program::QuantumProgram;

Generated by: LCOV version 1.13