Struct roqoqo_mock::Backend
source · [−]pub struct Backend { /* private fields */ }
Expand description
Mocked backend to qoqo
Provides functions to run circuits and measurements. The mocked backend mock-simulates a quantum circuit on a given device by translating the roqoqo Circuit using the roqoqo_mocked interface. This interface produces random measurements coherent with the measured quantity. These results are then output from the run function in this backend and are accessible through the classical registers dictionary.
Arguments
number_qubits
- Number of qubits in the Backend
Implementations
Trait Implementations
sourceimpl EvaluatingBackend for Backend
impl EvaluatingBackend for Backend
Trait for Backends that can evaluate measurements to expectation values.
Example
use roqoqo::{Circuit, backends::EvaluatingBackend, operations::*};
use roqoqo_mock::Backend;
let backend = Backend::new(2_usize);
let mut circuit = Circuit::new();
circuit += DefinitionBit::new("ro".to_string(), 2, true);
circuit += RotateX::new(0, std::f64::consts::FRAC_PI_2.into());
circuit += PauliX::new(1);
circuit += PragmaRepeatedMeasurement::new("ro".to_string(), None, 20);
let (bit_registers, _float_registers, _complex_registers) =
backend.run_circuit(&circuit).unwrap();
assert!(bit_registers.contains_key("ro"));
let out_reg = bit_registers.get("ro").unwrap();
assert_eq!(out_reg.len(), 20);
for reg in out_reg.iter() {
assert_eq!(reg.len(), 2);
}
sourcefn run_circuit_iterator<'a>(
&self,
circuit: impl Iterator<Item = &'a Operation>
) -> Result<(HashMap<String, BitOutputRegister>, HashMap<String, FloatOutputRegister>, HashMap<String, ComplexOutputRegister>), RoqoqoBackendError>
fn run_circuit_iterator<'a>(
&self,
circuit: impl Iterator<Item = &'a Operation>
) -> Result<(HashMap<String, BitOutputRegister>, HashMap<String, FloatOutputRegister>, HashMap<String, ComplexOutputRegister>), RoqoqoBackendError>
Runs a circuit with the backend.
A circuit is passed to the roqoqo-mock backend and executed. During execution values are written to and read from classical registers ([crate::registers::BitRegister], [crate::registers::FloatRegister] and [crate::registers::ComplexRegister]). To produce sufficient statistics for evaluating expectationg values, circuits have to be run multiple times. The results of each repetition are concatenated in OutputRegisters ([crate::registers::BitOutputRegister], [crate::registers::FloatOutputRegister] and [crate::registers::ComplexOutputRegister]).
Arguments
circuit
- The circuit that is run on the backend.
Returns
RegisterResult
- The output registers written by the evaluated circuits.
sourcefn run_circuit(
&self,
circuit: &Circuit
) -> Result<(HashMap<String, Vec<Vec<bool, Global>, Global>, RandomState>, HashMap<String, Vec<Vec<f64, Global>, Global>, RandomState>, HashMap<String, Vec<Vec<Complex<f64>, Global>, Global>, RandomState>), RoqoqoBackendError>
fn run_circuit(
&self,
circuit: &Circuit
) -> Result<(HashMap<String, Vec<Vec<bool, Global>, Global>, RandomState>, HashMap<String, Vec<Vec<f64, Global>, Global>, RandomState>, HashMap<String, Vec<Vec<Complex<f64>, Global>, Global>, RandomState>), RoqoqoBackendError>
Runs a circuit with the backend. Read more
sourcefn run_measurement_registers<T>(
&self,
measurement: &T
) -> Result<(HashMap<String, Vec<Vec<bool, Global>, Global>, RandomState>, HashMap<String, Vec<Vec<f64, Global>, Global>, RandomState>, HashMap<String, Vec<Vec<Complex<f64>, Global>, Global>, RandomState>), RoqoqoBackendError> where
T: Measure,
fn run_measurement_registers<T>(
&self,
measurement: &T
) -> Result<(HashMap<String, Vec<Vec<bool, Global>, Global>, RandomState>, HashMap<String, Vec<Vec<f64, Global>, Global>, RandomState>, HashMap<String, Vec<Vec<Complex<f64>, Global>, Global>, RandomState>), RoqoqoBackendError> where
T: Measure,
Runs all circuits corresponding to one measurement with the backend. Read more
sourcefn run_measurement<T>(
&self,
measurement: &T
) -> Result<Option<HashMap<String, f64, RandomState>>, RoqoqoBackendError> where
T: MeasureExpectationValues,
fn run_measurement<T>(
&self,
measurement: &T
) -> Result<Option<HashMap<String, f64, RandomState>>, RoqoqoBackendError> where
T: MeasureExpectationValues,
Evaluates expectation values of a measurement with the backend. Read more
impl StructuralPartialEq for Backend
Auto Trait Implementations
impl RefUnwindSafe for Backend
impl Send for Backend
impl Sync for Backend
impl Unpin for Backend
impl UnwindSafe for Backend
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct self
from the equivalent element of its
superset. Read more
fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if self
is actually part of its subset T
(and can be converted to it).
fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as self.to_subset
but without any property checks. Always succeeds.
fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts self
to the equivalent element of its superset.
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more