Skip to content

Commit

Permalink
Merge pull request #688 from qiboteam/rmstart
Browse files Browse the repository at this point in the history
Remove `platform.start()`
  • Loading branch information
andrea-pasquale authored Jan 27, 2024
2 parents 5061441 + 892fe70 commit 82a2125
Show file tree
Hide file tree
Showing 12 changed files with 551 additions and 605 deletions.
1,098 changes: 526 additions & 572 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ classifiers = [

[tool.poetry.dependencies]
python = ">=3.9,<3.12"
qibolab = "^0.1.4"
qibolab = "^0.1.5"
qibo = "^0.2.1"
numpy = "^1.24.0"
scipy = "^1.10.1"
Expand Down
8 changes: 3 additions & 5 deletions src/qibocal/cli/acquisition.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from dataclasses import asdict

import yaml
from qibolab.serialize import dump_runcard
from qibolab.serialize import dump_platform

from ..auto.execute import Executor
from ..auto.history import add_timings_to_meta
Expand Down Expand Up @@ -39,7 +39,8 @@ def acquire(runcard, folder, force):
meta = generate_meta(backend, platform, path)
# dump platform
if backend.name == "qibolab":
dump_runcard(platform, path / PLATFORM)
(path / PLATFORM).mkdir(parents=True, exist_ok=True)
dump_platform(platform, path / PLATFORM)

# dump action runcard
(path / RUNCARD).write_text(yaml.safe_dump(asdict(runcard)))
Expand All @@ -51,8 +52,6 @@ def acquire(runcard, folder, force):
# connect and initialize platform
if platform is not None:
platform.connect()
platform.setup()
platform.start()

# run protocols
list(executor.run(mode=ExecutionMode.acquire))
Expand All @@ -62,7 +61,6 @@ def acquire(runcard, folder, force):

# stop and disconnect platform
if platform is not None:
platform.stop()
platform.disconnect()

# dump updated meta
Expand Down
11 changes: 5 additions & 6 deletions src/qibocal/cli/autocalibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from dataclasses import asdict

import yaml
from qibolab.serialize import dump_runcard
from qibolab.serialize import dump_platform

from ..auto.execute import Executor
from ..auto.history import add_timings_to_meta
Expand Down Expand Up @@ -41,7 +41,8 @@ def autocalibrate(runcard, folder, force, update):
meta = generate_meta(backend, platform, path)
# dump platform
if backend.name == "qibolab":
dump_runcard(platform, path / PLATFORM)
(path / PLATFORM).mkdir(parents=True, exist_ok=True)
dump_platform(platform, path / PLATFORM)

# dump action runcard
(path / RUNCARD).write_text(yaml.safe_dump(asdict(runcard)))
Expand All @@ -54,8 +55,6 @@ def autocalibrate(runcard, folder, force, update):
# connect and initialize platform
if platform is not None:
platform.connect()
platform.setup()
platform.start()

# run protocols
for _ in executor.run(mode=ExecutionMode.autocalibration):
Expand All @@ -70,9 +69,9 @@ def autocalibrate(runcard, folder, force, update):

# stop and disconnect platform
if platform is not None:
platform.stop()
platform.disconnect()

# dump updated runcard
if platform is not None:
dump_runcard(platform, path / UPDATED_PLATFORM)
(path / UPDATED_PLATFORM).mkdir(parents=True, exist_ok=True)
dump_platform(platform, path / UPDATED_PLATFORM)
4 changes: 2 additions & 2 deletions src/qibocal/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from qibocal.utils import allocate_qubits_pairs, allocate_single_qubits

RUNCARD = "runcard.yml"
UPDATED_PLATFORM = "new_platform.yml"
PLATFORM = "platform.yml"
UPDATED_PLATFORM = "new_platform"
PLATFORM = "platform"
META = "meta.json"


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ def _acquisition(
amplitudes[qubit] = ro_pulses[qubit].amplitude

if params.attenuation is not None:
platform.set_attenuation(qubit, params.attenuation)
qubits[qubit].readout.attenuation = params.attenuation

attenuations[qubit] = platform.get_attenuation(qubit)
attenuations[qubit] = qubits[qubit].readout.attenuation

sequence.add(ro_pulses[qubit])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _acquisition(
)

data = TimeOfFlightReadoutData(
windows_size=params.window_size, sampling_rate=platform.settings.sampling_rate
windows_size=params.window_size, sampling_rate=platform.sampling_rate
)

# retrieve and store the results for every qubit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ def _aquisition(
# Patch to get the coupler until the routines use QubitPair
if platform.couplers:
sequence.add(
cz.coupler_pulses(
platform.pairs[tuple(sorted(ordered_pair))].coupler.name
)
cz.coupler_pulses(platform.pairs[tuple(ordered_pair)].coupler.name)
)

if params.parking:
Expand Down
4 changes: 0 additions & 4 deletions src/qibocal/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,13 @@ def virtual_phases(phases: dict[QubitId, float], platform: Platform, pair: Qubit

def CZ_duration(duration: int, platform: Platform, pair: QubitPairId):
"""Update CZ duration for specific pair."""
if pair not in platform.pairs:
pair = (pair[1], pair[0])
for pulse in platform.pairs[pair].native_gates.CZ.pulses:
if pulse.qubit.name == pair[1]:
pulse.duration = int(duration)


def CZ_amplitude(amp: float, platform: Platform, pair: QubitPairId):
"""Update CZ amplitude for specific pair."""
if pair not in platform.pairs:
pair = (pair[1], pair[0])
for pulse in platform.pairs[pair].native_gates.CZ.pulses:
if pulse.qubit.name == pair[1]:
pulse.amplitude = float(amp)
Expand Down
2 changes: 1 addition & 1 deletion src/qibocal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def allocate_qubits_pairs(
platform: Optional[Platform], qubit_pairs_ids: list[tuple[QubitId, QubitId]]
) -> dict[tuple[QubitId, QubitId], QubitPair]:
"""Construct the map from the chosen id pairs to the corresponding physical qubit pairs available on the platform."""
return {tuple(qq): platform.pairs[tuple(sorted(qq))] for qq in qubit_pairs_ids}
return {tuple(qq): platform.pairs[tuple(qq)] for qq in qubit_pairs_ids}


def allocate_single_qubits_lists(
Expand Down
2 changes: 1 addition & 1 deletion tests/runcards/protocols.yml
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ actions:
- id: chevron id
priority: 0
operation: chevron
qubits: [[0, 2],[1,2],[3,2], [2,3]]
qubits: [[0, 2],[1,2]]
parameters:
amplitude_min: 0.1
amplitude_max: 0.6
Expand Down
15 changes: 8 additions & 7 deletions tests/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,15 @@ def test_virtual_phases_update(pair):

@pytest.mark.parametrize("pair", PAIRS)
def test_CZ_params_update(pair):
update.CZ_amplitude(RANDOM_FLOAT, PLATFORM, pair)
update.CZ_duration(RANDOM_INT, PLATFORM, pair)
if hasattr(PLATFORM.pairs[pair].native_gates, "CZ"):
if PLATFORM.pairs[pair].native_gates.CZ is not None:
update.CZ_amplitude(RANDOM_FLOAT, PLATFORM, pair)
update.CZ_duration(RANDOM_INT, PLATFORM, pair)

if PLATFORM.pairs[pair].native_gates.CZ is not None:
for pulse in PLATFORM.pairs[pair].native_gates.CZ.pulses:
if pulse.qubit.name == pair[1]:
assert pulse.duration == RANDOM_INT
assert pulse.amplitude == RANDOM_FLOAT
for pulse in PLATFORM.pairs[pair].native_gates.CZ.pulses:
if pulse.qubit.name == pair[1]:
assert pulse.duration == RANDOM_INT
assert pulse.amplitude == RANDOM_FLOAT


@pytest.mark.parametrize("qubit", QUBITS)
Expand Down

0 comments on commit 82a2125

Please sign in to comment.