Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dump report after each protocol #438

Merged
merged 6 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/qibocal/auto/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,4 @@ def run(self):
if self.platform is not None:
if self.update and task.update:
self.platform.update(completed.results.update)
yield
1 change: 0 additions & 1 deletion src/qibocal/cli/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def command(runcard, folder, force, update):
builder.run()
if update:
builder.dump_platform_runcard()
builder.dump_report()


@click.command(context_settings=CONTEXT_SETTINGS)
Expand Down
4 changes: 2 additions & 2 deletions src/qibocal/cli/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ def _prepare_output(self, runcard):

def run(self):
"""Execute protocols in runcard."""

if self.platform is not None:
self.platform.connect()
self.platform.setup()
self.platform.start()

self.executor.run()
for _ in self.executor.run():
self.dump_report()

if self.platform is not None:
self.platform.stop()
Expand Down
1 change: 0 additions & 1 deletion src/qibocal/protocols/characterization/ramsey.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ def _fit(data: RamseyData) -> RamseyResults:
log.warning(f"ramsey_fit: the fitting was not succesful. {e}")
popt = [0] * 5
t2 = 5.0
print(qubit_freq)
corrected_qubit_frequency = int(qubit_freq)
delta_phys = 0

Expand Down
29 changes: 27 additions & 2 deletions src/qibocal/protocols/characterization/resonator_spectroscopy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dataclasses import dataclass, field
from dataclasses import dataclass, field, fields
from typing import Optional, Union

import numpy as np
Expand All @@ -9,7 +9,14 @@
from qibolab.qubits import QubitId
from qibolab.sweeper import Parameter, Sweeper, SweeperType

from qibocal.auto.operation import Data, Parameters, Qubits, Results, Routine
from qibocal.auto.operation import (
Data,
Parameters,
ParameterValue,
Qubits,
Results,
Routine,
)

from .utils import PowerLevel, lorentzian_fit, spectroscopy_plot

Expand Down Expand Up @@ -61,6 +68,24 @@ class ResonatorSpectroscopyResults(Results):
)
"""Readout attenuation [dB] for each qubit."""

@property
def update(self):
"""Method overwritten from Results to not update
amplitude when running resonator spectroscopy at
high power."""
up: dict[str, ParameterValue] = {}
fields_to_updated = (
[fld for fld in fields(self) if fld.name != "amplitude"]
if self.bare_frequency == {}
else fields(self)
)

for fld in fields_to_updated:
if "update" in fld.metadata:
up[fld.metadata["update"]] = getattr(self, fld.name)

return up


ResSpecType = np.dtype(
[("freq", np.float64), ("msr", np.float64), ("phase", np.float64)]
Expand Down
6 changes: 0 additions & 6 deletions src/qibocal/protocols/characterization/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ def spectroscopy_plot(data, fit: Results, qubit):
qubit_data = data[qubit]

fitting_report = ""

frequencies = qubit_data.freq * HZ_TO_GHZ
fig.add_trace(
go.Scatter(
Expand Down Expand Up @@ -145,14 +144,9 @@ def spectroscopy_plot(data, fit: Results, qubit):
else:
label = "qubit frequency"
freq = fit.frequency

fitting_report += f"{qubit} | {label}: {freq[qubit]*GHZ_TO_HZ:,.0f} Hz<br>"

if fit.amplitude[qubit] is not None:
fitting_report += f"{qubit} | amplitude: {fit.amplitude[qubit]} <br>"
if data.power_level is PowerLevel.high:
# TODO: find better solution for not updating amplitude in high power
fit.amplitude.pop(qubit)

if data.__class__.__name__ == "ResonatorSpectroscopyAttenuationData":
if fit.attenuation[qubit] is not None and fit.attenuation[qubit] != 0:
Expand Down
3 changes: 2 additions & 1 deletion tests/test_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def test_execution(card: pathlib.Path):
"""
testcard = TestCard(**yaml.safe_load(card.read_text(encoding="utf-8")))
executor = Executor.load(testcard.runcard, output=pathlib.Path(tempfile.mkdtemp()))
executor.run()
for _ in executor.run():
pass

assert testcard.validation.result == [step[0] for step in executor.history]
36 changes: 20 additions & 16 deletions tests/test_task_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,17 @@
"nshots": 10,
},
},
{
"id": "resonator frequency",
"priority": 0,
"operation": "resonator_spectroscopy",
"parameters": {
"freq_width": 10_000_000,
"freq_step": 100_000,
"amplitude": 0.4,
"power_level": "low",
},
},
],
}


def modify_card(card, qubits=None, update=None):
"""Modify runcard to change local qubits or update."""
if qubits is not None:
card["actions"][0]["qubits"] = qubits
elif update is not None:
card["actions"][0]["update"] = update
for action in card["actions"]:
if qubits is not None:
action["qubits"] = qubits
elif update is not None:
action["update"] = update
return card


Expand Down Expand Up @@ -74,13 +64,20 @@ def test_qubits_argument(platform, local_qubits):
"id": "resonator frequency",
"priority": 0,
"operation": "resonator_spectroscopy",
"main": "classification",
"parameters": {
"freq_width": 10_000_000,
"freq_step": 100_000,
"amplitude": 0.4,
"power_level": "low",
},
},
{
"id": "classification",
"priority": 0,
"operation": "single_shot_classification",
"parameters": {"nshots": 100},
},
],
}

Expand All @@ -91,6 +88,7 @@ def test_update_argument(global_update, local_update):
"""Test possible update combinations between global and local."""
platform = deepcopy(create_platform("dummy"))
old_readout_frequency = platform.qubits[0].readout_frequency
old_iq_angle = platform.qubits[1].iq_angle
NEW_CARD = modify_card(deepcopy(UPDATE_CARD), update=local_update)
executor = Executor.load(
Runcard.load(NEW_CARD),
Expand All @@ -99,8 +97,14 @@ def test_update_argument(global_update, local_update):
platform.qubits,
global_update,
)
executor.run()

for _ in executor.run():
pass

if local_update and global_update:
assert old_readout_frequency != platform.qubits[0].readout_frequency
assert old_iq_angle != platform.qubits[1].iq_angle

else:
assert old_readout_frequency == platform.qubits[0].readout_frequency
assert old_iq_angle == platform.qubits[1].iq_angle