Skip to content

Commit

Permalink
Merge pull request #710 from qiboteam/dump_platform_iteratively
Browse files Browse the repository at this point in the history
Dump platform iteratively
  • Loading branch information
andrea-pasquale authored Feb 13, 2024
2 parents edb69c5 + 4e6764b commit 89098d7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/qibocal/auto/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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_DIR = "platform"
"""Folder where platform will be dumped."""


@dataclass
Expand Down Expand Up @@ -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_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."""
Expand Down
3 changes: 0 additions & 3 deletions tests/runcards/protocols.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -517,7 +515,6 @@ actions:
- id: flipping
priority: 0
operation: flipping
update: false
parameters:
nflips_max: 5
nflips_step: 1
Expand Down
15 changes: 15 additions & 0 deletions tests/test_protocols.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from click.testing import CliRunner
from qibolab import create_platform

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
from qibocal.protocols.characterization.rabi.ef import RabiAmplitudeEFData
Expand Down Expand Up @@ -43,6 +45,7 @@ def idfn(val):
def test_auto_command(runcard, update, platform, backend, tmp_path):
"""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(
Expand All @@ -62,13 +65,17 @@ 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 / utils.UPDATED_PLATFORM).is_dir()
assert (tmp_path / "data" / f"{protocol}_0" / PLATFORM_DIR).is_dir()


@pytest.mark.parametrize("platform", ["dummy"])
@pytest.mark.parametrize("backend", ["qibolab"])
@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()

Expand All @@ -89,17 +96,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()

Expand All @@ -123,10 +133,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 / utils.UPDATED_PLATFORM).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)])
assert not results_plot.exception
assert results_plot.exit_code == 0
assert (tmp_path / "index.html").is_file()


def test_extract_rabi():
Expand Down

0 comments on commit 89098d7

Please sign in to comment.