Skip to content

Commit

Permalink
Merge pull request #75 from qiboteam/david/fitting_dispersive_shift
Browse files Browse the repository at this point in the history
David/fitting dispersive shift
  • Loading branch information
scarrazza authored Oct 4, 2022
2 parents 3248346 + 3308d5e commit 0c6b3fb
Show file tree
Hide file tree
Showing 4 changed files with 314 additions and 26 deletions.
26 changes: 13 additions & 13 deletions runcards/actions_qq_5q.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
platform: tii5q

qubits: [2]
qubits: [3]

format: csv

Expand Down Expand Up @@ -44,6 +44,12 @@ actions:
# software_averages: 1
# points: 10

dispersive_shift:
freq_width: 5_000_000
freq_step: 200_000
software_averages: 1
points: 5

# qubit_spectroscopy:
# fast_start: -50_000_000
# fast_end: 50_000_000
Expand Down Expand Up @@ -135,12 +141,12 @@ actions:
# niter: 1024
# points: 1

allXY_iteration:
beta_start: -0.09
beta_end: 0
beta_step: 0.01
software_averages: 1
points: 1
# allXY_iteration:
# beta_start: -0.09
# beta_end: 0
# beta_step: 0.01
# software_averages: 1
# points: 1

# allXY:
# beta_param: Null
Expand All @@ -153,12 +159,6 @@ actions:
# beta_step: 0.01
# points: 1

# dispersive_shift:
# freq_width: 5_000_000
# freq_step: 200_000
# software_averages: 1
# points: 5

# RO_matrix:
# niter: 10 # set niter = 1024 to collect good statistics

Expand Down
93 changes: 93 additions & 0 deletions src/qcvv/calibrations/characterization/resonator_spectroscopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,96 @@ def resonator_spectroscopy_flux_matrix(
count += 1

yield data


@plot("MSR and Phase vs Frequency", plots.dispersive_frequency_msr_phase)
def dispersive_shift(
platform: AbstractPlatform,
qubit: int,
freq_width,
freq_step,
software_averages,
points=10,
):

platform.reload_settings()

sequence = PulseSequence()
ro_pulse = platform.create_qubit_readout_pulse(qubit, start=0)
sequence.add(ro_pulse)

resonator_frequency = platform.characterization["single_qubit"][qubit][
"resonator_freq"
]

frequency_range = (
np.arange(-freq_width, freq_width, freq_step) + resonator_frequency
)

data_spec = Dataset(name=f"data_q{qubit}", quantities={"frequency": "Hz"})
count = 0
for _ in range(software_averages):
for freq in frequency_range:
if count % points == 0 and count > 0:
yield data_spec
yield lorentzian_fit(
data_spec,
x="frequency[GHz]",
y="MSR[uV]",
qubit=qubit,
nqubits=platform.settings["nqubits"],
labels=["resonator_freq", "peak_voltage"],
)
platform.ro_port[qubit].lo_frequency = freq - ro_pulse.frequency
msr, phase, i, q = platform.execute_pulse_sequence(sequence)[
ro_pulse.serial
]
results = {
"MSR[V]": msr,
"i[V]": i,
"q[V]": q,
"phase[rad]": phase,
"frequency[Hz]": freq,
}
data_spec.add(results)
count += 1
yield data_spec

# Shifted Spectroscopy
sequence = PulseSequence()
RX_pulse = platform.create_RX_pulse(qubit, start=0)
ro_pulse = platform.create_qubit_readout_pulse(qubit, start=RX_pulse.finish)
sequence.add(RX_pulse)
sequence.add(ro_pulse)

data_shifted = Dataset(
name=f"data_shifted_q{qubit}", quantities={"frequency": "Hz"}
)
count = 0
for _ in range(software_averages):
for freq in frequency_range:
if count % points == 0 and count > 0:
yield data_shifted
yield lorentzian_fit(
data_spec,
x="frequency[GHz]",
y="MSR[uV]",
qubit=qubit,
nqubits=platform.settings["nqubits"],
labels=["resonator_freq", "peak_voltage"],
fit_file_name="fit_shifted",
)
platform.ro_port[qubit].lo_frequency = freq - ro_pulse.frequency
msr, phase, i, q = platform.execute_pulse_sequence(sequence)[
ro_pulse.serial
]
results = {
"MSR[V]": msr,
"i[V]": i,
"q[V]": q,
"phase[rad]": phase,
"frequency[Hz]": freq,
}
data_shifted.add(results)
count += 1
yield data_shifted
38 changes: 25 additions & 13 deletions src/qcvv/fitting/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,32 @@
from qcvv.fitting.utils import cos, exp, flipping, lorenzian, parse, rabi, ramsey


def lorentzian_fit(data, x, y, qubit, nqubits, labels):
def lorentzian_fit(data, x, y, qubit, nqubits, labels, fit_file_name=None):
"""Fitting routine for resonator spectroscopy"""

data_fit = Data(
name=f"fit_q{qubit}",
quantities=[
"fit_amplitude",
"fit_center",
"fit_sigma",
"fit_offset",
labels[1],
labels[0],
],
)
if fit_file_name == None:
data_fit = Data(
name=f"fit_q{qubit}",
quantities=[
"fit_amplitude",
"fit_center",
"fit_sigma",
"fit_offset",
labels[1],
labels[0],
],
)
else:
data_fit = Data(
name=fit_file_name + f"_q{qubit}",
quantities=[
"fit_amplitude",
"fit_center",
"fit_sigma",
"fit_offset",
labels[1],
labels[0],
],
)

frequencies = data.get_values(*parse(x))
voltages = data.get_values(*parse(y))
Expand Down
183 changes: 183 additions & 0 deletions src/qcvv/plots/scatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1077,3 +1077,186 @@ def msr_beta(folder, routine, qubit, format):
yaxis_title="MSR[uV]",
)
return fig


