[][src]Trait q1tsim::gates::Gate

pub trait Gate {
    fn description(&self) -> &str;
fn nr_affected_bits(&self) -> usize;
fn matrix(&self) -> CMatrix; fn cost(&self) -> f64 { ... }
fn apply(&self, state: &mut CVector) { ... }
fn apply_mat(&self, state: &mut CMatrix) { ... }
fn apply_slice(&self, state: CVecSliceMut) { ... }
fn apply_mat_slice(&self, state: CMatSliceMut) { ... }
fn check_nr_bits(&self, n: usize) -> Result<()> { ... }
fn is_stabilizer(&self) -> bool { ... }
fn conjugate(&self, _ops: &mut [PauliOp]) -> Result<bool> { ... } }

Required methods

fn description(&self) -> &str

Return a short description of the gate. This may be the name of the gate (e.g. "H", "CX"), or the way the gate was constructed (like "I⊗Z")

fn nr_affected_bits(&self) -> usize

The number of qubits affected by this gate.

fn matrix(&self) -> CMatrix

Return a matrix describing the unitary transformation that the gate provides

Loading content...

Provided methods

fn cost(&self) -> f64

Cost of this gate.

An estimate of the cost of using this gate. This can be used e.g. in optimizing circuits, or when trying to decompose a transformation in an optimal gate sequence. The default implementation returns std::f64::INFINITY.

fn apply(&self, state: &mut CVector)

Apply a gate.

Apply a gate to quantum state state. The number of rows r in state must be a multiple of 2n, where n is the number of qubits this gate acts upon. The rows must be ordered, such that the first block of r/2n rows corresponds to qustates with basis states |00...0⟩ for the affected qubits, the second block to |00...1⟩, etc., up until |11...1⟩.

fn apply_mat(&self, state: &mut CMatrix)

Apply a gate.

Apply a gate to quantum state state. The number of rows r in state must be a multiple of 2n, where n is the number of qubits this gate acts upon. The rows must be ordered, such that the first block of r/2n rows corresponds to qustates with basis states |00...0⟩ for the affected qubits, the second block to |00...1⟩, etc., up until |11...1⟩.

fn apply_slice(&self, state: CVecSliceMut)

Apply a gate.

Apply a gate to quantum state state. The number of rows r in state must be a multiple of 2n, where n is the number of qubits this gate acts upon. The rows must be ordered, such that the first block of r/2n rows corresponds to qustates with basis states |00...0⟩ for the affected qubits, the second block to |00...1⟩, etc., up until |11...1⟩.

fn apply_mat_slice(&self, state: CMatSliceMut)

Apply a gate.

Apply a gate to quantum state state. The number of rows r in state must be a multiple of 2n, where n is the number of qubits this gate acts upon. The rows must be ordered, such that the first block of r/2n rows corresponds to qustates with basis states |00...0⟩ for the affected qubits, the second block to |00...1⟩, etc., up until |11...1⟩.

fn check_nr_bits(&self, n: usize) -> Result<()>

Check the number of bits

Check if the number of bit indices n is equal to the number of bits this gate operates on. If not, return an InvalidNrBits error.

fn is_stabilizer(&self) -> bool

Whether this gate is a stabilizer gate

Return true if this gate is a stabilizer gate, i.e. if conjugating a Pauli operator (or tensor product thereof for multi-bit gates) with this gate, again returns a Pauli operator. Circuits consisting of only these types of gates can be simulated more efficiently. The default implementation returns false.

fn conjugate(&self, _ops: &mut [PauliOp]) -> Result<bool>

Conjugate Pauli operators

Conjugate the (tensor product of) Pauli operator ops with this gate, and return the sign of the resulting operator. I.e., if this gate is called G, replace the operator O described by ops with GOG. This of course only works if the result can be expressed in Pauli operators, so only if this gate can be written in terms of H, S and CX gates. The default implementation of this function returns a NotAStabilizer error.

Loading content...

Implementors

