Calculating the Transformation Matrix
Learn how we can calculate the transformation matrix.
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 -gate to the one qubit and the -gate to the other.
from qiskit import QuantumCircuit, Aer, execute# Create a quantum circuit with one qubitqc = QuantumCircuit(2)# apply the Hadamard gate to the qubitqc.i(0)qc.h(1)backend = Aer.get_backend('unitary_simulator')unitary = execute(qc,backend).result().get_unitary()# Display the resultsprint(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 -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 ...