def dispersive_frequency_msr_phase(folder, routine, qubit, formato):

try:
data_spec = Dataset.load_data(folder, routine, formato, f"data_q{qubit}")
except:
data_spec = Dataset(name=f"data_q{qubit}", quantities={"frequency": "Hz"})

try:
data_shifted = Dataset.load_data(
folder, routine, formato, f"data_shifted_q{qubit}"
)
except:
data_shifted = Dataset(
name=f"data_shifted_q{qubit}", quantities={"frequency": "Hz"}
)

try:
data_fit = Data.load_data(folder, routine, formato, f"fit_q{qubit}")
except:
data_fit = Data(
quantities=[
"fit_amplitude",
"fit_center",
"fit_sigma",
"fit_offset",
"label1",
"label2",
]
)

try:
data_fit_shifted = Data.load_data(
folder, routine, formato, f"fit_shifted_q{qubit}"
)
except:
data_fit_shifted = Data(
quantities=[
"fit_amplitude",
"fit_center",
"fit_sigma",
"fit_offset",
"label1",
"label2",
]
)

fig = make_subplots(
rows=1,
cols=2,
horizontal_spacing=0.1,
vertical_spacing=0.1,
subplot_titles=(
"MSR (V)",
"phase (rad)",
),
)

fig.add_trace(
go.Scatter(
x=data_spec.get_values("frequency", "GHz"),
y=data_spec.get_values("MSR", "uV"),
name="Spectroscopy",
),
row=1,
col=1,
)
fig.add_trace(
go.Scatter(
x=data_spec.get_values("frequency", "GHz"),
y=data_spec.get_values("phase", "rad"),
name="Spectroscopy",
),
row=1,
col=2,
)

fig.add_trace(
go.Scatter(
x=data_shifted.get_values("frequency", "GHz"),
y=data_shifted.get_values("MSR", "uV"),
name="Shifted Spectroscopy",
),
row=1,
col=1,
)

fig.add_trace(
go.Scatter(
x=data_shifted.get_values("frequency", "GHz"),
y=data_shifted.get_values("phase", "rad"),
name="Shifted Spectroscopy",
),
row=1,
col=2,
)

# fitting traces
if len(data_spec) > 0 and len(data_fit) > 0:
freqrange = np.linspace(
min(data_spec.get_values("frequency", "GHz")),
max(data_spec.get_values("frequency", "GHz")),
20,
)
params = [i for i in list(data_fit.df.keys()) if "fit" not in i]
fig.add_trace(
go.Scatter(
x=freqrange,
y=lorenzian(
freqrange,
data_fit.df["fit_amplitude"][0],
data_fit.df["fit_center"][0],
data_fit.df["fit_sigma"][0],
data_fit.df["fit_offset"][0],
),
name="Fit spectroscopy",
line=go.scatter.Line(dash="dot"),
),
row=1,
col=1,
)
fig.add_annotation(
dict(
font=dict(color="black", size=12),
x=0,
y=-0.25,
showarrow=False,
text=f"The estimated {params[0]} is {data_fit.df[params[0]][0]:.1f} Hz.",
textangle=0,
xanchor="left",
xref="paper",
yref="paper",
)
)

# fitting shifted traces
if len(data_shifted) > 0 and len(data_fit_shifted) > 0:
freqrange = np.linspace(
min(data_shifted.get_values("frequency", "GHz")),
max(data_shifted.get_values("frequency", "GHz")),
20,
)
params = [i for i in list(data_fit_shifted.df.keys()) if "fit" not in i]
fig.add_trace(
go.Scatter(
x=freqrange,
y=lorenzian(
freqrange,
data_fit_shifted.df["fit_amplitude"][0],
data_fit_shifted.df["fit_center"][0],
data_fit_shifted.df["fit_sigma"][0],
data_fit_shifted.df["fit_offset"][0],
),
name="Fit shifted spectroscopy",
line=go.scatter.Line(dash="dot"),
),
row=1,
col=1,
)
fig.add_annotation(
dict(
font=dict(color="black", size=12),
x=0,
y=-0.30,
showarrow=False,
text=f"The estimated shifted {params[0]} is {data_fit_shifted.df[params[0]][0]:.1f} Hz.",
textangle=0,
xanchor="left",
xref="paper",
yref="paper",
)
)

fig.update_layout(
showlegend=True,
uirevision="0", # ``uirevision`` allows zooming while live plotting
xaxis_title="Frequency (GHz)",
yaxis_title="MSR (uV)",
xaxis2_title="Frequency (GHz)",
yaxis2_title="Phase (rad)",
)
return fig

0 comments on commit 0c6b3fb

Please sign in to comment.