diff --git a/src/qibocal/auto/execute.py b/src/qibocal/auto/execute.py index 9b59f5a96..d6736a378 100644 --- a/src/qibocal/auto/execute.py +++ b/src/qibocal/auto/execute.py @@ -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 diff --git a/src/qibocal/cli/_base.py b/src/qibocal/cli/_base.py index 28a9b45ee..62f0aab1b 100644 --- a/src/qibocal/cli/_base.py +++ b/src/qibocal/cli/_base.py @@ -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) diff --git a/src/qibocal/cli/builders.py b/src/qibocal/cli/builders.py index 344163038..c43632dd8 100644 --- a/src/qibocal/cli/builders.py +++ b/src/qibocal/cli/builders.py @@ -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() diff --git a/src/qibocal/protocols/characterization/ramsey.py b/src/qibocal/protocols/characterization/ramsey.py index 53828cbb0..b996905f3 100644 --- a/src/qibocal/protocols/characterization/ramsey.py +++ b/src/qibocal/protocols/characterization/ramsey.py @@ -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 diff --git a/src/qibocal/protocols/characterization/resonator_spectroscopy.py b/src/qibocal/protocols/characterization/resonator_spectroscopy.py index 7c1eaf418..1cb4372f5 100644 --- a/src/qibocal/protocols/characterization/resonator_spectroscopy.py +++ b/src/qibocal/protocols/characterization/resonator_spectroscopy.py @@ -1,4 +1,4 @@ -from dataclasses import dataclass, field +from dataclasses import dataclass, field, fields from typing import Optional, Union import numpy as np @@ -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 @@ -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)] diff --git a/src/qibocal/protocols/characterization/utils.py b/src/qibocal/protocols/characterization/utils.py index 3d644e3fb..3e84ada03 100644 --- a/src/qibocal/protocols/characterization/utils.py +++ b/src/qibocal/protocols/characterization/utils.py @@ -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( @@ -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
" - if fit.amplitude[qubit] is not None: fitting_report += f"{qubit} | amplitude: {fit.amplitude[qubit]}
" - 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: diff --git a/tests/test_auto.py b/tests/test_auto.py index ed7cf9519..dfc264f0e 100644 --- a/tests/test_auto.py +++ b/tests/test_auto.py @@ -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] diff --git a/tests/test_task_options.py b/tests/test_task_options.py index abaa7fe42..e822d5b27 100644 --- a/tests/test_task_options.py +++ b/tests/test_task_options.py @@ -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 @@ -74,6 +64,7 @@ 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, @@ -81,6 +72,12 @@ def test_qubits_argument(platform, local_qubits): "power_level": "low", }, }, + { + "id": "classification", + "priority": 0, + "operation": "single_shot_classification", + "parameters": {"nshots": 100}, + }, ], } @@ -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), @@ -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