Struct Circuit

Source
pub struct Circuit {
    pub gates: Vec<Gate>,
    pub num_qubits: usize,
}
Expand description

Represents a quantum circuit as a vector of gates.

§Fields

  • gates - A vector of gates in the circuit.
  • num_qubits - The number of qubits in the circuit.

Fields§

§gates: Vec<Gate>

A vector of gates in the circuit.

§num_qubits: usize

The number of qubits in the circuit.

Implementations§

Source§

impl Circuit

Source

pub fn new(num_qubits: usize) -> Self

Creates a new circuit with the specified number of qubits.

§Arguments
  • num_qubits - The number of qubits in the circuit.
§Returns
  • Circuit - A new instance of the Circuit struct.
Source

pub fn with_gates(gates: Vec<Gate>, num_qubits: usize) -> Result<Circuit, Error>

Creates a new circuit with the specified gates and number of qubits.

§Arguments
  • gates - A vector of gates in the circuit.
  • num_qubits - The number of qubits in the circuit.
§Returns
  • Result<Circuit, Error> - A new instance of the Circuit struct or an error if the circuit cannot be created.
Source

pub fn add_gate(&mut self, gate: Gate) -> Result<(), Error>

Adds a gate to the circuit.

§Arguments
  • gate - The gate to be added to the circuit.
§Returns
  • Result<(), Error> - An empty result if the gate is added successfully, or an error if the gate cannot be added.
Source

pub fn add_gates(&mut self, gates: Vec<Gate>) -> Result<(), Error>

Adds multiple gates to the circuit.

§Arguments
  • gates - A vector of gates to be added to the circuit.
§Returns
  • Result<(), Error> - An empty result if the gates are added successfully, or an error if any gate cannot be added.
Source

pub fn get_num_qubits(&self) -> usize

Gets the number of qubits in the circuit.

§Returns
  • usize - The number of qubits in the circuit.
Source

pub fn get_gates(&self) -> &Vec<Gate>

Gets the gates in the circuit.

§Returns
  • &Vec<Gate> - A reference to the vector of gates in the circuit.
Source

pub fn execute(&self, initial_state: &State) -> Result<State, Error>

Executes the circuit with the given initial state, and returns the final state.

§Arguments
  • initial_state - The initial state of the qubits in the circuit.
§Returns
  • Result<State, Error> - The final state of the qubits after executing the circuit.
§Errors
  • Returns an error if the number of qubits in the initial state does not match the number of qubits in the circuit.
  • Returns an error if the circuit cannot be executed due to invalid gate operations.
Source

pub fn trace_execution( &self, initial_state: &State, ) -> Result<Vec<State>, Error>

Executes the circuit with the given initial state, and returns all the intermediate states and the final state.

§Arguments
  • initial_state - The initial state of the qubits in the circuit.
§Returns
  • Result<Vec<State>, Error> - A vector of intermediate states and the final state after executing the circuit.
§Errors
  • Returns an error if the number of qubits in the initial state does not match the number of qubits in the circuit.
  • Returns an error if the circuit cannot be executed due to invalid gate operations.
Source

pub fn to_qasm( &self, to_dir: Option<impl AsRef<Path>>, ) -> Result<String, CompilerError>

Converts the circuit to its OpenQASM 3.0 (Quantum Assembly 3.0) representation.

Trait Implementations§

Source§

impl Debug for Circuit

Source§

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

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

impl TryFrom<Subroutine> for Circuit

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(value: Subroutine) -> Result<Self, Self::Error>

Performs the conversion.

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V