In order to create circuits with several qubits, we first need to
describe the mathematical state of more than one qubit. As with the
representation of classical bits, it should be possible to represent
classical states with qubits. This combination is called (as
in classical computer science) register or quantum register.
Theoretically quantum registers can represent an infinite number of
states, but when measured in a certain basis, there are only
possible measurement results.
Quantum Register
The combination of two qubits into a register is the tensor product
of the state vectors, :
Here, for the amplitudes and it still applies that:
To simplify this notation, the amplitudes and are
combined to :
As notation convention, the tensor product of qubits
can be combined to :
If a quantum register is measured, the state is obtained with
probability .
For the formal definition of registers with qubits, it makes sense
to switch from binary to decimal notation:
Definition
A quantum register with qubits
can have states of the form
The following applies:
The measurement of a quantum register therefore results in the state
with probability .
For clarity, the binary representation is preferred in the following, so
the basis states of a 2-qubit register are:
One can see that in
the vector representation there is always exactly one 1 at the position
(starting from 0) that corresponds to the binary number.
Simple Multi-Qubit Gates
To transform a quantum register to a new state, gates can be applied to
multiple qubits. In the following circuit, the state [^1]
is transformed to using the multi-qubit operation :
For example, we can combine the single qubit U3-gates presented in the
previous section as QASM code:
Get hands on and change the angles to see the difference in the result
OpenQASM
OPENQASM 2.0;
include "qelib1.inc";
qreg q[2];
u(pi,pi/2,pi/4) q[0];
u(pi,pi/2,pi/8) q[1];
The tensor product of the two 1-qubit matrices then results in the
2-qubit gate, i.e:
For example, for the gate, this results in
It is also possible to apply multi-qubit gates only to parts of a
register:
If no operation is performed on qubit , this
corresponds to multiplication by the identity matrix (or ). The identity
matrix can also be represented as a gate:
OpenQASM
OPENQASM 2.0;
include "qelib1.inc";
qreg q[1];
id q[0];
There are special multi-qubit gates that require several qubits as input
and cannot be represented as a tensor product of individual gates. This
allows that the state of one qubit can influence the state of another.
An example of this is the Controlled-NOT gate, or short CNOT gate:
OpenQASM
OPENQASM 2.0;
include "qelib1.inc";
qreg q[2];
cx q[0],q[1];
The so-called control qubit controls the application of
the X gate to the target qubit.
If the control qubit is in a basis state , an X
gate is applied to the target qubit only if the control qubit is
. The state of the control qubit remains unchanged. For a
control qubit in superposition, only the amplitudes of the basis states
in which the control qubit is are affected. The matrix of the
gate is:
If we apply this matrix to the state vector , for example, we
obtain the result:
The principle of controlling gates is not limited to the X gate, it can
be combined with all other gates, e.g:
In general, the matrix of a controlled gate on a state
with as the control qubit and as the target qubit looks like
this:
Similarly, in Braket notation a controlled gate is defined as:
The principle of controlled gates is not limited to two qubits, but can
also be used with more qubits, e.g. in the form of the so-called
controlled CNOT or CCNOT gate, which is also known as the Toffoli
gate named after its inventor.
OpenQASM
OPENQASM 2.0;
include "qelib1.inc";
qreg q[3];
ccx q[0],q[1],q[2];
The NOT gate is only applied to the target qubit if both control qubits
are . As with the CNOT, the state of the two control qubits
remains unchanged. For the CCNOT gate we get the matrix
Similarly in Braket notation, we can define multi-controlled gates as