from qiskit.quantum_info.operators import Operator, Pauli
from qiskit.visualization import *
from qiskit.extensions import XGate,HGate
from qiskit import QuantumCircuit,BasicAer,execute

X=Operator([[0,1],[1,0]])

X

X.data

array_to_latex(X.data)

pauli_Xgate = Pauli(label='X')
Operator(pauli_Xgate)

array_to_latex(Operator(pauli_Xgate).data)

Operator(pauli_Xgate).is_unitary()

Operator(XGate())

array_to_latex(Operator(XGate()).data)

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

# Convert circuit to an operator by implicit unitary simulation
Operator(qc)

array_to_latex(Operator(qc).data)

#Create an operator

XX = Operator(Pauli(label='XX'))

# Add to a circuit
qc = QuantumCircuit(2)
qc.append(XX, [0,1])
qc.measure_all()
qc.draw('mpl')

#Get the backend
backend=BasicAer.get_backend('qasm_simulator')

job=backend.run(qc)
result=job.result()
counts=result.get_counts()
print(counts)


# Add to a circuit
qc = QuantumCircuit(2)
qc.append(Pauli(label='XX'), [0,1])
qc.measure_all()
qc.draw('mpl')

#Get the backend
backend=BasicAer.get_backend('qasm_simulator')

job=execute(qc,backend)
result=job.result()
counts=result.get_counts()
print(counts)

array_to_latex(Operator(HGate()).data)

