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
The combination of two qubits into a register
Here, for the amplitudes
To simplify this notation, the amplitudes
As notation convention, the tensor product of qubits
If a quantum register is measured, the state
For the formal definition of registers with
Definition
A quantum register with
The measurement of a quantum register therefore results in the state
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.
To transform a quantum register to a new state, gates can be applied to
multiple qubits. In the following circuit, the state
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
Diagram
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];
Simulation
Not run yet
The tensor product of the two 1-qubit matrices then results in the 2-qubit gate, i.e:
For example, for the
It is also possible to apply multi-qubit gates only to parts of a register:
If no operation is performed on qubit
Diagram
OPENQASM 2.0; include "qelib1.inc"; qreg q[1]; id q[0];
Simulation
Not run yet
The result of the tensor product is:
Using the example of the
And the corresponding matrix is calculated in the same way:
If this matrix is applied to a state vector (e.g.,
In the QASM language, this looks as follows:
Diagram
OPENQASM 2.0; include "qelib1.inc"; qreg q[3]; x q[1]; x q[2];
Simulation
Not run yet
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:
Diagram
OPENQASM 2.0; include "qelib1.inc"; qreg q[2]; cx q[0],q[1];
Translation
Powered by Perceval, Qiskit, PyZX
Not run yet
Simulation
Not run yet
The so-called control qubit
If the control qubit is in a basis state
If we apply this matrix to the state vector
The principle of controlling gates is not limited to the X gate, it can be combined with all other gates, e.g:
Diagram
OPENQASM 2.0; include "qelib1.inc"; qreg q[2]; cy q[0],q[1]; cz q[0],q[1]; ch q[0],q[1]; cu(pi,pi/2,pi/4,pi/8) q[0],q[1];
Translation
Powered by Perceval, Qiskit, PyZX
Not run yet
Simulation
Not run yet
In general, the matrix of a controlled gate
Similarly, in Braket notation a controlled gate
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.
Diagram
OPENQASM 2.0; include "qelib1.inc"; qreg q[3]; ccx q[0],q[1],q[2];
Simulation
Not run yet
The NOT gate is only applied to the target qubit if both control qubits
are
Similarly in Braket notation, we can define multi-controlled gates as