#Para la construccion de circuitos cuanticos
from qiskit import QuantumCircuit, execute

#Para la construccion de las calibraciones y su vinculacion
from qiskit import pulse, transpile
from qiskit.pulse.library import Gaussian
from qiskit.providers.fake_provider import FakeValencia, FakeHanoi

#Compuertas personalizadas
from qiskit.circuit import Gate
from qiskit import QiskitError

#informacion
import qiskit.tools.jupyter


circ = QuantumCircuit(2, 2);
circ.h(0);
circ.cx(0, 1);
circ.measure(0, 0);
circ.measure(1, 1);

circ.draw('mpl');

result = execute(circ, backend=FakeValencia()).result();
counts = result.get_counts();
print("El resultado de la estadística es: \n|00>: {S00}  \n|01>: {S01}  \n|10>: {S10}  \n|11>: {S11}".format(S00=counts['00'],S01=counts['01'],S10=counts['10'],S11=counts['11']))

backend = FakeValencia();

with pulse.build(backend, name='hadamard') as h_q0:
    pulse.play(Gaussian(duration=100, amp=0.1, sigma=3), pulse.drive_channel(0));


h_q0.draw()

backend = FakeValencia()ñ

with pulse.build(backend, name='hadamard') as h_q0:
    pulse.play(Gaussian(duration=128, amp=0.1, sigma=16), pulse.drive_channel(0))

h_q0.draw()

circ.add_calibration('h', [0], h_q0)

backend = FakeHanoi()

circ = transpile(circ, backend)

print(backend.configuration().basis_gates)
circ.draw('mpl', idle_wires=False)

result = execute(circ, backend=FakeValencia()).result();
counts = result.get_counts();
print("El resultado de la estadística es: \n|00>: {S00}  \n|01>: {S01}  \n|10>: {S10}  \n|11>: {S11}".format(S00=counts['00'],S01=counts['01'],S10=counts['10'],S11=counts['11']))

circ = QuantumCircuit(1, 1)
custom_gate = Gate('my_custom_gate', 1, [3.14, 1])
# 3.14 is an arbitrary parameter for demonstration
circ.append(custom_gate, [0])
circ.measure(0, 0)

circ.draw('mpl')

with pulse.build(backend, name='custom') as my_schedule:
    pulse.play(Gaussian(duration=64, amp=0.2, sigma=8), pulse.drive_channel(0))

circ.add_calibration('my_custom_gate', [0], my_schedule, [3.14, 1])
# Alternatively: circ.add_calibration(custom_gate, [0], my_schedule)

circ = transpile(circ, backend)
circ.draw('mpl', idle_wires=False)

circ = QuantumCircuit(2, 2)
circ.append(custom_gate, [1])


from qiskit import QiskitError
try:
    circ = transpile(circ, backend)
except QiskitError as e:
    print(e)

%qiskit_version_table
%qiskit_copyright