Struct qoqo::QuantumProgramWrapper
source · pub struct QuantumProgramWrapper {
pub internal: QuantumProgram,
}
Expand description
Represents a quantum program evaluating measurements based on a one or more free float parameters.
The main use of QuantumProgram is to contain a Measurements implementing [crate::measurements::Measure]
that measures expectation values or output registers of [crate::Circuit] quantum circuits that contain
symbolic parameters. Circuit with symbolic parameters can not be simulated or executed on real hardware.
The symbolic parameters need to be replaced with real floating point numbers first.
A QuantumProgram contains a list of the free parameters (input_parameter_names
) and can automatically
replace the parameters with its run
methods and return the result.
The QuantumProgram should correspond as closely as possible to a normal multi-parameter function in classical computing that can be called with a set of parameters and returns a result. It is the intended way to interface between normal program code and roqoqo based quantum programs.
Fields§
§internal: QuantumProgram
Internal storage of roqoqo::QuantumProgram
Implementations§
source§impl QuantumProgramWrapper
impl QuantumProgramWrapper
sourcepub fn from_pyany(input: Py<PyAny>) -> PyResult<QuantumProgram>
pub fn from_pyany(input: Py<PyAny>) -> PyResult<QuantumProgram>
Extracts a QuantumProgram from a QuantumProgramWrapper python object.
When working with qoqo and other rust based python packages compiled separately a downcast will not detect that two QuantumProgramWrapper objects are compatible. Provides a custom function to convert qoqo QuantumPrograms between different Python packages.
§Arguments:
input
- The Python object that should be casted to a roqoqo::QuantumProgram
source§impl QuantumProgramWrapper
impl QuantumProgramWrapper
sourcepub fn new(
measurement: &PyAny,
input_parameter_names: Vec<String>
) -> PyResult<Self>
pub fn new( measurement: &PyAny, input_parameter_names: Vec<String> ) -> PyResult<Self>
Create a QuantumProgram.
Args: measurement: input_parameter_names (Liststr):
Returns: self: The new .
sourcepub fn measurement(&self) -> PyObject
pub fn measurement(&self) -> PyObject
Returns the measurement attribute of the QuantumProgram as Python object.
Returns: PyObject corresponding to the qoqo measurement type of the QuantumProgram, i.e. PauliZProduct, CheatedPauliZProduct, Cheated or ClassicalRegister.
sourcepub fn input_parameter_names(&self) -> Vec<String>
pub fn input_parameter_names(&self) -> Vec<String>
Returns the input_parameter_names attribute of the qoqo QuantumProgram.
Returns: List of input parameter names.
sourcepub fn run(
&self,
backend: Py<PyAny>,
parameters: Option<Vec<f64>>
) -> PyResult<Py<PyAny>>
pub fn run( &self, backend: Py<PyAny>, parameters: Option<Vec<f64>> ) -> PyResult<Py<PyAny>>
Runs the QuantumProgram and returns expectation values.
Runs the quantum programm for a given set of parameters passed in the same order as the parameters
listed in input_parameter_names
and returns expectation values.
Args:
backend (Backend): The backend the program is executed on.
parameters (Optional[List[float]): List of float parameters of the function call in order of input_parameter_names
sourcepub fn run_registers(
&self,
backend: Py<PyAny>,
parameters: Option<Vec<f64>>
) -> PyResult<Py<PyAny>>
pub fn run_registers( &self, backend: Py<PyAny>, parameters: Option<Vec<f64>> ) -> PyResult<Py<PyAny>>
Runs the QuantumProgram and returns the classical registers of the quantum program.
Runs the quantum programm for a given set of parameters passed in the same order as the parameters
listed in input_parameter_names
and returns the classical register output.
The classical registers usually contain a record of measurement values for the repeated execution
of a [crate::Circuit] quantum circuit for real quantum hardware
or the readout of the statevector or the density matrix for simulators.
Args:
backend (Backend): The backend the program is executed on.
parameters (Optional[List[float]): List of float parameters of the function call in order of input_parameter_names
sourcepub fn __copy__(&self) -> QuantumProgramWrapper
pub fn __copy__(&self) -> QuantumProgramWrapper
Return a copy of the QuantumProgram (copy here produces a deepcopy).
Returns: QuantumProgram: A deep copy of self.
sourcepub fn __deepcopy__(&self, _memodict: Py<PyAny>) -> QuantumProgramWrapper
pub fn __deepcopy__(&self, _memodict: Py<PyAny>) -> QuantumProgramWrapper
Return a deep copy of the QuantumProgram.
Returns: QuantumProgram: A deep copy of self.
sourcepub fn to_bincode(&self) -> PyResult<Py<PyByteArray>>
pub fn to_bincode(&self) -> PyResult<Py<PyByteArray>>
sourcepub fn from_bincode(input: &PyAny) -> PyResult<Self>
pub fn from_bincode(input: &PyAny) -> PyResult<Self>
Convert the bincode representation of the QuantumProgram to a QuantumProgram using the bincode crate.
Args: input (ByteArray): The serialized QuantumProgram (in bincode form).
Returns: QuantumProgram: The deserialized QuantumProgram.
Raises: TypeError: Input cannot be converted to byte array. ValueError: Input cannot be deserialized to QuantumProgram.
Trait Implementations§
source§impl Clone for QuantumProgramWrapper
impl Clone for QuantumProgramWrapper
source§fn clone(&self) -> QuantumProgramWrapper
fn clone(&self) -> QuantumProgramWrapper
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for QuantumProgramWrapper
impl Debug for QuantumProgramWrapper
source§impl<'de> Deserialize<'de> for QuantumProgramWrapper
impl<'de> Deserialize<'de> for QuantumProgramWrapper
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl PartialEq for QuantumProgramWrapper
impl PartialEq for QuantumProgramWrapper
source§fn eq(&self, other: &QuantumProgramWrapper) -> bool
fn eq(&self, other: &QuantumProgramWrapper) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PyClass for QuantumProgramWrapper
impl PyClass for QuantumProgramWrapper
source§impl PyClassImpl for QuantumProgramWrapper
impl PyClassImpl for QuantumProgramWrapper
source§const IS_BASETYPE: bool = false
const IS_BASETYPE: bool = false
source§const IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
source§const IS_MAPPING: bool = false
const IS_MAPPING: bool = false
source§const IS_SEQUENCE: bool = false
const IS_SEQUENCE: bool = false
§type ThreadChecker = SendablePyClass<QuantumProgramWrapper>
type ThreadChecker = SendablePyClass<QuantumProgramWrapper>
type Inventory = Pyo3MethodsInventoryForQuantumProgramWrapper
§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
§type BaseNativeType = PyAny
type BaseNativeType = PyAny
PyAny
by default, and when you declare
#[pyclass(extends=PyDict)]
, it’s PyDict
.fn items_iter() -> PyClassItemsIter
fn lazy_type_object() -> &'static LazyTypeObject<Self>
fn dict_offset() -> Option<isize>
fn weaklist_offset() -> Option<isize>
source§impl PyClassNewTextSignature<QuantumProgramWrapper> for PyClassImplCollector<QuantumProgramWrapper>
impl PyClassNewTextSignature<QuantumProgramWrapper> for PyClassImplCollector<QuantumProgramWrapper>
fn new_text_signature(self) -> Option<&'static str>
source§impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a QuantumProgramWrapper
impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a QuantumProgramWrapper
source§impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a mut QuantumProgramWrapper
impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a mut QuantumProgramWrapper
source§impl PyTypeInfo for QuantumProgramWrapper
impl PyTypeInfo for QuantumProgramWrapper
§type AsRefTarget = PyCell<QuantumProgramWrapper>
type AsRefTarget = PyCell<QuantumProgramWrapper>
source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
source§fn type_object(py: Python<'_>) -> &PyType
fn type_object(py: Python<'_>) -> &PyType
source§fn is_type_of(object: &PyAny) -> bool
fn is_type_of(object: &PyAny) -> bool
object
is an instance of this type or a subclass of this type.source§fn is_exact_type_of(object: &PyAny) -> bool
fn is_exact_type_of(object: &PyAny) -> bool
object
is an instance of this type.source§impl Serialize for QuantumProgramWrapper
impl Serialize for QuantumProgramWrapper
impl StructuralPartialEq for QuantumProgramWrapper
Auto Trait Implementations§
impl Freeze for QuantumProgramWrapper
impl RefUnwindSafe for QuantumProgramWrapper
impl Send for QuantumProgramWrapper
impl Sync for QuantumProgramWrapper
impl Unpin for QuantumProgramWrapper
impl UnwindSafe for QuantumProgramWrapper
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
source§impl<'a, T> FromPyObject<'a> for T
impl<'a, T> FromPyObject<'a> for T
source§impl<T> PyErrArguments for T
impl<T> PyErrArguments for T
source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moresource§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).source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.