Struct qoqo::CircuitWrapper

source ·
pub struct CircuitWrapper {
    pub internal: Circuit,
}
Expand description

Circuit of Operations.

A quantum program is represented as a linear sequence of Operations.

Fields§

§internal: Circuit

Internal storage of roqoqo::Circuit

Implementations§

source§

impl CircuitWrapper

source

pub fn from_pyany(input: Py<PyAny>) -> PyResult<Circuit>

Extracts a Circuit from a CircuitWrapper python object.

When working with qoqo and other rust based python packages compiled separately a downcast will not detect that two CircuitWrapper objects are compatible. Provides a custom function to convert qoqo Circuits between different Python packages.

§Arguments:

input - The Python object that should be casted to a roqoqo::Circuit

source§

impl CircuitWrapper

source

pub fn new() -> Self

Create an empty quantum Circuit.

Returns: self: The new, empty Circuit.

source

pub fn substitute_parameters( &self, substitution_parameters: HashMap<&str, f64> ) -> PyResult<Self>

Substitute the symbolic parameters in a clone of the Circuit according to the substitution_parameters input.

Args: substitution_parameters (dict[str, float]): The dictionary containing the substitutions to use in the Circuit.

Returns: self: The Circuit with the parameters substituted.

Raises: RuntimeError: The parameter substitution failed.

source

pub fn remap_qubits(&self, mapping: HashMap<usize, usize>) -> PyResult<Self>

Remap qubits in operations in clone of Circuit.

Args: mapping (dict[int, int]): The dictionary containing the {qubit: qubit} mapping to use in the Circuit.

Returns: self: The Circuit with the qubits remapped.

Raises: RuntimeError: The qubit remapping failed.

source

pub fn overrotate(&self) -> PyResult<Self>

Return clone of the circuit with all overrotation Pragmas applied.

Returns: Circuit: Circuit with the overrotation applied

Raises: RuntimeError: Error applying PragmaOverrotation in circuit. Example:

circuit = Circuit() circuit += PragmaOverrotation(“RotateY”, [1,], 20.0, 30.0) circuit += RotateX(0, 0.0) circuit += RotateY(0, 1.0) circuit += RotateY(1, 2.0) circuit += RotateY(1, 3.0) circuit_overrotated = circuit.overrotate() print(circuit) print(circuit_overrotated)

source

pub fn count_occurences(&self, operations: Vec<&str>) -> usize

Count the number of occurences of a set of operation tags in the circuit.

Args: operations (liststr): List of operation tags that should be counted.

Returns: int: The number of occurences of these operation tags.

source

pub fn get_operation_types(&self) -> HashSet<&str>

Return a list of the hqslang names of all operations occuring in the circuit.

Returns: setstr: The operation types in the Circuit.

source

pub fn __copy__(&self) -> CircuitWrapper

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

Returns: Circuit: A deep copy of self.

source

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

Return a deep copy of the Circuit.

Returns: Circuit: A deep copy of self.

source

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

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

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

Raises: ValueError: Cannot serialize Circuit to bytes.

source

pub fn from_bincode(input: &PyAny) -> PyResult<Self>

Convert the bincode representation of the Circuit to a Circuit using the bincode crate.

Args: input (ByteArray): The serialized Circuit (in bincode form).

Returns: Circuit: The deserialized Circuit.

Raises: TypeError: Input cannot be converted to byte array. ValueError: Input cannot be deserialized to Circuit.

source

pub fn from_json(json_string: &str) -> PyResult<Self>

Convert the json representation of a Circuit to a Circuit.

Args: input (str): The serialized Circuit in json form.

Returns: Circuit: The deserialized Circuit.

Raises: ValueError: Input cannot be deserialized to Circuit.

source

pub fn get(&self, index: usize) -> PyResult<PyObject>

Return a copy of the Operation at a certain index of the Circuit.

Args: index (int): The index of the Operation to get in the Circuit.

Returns: Operation: The operation at the given index (if it exists).

Raises: IndexError: Index out of range.

source

pub fn get_slice( &self, start: Option<usize>, stop: Option<usize> ) -> PyResult<CircuitWrapper>

Return the copy of a slice of the Circuit.

Args: start (Optional[int]): The starting index of the slice (inclusive). stop (Optional[int]): The stopping index of the slice (exclusive).

Returns: Circuit: The slice of the operations in the Circuit with the specified indices.

Raises: IndexError: Stop index smaller than start index. IndexError: Stop index out of range. IndexError: Start index out of range.

source

pub fn definitions(&self) -> PyResult<Vec<PyObject>>

Return a list of definitions in the Circuit.

Definitions need to be unique.

Returns: list[Operation]: A vector of the definitions in the Circuit.

source

pub fn operations(&self) -> PyResult<Vec<PyObject>>

Return a list of all operations in the Circuit.

Returns: list[Operation]: A vector of the operations in the Circuit.

source

pub fn filter_by_tag(&self, tag: &str) -> PyResult<Vec<PyObject>>

Return a list of operations with given tag.

Args: tag (str): tag by which to filter operations.

Returns: list[Operation]: A vector of the operations with the specified tag in the Circuit.

source

pub fn add(&mut self, op: &PyAny) -> PyResult<()>

Add an Operation to Circuit.

Args: op (Operation): The Operation to add to the Circuit.

Trait Implementations§

source§

impl Clone for CircuitWrapper

source§

fn clone(&self) -> CircuitWrapper

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 CircuitWrapper

source§

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

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

impl Default for CircuitWrapper

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl IntoPy<Py<PyAny>> for CircuitWrapper

source§

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

Performs the conversion.
source§

impl PartialEq for CircuitWrapper

source§

fn eq(&self, other: &CircuitWrapper) -> 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 CircuitWrapper

§

type Frozen = False

Whether the pyclass is frozen. Read more
source§

impl PyClassImpl for CircuitWrapper

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<CircuitWrapper>

This handles following two situations: Read more
§

type Inventory = Pyo3MethodsInventoryForCircuitWrapper

§

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<CircuitWrapper> for PyClassImplCollector<CircuitWrapper>

source§

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

source§

impl PyClass__add__SlotFragment<CircuitWrapper> for PyClassImplCollector<CircuitWrapper>

source§

unsafe fn __add__( self, py: Python<'_>, _raw_slf: *mut PyObject, arg0: *mut PyObject ) -> PyResult<*mut PyObject>

Safety: _slf and _other must be valid non-null Python objects Read more
source§

impl PyClass__setitem__SlotFragment<CircuitWrapper> for PyClassImplCollector<CircuitWrapper>

source§

unsafe fn __setitem__( self, py: Python<'_>, _raw_slf: *mut PyObject, arg0: *mut PyObject, arg1: NonNull<PyObject> ) -> PyResult<()>

Safety: _slf and _attr must be valid non-null Python objects Read more
source§

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

§

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

source§

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

source§

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

§

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

source§

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

source§

impl PyTypeInfo for CircuitWrapper

§

type AsRefTarget = PyCell<CircuitWrapper>

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

const NAME: &'static str = "Circuit"

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 StructuralPartialEq for CircuitWrapper

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> Scalar for T
where T: 'static + Clone + PartialEq + Debug,

source§

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