Struct roqoqo::Circuit

source ·
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, such as len(), is_empty(), get(), iter() and into_iter().

§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 Circuit
  • add_operation(operation): adds the specified operation to the Circuit
  • get(index): returns the operation at the specified index in the Circuit
  • get_mut(index): returns mutable reference to the operation at the specified index in the Circuit
  • iter(): creates an iterator of the Circuit
  • len(): returns the length of the Circuit
  • is_empty(): returns a boolean of whether the Circuit contains any definitions and operations or not
  • involved_qubits(): returns the qubits invovlved in the whole Circuit
  • definitions(): returns the definitions in the Circuit
  • operations(): returns the operations in the Circuit
  • substitute_parameters(calculator): substitutes any symbolic parameters in (a copy of) the Circuit according to the specified Calculator
  • remap_qubits(mapping): remaps the qubits in (a copy of) the Circuit according to the specified mapping
  • count_occurences(operations): returns the number of operations in the Circuit with the specified operation tags
  • get_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 iterator
  • extend(iterator): adds the operations in the specified iterator to the Circuit
  • default(): 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

source

pub fn new() -> Self

Creates an empty quantum Circuit.

§Returns
  • Self - The empty Circuit.
source

pub fn add_operation<T>(&mut self, op: T)
where T: Into<Operation>,

Adds an Operation to Circuit (self).

§Arguments
  • op - The Operation to add to the Circuit.
source

pub fn get(&self, index: usize) -> Option<&Operation>

Returns a 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<&Operation> - The operation at the given index (if it exists).
source

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).
source

pub fn iter(&self) -> impl Iterator<Item = &Operation>

Creates an iterator of the Circuit.

§Returns

Iterator<Item = &Operation> - The Circuit in iterator form.

source

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.
source

pub fn len(&self) -> usize

Returns the length of the Circuit.

§Returns
  • usize - The length of the Circuit.
source

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.
source

pub fn involved_qubits(&self) -> InvolvedQubits

Returns qubits the Circuit acts on.

§Returns
  • InvolvedQubits - The qubits involved in the Circuit.
source

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.
source

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.
source

pub fn substitute_parameters( &self, calculator: &Calculator ) -> Result<Self, RoqoqoError>

Substitutes the symbolic parameters in a clone of Circuit according to the calculator input.

§Arguments
  • ``calculator` - The Calculator containing the substitutions to use in the Circuit.
§Returns
  • Ok(Self) - The Circuit with the parameters substituted.
  • Err(RoqoqoError) - The subsitution failed.
source

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

Remaps the qubits in operations in clone of Circuit.

§Arguments
  • ``mapping` - The HashMap containing the {qubit: qubit} mapping to use in the Circuit.
§Returns
  • Ok(Self) - The Circuit with the qubits remapped.
  • Err(RoqoqoError) - The remapping failed.
source

pub fn count_occurences(&self, operations: &[&str]) -> usize

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

§Arguments

operations - The list of operation tags that should be counted.

§Returns
  • usize - The number of occurences of these operation tags.
source

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

Implements + (add) for Circuit and Circuit reference.

§Arguments

  • other - The Circuit reference to be added.
§

type Output = Circuit

The resulting type after applying the + operator.
source§

fn add(self, other: &Circuit) -> Self

Performs the + operation. Read more
source§

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 Into trait.
§

type Output = Circuit

The resulting type after applying the + operator.
source§

fn add(self, other: T) -> Self

Performs the + operation. Read more
source§

impl Add for Circuit

Implements + (add) for two Circuits.

§Arguments

  • other - The Circuit to be added.
§

type Output = Circuit

The resulting type after applying the + operator.
source§

fn add(self, other: Circuit) -> Self

Performs the + operation. Read more
source§

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)

Performs the += operation. Read more
source§

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 Into trait.
source§

fn add_assign(&mut self, other: T)

Performs the += operation. Read more
source§

impl AddAssign for Circuit

Implements += (add) for two Circuits.

§Arguments

  • other - The Circuit to be appended.
source§

fn add_assign(&mut self, other: Circuit)

Performs the += operation. Read more
source§

impl AsVec<Range<usize>> for Circuit

source§

fn as_vec(&self, range: Range<usize>) -> Option<Vec<Operation>>

Returns slice of Circuit as Vec.

§Arguments
  • range - The indices of the slice of the Circuit to be returned.
§Returns
  • Option<Vec<Operation>> - A vector of the operations in the Circuit with the specified indices.
source§

impl AsVec<RangeFrom<usize>> for Circuit

source§

fn as_vec(&self, range: RangeFrom<usize>) -> Option<Vec<Operation>>

Returns slice of Circuit as Vec.

§Arguments
  • range - The indices of the slice of the Circuit to be returned.
§Returns
  • Option<Vec<Operation>> - A vector of the operations in the Circuit with the specified indices.
source§

impl AsVec<RangeTo<usize>> for Circuit

source§

fn as_vec(&self, range: RangeTo<usize>) -> Option<Vec<Operation>>

Returns slice of Circuit as Vec.

§Arguments
  • range - The indices of the slice of the Circuit to be returned.
§Returns
  • Option<Vec<Operation>> - A vector of the operations in the Circuit with the specified indices.
source§

impl Clone for Circuit

source§

fn clone(&self) -> Circuit

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 Circuit

source§

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

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

impl Default for Circuit

source§

fn default() -> Self

Creates a default implementation of the Circuit, which is an empty Circuit.

§Returns
  • Self - The default Circuit (empty).
source§

impl<'de> Deserialize<'de> for Circuit

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 Display for Circuit

Implements the Display trait for Circuit.

source§

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

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

impl<T> Extend<T> for Circuit
where T: Into<Operation>,

source§

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)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl From<Circuit> for CircuitDag

Creates a new CircuitDag from a given Circuit.

source§

fn from(circuit: Circuit) -> Self

Converts to this type from the input type.
source§

impl From<CircuitDag> for Circuit

Creates a new Circuit from a given CircuitDag.

source§

fn from(dag: CircuitDag) -> Circuit

Converts to this type from the input type.
source§

impl<T> FromIterator<T> for Circuit
where T: Into<Operation>,

source§

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

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§

fn index(&self, index: usize) -> &Self::Output

Returns reference to Operation at index.

§Arguments
  • index - The index of the operation.
§Panics

Panics when index is out of range of operations in circuit.

§

type Output = Operation

The returned type after indexing.
source§

impl IndexMut<usize> for Circuit

source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Returns reference to Operation at index.

§Arguments
  • index - The index of the operation.
§Panics

Panics when index is out of range of operations in circuit.

source§

impl IntoIterator for Circuit

source§

fn into_iter(self) -> Self::IntoIter

Returns the Circuit in Iterator form.

§Returns
  • Self::IntoIter - The Circuit in Iterator form.
§

type Item = Operation

The type of the elements being iterated over.
§

type IntoIter = OperationIterator

Which kind of iterator are we turning this into?
source§

impl PartialEq for Circuit

source§

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

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 SupportedVersion for Circuit

source§

fn minimum_supported_roqoqo_version(&self) -> (u32, u32, u32)

Returns the minimum roqoqo version that supports the operation. Read more
source§

impl StructuralPartialEq for Circuit

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§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

§

type Output = T

Should always be Self
§

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

§

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

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

fn is_in_subset(&self) -> bool

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

fn to_subset_unchecked(&self) -> SS

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

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. 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.
§

impl<T, Right> ClosedAdd<Right> for T
where T: Add<Right, Output = T> + AddAssign<Right>,

source§

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

source§

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