Standard Gates
Quantum gates are the meat of quantum algorithms. Each Gate
is an Op
with several basic methods. There are three types of gates defined with TargetGate
, ControlGate
, and SwapGate
traits. The former is a gate applied to one qubit. All it needs is a qubit index and a gate matrix generator, which is an anonymous function. ControlGate
provides an abstraction for controlled quantum gates. Finally, SwapGate
defines a structure for different types of swap gates.
All target gates can be parametric depending on the gate. Gate parameters are supposed to be listed first followed by qubit indexes:
SomeGate(param1, param2, index1, index2, ...)
Gate parameters are expected to be individual method parameters and indexes are represented by variable arguments (varargs).
Scotty provides a set of standard gates that matches gates in the Quil gate set:
Name | Qubits | Params | Description |
---|---|---|---|
I | 1 | The identity gate. Doesn’t change the state. | |
X | 1 | Pauli X gate (the NOT gate). Rotates the qubit around the x-axis by $pi$ radians. | |
Y | 1 | Pauli Y gate. Rotates the qubit around the y-axis by $\pi$ radians. | |
Z | 1 | Pauli Z gate. Rotates the qubit around the z-axis by $\pi$ radians. | |
RX | 1 | theta | Rotates the qubit around the x-axis by $\theta$ radians. |
RY | 1 | theta | Rotates the qubit around the y-axis by $\theta$ radians. |
RZ | 1 | theta | Rotates the qubit around the z-axis by $\theta$ radians. |
CNOT | 2 | Controlled-NOT gate. | |
CCNOT | 3 | Controlled-controlled-NOT gate (the Toffoli gate). | |
CZ | 2 | Controlled-Z gate. | |
SWAP | 2 | Swap gate. | |
CSWAP | 2 | Controlled-SWAP gate. | |
ISWAP | 2 | Swaps the state of two qubits, applying an i phase to the first qubit when it’s in the $\lvert1\rangle$ state and an i phase to the second qubit when it’ i’s in the $\lvert0\rangle$ state. | |
PSWAP | 2 | phi | Swaps the state of two qubits, applying a custom phase $\phi$ to the first qubit when it’s in the $\lvert1\rangle$ state and a custom phase $\phi$ to the second qubit when it’ i’s in the $\lvert0\rangle$ state. |
PHASE | 1 | phi | Leaves $\lvert0\rangle$ unchanged and maps $\lvert1\rangle$ to $e^{i\phi}\lvert1\rangle$. |
CPHASE | 2 | phi | Controlled PHASE gate acting on the $\lvert11\rangle$ state. |
CPHASE00 | 2 | phi | Controlled PHASE gate acting on the $\lvert00\rangle$ state. |
CPHASE10 | 2 | phi | Controlled PHASE gate acting on the $\lvert10\rangle$ state. |
CPHASE01 | 2 | phi | Controlled PHASE gate acting on the $\lvert01\rangle$ state. |
S | 1 | PHASE gate that represents a $\frac{\pi}{2}$ rotation around the z-axis. | |
T | 1 | PHASE gate that represents a $\frac{\pi}{4}$ rotation around the z-axis. |
How Are Gates Implemented
Single-qubit gates are implemented in the framework itself with a gate matrix or with other gates. For example, S
and T
are implemented with PHASE
.
Multi-qubit gates are different and their internals depends on the QuantumContext
implementation. In the QuantumSimulator
we use an efficient algorithm for single-qubit and control gate state application implementations that has a running time of $\mathcal{O}(n)$.
The simulator treats each gate as a separate sequential step. However, each step is parallelized.
For multi-qubit gates that are not simple controlled gates we use CompositeGate
s that are covered in the next section.