[][src]Struct q1tsim::circuit::Circuit

pub struct Circuit { /* fields omitted */ }

A quantum circuit

Struct Circuit represents a quantum circuit, holding a quantum state and the operations to be performed on it.

Methods

impl Circuit[src]

pub fn new(nr_qbits: usize, nr_cbits: usize) -> Self[src]

Create a new circuit.

Create a new (empty) quantum circuit, with nr_qbits quantum bits and nr_cbits classical bits.

pub fn nr_qbits(&self) -> usize[src]

The number of quantum bits in this circuit

pub fn nr_cbits(&self) -> usize[src]

The number of classical bits in this circuit

pub fn is_stabilizer_circuit(&self) -> bool[src]

Return whether this circuit is a stabilizer circuit

pub fn cstate(&self) -> Option<&Array1<u64>>[src]

The classical register.

Return a reference to the classical bit register, containing the results of any measurements made on the system. If no experiment has been run yet, None is returned.

pub fn add_gate<G: 'static>(&mut self, gate: G, bits: &[usize]) -> Result<()> where
    G: CircuitGate
[src]

Add a gate.

Append a n-ary gate gate, operating on the n qubits in bits, to this circuit.

pub fn add_conditional_gate<G: 'static>(
    &mut self,
    control: &[usize],
    target: u64,
    gate: G,
    qbits: &[usize]
) -> Result<()> where
    G: CircuitGate
[src]

Add a conditional gate.

Append a n-ary gate gate, that will operate on the n qubits in bits to this circuit. The gate will only be applied only when the classical bits with indices from control form the target word target. The bit at the position of the first index in control is interpreted as the most significant bit to check.

pub fn measure_basis(
    &mut self,
    qbit: usize,
    cbit: usize,
    basis: Basis
) -> Result<()>
[src]

Add a measurement

Add measurement of qubit qbit in basis basis, into classical bit cbit, to this circuit.

pub fn measure_x(&mut self, qbit: usize, cbit: usize) -> Result<()>[src]

Add a measurement.

Add measurement of qubit qbit in the Pauli X basis, into classical bit cbit to this circuit.

pub fn measure_y(&mut self, qbit: usize, cbit: usize) -> Result<()>[src]

Add a measurement.

Add measurement of qubit qbit in the Pauli Y basis, into classical bit cbit to this circuit.

pub fn measure_z(&mut self, qbit: usize, cbit: usize) -> Result<()>[src]

Add a measurement.

Add measurement of qubit qbit in the Pauli Z basis, into classical bit cbit to this circuit.

pub fn measure(&mut self, qbit: usize, cbit: usize) -> Result<()>[src]

Add a measurement.

Add measurement of qubit qbit into classical bit cbit to this circuit. This is an alias for measure_z().

pub fn measure_all_basis(&mut self, cbits: &[usize], basis: Basis) -> Result<()>[src]

Add a measurement.

Add the measurement of all qubits in the quantum state into the classical bits cbits. Measurement is done in basis basis.

pub fn measure_all(&mut self, cbits: &[usize]) -> Result<()>[src]

Add a measurement.

Add the measurement of all qubits in the quantum state into the classical bits cbits. Measurement is done in the Pauli Z basis.

pub fn peek_basis(
    &mut self,
    qbit: usize,
    cbit: usize,
    basis: Basis
) -> Result<()>
[src]

Add a measurement.

Add the measurement of qubit qbit in the quantum state into the classical bit cbit. Measurement is done in basis basis, without collapsing the quantum state. NOTE: this is not a physical process, and cannot be reproduced on a real quantum computer.

pub fn peek_x(&mut self, qbit: usize, cbit: usize) -> Result<()>[src]

Add a measurement.

Add measurement of qubit qbit in the Pauli X basis, into classical bit cbit to this circuit, without collapsing the quantum state. NOTE: this is not a physical process, and cannot be reproduced on a real quantum computer.

pub fn peek_y(&mut self, qbit: usize, cbit: usize) -> Result<()>[src]

Add a measurement.

Add measurement of qubit qbit in the Pauli Y basis, into classical bit cbit to this circuit, without collapsing the quantum state. NOTE: this is not a physical process, and cannot be reproduced on a real quantum computer.

