Skip to content

Commit

Permalink
Bring in changes from the v0.14.0 release
Browse files Browse the repository at this point in the history
Bring in changes from v0.14.0 release
  • Loading branch information
HGSilveri authored Jul 14, 2023
2 parents d823535 + f56a19f commit b1e6393
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 269 deletions.
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.14dev3
0.15dev0
1 change: 0 additions & 1 deletion pulser-pasqal/pulser_pasqal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@

from pulser_pasqal._version import __version__
from pulser_pasqal.backends import EmuFreeBackend, EmuTNBackend
from pulser_pasqal.job_parameters import JobParameters, JobVariables
from pulser_pasqal.pasqal_cloud import PasqalCloud
65 changes: 0 additions & 65 deletions pulser-pasqal/pulser_pasqal/job_parameters.py

This file was deleted.

87 changes: 1 addition & 86 deletions pulser-pasqal/pulser_pasqal/pasqal_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@

import copy
import json
import warnings
from dataclasses import fields
from typing import Any, Optional, Type, cast
from typing import Any, Type, cast

import backoff
import numpy as np
Expand All @@ -40,7 +39,6 @@
from pulser.devices import Device
from pulser.json.abstract_repr.deserializer import deserialize_device
from pulser.result import Result, SampledResult
from pulser_pasqal.job_parameters import JobParameters

EMU_TYPE_TO_CONFIG: dict[pasqal_cloud.EmulatorType, Type[BaseConfig]] = {
pasqal_cloud.EmulatorType.EMU_FREE: EmuFreeConfig,
Expand Down Expand Up @@ -233,86 +231,3 @@ def _convert_configuration(
pasqal_config_kwargs["dt"] = 1.0 / config.sampling_rate

return emu_cls(**pasqal_config_kwargs)

def create_batch(
self,
seq: Sequence,
jobs: list[JobParameters],
emulator: pasqal_cloud.EmulatorType | None = None,
configuration: Optional[pasqal_cloud.BaseConfig] = None,
wait: bool = False,
fetch_results: bool = False,
) -> pasqal_cloud.Batch:
"""Create a new batch and send it to the API.
For Iroise MVP, the batch must contain at least one job and will be
declared as complete immediately.
Args:
seq: Pulser sequence.
jobs: List of jobs to be added to the batch at creation.
emulator: TThe type of emulator to use. If set to None, the device
will be set to the one stored in the serialized sequence.
configuration: Optional extra configuration for emulators.
wait: Whether to wait for the batch to be done.
fetch_results: Whether to download the results. Implies waiting for the batch. # noqa: 501
Returns:
Batch: The new batch that has been created in the database.
"""
with warnings.catch_warnings():
warnings.simplefilter("always", DeprecationWarning)
warnings.warn(
"'PasqalCloud.create_batch()' is deprecated and will be "
"removed after v0.14. To submit jobs to the Pasqal Cloud, "
"use one of the remote backends (eg QPUBackend, EmuTNBacked,"
" EmuFreeBackend) with an open PasqalCloud() connection.",
category=DeprecationWarning,
stacklevel=2,
)

if emulator is None and not isinstance(seq.device, Device):
raise TypeError(
"To be sent to a real QPU, the device of the sequence "
"must be a real device, instance of 'Device'."
)

for params in jobs:
seq.build(**params.variables.get_dict()) # type: ignore

return self._sdk_connection.create_batch(
serialized_sequence=seq.to_abstract_repr(),
jobs=[j.get_dict() for j in jobs],
emulator=emulator,
configuration=configuration,
wait=wait,
fetch_results=fetch_results,
)

def get_batch(
self, id: str, fetch_results: bool = False
) -> pasqal_cloud.Batch:
"""Retrieve a batch's data and all its jobs.
Args:
id: Id of the batch.
fetch_results: Whether to load job results.
Returns:
Batch: The batch stored in the database.
"""
with warnings.catch_warnings():
warnings.simplefilter("always", DeprecationWarning)
warnings.warn(
"'PasqalCloud.get_batch()' is deprecated and will be removed "
"after v0.14. To retrieve the results from a job executed "
"through the Pasqal Cloud, use the RemoteResults instance "
"returned after calling run() on one of the remote backends"
" (eg QPUBackend, EmuTNBacked, EmuFreeBackend) with an open "
"PasqalCloud() connection.",
category=DeprecationWarning,
stacklevel=2,
)
return self._sdk_connection.get_batch(
id=id, fetch_results=fetch_results
)
117 changes: 1 addition & 116 deletions tests/test_pasqal.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@
SubmissionStatus,
)
from pulser.devices import Chadoq2
from pulser.register import Register
from pulser.register.special_layouts import SquareLatticeLayout
from pulser.result import SampledResult
from pulser.sequence import Sequence
from pulser_pasqal import BaseConfig, EmulatorType, Endpoints, PasqalCloud
from pulser_pasqal import EmulatorType, Endpoints, PasqalCloud
from pulser_pasqal.backends import EmuFreeBackend, EmuTNBackend
from pulser_pasqal.job_parameters import JobParameters, JobVariables

root = Path(__file__).parent.parent

Expand Down Expand Up @@ -335,116 +333,3 @@ def test_emulators_run(fixt, seq, emu_cls, parametrized: bool):
configuration=sdk_config,
wait=False,
)


