From 175a410fc6aa8b08a4acabc1ef7d0e4904d8ff48 Mon Sep 17 00:00:00 2001 From: Andrea Date: Mon, 12 Feb 2024 16:46:59 +0400 Subject: [PATCH 1/5] feat: Dump platform after each protocol --- src/qibocal/auto/task.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/qibocal/auto/task.py b/src/qibocal/auto/task.py index bdddf0ec6..9342921ed 100644 --- a/src/qibocal/auto/task.py +++ b/src/qibocal/auto/task.py @@ -8,6 +8,7 @@ from qibolab.platform import Platform from qibolab.qubits import QubitId, QubitPairId +from qibolab.serialize import dump_platform from ..config import raise_error from ..protocols.characterization import Operation @@ -33,6 +34,8 @@ """A number bigger than whatever will be manually typed. But not so insanely big not to fit in a native integer.""" TaskId = tuple[Id, int] """Unique identifier for executed tasks.""" +PLATFORM_FOLDER = "platform" +"""Folder where platform will be dumped.""" @dataclass @@ -237,6 +240,8 @@ def update_platform(self, platform: Platform, update: bool): if self.task.update and update: for qubit in self.task.qubits: self.task.operation.update(self.results, platform, qubit) + (self.datapath / "platform").mkdir(parents=True, exist_ok=True) + dump_platform(platform, self.datapath / "platform") def validate(self) -> tuple[Optional[TaskId], Optional[dict]]: """Check status of completed and handle Failure using handler.""" From f0274a3bb83e4243ad782d14daf6b028bd9bdcef Mon Sep 17 00:00:00 2001 From: Andrea Date: Mon, 12 Feb 2024 17:31:48 +0400 Subject: [PATCH 2/5] test: Improve tests by checking files/folders --- src/qibocal/auto/task.py | 4 ++-- tests/runcards/protocols.yml | 3 --- tests/test_protocols.py | 15 ++++++++++++++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/qibocal/auto/task.py b/src/qibocal/auto/task.py index 9342921ed..9f4961ac2 100644 --- a/src/qibocal/auto/task.py +++ b/src/qibocal/auto/task.py @@ -240,8 +240,8 @@ def update_platform(self, platform: Platform, update: bool): if self.task.update and update: for qubit in self.task.qubits: self.task.operation.update(self.results, platform, qubit) - (self.datapath / "platform").mkdir(parents=True, exist_ok=True) - dump_platform(platform, self.datapath / "platform") + (self.datapath / "platform").mkdir(parents=True, exist_ok=True) + dump_platform(platform, self.datapath / "platform") def validate(self) -> tuple[Optional[TaskId], Optional[dict]]: """Check status of completed and handle Failure using handler.""" diff --git a/tests/runcards/protocols.yml b/tests/runcards/protocols.yml index 21d3ea96a..ee8b9a825 100644 --- a/tests/runcards/protocols.yml +++ b/tests/runcards/protocols.yml @@ -217,7 +217,6 @@ actions: - id: rabi priority: 0 operation: rabi_amplitude - update: false parameters: min_amp_factor: 0.0 max_amp_factor: 4.0 @@ -237,7 +236,6 @@ actions: - id: rabi signal priority: 0 operation: rabi_amplitude_signal - update: false parameters: min_amp_factor: 0.0 max_amp_factor: 4.0 @@ -517,7 +515,6 @@ actions: - id: flipping priority: 0 operation: flipping - update: false parameters: nflips_max: 5 nflips_step: 1 diff --git a/tests/test_protocols.py b/tests/test_protocols.py index 6428867be..ad5e86307 100644 --- a/tests/test_protocols.py +++ b/tests/test_protocols.py @@ -40,9 +40,10 @@ def idfn(val): @pytest.mark.parametrize("backend", ["qibolab"]) @pytest.mark.parametrize("update", ["--update", "--no-update"]) @pytest.mark.parametrize("runcard", generate_runcard_single_protocol(), ids=idfn) -def test_auto_command(runcard, update, platform, backend, tmp_path): +def test_auto_command(runcard, update, platform, backend, tmp_path, request): """Test auto command pipeline.""" + protocol = runcard["actions"][0]["id"] (tmp_path / SINGLE_ACTION_RUNCARD).write_text(yaml.safe_dump(runcard)) runner = CliRunner() results = runner.invoke( @@ -62,6 +63,9 @@ def test_auto_command(runcard, update, platform, backend, tmp_path): ) assert not results.exception assert results.exit_code == 0 + if update == "--update": + assert (tmp_path / "new_platform").is_dir() + assert (tmp_path / "data" / f"{protocol}_0" / "platform").is_dir() @pytest.mark.parametrize("platform", ["dummy"]) @@ -69,6 +73,7 @@ def test_auto_command(runcard, update, platform, backend, tmp_path): @pytest.mark.parametrize("runcard", generate_runcard_single_protocol(), ids=idfn) def test_acquire_command(runcard, backend, platform, tmp_path): """Test acquire command pipeline and report generated.""" + protocol = runcard["actions"][0]["id"] (tmp_path / SINGLE_ACTION_RUNCARD).write_text(yaml.safe_dump(runcard)) runner = CliRunner() @@ -89,17 +94,20 @@ def test_acquire_command(runcard, backend, platform, tmp_path): ) assert not results.exception assert results.exit_code == 0 + assert (tmp_path / "data" / f"{protocol}_0").is_dir() # generate report from acquired data results_report = runner.invoke(command, ["report", str(tmp_path)]) assert not results_report.exception assert results_report.exit_code == 0 + assert (tmp_path / "index.html").is_file() @pytest.mark.parametrize("update", ["--update", "--no-update"]) @pytest.mark.parametrize("runcard", generate_runcard_single_protocol(), ids=idfn) def test_fit_command(runcard, update, tmp_path): """Test fit builder and report generated.""" + protocol = runcard["actions"][0]["id"] (tmp_path / SINGLE_ACTION_RUNCARD).write_text(yaml.safe_dump(runcard)) runner = CliRunner() @@ -123,10 +131,15 @@ def test_fit_command(runcard, update, tmp_path): assert not results_fit.exception assert results_fit.exit_code == 0 + if update == "--update": + assert (tmp_path / "new_platform").is_dir() + assert (tmp_path / "data" / f"{protocol}_0" / "platform").is_dir() + # generate report with fit and plot results_plot = runner.invoke(command, ["report", str(tmp_path)]) assert not results_plot.exception assert results_plot.exit_code == 0 + assert (tmp_path / "index.html").is_file() def test_extract_rabi(): From c31c6eb0d5f893a4580428b6b110773f0173ea1c Mon Sep 17 00:00:00 2001 From: Andrea Date: Mon, 12 Feb 2024 17:50:22 +0400 Subject: [PATCH 3/5] refactor: Use correct global variables --- src/qibocal/auto/task.py | 4 ++-- tests/test_protocols.py | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/qibocal/auto/task.py b/src/qibocal/auto/task.py index 9f4961ac2..5cb9986e9 100644 --- a/src/qibocal/auto/task.py +++ b/src/qibocal/auto/task.py @@ -240,8 +240,8 @@ def update_platform(self, platform: Platform, update: bool): if self.task.update and update: for qubit in self.task.qubits: self.task.operation.update(self.results, platform, qubit) - (self.datapath / "platform").mkdir(parents=True, exist_ok=True) - dump_platform(platform, self.datapath / "platform") + (self.datapath / PLATFORM_FOLDER).mkdir(parents=True, exist_ok=True) + dump_platform(platform, self.datapath / PLATFORM_FOLDER) def validate(self) -> tuple[Optional[TaskId], Optional[dict]]: """Check status of completed and handle Failure using handler.""" diff --git a/tests/test_protocols.py b/tests/test_protocols.py index ad5e86307..d6d84e150 100644 --- a/tests/test_protocols.py +++ b/tests/test_protocols.py @@ -7,6 +7,8 @@ from click.testing import CliRunner from qibolab import create_platform +from qibocal.auto.task import PLATFORM_FOLDER +from qibocal.cli import utils from qibocal.cli._base import command from qibocal.protocols.characterization.rabi.amplitude import RabiAmplitudeData from qibocal.protocols.characterization.rabi.ef import RabiAmplitudeEFData @@ -64,8 +66,8 @@ def test_auto_command(runcard, update, platform, backend, tmp_path, request): assert not results.exception assert results.exit_code == 0 if update == "--update": - assert (tmp_path / "new_platform").is_dir() - assert (tmp_path / "data" / f"{protocol}_0" / "platform").is_dir() + assert (tmp_path / utils.UPDATED_PLATFORM).is_dir() + assert (tmp_path / "data" / f"{protocol}_0" / PLATFORM_FOLDER).is_dir() @pytest.mark.parametrize("platform", ["dummy"]) @@ -132,8 +134,8 @@ def test_fit_command(runcard, update, tmp_path): assert results_fit.exit_code == 0 if update == "--update": - assert (tmp_path / "new_platform").is_dir() - assert (tmp_path / "data" / f"{protocol}_0" / "platform").is_dir() + assert (tmp_path / utils.UPDATED_PLATFORM).is_dir() + assert (tmp_path / "data" / f"{protocol}_0" / PLATFORM_FOLDER).is_dir() # generate report with fit and plot results_plot = runner.invoke(command, ["report", str(tmp_path)]) From 356e74220faf02f8e99e797f99b9dbce0d11a47d Mon Sep 17 00:00:00 2001 From: Andrea Date: Mon, 12 Feb 2024 17:52:39 +0400 Subject: [PATCH 4/5] fix: Remove unused request argument --- tests/test_protocols.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_protocols.py b/tests/test_protocols.py index d6d84e150..21dfe693e 100644 --- a/tests/test_protocols.py +++ b/tests/test_protocols.py @@ -42,7 +42,7 @@ def idfn(val): @pytest.mark.parametrize("backend", ["qibolab"]) @pytest.mark.parametrize("update", ["--update", "--no-update"]) @pytest.mark.parametrize("runcard", generate_runcard_single_protocol(), ids=idfn) -def test_auto_command(runcard, update, platform, backend, tmp_path, request): +def test_auto_command(runcard, update, platform, backend, tmp_path): """Test auto command pipeline.""" protocol = runcard["actions"][0]["id"] From 4e6764b37e01f5242f4b3c0f0121aa4c6c25e96c Mon Sep 17 00:00:00 2001 From: Andrea Date: Tue, 13 Feb 2024 10:26:04 +0400 Subject: [PATCH 5/5] refactor: PLATFORM_FOLDER -> PLATFORM_DIR --- src/qibocal/auto/task.py | 6 +++--- tests/test_protocols.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/qibocal/auto/task.py b/src/qibocal/auto/task.py index 5cb9986e9..c2d3c8954 100644 --- a/src/qibocal/auto/task.py +++ b/src/qibocal/auto/task.py @@ -34,7 +34,7 @@ """A number bigger than whatever will be manually typed. But not so insanely big not to fit in a native integer.""" TaskId = tuple[Id, int] """Unique identifier for executed tasks.""" -PLATFORM_FOLDER = "platform" +PLATFORM_DIR = "platform" """Folder where platform will be dumped.""" @@ -240,8 +240,8 @@ def update_platform(self, platform: Platform, update: bool): if self.task.update and update: for qubit in self.task.qubits: self.task.operation.update(self.results, platform, qubit) - (self.datapath / PLATFORM_FOLDER).mkdir(parents=True, exist_ok=True) - dump_platform(platform, self.datapath / PLATFORM_FOLDER) + (self.datapath / PLATFORM_DIR).mkdir(parents=True, exist_ok=True) + dump_platform(platform, self.datapath / PLATFORM_DIR) def validate(self) -> tuple[Optional[TaskId], Optional[dict]]: """Check status of completed and handle Failure using handler.""" diff --git a/tests/test_protocols.py b/tests/test_protocols.py index 21dfe693e..c08c44353 100644 --- a/tests/test_protocols.py +++ b/tests/test_protocols.py @@ -7,7 +7,7 @@ from click.testing import CliRunner from qibolab import create_platform -from qibocal.auto.task import PLATFORM_FOLDER +from qibocal.auto.task import PLATFORM_DIR from qibocal.cli import utils from qibocal.cli._base import command from qibocal.protocols.characterization.rabi.amplitude import RabiAmplitudeData @@ -67,7 +67,7 @@ def test_auto_command(runcard, update, platform, backend, tmp_path): assert results.exit_code == 0 if update == "--update": assert (tmp_path / utils.UPDATED_PLATFORM).is_dir() - assert (tmp_path / "data" / f"{protocol}_0" / PLATFORM_FOLDER).is_dir() + assert (tmp_path / "data" / f"{protocol}_0" / PLATFORM_DIR).is_dir() @pytest.mark.parametrize("platform", ["dummy"]) @@ -135,7 +135,7 @@ def test_fit_command(runcard, update, tmp_path): if update == "--update": assert (tmp_path / utils.UPDATED_PLATFORM).is_dir() - assert (tmp_path / "data" / f"{protocol}_0" / PLATFORM_FOLDER).is_dir() + assert (tmp_path / "data" / f"{protocol}_0" / PLATFORM_DIR).is_dir() # generate report with fit and plot results_plot = runner.invoke(command, ["report", str(tmp_path)])