from qiskit import *
from qiskit.quantum_info import Statevector
from math import pi
from qiskit.visualization import *

qc=QuantumCircuit(1)
qc.x(0)
qc.draw(output="mpl")

backend = Aer.get_backend('unitary_simulator')
job = execute(qc, backend)
result = job.result()
#Obtain the unitary matrix for Pauli-X gate
print(result.get_unitary(qc, decimals=3))

qc=QuantumCircuit(1)
qc.x(0)
qc.x(0)
qc.draw(output="mpl")

backend = Aer.get_backend('unitary_simulator')

job = execute(qc, backend)
result = job.result()
#Obtain the unitary matrix for Pauli-X gate
print(result.get_unitary(qc, decimals=3))

qc=QuantumCircuit(1)
qc.y(0)
qc.draw(output="mpl")

backend = Aer.get_backend('unitary_simulator')

job = execute(qc, backend)
result = job.result()
#Obtain the unitary matrix for Pauli-Y gate
print(result.get_unitary(qc, decimals=3))

qc=QuantumCircuit(1)
qc.x(0)
qc.y(0)
qc.draw(output="mpl")

backend = Aer.get_backend('unitary_simulator')

job = execute(qc, backend)
result = job.result()
#Obtain the unitary matrix for Pauli-Y gate
print(result.get_unitary(qc, decimals=3))

state = Statevector.from_instruction(qc)
state.draw(output='latex')

qc=QuantumCircuit(1)
qc.z(0)
qc.draw(output="mpl")

backend = Aer.get_backend('unitary_simulator')

job = execute(qc, backend)
result = job.result()
#Obtain the unitary matrix for Pauli-Z gate
print(result.get_unitary(qc, decimals=3))

state = Statevector.from_instruction(qc)
state.draw(output='latex')

qc=QuantumCircuit(1)
qc.z(0)
qc.draw(output="mpl")

qc=QuantumCircuit(1)
qc.x(0)
qc.z(0)
qc.draw(output="mpl")

backend = Aer.get_backend('unitary_simulator')

job = execute(qc, backend)
result = job.result()
#Obtain the unitary matrix for Pauli-Z gate
print(result.get_unitary(qc, decimals=3))

state = Statevector.from_instruction(qc)
state.draw(output='latex')

qc=QuantumCircuit(1)
qc.h(0)
qc.draw(output="mpl")

backend = Aer.get_backend('unitary_simulator')

job = execute(qc, backend)
result = job.result()
#Obtain the unitary matrix for Hadamard gate
print(result.get_unitary(qc, decimals=3))

state = Statevector.from_instruction(qc)
state.draw(output='latex')

qc=QuantumCircuit(1)
qc.x(0)
qc.h(0)
qc.draw(output="mpl")

backend = Aer.get_backend('unitary_simulator')

job = execute(qc, backend)
result = job.result()
#Obtain the unitary matrix for Hadamard gate
print(result.get_unitary(qc, decimals=3))

qc=QuantumCircuit(1)
qc.s(0)
qc.draw(output="mpl")

backend = Aer.get_backend('unitary_simulator')

job = execute(qc, backend)
result = job.result()
#Obtain the unitary matrix for S gate
print(result.get_unitary(qc, decimals=3))

qc=QuantumCircuit(1)
qc.x(0)
qc.s(0)
qc.draw(output="mpl")

backend = Aer.get_backend('unitary_simulator')

job = execute(qc, backend)
result = job.result()
#Obtain the unitary matrix for S gate
print(result.get_unitary(qc, decimals=3))

qc=QuantumCircuit(1)
qc.s(0)
qc.s(0)
qc.draw(output="mpl")

backend = Aer.get_backend('unitary_simulator')

job = execute(qc, backend)
result = job.result()
#Obtain the unitary matrix for S dagger gate
print(result.get_unitary(qc, decimals=3))

qc=QuantumCircuit(1)
qc.sdg(0)
qc.draw(output="mpl")

backend = Aer.get_backend('unitary_simulator')

job = execute(qc, backend)
result = job.result()
#Obtain the unitary matrix for Sdg gate
print(result.get_unitary(qc, decimals=3))

qc=QuantumCircuit(1)
qc.x(0)
qc.sdg(0)
qc.draw(output="mpl")

