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§
source§impl Circuit
impl Circuit
sourcepub fn add_operation<T>(&mut self, op: T)
pub fn add_operation<T>(&mut self, op: T)
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: &Calculator
) -> Result<Self, RoqoqoError>
pub fn substitute_parameters( &self, calculator: &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 count_occurences(&self, operations: &[&str]) -> usize
pub fn count_occurences(&self, operations: &[&str]) -> usize
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§
source§impl Add<&Circuit> for Circuit
impl Add<&Circuit> for Circuit
Implements +
(add) for Circuit and Circuit reference.
§Arguments
other
- The Circuit reference to be added.
source§impl<T> Add<T> for Circuit
impl<T> Add<T> for Circuit
Implements +
(add) for Circuit and generic type T
.
§Arguments
other
- Any type T that implements Intotrait.
source§impl AddAssign<&Circuit> for Circuit
impl AddAssign<&Circuit> for Circuit
Implements +=
(add) for Circuits and Circuit reference.
§Arguments
other
- The Circuit to be appended.
source§fn add_assign(&mut self, other: &Circuit)
fn add_assign(&mut self, other: &Circuit)
+=
operation. Read moresource§impl<T> AddAssign<T> for Circuit
impl<T> AddAssign<T> for Circuit
Implements +=
(add) for Circuit and generic type T
.
§Arguments
other
- Any type T that implements Intotrait.
source§fn add_assign(&mut self, other: T)
fn add_assign(&mut self, other: T)
+=
operation. Read moresource§impl AddAssign for Circuit
impl AddAssign for Circuit
source§fn add_assign(&mut self, other: Circuit)
fn add_assign(&mut self, other: Circuit)
+=
operation. Read moresource§impl<'de> Deserialize<'de> for Circuit
impl<'de> Deserialize<'de> for Circuit
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<T> Extend<T> for Circuit
impl<T> Extend<T> for Circuit
source§fn 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.
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl From<Circuit> for CircuitDag
impl From<Circuit> for CircuitDag
Creates a new CircuitDag from a given Circuit.
source§impl From<CircuitDag> for Circuit
impl From<CircuitDag> for Circuit
Creates a new Circuit from a given CircuitDag.
source§fn from(dag: CircuitDag) -> Circuit
fn from(dag: CircuitDag) -> Circuit
source§impl<T> FromIterator<T> for Circuit
impl<T> FromIterator<T> for Circuit
source§fn 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.
source§impl 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.
source§impl IntoIterator for Circuit
impl IntoIterator for Circuit
source§impl PartialEq for Circuit
impl PartialEq for Circuit
source§impl SupportedVersion for Circuit
impl SupportedVersion 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§
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<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.