I am using jupyter notebook and qiskit. I have a simple quantum circuit and I want to know how to get the unitary matrix of the circuit without using 'get_unitary' from the Aer unitary_simulator. i.e.: By just using matrix manipulation, how do I get the unitary matrix of the circuit below by just using numpy and normal matrix properties?
I have figured out how to get the unitary matrix of the circuit below:
By using this code:
import numpy as np
swapcnot = np.array([[1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0], [0, 1, 0, 0]])
cnot = np.array([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]])
layer1 = np.kron(np.eye(2),swapcnot)
layer2 = np.kron(swapcnot, np.eye(2))
print(layer2@layer1)
However when I try to add another qubit and another cnot gate, I do not get the correct result