# Deprecated


def check_pasqal_cloud(fixt, seq, emulator, expected_seq_representation):
create_batch_kwargs = dict(
jobs=[JobParameters(runs=10, variables=JobVariables(a=[3, 5]))],
emulator=emulator,
configuration=BaseConfig(
extra_config={
"dt": 10.0,
"precision": "normal",
}
),
wait=True,
fetch_results=False,
)

expected_create_batch_kwargs = {
**create_batch_kwargs,
"jobs": [{"runs": 10, "variables": {"qubits": None, "a": [3, 5]}}],
}

with pytest.warns(UserWarning, match="No declared variables named: a"):
fixt.pasqal_cloud.create_batch(
seq,
**create_batch_kwargs,
)
assert pulser_pasqal.__version__ < "0.15"

fixt.mock_cloud_sdk.create_batch.assert_called_once_with(
serialized_sequence=expected_seq_representation,
**expected_create_batch_kwargs,
)

get_batch_kwargs = dict(
id="uuid",
fetch_results=True,
)
with pytest.deprecated_call():
fixt.pasqal_cloud.get_batch(**get_batch_kwargs)
assert pulser_pasqal.__version__ < "0.15"

fixt.mock_cloud_sdk.get_batch.assert_called_once_with(**get_batch_kwargs)


@pytest.mark.parametrize(
"emulator, device",
[
[emulator, device]
for emulator in (EmulatorType.EMU_FREE, EmulatorType.EMU_TN)
for device in (test_device, virtual_device)
],
)
def test_pasqal_cloud_emu(fixt, emulator, device):
reg = Register.from_coordinates(
[(0, 0), (0, 10)], center=False, prefix="q"
)
seq = Sequence(reg, device)

check_pasqal_cloud(
fixt=fixt,
seq=seq,
emulator=emulator,
expected_seq_representation=seq.to_abstract_repr(),
)


def test_pasqal_cloud_qpu(fixt):
device = test_device

reg = Register.from_coordinates([(0, 0), (0, 10)], prefix="q")
seq = Sequence(reg, device)

check_pasqal_cloud(
fixt=fixt,
seq=seq,
emulator=None,
expected_seq_representation=seq.to_abstract_repr(),
)


def test_virtual_device_on_qpu_error(fixt):
reg = Register.from_coordinates([(0, 0), (0, 10)], prefix="q")
device = Chadoq2.to_virtual()
seq = Sequence(reg, device)

with pytest.deprecated_call(), pytest.raises(
TypeError, match="must be a real device"
):
fixt.pasqal_cloud.create_batch(
seq,
jobs=[JobParameters(runs=10, variables=JobVariables(a=[3, 5]))],
emulator=None,
wait=True,
)


def test_wrong_parameters(fixt):
reg = Register.from_coordinates([(0, 0), (0, 10)], prefix="q")
seq = Sequence(reg, test_device)
seq.declare_variable("unset", dtype=int)

with pytest.warns(
UserWarning, match="No declared variables named: a"
), pytest.raises(TypeError, match="Did not receive values for variables"):
fixt.pasqal_cloud.create_batch(
seq,
jobs=[JobParameters(runs=10, variables=JobVariables(a=[3, 5]))],
emulator=None,
wait=True,
)

0 comments on commit b1e6393

Please sign in to comment.