Struct roqoqo::Circuit [−][src]
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.
Implementations
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).
Creates an iterator of the Circuit.
Returns
Iterator<Item = &Operation>
- The Circuit in iterator form.
Returns true if the Circuit contains symbolic variables.
Returns
bool
- True if the Circuit contains symbolic values, false if it does not.
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.
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.
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.
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
Implements +
(add) for Circuit and Circuit reference.
Arguments
other
- The Circuit reference to be added.
Implements +
(add) for Circuit and generic type T
.
Arguments
other
- Any type T that implements Intotrait.
Implements +=
(add) for Circuits and Circuit reference.
Arguments
other
- The Circuit to be appended.
Performs the +=
operation. Read more
Performs the +=
operation. Read more
Implements +=
(add) for Circuit and generic type T
.
Arguments
other
- Any type T that implements Intotrait.
Performs the +=
operation. Read more
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>,
Deserialize this value from the given Serde deserializer. Read more
Implements the Display trait for Circuit.
Extends the Circuit by the specified operations (in Iterator form).
Arguments
iter
- The iterator containing the operations by which to extend the Circuit.
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
Returns the circuit in Circuit form, from an Iterator form of the circuit.
Returns
Self::IntoIter
- The Circuit in Circuit form.
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.
Auto Trait Implementations
impl RefUnwindSafe for Circuit
impl UnwindSafe for Circuit
Blanket Implementations
Mutably borrows from an owned value. Read more
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.