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

source

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

source

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 .

source

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.

source

pub fn input_parameter_names(&self) -> Vec<String>

Returns the input_parameter_names attribute of the qoqo QuantumProgram.

Returns: List of input parameter names.

source

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

source

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

source

pub fn __copy__(&self) -> QuantumProgramWrapper

Return a copy of the QuantumProgram (copy here produces a deepcopy).

Returns: QuantumProgram: A deep copy of self.

source

pub fn __deepcopy__(&self, _memodict: Py<PyAny>) -> QuantumProgramWrapper

Return a deep copy of the QuantumProgram.

Returns: QuantumProgram: A deep copy of self.

source

pub fn to_bincode(&self) -> PyResult<Py<PyByteArray>>

Return the bincode representation of the QuantumProgram using the bincode crate.

Returns: ByteArray: The serialized QuantumProgram (in bincode form).

Raises: ValueError: Cannot serialize QuantumProgram to bytes.

source

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

source§

fn clone(&self) -> QuantumProgramWrapper

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for QuantumProgramWrapper

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for QuantumProgramWrapper

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl IntoPy<Py<PyAny>> for QuantumProgramWrapper

source§

fn into_py(self, py: Python<'_>) -> PyObject

Performs the conversion.
source§

impl PartialEq for QuantumProgramWrapper

source§

fn eq(&self, other: &QuantumProgramWrapper) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PyClass for QuantumProgramWrapper

§

type Frozen = False

Whether the pyclass is frozen. Read more
source§

impl PyClassImpl for QuantumProgramWrapper

source§

const IS_BASETYPE: bool = false

#[pyclass(subclass)]
source§

const IS_SUBCLASS: bool = false

#[pyclass(extends=…)]
source§

const IS_MAPPING: bool = false

#[pyclass(mapping)]
source§

const IS_SEQUENCE: bool = false

#[pyclass(sequence)]
§

type BaseType = PyAny

Base class
§

type ThreadChecker = SendablePyClass<QuantumProgramWrapper>

This handles following two situations: Read more
§

type Inventory = Pyo3MethodsInventoryForQuantumProgramWrapper

§

type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild

Immutable or mutable
§

type Dict = PyClassDummySlot

Specify this class has #[pyclass(dict)] or not.
§

type WeakRef = PyClassDummySlot

Specify this class has #[pyclass(weakref)] or not.
§

type BaseNativeType = PyAny

The closest native ancestor. This is PyAny by default, and when you declare #[pyclass(extends=PyDict)], it’s PyDict.
source§

fn items_iter() -> PyClassItemsIter

source§

fn doc(py: Python<'_>) -> PyResult<&'static CStr>

Rendered class doc
source§

fn lazy_type_object() -> &'static LazyTypeObject<Self>

source§

fn dict_offset() -> Option<isize>

source§

fn weaklist_offset() -> Option<isize>

source§

impl PyClassNewTextSignature<QuantumProgramWrapper> for PyClassImplCollector<QuantumProgramWrapper>

source§

fn new_text_signature(self) -> Option<&'static str>

source§

impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a QuantumProgramWrapper

§

type Holder = Option<PyRef<'py, QuantumProgramWrapper>>

source§

fn extract(obj: &'py PyAny, holder: &'a mut Self::Holder) -> PyResult<Self>

source§

impl<'a, 'py> PyFunctionArgument<'a, 'py> for &'a mut QuantumProgramWrapper

§

type Holder = Option<PyRefMut<'py, QuantumProgramWrapper>>

source§

fn extract(obj: &'py PyAny, holder: &'a mut Self::Holder) -> PyResult<Self>

source§

impl PyTypeInfo for QuantumProgramWrapper

§

type AsRefTarget = PyCell<QuantumProgramWrapper>

Utility type to make Py::as_ref work.
source§

const NAME: &'static str = "QuantumProgram"

Class name.
source§

const MODULE: Option<&'static str> = _

Module name, if any.
source§

fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject

Returns the PyTypeObject instance for this type.
source§

fn type_object(py: Python<'_>) -> &PyType

Returns the safe abstraction over the type object.
source§

fn is_type_of(object: &PyAny) -> bool

Checks if object is an instance of this type or a subclass of this type.
source§

fn is_exact_type_of(object: &PyAny) -> bool

Checks if object is an instance of this type.
source§

impl Serialize for QuantumProgramWrapper

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl StructuralPartialEq for QuantumProgramWrapper

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> DynClone for T
where T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<'a, T> FromPyObject<'a> for T
where T: PyClass + Clone,

source§

fn extract(obj: &'a PyAny) -> Result<T, PyErr>

Extracts Self from the source PyObject.
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> PyErrArguments for T
where T: IntoPy<Py<PyAny>> + Send + Sync,

source§

fn arguments(self, py: Python<'_>) -> Py<PyAny>

Arguments for exception
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

source§

impl<T> Ungil for T
where T: Send,