Skip to main content
edited tags
Link
glS
  • 26.9k
  • 6
  • 35
  • 121
edited tags
Link
glS
  • 26.9k
  • 6
  • 35
  • 121
Source Link
Jared
  • 75
  • 6

How do I get the Unitary matrix of this circuit without using 'unitary_simulator'?

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?

enter image description here

I have figured out how to get the unitary matrix of the circuit below:

enter image description here

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

The result I should be getting:

enter image description here