pub struct Circuit {
definitions: Vec<Operation>,
operations: Vec<Operation>,
_roqoqo_version: RoqoqoVersion,
}
Expand description
Represents a quantum circuit in roqoqo.
In roqoqo, single operations are collected in a circuit to build up a quantum program.
Roqoqo circuits are strictly linear sequences of operations.
The circuit struct behaves similar to a list and provides several standard
functions of a Vec
Example
use roqoqo::Circuit;
use roqoqo::operations::{Operation, RotateX};
use qoqo_calculator::CalculatorFloat;
// creating circuit
let mut circuit = Circuit::new();
// adding operation to circuit
circuit.add_operation(RotateX::new(0,CalculatorFloat::from(0)));
assert_eq!(circuit.len(), 1);
// iterating over circuit I
let operation_vector: Vec<&Operation>= circuit.iter().collect();
// iterating over circuit II
for op in circuit{
println!("{:?}", op);
}
// collecting operations into circuit
let vector = vec![Operation::from(RotateX::new(0,CalculatorFloat::from(0))), Operation::from(RotateX::new(0,CalculatorFloat::from(0)))];
let new_circuit: Circuit = vector.into_iter().collect();
Similarly to single Operations, Circuits can be translated to other frameworks via interfaces.
For Circuits the following functions are defined:
new()
: creates an empty Circuitadd_operation(operation)
: adds the specified operation to the Circuitget(index)
: returns the operation at the specified index in the Circuitget_mut(index)
: returns mutable reference to the operation at the specified index in the Circuititer()
: creates an iterator of the Circuitlen()
: returns the length of the Circuitis_empty()
: returns a boolean of whether the Circuit contains any definitions and operations or notinvolved_qubits()
: returns the qubits invovlved in the whole Circuitdefinitions()
: returns the definitions in the Circuitoperations()
: returns the operations in the Circuitsubstitute_parameters(calculator)
: substitutes any symbolic parameters in (a copy of) the Circuit according to the specified Calculatorremap_qubits(mapping)
: remaps the qubits in (a copy of) the Circuit according to the specified mappingcount_occurences(operations)
: returns the number of operations in the Circuit with the specified operation tagsget_operation_types()
: returns a list of all of the operations in the Circuit (in hqslang)from_iter(iterator)
: creates a Circuit from the items in the specified iteratorextend(iterator)
: adds the operations in the specified iterator to the Circuitdefault()
: creates an empty Circuit[...]
: gets a slice of the Circuit (returned as a vector)+
and+=
: add two circuits or an operation to the Circuit
Fields
definitions: Vec<Operation>
Definitions in the quantum circuit, must be unique.
operations: Vec<Operation>
Operations of the quantum circuit, do not have to be unique.
_roqoqo_version: RoqoqoVersion
The roqoqo version
Implementations
sourceimpl Circuit
impl Circuit
sourcepub fn add_operation<T>(&mut self, op: T) where
T: Into<Operation>,
pub fn add_operation<T>(&mut self, op: T) where
T: Into<Operation>,
sourcepub fn get_mut(&mut self, index: usize) -> Option<&mut Operation>
pub fn get_mut(&mut self, index: usize) -> Option<&mut Operation>
Returns a mutable reference to the element at index similar to std::Vec get function.
Contrary to std::Vec get function not implemented for slices.
Arguments
index
- The index of the Operation to get in the Circuit.
Returns
Option<mut &Operation>
- A mutable reference to the operation at the given index (if it exists).
sourcepub fn iter(&self) -> impl Iterator<Item = &Operation>
pub fn iter(&self) -> impl Iterator<Item = &Operation>
Creates an iterator of the Circuit.
Returns
Iterator<Item = &Operation>
- The Circuit in iterator form.
sourcepub fn is_parametrized(&self) -> bool
pub fn is_parametrized(&self) -> bool
Returns true if the Circuit contains symbolic variables.
Returns
bool
- True if the Circuit contains symbolic values, false if it does not.
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the Circuit does not contain any operations and definitions.
Returns
bool
- True if the Circuit is empty, false if it is not.
sourcepub fn involved_qubits(&self) -> InvolvedQubits
pub fn involved_qubits(&self) -> InvolvedQubits
sourcepub fn definitions(&self) -> &Vec<Operation>
pub fn definitions(&self) -> &Vec<Operation>
Returns reference to the vector of definitions in Circuit.
Definitions need to be unique.
Returns
&Vec<Operation>
- A vector of the definitions in the Circuit.
sourcepub fn operations(&self) -> &Vec<Operation>
pub fn operations(&self) -> &Vec<Operation>
Returns reference to the vector of quantum operations in Circuit.
Operations do not need to be unique.
Returns
&Vec<Operation>
- A vector of the operations in the Circuit.
sourcepub fn substitute_parameters(
&self,
calculator: &mut Calculator
) -> Result<Self, RoqoqoError>
pub fn substitute_parameters(
&self,
calculator: &mut Calculator
) -> Result<Self, RoqoqoError>
sourcepub fn remap_qubits(
&self,
mapping: &HashMap<usize, usize>
) -> Result<Self, RoqoqoError>
pub fn remap_qubits(
&self,
mapping: &HashMap<usize, usize>
) -> Result<Self, RoqoqoError>
sourcepub fn get_operation_types(&self) -> HashSet<&str>
pub fn get_operation_types(&self) -> HashSet<&str>
Returns a list of the hqslang names of all operations occuring in the circuit.
Returns
HashSet<&str>
- The operation types in the Circuit.
Trait Implementations
sourceimpl Add<&'_ Circuit> for Circuit
impl Add<&'_ Circuit> for Circuit
Implements +
(add) for Circuit and Circuit reference.
Arguments
other
- The Circuit reference to be added.
sourceimpl<T> Add<T> for Circuit where
T: Into<Operation>,
impl<T> Add<T> for Circuit where
T: Into<Operation>,
Implements +
(add) for Circuit and generic type T
.
Arguments
other
- Any type T that implements Intotrait.
sourceimpl AddAssign<&'_ Circuit> for Circuit
impl AddAssign<&'_ Circuit> for Circuit
Implements +=
(add) for Circuits and Circuit reference.
Arguments
other
- The Circuit to be appended.
sourcefn add_assign(&mut self, other: &Circuit)
fn add_assign(&mut self, other: &Circuit)
Performs the +=
operation. Read more
sourceimpl AddAssign<Circuit> for Circuit
impl AddAssign<Circuit> for Circuit
sourcefn add_assign(&mut self, other: Circuit)
fn add_assign(&mut self, other: Circuit)
Performs the +=
operation. Read more
sourceimpl<T> AddAssign<T> for Circuit where
T: Into<Operation>,
impl<T> AddAssign<T> for Circuit where
T: Into<Operation>,
Implements +=
(add) for Circuit and generic type T
.
Arguments
other
- Any type T that implements Intotrait.
sourcefn add_assign(&mut self, other: T)
fn add_assign(&mut self, other: T)
Performs the +=
operation. Read more
sourceimpl<'de> Deserialize<'de> for Circuit
impl<'de> Deserialize<'de> for Circuit
sourcefn 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>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl<T> Extend<T> for Circuit where
T: Into<Operation>,
impl<T> Extend<T> for Circuit where
T: Into<Operation>,
sourcefn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
Extends the Circuit by the specified operations (in Iterator form).
Arguments
iter
- The iterator containing the operations by which to extend the Circuit.
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
sourceimpl<T> FromIterator<T> for Circuit where
T: Into<Operation>,
impl<T> FromIterator<T> for Circuit where
T: Into<Operation>,
sourcefn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
Returns the circuit in Circuit form, from an Iterator form of the circuit.
Returns
Self::IntoIter
- The Circuit in Circuit form.
sourceimpl Index<usize> for Circuit
impl Index<usize> for Circuit
Implements Index Access for Circuit.
Panics
Panics when index is out of range of operations in circuit. This is consistent with standard Vec behaviour and returning Option or Result enums instead would conflict with definition of Output type.
sourceimpl IntoIterator for Circuit
impl IntoIterator for Circuit
impl StructuralPartialEq for Circuit
Auto Trait Implementations
impl RefUnwindSafe for Circuit
impl Send for Circuit
impl Sync for Circuit
impl Unpin for Circuit
impl UnwindSafe for Circuit
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub 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>,
pub fn to_subset(&self) -> Option<SS>
pub fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct self
from the equivalent element of its
superset. Read more
pub fn is_in_subset(&self) -> bool
pub fn is_in_subset(&self) -> bool
Checks if self
is actually part of its subset T
(and can be converted to it).
pub fn to_subset_unchecked(&self) -> SS
pub fn to_subset_unchecked(&self) -> SS
Use with care! Same as self.to_subset
but without any property checks. Always succeeds.
pub fn from_subset(element: &SS) -> SP
pub 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.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more