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

Using custom dummy platform #1101

Merged
merged 13 commits into from
Mar 5, 2025
Merged
Changes from 10 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
2 changes: 1 addition & 1 deletion calibration_scripts/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Runcards
# Calibration scripts

The following folder contains examples of Qibocal scripts.
6 changes: 4 additions & 2 deletions calibration_scripts/rx_calibration.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from qibocal.auto.execute import Executor
from qibocal.cli.report import report

target = 0
platform = "my_platform"
target = [0, 1]

with Executor.open(
"myexec",
path="test_rx_calibration",
platform="dummy",
platform=platform,
targets=[target],
update=True,
force=True,
22 changes: 13 additions & 9 deletions calibration_scripts/single_shot.py
Original file line number Diff line number Diff line change
@@ -14,17 +14,21 @@
programmatically
"""

from pathlib import Path

from qibocal import Executor
from qibocal.cli.report import report
from qibocal.routines import close, init, single_shot_classification

path = Path("test_x")
init(platform="dummy", path=path, force=True)
# ADD HERE PLATFORM AND PATH
platform = "my_platform"
path = "my_path"

# Here
ssc = single_shot_classification(nshots=1000)
print("\nfidelities:\n", ssc.results.fidelity, "\n")
with Executor.open(
"myexec",
path=path,
platform=platform,
update=True,
force=True,
) as e:
ssc = e.single_shot_classification(nshots=1000)
print("\nfidelities:\n", ssc.results.fidelity, "\n")

close()
report(path)
4 changes: 2 additions & 2 deletions doc/source/tutorials/advanced.rst
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ The fastest way consists in using the `Executor` class in the following way
with Executor.open(
"myexec", # arbitrary name for executor
path="test_t1_signal", # path where the data will be stored
platform="dummy", # platform to be used
platform="my_platform", # platform to be used
targets=[0], # qubits on which the experiment will be executed
) as e:

@@ -402,7 +402,7 @@ To launch the protocol a possible runcard could be the following one:

.. code-block:: yaml

platform: dummy
platform: my_platform

targets: [0,1]

15 changes: 15 additions & 0 deletions platforms/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Example platforms

In this folder there are a few example platforms that can be used with Qibocal. To use these platforms, `platforms` folder needs to be added to `QIBOLAB_PLATFORMS` environment variable. If the qibocal directory is cloned in the `HOME` directory this can be done with

```bash
export QIBOLAB_PLATFORMS=~/qibocal/platforms
```

If there is more than one directory containing platforms they can be concatenated in this way.

```bash
export QIBOLAB_PLATFORMS=~/qibocal/platforms:<path_to_platforms>:<another_path_to_platforms>
```

This instructions can be added to the configuration file to avoid repeating the instructions for each session.
1 change: 1 addition & 0 deletions platforms/mock
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -84,7 +84,6 @@ docs-clean = "make -C doc clean"
test-docs = "make -C doc doctest"

[tool.pytest.ini_options]
env = ["QIBO_PLATFORM = dummy"]
testpaths = ['tests/']
addopts = ['--cov=qibocal', '--cov-report=xml', '--cov-report=html']

20 changes: 8 additions & 12 deletions src/qibocal/__init__.py
Original file line number Diff line number Diff line change
@@ -2,18 +2,14 @@

from . import protocols
from .auto.execute import Executor
from .calibration import create_calibration_platform
from .cli import command
from .version import __version__

__all__ = ["Executor", "protocols", "command", "__version__"]

DEFAULT_EXECUTOR = Executor.create(".routines", platform="dummy")
"""Default executor, registered as a qibocal submodule.

It is defined for streamlined usage of qibocal protocols in simple
contexts, where no additional options has to be defined for the
executor.

This is not meant to be used directly, thus is not meant to be publicly
exposed.
"""
__all__ = [
"Executor",
"protocols",
"command",
"__version__",
"create_calibration_platform",
]
7 changes: 2 additions & 5 deletions src/qibocal/auto/execute.py
Original file line number Diff line number Diff line change
@@ -103,9 +103,7 @@ def create(cls, name: str, platform: Union[CalibrationPlatform, str, None] = Non
platform = (
platform
if isinstance(platform, CalibrationPlatform)
else create_calibration_platform(
platform if platform is not None else "dummy"
)
else create_calibration_platform("mock")
)
return cls(
name=name,
@@ -124,7 +122,6 @@ def run_protocol(
"""Run single protocol in ExecutionMode mode."""
task = Task(action=parameters, operation=protocol)
log.info(f"Executing mode {mode} on {task.action.id}.")

completed = task.run(platform=self.platform, targets=self.targets, mode=mode)
self.history.push(completed)

@@ -263,7 +260,7 @@ def init(

assert isinstance(platform, CalibrationPlatform)

backend = construct_backend(backend="qibolab", platform=platform.name)
backend = construct_backend(backend="qibolab", platform=platform)

if update is not None:
self.update = update
2 changes: 1 addition & 1 deletion src/qibocal/auto/runcard.py
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ class Runcard:
"""
backend: str = "qibolab"
"""Qibo backend."""
platform: str = "dummy"
platform: str = "mock"
"""Qibolab platform."""
update: bool = True

139 changes: 0 additions & 139 deletions src/qibocal/calibration/dummy.json

This file was deleted.

11 changes: 2 additions & 9 deletions src/qibocal/calibration/platform.py
Original file line number Diff line number Diff line change
@@ -16,15 +16,8 @@ class CalibrationPlatform(Platform):
@classmethod
def from_platform(cls, platform: Platform):
name = platform.name
if name == "dummy":
calibration = Calibration.model_validate_json(
(Path(__file__).parent / "dummy.json").read_text()
)
else: # pragma: no cover
path = locate_platform(name)
calibration = Calibration.model_validate_json(
(path / CALIBRATION).read_text()
)
path = locate_platform(name)
calibration = Calibration.model_validate_json((path / CALIBRATION).read_text())
# TODO: this is loading twice a platform
return cls(**vars(platform), calibration=calibration)

38 changes: 1 addition & 37 deletions tests/circuit.json
Original file line number Diff line number Diff line change
@@ -23,45 +23,9 @@
],
"_control_qubits": [],
"_class": "X"
},
{
"name": "x",
"init_args": [
2
],
"init_kwargs": {},
"_target_qubits": [
2
],
"_control_qubits": [],
"_class": "X"
},
{
"name": "x",
"init_args": [
3
],
"init_kwargs": {},
"_target_qubits": [
3
],
"_control_qubits": [],
"_class": "X"
},
{
"name": "x",
"init_args": [
4
],
"init_kwargs": {},
"_target_qubits": [
4
],
"_control_qubits": [],
"_class": "X"
}
],
"nqubits": 5,
"nqubits": 2,
"density_matrix": false,
"qibo_version": "0.2.8"
}
2 changes: 1 addition & 1 deletion tests/circuit2q.json
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@
"_class": "H"
}
],
"nqubits": 4,
"nqubits": 2,
"density_matrix": false,
"qibo_version": "0.2.7"
}
Loading