The Gate Library¶
An operation
is gate
that is applied to a collection of wires
, i.e., objects with a
wire::id
given by a circuit
. A gate
can be applied to wire(s) by directly
constructing a operation
object, or by calling one of the create_op
methods from a
circuit
—this will also create an operation
object. For example:
#include <tweedledum/tweedledum.hpp>
int main()
{
using namespace tweedledum;
netlist<w3_op> circuit;
wire::id q0 = circuit.create_qubit();
wire::id q1 = circuit.create_qubit();
// directly constructing an operation object and emplacing it in the circuit
w3_op cx_op(gate_lib::cx, q0, q1);
circuit.emplace_op(cx_op);
// directly creating an operation in the circuit
circuit.create_op(gate_lib::cx, q0, q1);
}
Note
When using a network create_op
methdos, the returned value is a node::id
, which is
basically a identifier to a network node that encapsulates the operation.
Gates are classified into three categories: Meta, non-parameterisable, and
parameterisable. Meta gates are internal helpers. Non-parameterisable gates are uniquely
indentified by a symbol, e.g., a \(\mathrm{T}\) gate is identifed by gate_lib::t
, and from that we know its
parameters. Parameterisable gates, on the other hand, require the user to define a symbol and the
parameters, e.g., we can define a \(\mathrm{R}_1\) gate by gate_lib:r1
and a angle parameter
\(\frac\pi4\) (in fact, this gate is the \(\mathrm{T}\) gate).
Warning
It is possible to mix parameterisable and non-parameterisable gates in a quantum circuit representation, but some methods will work sub-optimally. For example:
Suppose you want to optimize your circuit using gate_cancellation()
. Somewhere
in your circuit, two conditional phase shifts that cancel each other out, say \(\mathrm{T}\) and
its adjoint \(\mathrm{T}^{\dagger}\), appear. One is defined symbolically, and the other parametrically (using
gate_lib::r1
and pi/4). They won’t be identified as adjoint by the is_adjoint()
method
defined in the gate
class! Hence, this optimization oportunity will be missed.*
Meta gates¶
Meta gates |
|
---|---|
Name(s) |
tweedledum symbol |
Undefined |
|
Opaque |
|
Input |
|
Non-parameterisable gates¶
One-qubit gates¶
Name(s) |
Symbol |
tweedledum symbol |
---|---|---|
Identity |
\(\mathrm{I}\) |
|
Hadamard |
\(\mathrm{H}\) |
|
Pauli X, NOT |
\(\mathrm{X}\) |
|
Pauli Y |
\(\mathrm{Y}\) |
|
Pauli Z, Phase flip |
\(\mathrm{Z}\) |
|
Phase |
\(\mathrm{S}\) |
|
Adjoint Phase |
\(\mathrm{S}^{\dagger}\) |
|
T |
\(\mathrm{T}\) |
|
Adjoint T |
\(\mathrm{T}^{\dagger}\) |
|
Hadamard¶
The Hadamard is a half rotation of the Bloch sphere. It rotates around an axis located halfway between the x and z axis. This gives it the effect of rotating states that point along the z axis to those pointing along x, and vice versa.
Note
The Hadamard gates is central in quantum computing. I can be used to create states in superposition from classical base states:
Since \(\mathrm{H}\) is self-adjoint, i.e., \(\mathrm{H}^\dagger = \mathrm{H}\), the inverse direction also holds:
Remember that both \(|+\rangle\) and \(|-\rangle\), when measured in the computational basis, have 0.5 probability of beign \(|0\rangle\) and 0.5 probability of beign \(|1\rangle\). In other words, one can perceive the behaviour of the hadamard gate as deterministically turning a “random state” into a classical one.
Identity¶
The identity element of the unitary group \(U(2)\). This does not change the quantum state, so it can be perceived as the absence of a gate.
Pauli-X¶
The Pauli X gate swaps the amplitudes of the quantum base states. As \(X|0\rangle = |1\rangle\) and \(X|1\rangle = |0\rangle\), this gate is also known as \(\mathrm{NOT}\).
Pauli-Y¶
Pauli-Z¶
The Pauli Z gate inverts the sign of the second amplitudes of a quantum state.
Phase¶
T¶
Two-qubit gates¶
Name(s) |
Symbol |
tweedledum symbol |
---|---|---|
Controlled X, Controlled NOT, CNOT |
\(\mathrm{CX}\) |
|
Controlled Y |
\(\mathrm{CY}\) |
|
Controlled Z |
\(\mathrm{CZ}\) |
|
Swap |
\(\mathrm{SWAP}\) |
|
CX¶
CY¶
CZ¶
Swap¶
N-qubit gates¶
Name(s) |
Symbol |
tweedledum symbol |
---|---|---|
n-Controlled NOT, Toffoli |
|
|
n-Controlled Y |
|
|
n-Controlled Z |
|
MCX¶
MCY¶
MCZ¶
Parameterisable gates¶
One-qubit gates¶
Name(s) |
Symbol |
tweedledum symbol |
---|---|---|
Rotation 1, Phase shift |
\(\mathrm{R}_1\) |
|
Rotation X |
\(\mathrm{R}_x\) |
|
Rotation Y |
\(\mathrm{R}_y\) |
|
Rotation Z |
\(\mathrm{R}_z\) |
|
U |
\(\mathrm{U}\) |
|
R1¶
This is a parameterisable conditional phase shift gate. This gate leaves the basis state \(|0\rangle\) unchanged and map \(|1\rangle\) to \(e^{{i\theta }}|1\rangle\). It does not affect probability of measuring a \(|0\rangle\) or \(|1\rangle\), however it modifies the phase of the quantum state. The angle of rotation must be specified in radians and can be positive or negative. It’s matrix form is:
The gates \(\mathrm{T}\), \(\mathrm{S}\), \(\mathrm{Z}\), \(\mathrm{S}^{\dagger}\), and \(\mathrm{T}^{\dagger}\) can be implemented using this gate:
Note that one can obtain it’s adjoint by changing the sign of \(\theta\), i.e.:
Note
One might be asking: “Why \(\theta\) is not devided by two?”. As you can see, on all other parameterisable gates this is the case. Well, the answer lies on the following equation:
This means that \(\mathrm{R}_1(\theta)\) is up to global phase equal to \(\mathrm{R}_z(\theta)\). As long as we don’t do anything that could make the global phases relevant, e.g. adding a control to \(\mathrm{R}_z\), those gates can have the same implementation.
Rx¶
On the Bloch sphere, this gate corresponds to rotating the qubit state around the x axis by the given angle \(\theta\). The angle of rotation must be specified in radians and can be positive or negative. It’s matrix form is:
Ry¶
On the Bloch sphere, this gate corresponds to rotating the qubit state around the y axis by the given angle \(\theta\). The angle of rotation must be specified in radians and can be positive or negative. It’s matrix form is:
Rz¶
On the Bloch sphere, this gate corresponds to rotating the qubit state around the z axis by the given angle \(\theta\). The angle of rotation must be specified in radians and can be positive or negative. It’s matrix form is
U¶
Most one-qubit gates can be implemented using this gates:
Two-qubit gates¶
Name(s) |
Symbol |
tweedledum symbol |
---|---|---|
Controlled rotation X |
\(\mathrm{CR}_x\) |
|
Controlled rotation Y |
\(\mathrm{CR}_y\) |
|
Controlled rotation Z |
\(\mathrm{CR}_z\) |
|
CRx¶
CRy¶
CRz¶
N-qubit gates¶
Name(s) |
Symbol |
tweedledum symbol |
---|---|---|
n-Controlled rotation X |
\(\mathrm{MCR}_x\) |
|
n-Controlled rotation Y |
\(\mathrm{MCR}_y\) |
|
n-Controlled rotation Z |
\(\mathrm{MCR}_z\) |
|