impl Gate for CCRX[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

fn is_stabilizer(&self) -> bool[src]

fn conjugate(&self, _ops: &mut [PauliOp]) -> Result<bool>[src]

impl Gate for CCRY[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

fn is_stabilizer(&self) -> bool[src]

fn conjugate(&self, _ops: &mut [PauliOp]) -> Result<bool>[src]

impl Gate for CCRZ[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

fn is_stabilizer(&self) -> bool[src]

fn conjugate(&self, _ops: &mut [PauliOp]) -> Result<bool>[src]

impl Gate for CCX[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

fn is_stabilizer(&self) -> bool[src]

fn conjugate(&self, _ops: &mut [PauliOp]) -> Result<bool>[src]

impl Gate for CCZ[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

fn is_stabilizer(&self) -> bool[src]

fn conjugate(&self, _ops: &mut [PauliOp]) -> Result<bool>[src]

impl Gate for CH[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

fn is_stabilizer(&self) -> bool[src]

fn conjugate(&self, _ops: &mut [PauliOp]) -> Result<bool>[src]

impl Gate for CRX[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

fn is_stabilizer(&self) -> bool[src]

fn conjugate(&self, _ops: &mut [PauliOp]) -> Result<bool>[src]

impl Gate for CRY[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

fn is_stabilizer(&self) -> bool[src]

fn conjugate(&self, _ops: &mut [PauliOp]) -> Result<bool>[src]

impl Gate for CRZ[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

fn is_stabilizer(&self) -> bool[src]

fn conjugate(&self, _ops: &mut [PauliOp]) -> Result<bool>[src]

impl Gate for CS[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

fn is_stabilizer(&self) -> bool[src]

fn conjugate(&self, _ops: &mut [PauliOp]) -> Result<bool>[src]

impl Gate for CSdg[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

fn is_stabilizer(&self) -> bool[src]

fn conjugate(&self, _ops: &mut [PauliOp]) -> Result<bool>[src]

impl Gate for CT[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

fn is_stabilizer(&self) -> bool[src]

fn conjugate(&self, _ops: &mut [PauliOp]) -> Result<bool>[src]

impl Gate for CTdg[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

fn is_stabilizer(&self) -> bool[src]

fn conjugate(&self, _ops: &mut [PauliOp]) -> Result<bool>[src]

impl Gate for CU1[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

fn is_stabilizer(&self) -> bool[src]

fn conjugate(&self, _ops: &mut [PauliOp]) -> Result<bool>[src]

impl Gate for CU2[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

fn is_stabilizer(&self) -> bool[src]

fn conjugate(&self, _ops: &mut [PauliOp]) -> Result<bool>[src]

impl Gate for CU3[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

fn is_stabilizer(&self) -> bool[src]

fn conjugate(&self, _ops: &mut [PauliOp]) -> Result<bool>[src]

impl Gate for CV[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

fn is_stabilizer(&self) -> bool[src]

fn conjugate(&self, _ops: &mut [PauliOp]) -> Result<bool>[src]

impl Gate for CVdg[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

fn is_stabilizer(&self) -> bool[src]

fn conjugate(&self, _ops: &mut [PauliOp]) -> Result<bool>[src]

impl Gate for CX[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

impl Gate for CY[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

impl Gate for CZ[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

impl Gate for Composite[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

impl Gate for H[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

impl Gate for I[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn apply_mat_slice(&self, state: CMatSliceMut)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

impl Gate for Loop[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

impl Gate for RX[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

fn is_stabilizer(&self) -> bool[src]

fn conjugate(&self, _ops: &mut [PauliOp]) -> Result<bool>[src]

impl Gate for RY[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

fn is_stabilizer(&self) -> bool[src]

fn conjugate(&self, _ops: &mut [PauliOp]) -> Result<bool>[src]

impl Gate for RZ[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

fn is_stabilizer(&self) -> bool[src]

fn conjugate(&self, _ops: &mut [PauliOp]) -> Result<bool>[src]

impl Gate for S[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

impl Gate for Sdg[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

impl Gate for Swap[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

impl Gate for T[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

fn is_stabilizer(&self) -> bool[src]

fn conjugate(&self, _ops: &mut [PauliOp]) -> Result<bool>[src]

impl Gate for Tdg[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

fn is_stabilizer(&self) -> bool[src]

fn conjugate(&self, _ops: &mut [PauliOp]) -> Result<bool>[src]

impl Gate for U1[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn apply_mat_slice(&self, state: CMatSliceMut)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

fn is_stabilizer(&self) -> bool[src]

fn conjugate(&self, _ops: &mut [PauliOp]) -> Result<bool>[src]

impl Gate for U2[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn apply_slice(&self, state: CVecSliceMut)[src]

fn apply_mat_slice(&self, state: CMatSliceMut)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

fn is_stabilizer(&self) -> bool[src]

fn conjugate(&self, _ops: &mut [PauliOp]) -> Result<bool>[src]

impl Gate for U3[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn apply_slice(&self, state: CVecSliceMut)[src]

fn apply_mat_slice(&self, state: CMatSliceMut)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

fn is_stabilizer(&self) -> bool[src]

fn conjugate(&self, _ops: &mut [PauliOp]) -> Result<bool>[src]

impl Gate for V[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn apply_slice(&self, state: CVecSliceMut)[src]

fn apply_mat_slice(&self, state: CMatSliceMut)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

impl Gate for Vdg[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn apply_slice(&self, state: CVecSliceMut)[src]

fn apply_mat_slice(&self, state: CMatSliceMut)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

impl Gate for X[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

impl Gate for Y[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

impl Gate for Z[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

impl<G> Gate for C<G> where
    G: Gate
[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

fn is_stabilizer(&self) -> bool[src]

fn conjugate(&self, _ops: &mut [PauliOp]) -> Result<bool>[src]

impl<G0, G1> Gate for Kron<G0, G1> where
    G0: Gate,
    G1: Gate
[src]

fn apply(&self, state: &mut CVector)[src]

fn apply_mat(&self, state: &mut CMatrix)[src]

fn apply_mat_slice(&self, state: CMatSliceMut)[src]

fn check_nr_bits(&self, n: usize) -> Result<()>[src]

Loading content...