Search⌘ K

Calculating the Transformation Matrix

Explore how to compute transformation matrices for two-qubit quantum circuits, including the application of quantum gates like H and X, and understand how tensor products represent combined qubit operations. Learn to use Qiskit's UnitarySimulator to obtain final circuit matrices without measurements, enhancing your grasp of multi-qubit quantum transformations.

We'll cover the following...

Calculate the transformation matrix

In line 4, we create the QuantumCircuit with two qubits. Then, in lines 7 and 8, we apply the XX-gate to the one qubit and the HH-gate to the other.

Javascript (babel-node)
from qiskit import QuantumCircuit, Aer, execute
# Create a quantum circuit with one qubit
qc = QuantumCircuit(2)
# apply the Hadamard gate to the qubit
qc.i(0)
qc.h(1)
backend = Aer.get_backend('unitary_simulator')
unitary = execute(qc,backend).result().get_unitary()
# Display the results
print(unitary)

Note: Qiskit orders the qubits from back to front about the matrix calculation, so we need to switch the positions.

This time, in line 10, we use a different Qiskit simulator as the backend, the UnitarySimulator. This simulator executes the circuit once and returns the final transformation matrix of the circuit itself. Note that this simulator does not contain any measurements.

The result is the matrix our circuit represents.

What if we only wanted to apply the HH-gate to one of the qubits and leave the other unchanged? How would we calculate such a two-qubit transformation matrix?

We can use the II-gate as a placeholder when we calculate the tensor product. If we want to apply the HH-gate to the first qubit and leave the second qubit unchanged, we calculate the transformation matrix as follows:

HI=12[IIII]=12[1010010110100101]H\otimes I=\frac{1}{\sqrt{2}}\begin{bmatrix}I&I\\I&-I\end{bmatrix}=\frac{1}{\sqrt{2}}\begin{bmatrix}1&0&1&0\\0&1&0&1\\1&0&-1&0\\0&1&0&-1\end{bmatrix} ...