pub fn peek_z(&mut self, qbit: usize, cbit: usize) -> Result<()>[src]

Add a measurement.

Add measurement of qubit qbit in the Pauli Z basis, into classical bit cbit to this circuit, without collapsing the quantum state. NOTE: this is not a physical process, and cannot be reproduced on a real quantum computer.

pub fn peek(&mut self, qbit: usize, cbit: usize) -> Result<()>[src]

Add a measurement.

Add measurement of qubit qbit in the Pauli Z basis, into classical bit cbit to this circuit, without collapsing the quantum state. NOTE: this is not a physical process, and cannot be reproduced on a real quantum computer.

pub fn peek_all_basis(&mut self, cbits: &[usize], basis: Basis) -> Result<()>[src]

Add a measurement.

Add the measurement of all qubits in the quantum state into the classical bits cbits. Measurement is done in basis basis, without collapsing the quantum state. NOTE: this is not a physical process, and cannot be reproduced on a real quantum computer.

pub fn peek_all(&mut self, cbits: &[usize]) -> Result<()>[src]

Add a measurement.

Add the measurement of all qubits in the quantum state into the classical bits cbits. Measurement is done in the Pauli Z basis, without collapsing the quantum state. NOTE: this is not a physical process, and cannot be reproduced on a real quantum computer.

pub fn reset(&mut self, qbit: usize) -> Result<()>[src]

Reset a qubit

Reset the qubit qbit to |0⟩. This is done by measuring the bit, and flipping it if the result is 1, so this is potentially an expensive operation.

pub fn reset_all(&mut self)[src]

Reset all qubits

Reset the entire quantum state of the circuit to |00...0⟩. The classical register is not affected.

pub fn h(&mut self, qbit: usize) -> Result<()>[src]

Add a Hadamard gate.

Add a Hadamard gate operating on qubit qbit, to this circuit.

pub fn x(&mut self, bit: usize) -> Result<()>[src]

Add a Pauli X gate.

Add a Pauli X gate operating on qubit bit, to this circuit.

pub fn y(&mut self, bit: usize) -> Result<()>[src]

Add a Pauli Y gate.

Add a Pauli Y gate operating on qubit bit, to this circuit.

pub fn z(&mut self, bit: usize) -> Result<()>[src]

Add a Pauli Z gate.

Add a Pauli Z gate operating on qubit bit, to this circuit.

pub fn s(&mut self, bit: usize) -> Result<()>[src]

Add a phase gate

Add an S phase gate operating on qubit bit, to this circuit.

pub fn sdg(&mut self, bit: usize) -> Result<()>[src]

Add a phase gate

Add an S\dagger phase gate operating on qubit bit, to this circuit.

pub fn rx<T>(&mut self, theta: T, bit: usize) -> Result<()> where
    Parameter: From<T>, 
[src]

Add a RX gate.

Add a RX(θ) gate operating on qubit bit, to this circuit.

pub fn ry<T>(&mut self, theta: T, bit: usize) -> Result<()> where
    Parameter: From<T>, 
[src]

Add a RY gate.

Add a RY(θ) gate operating on qubit bit, to this circuit.

pub fn rz<T>(&mut self, lambda: T, bit: usize) -> Result<()> where
    Parameter: From<T>, 
[src]

Add a RZ gate.

Add a RZ(λ) gate operating on qubit bit, to this circuit.

pub fn u1<T>(&mut self, lambda: T, bit: usize) -> Result<()> where
    Parameter: From<T>, 
[src]

Add a U1 gate.

Add a U1(λ) gate operating on qubit bit, to this circuit.

pub fn u2<Tp, Tl>(&mut self, phi: Tp, lambda: Tl, bit: usize) -> Result<()> where
    Parameter: From<Tp> + From<Tl>, 
[src]

Add a U2 gate.

Add a U2(ϕ, λ) gate operating on qubit bit, to this circuit.

pub fn u3<Tt, Tp, Tl>(
    &mut self,
    theta: Tt,
    phi: Tp,
    lambda: Tl,
    bit: usize
) -> Result<()> where
    Parameter: From<Tt> + From<Tp> + From<Tl>, 