backend = Aer.get_backend('unitary_simulator')

job = execute(qc, backend)
result = job.result()
#Obtain the unitary matrix for Sdg gate
print(result.get_unitary(qc, decimals=3))

qc=QuantumCircuit(1)
qc.sdg(0)
qc.sdg(0)
qc.draw(output="mpl")

backend = Aer.get_backend('unitary_simulator')

job = execute(qc, backend)
result = job.result()
#Obtain the unitary matrix for Sdg gate
print(result.get_unitary(qc, decimals=3))

qc=QuantumCircuit(1)
qc.t(0)
qc.draw(output="mpl")

backend = Aer.get_backend('unitary_simulator')

job = execute(qc, backend)
result = job.result()
#Obtain the unitary matrix for T gate
print(result.get_unitary(qc, decimals=3))

qc=QuantumCircuit(1)
qc.x(0)
qc.t(0)
qc.draw(output="mpl")

backend = Aer.get_backend('unitary_simulator')

job = execute(qc, backend)
result = job.result()
#Obtain the unitary matrix for T gate
print(result.get_unitary(qc, decimals=3))

qc=QuantumCircuit(1)
qc.tdg(0)
qc.draw(output="mpl")

backend = Aer.get_backend('unitary_simulator')

job = execute(qc, backend)
result = job.result()
#Obtain the unitary matrix for Tdg gate
print(result.get_unitary(qc, decimals=3))

qc=QuantumCircuit(1)
qc.x(0)
qc.tdg(0)
qc.draw(output="mpl")

backend = Aer.get_backend('unitary_simulator')

job = execute(qc, backend)
result = job.result()
#Obtain the unitary matrix for Tdg gate
print(result.get_unitary(qc, decimals=3))

qc=QuantumCircuit(1)
qc.tdg(0)
qc.tdg(0)
qc.tdg(0)
qc.tdg(0)
qc.draw(output="mpl")

backend = Aer.get_backend('unitary_simulator')

job = execute(qc, backend)
result = job.result()
#Obtain the unitary matrix for Tdg gate
print(result.get_unitary(qc, decimals=3))

qc=QuantumCircuit(1)
qc.z(0)

backend = Aer.get_backend('unitary_simulator')

job = execute(qc, backend)
result = job.result()
#Obtain the unitary matrix for Tdg gate
print(result.get_unitary(qc, decimals=3))

qc=QuantumCircuit(1)
qc.p(pi,0)

qc.draw(output="mpl")

backend = Aer.get_backend('unitary_simulator')

job = execute(qc, backend)
result = job.result()
#Obtain the unitary matrix for P gate
print(result.get_unitary(qc, decimals=3))

qc=QuantumCircuit(1)
qc.p(pi/2,0)

qc.draw(output="mpl")

backend = Aer.get_backend('unitary_simulator')

job = execute(qc, backend)
result = job.result()
#Obtain the unitary matrix for P gate
print(result.get_unitary(qc, decimals=3))

qc=QuantumCircuit(1)
qc.p(pi/4,0)

qc.draw(output="mpl")

backend = Aer.get_backend('unitary_simulator')

job = execute(qc, backend)
result = job.result()
#Obtain the unitary matrix for P gate
print(result.get_unitary(qc, decimals=3))

qc=QuantumCircuit(1)
qc.x(0)
qc.p(pi,0)

qc.draw(output="mpl")

backend = Aer.get_backend('unitary_simulator')

job = execute(qc, backend)
result = job.result()
#Obtain the unitary matrix for P gate
print(result.get_unitary(qc, decimals=3))

qc=QuantumCircuit(1)
qc.x(0)
qc.p(pi/2,0)

qc.draw(output="mpl")

qc=QuantumCircuit(1)
qc.x(0)
qc.p(pi/4,0)

qc.draw(output="mpl")

qc=QuantumCircuit(1)
qc.p(0,0)

qc.draw(output="mpl")

backend = Aer.get_backend('unitary_simulator')

job = execute(qc, backend)
result = job.result()
#Obtain the unitary matrix for P gate
print(result.get_unitary(qc, decimals=3))

I=result.get_unitary(qc, decimals=3)

array_to_latex(I)