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§
source§impl 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(), 20, None);
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);
}
source§fn 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.
source§fn run_circuit(
&self,
circuit: &Circuit
) -> Result<(HashMap<String, Vec<Vec<bool>>>, HashMap<String, Vec<Vec<f64>>>, HashMap<String, Vec<Vec<Complex<f64>>>>), RoqoqoBackendError>
fn run_circuit( &self, circuit: &Circuit ) -> Result<(HashMap<String, Vec<Vec<bool>>>, HashMap<String, Vec<Vec<f64>>>, HashMap<String, Vec<Vec<Complex<f64>>>>), RoqoqoBackendError>
source§fn run_measurement_registers<T>(
&self,
measurement: &T
) -> Result<(HashMap<String, Vec<Vec<bool>>>, HashMap<String, Vec<Vec<f64>>>, HashMap<String, Vec<Vec<Complex<f64>>>>), RoqoqoBackendError>where
T: Measure,
fn run_measurement_registers<T>(
&self,
measurement: &T
) -> Result<(HashMap<String, Vec<Vec<bool>>>, HashMap<String, Vec<Vec<f64>>>, HashMap<String, Vec<Vec<Complex<f64>>>>), RoqoqoBackendError>where
T: Measure,
source§fn run_measurement<T>(
&self,
measurement: &T
) -> Result<Option<HashMap<String, f64>>, RoqoqoBackendError>where
T: MeasureExpectationValues,
fn run_measurement<T>(
&self,
measurement: &T
) -> Result<Option<HashMap<String, f64>>, RoqoqoBackendError>where
T: MeasureExpectationValues,
source§impl PartialEq for Backend
impl PartialEq for Backend
impl Eq for Backend
impl StructuralEq for Backend
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§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
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
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.