[src]

Add a U3 gate.

Add a U3(θ, ϕ, λ) gate operating on qubit bit, to this circuit.

pub fn cx(&mut self, control: usize, target: usize) -> Result<()>[src]

Add a CX gate.

Add a CX gate, controlled by qubit control and operating on qubit target, to this circuit.

pub fn barrier(&mut self, qbits: &[usize]) -> Result<()>[src]

Add a barrier

Add a barrier on the bits in bits. No transformations on these bits are allowed across this barrier.

pub fn execute(&mut self, nr_shots: usize) -> Result<()>[src]

Execute this circuit

Execute this circuit, performing its operations and measurements. Measurements are made over nr_shots executions of the circuit. This function clears any previous states of the system (quantum or classical).

pub fn execute_with_rng<R: RngCore>(
    &mut self,
    nr_shots: usize,
    rng: &mut R
) -> Result<()>
[src]

Execute this circuit

Execute this circuit, performing its operations and measurements. Measurements are made over nr_shots executions of the circuit, using random number generator rng for sampling. This function clears any previous states of the system (quantum or classical).

pub fn execute_with<R: RngCore>(
    &mut self,
    nr_shots: usize,
    rng: &mut R,
    q_state: QuStateRepr
) -> Result<()>
[src]

Execute this circuit

Execute this circuit, performing its operations and measurements. Measurements are made over nr_shots executions of the circuit, using random number generator rng for sampling. The initial quantum state of the system is set to q_state. The classical state is cleared before execution.

pub fn reexecute(&mut self) -> Result<()>[src]

Execute a circuit again.

Run this circuit again, starting with the state from the previous execution. If this circuit has not been run before, a NotExecuted error is returned.

pub fn reexecute_with_rng<R: Rng>(&mut self, rng: &mut R) -> Result<()>[src]

Execute a circuit again.

Run this circuit again, starting with the state from the previous execution, using random number generator rng for sampling. If this circuit has not been run before, a NotExecuted error is returned.

pub fn histogram(&self) -> Result<HashMap<u64, usize, BuildIdentityHasher>>[src]

Create a histogram of measurements.

Create a histogram of the measured classical bits. The n bits in the classical register are collected in a single u64 integer value. The first bit in the classical register (at index 0) corresponds to the least significant bit in the key; the last classical bit (at index n-1) to the most significant bit in the key. This function of course only works when there are at most 64 bits in the register. If there are more, use histogram_string().

pub fn histogram_vec(&self) -> Result<Vec<usize>>[src]

Create a histogram of measurements.

Create a histogram of the measured classical bits. The n bits in the classical register are collected in a single usize integer value, which is used as an index in a vector. The bit order of the indices is the same as in the histogram() function. The vector is of length 2n, so use this function only for reasonably small numbers of n. For sparse collections, using histogram() or histogram_string may be better.

pub fn histogram_string(&self) -> Result<HashMap<String, usize>>[src]

Create a histogram of measurements.

Create a histogram of the measured classical bits. The n bits in the classical register are collected in a string key, with the last character in the key corresponding to the first bit (at index 0) in the classical register and vice versa.

pub fn open_qasm(&self) -> Result<String>[src]

Export to OpenQasm

Export this circuit to a program in OpenQasm format. On a successful conversion, the result is Ok with the program text. When the conversion to OpenQasm fails, Err with an error message is returned.

pub fn c_qasm(&self) -> Result<String>[src]

Export to c-Qasm

Export this circuit to a program in c-Qasm format. On a successful conversion, the result is Ok with the program text. When the conversion to c-Qasm fails, Err with an error message is returned.

pub fn latex(&self) -> Result<String>[src]

Export to LaTeX

Export this circuit to LaTeX using the qcircuit package. On a successful conversion, the result is Ok with the LaTeX code. When the conversion to LaTeX fails, Err with an error message is returned.

Auto Trait Implementations

impl !Send for Circuit

impl Unpin for Circuit

impl !Sync for Circuit

impl !UnwindSafe for Circuit

impl !RefUnwindSafe for Circuit

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

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