Struct roqoqo::Circuit[][src]

pub struct Circuit {
    definitions: Vec<Operation>,
    operations: Vec<Operation>,
}
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.

Implementations

Creates an empty quantum Circuit.

Returns

  • Self - The empty Circuit.

Adds an Operation to Circuit (self).

Arguments

  • op - The Operation to add to the Circuit.

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

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 the length of the Circuit.

Returns

  • usize - The length of the Circuit.

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 qubits the Circuit acts on.

Returns

  • InvolvedQubits - The qubits involved in the Circuit.

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.

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.

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.

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.

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.

The resulting type after applying the + operator.

Performs the + operation. Read more

Implements + (add) for two Circuits.

Arguments

  • other - The Circuit to be added.

The resulting type after applying the + operator.

Performs the + operation. Read more

Implements + (add) for Circuit and generic type T.

Arguments

  • other - Any type T that implements Into trait.

The resulting type after applying the + operator.

Performs the + operation. Read more

Implements += (add) for Circuits and Circuit reference.

Arguments

  • other - The Circuit to be appended.

Performs the += operation. Read more

Implements += (add) for two Circuits.

Arguments

  • other - The Circuit to be appended.

Performs the += operation. Read more

Implements += (add) for Circuit and generic type T.

Arguments

  • other - Any type T that implements Into trait.

Performs the += operation. Read more

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.

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.

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.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

Returns

  • Self - The default Circuit (empty).

Deserialize this value from the given Serde deserializer. Read more

Implements the Display trait for Circuit.

Formats the value using the given formatter. Read more

Extends the Circuit by the specified operations (in Iterator form).

Arguments

  • iter - The iterator containing the operations by which to extend the Circuit.
🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (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.

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.

The returned type after indexing.

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.

Returns the Circuit in Iterator form.

Returns

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

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

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

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

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

The inclusion map: converts self to the equivalent element of its superset.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.