pub enum Gate<'a> {
}
Expand description
Gates that can be added to a crate::Circuit struct.
Matrix representations of these gates can be found at https://www.quantum-inspire.com/kbase/cqasm-qubit-gate-operations/.
Variants§
Id
Identity.
H
Hadamard.
X
Pauli-X.
Y
Pauli-Y.
Z
Pauli-Z.
S
Phase, rotation of +π/2 around the z-axis.
Sdag
Phase dagger, rotation of -π/2 around the z-axis.
T
T.
Tdag
T dagger.
Rx(f64)
Rotation around x-axis, with angle.
Ry(f64)
Rotation around y-axis, with angle.
Rz(f64)
Rotation around z-axis, with angle.
X90
Rotation of +π/2 around x-axis.
Y90
Rotation of +π/2 around y-axis.
MX90
Rotation of -π/2 around x-axis.
MY90
Rotation of -π/2 around y-axis.
Phase(f64)
Global phase, exp(i*theta/2) * Identity
, with angle.
CR(f64, usize)
Controlled phase shift, with rotation and position of control node respectively.
CRk(i32, usize)
Controlled phase shift for Quantum Fourier Transforms, with rotation and position of control node respectively.
CZ(usize)
Controlled Pauli-Z, with position of control node.
CY(usize)
Controlled Pauli-Y, with position of control node.
CNot(usize)
Controlled Not, with position of control node.
Swap(usize)
Swap, with position of control node.
Toffoli(usize, usize)
Toffoli, with position of control nodes.
Custom(fn(_: ProductState) -> Option<SuperPosition>, &'a [usize], String)
Defines a custom gate.
Note, that the custom function isn’t checked for unitarity.
The arguments define the mapping of the gate; the position of the control node and a name that will be displayed in the printed diagram respectively. The name of the custom gate should be in ASCII for it to render properly when printing the circuit diagram.
§Example
use quantr::{Circuit, Gate};
use quantr::states::{SuperPosition, ProductState, Qubit};
use quantr::{Complex, complex_re_array};
// Defines a C-Not gate
fn example_cnot(prod: ProductState) -> Option<SuperPosition> {
let input_register: [Qubit; 2] = [prod.get_qubits()[0], prod.get_qubits()[0]];
Some(SuperPosition::new_with_amplitudes(match input_register {
[Qubit::Zero, Qubit::Zero] => return None,
[Qubit::Zero, Qubit::One] => return None,
[Qubit::One, Qubit::Zero] => &complex_re_array!(0f64, 0f64, 0f64, 1f64),
[Qubit::One, Qubit::One] => &complex_re_array!(0f64, 0f64, 1f64, 0f64),
}).unwrap())
}
let mut quantum_circuit = Circuit::new(3).unwrap();
quantum_circuit.add_gate(Gate::Custom(example_cnot, &[2], String::from("X")), 1).unwrap();
// This is equivalent to
quantum_circuit.add_gate(Gate::CNot(2), 1).unwrap();