from qiskit.tools.jupyter import *
from qiskit import IBMQ
IBMQ.load_account()
#provider = IBMQ.get_provider(hub='ibm-q', group='open', project='main')
provider=IBMQ.get_provider(hub='ibm-q-research', group='uni-maryland-1', project='main')

backend = provider.get_backend('ibmq_rome')
backend_config = backend.configuration()
backend_defaults = backend.defaults()
assert backend_config.open_pulse, "Backend doesn't support Pulse"

inst_sched_map=backend_defaults.instruction_schedule_map

print(inst_sched_map)

from qiskit.visualization.pulse_v2 import draw

from qiskit import execute

dt = backend_config.dt
print(f"Sampling time: {dt*1e9} ns")    # The configuration returns dt in seconds, so multiply by
                                        # 1e9 to get nanoseconds

import numpy as np
from qiskit import pulse            # This is where we access all of our Pulse features!
from qiskit.pulse import Play
# This Pulse module helps us build sampled pulses for common pulse shapes
from qiskit.pulse import library as pulse_lib
from pulsecalibration import PulseCalibration as PulseCali

%load_ext autoreload

%autoreload

PC=PulseCali(backend=backend,qubit=0)

print(backend_defaults.qubit_freq_est)

f01=PC.find_freq_ground(verbose=True,visual=True)

f01_1=PC.get_qubit_freq_ground()
f01_1

PC=PulseCali(backend=backend,qubit=0,qubit_freq_ground=f01)

amp01=PC.find_pi_amp_ground(verbose=True,visual=True)

amp01_1=PC.get_pi_amp_ground()
amp01_1

PC=PulseCali(backend=backend,qubit=0,qubit_freq_ground=f01,pi_amp_ground=amp01)

f12=PC.find_freq_excited(verbose=True,visual=True)

PC=PulseCali(backend=backend,qubit=0,qubit_freq_ground=f01,pi_amp_ground=amp01,qubit_freq_excited=f12)

f12_1=PC.get_qubit_freq_excited()
f12_1

amp12=PC.find_pi_amp_excited(verbose=True,visual=True)

amp12_1=PC.get_pi_amp_excited()
amp12_1

PC=PulseCali(backend,0,qubit_freq_ground=f01,qubit_freq_excited=f12,
             pi_amp_ground=amp01, pi_amp_excited=amp12)

PC.T1_ground(verbose=True,visual=True)

PC.T1_excited(verbose=True,visual=True)

PC.T2_ground(verbose=True,visual=True)

