Standard Gates
Import standard gates from scotty.quantum.gate.StandardGate._. Angles are in radians. Constructors put angle parameters before numeric qubit indices.
import scotty.quantum._
import scotty.quantum.gate.StandardGate._
import scotty.simulator.QuantumSimulator
val circuit = Circuit(H(0), RX(Math.PI / 2, 1), CNOT(0, 1))
val state = QuantumSimulator().run(circuit)Single-qubit gates
| Constructor | Effect |
|---|---|
H(index) | Hadamard: creates an equal superposition from a basis state. |
I(index) | Identity. |
X(index) | Pauli X: exchanges zero and one amplitudes. |
Y(index) | Pauli Y: exchanges amplitudes with factors |
Z(index) | Pauli Z: negates the one amplitude. |
RX(theta, index) | Rotation about the x-axis by |
RY(theta, index) | Rotation about the y-axis by |
RZ(theta, index) | Rotation about the z-axis by |
PHASE(phi, index) | Multiplies the one amplitude by |
PHASE0(phi, index) | Multiplies the zero amplitude by |
S(index) | PHASE with |
T(index) | PHASE with |
Controlled and swap gates
| Constructor | Qubits | Effect |
|---|---|---|
CNOT(control, target) | 2 | Applies X when the control is one. |
CCNOT(control1, control2, target) | 3 | Applies X when both controls are one (Toffoli). |
CZ(control, target) | 2 | Applies Z when the control is one. |
SWAP(index1, index2) | 2 | Exchanges two qubits. |
CSWAP(control, index1, index2) | 3 | Exchanges two qubits when the control is one (Fredkin). |
ISWAP(index1, index2) | 2 | Exchanges 01 and 10, multiplying their amplitudes by |
PSWAP(phi, index1, index2) | 2 | Exchanges 01 and 10, multiplying their amplitudes by |
CPHASE(phi, control, target) | 2 | Applies a phase to control=1, target=1. |
CPHASE00(phi, control, target) | 2 | Applies a phase to control=0, target=0. |
CPHASE10(phi, control, target) | 2 | Applies a phase to control=1, target=0. |
CPHASE01(phi, control, target) | 2 | Applies a phase to control=0, target=1. |
For the phase variants, suffixes describe control then target, not necessarily the left-to-right order of a displayed register string. Gate indices use the ordering described here. Qubit indices within a controlled or swap gate must be distinct.
Swap phase caveat in 0.6.0
The simulator's ISWAP and PSWAP decompositions also apply an extra phase to 11: ISWAP multiplies it by PSWAP(phi, ...) multiplies it by 11 unchanged. The table describes the exchange of 01 and 10; do not assume these gates preserve the phase of a general two-qubit state. Use an explicit, verified decomposition when that phase matters.
Implementation
TargetGate supplies a single-qubit matrix. ControlGate supplies a control index and a target gate. SwapGate supplies two indices. The simulator implements swap and some phase gates as sequences of simpler gates.
Each gate step has work proportional to the number of state amplitudes:
See Modifiers and Custom Gates for controlled, adjoint and custom operations.