From 523e916f974c6b89842608857559c3aa805c984a Mon Sep 17 00:00:00 2001 From: HGSilveri Date: Thu, 13 Jul 2023 17:53:00 +0200 Subject: [PATCH 1/3] Bump version to 0.14.0 --- VERSION.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION.txt b/VERSION.txt index a37900288..a803cc227 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -0.14dev3 +0.14.0 From 3df29bd654093e8507882022c6f1136e9f46994f Mon Sep 17 00:00:00 2001 From: HGSilveri Date: Thu, 13 Jul 2023 18:33:44 +0200 Subject: [PATCH 2/3] Bump version to 0.15dev0 --- VERSION.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION.txt b/VERSION.txt index a803cc227..0fc46372f 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1 +1 @@ -0.14.0 +0.15dev0 From f56a19fe0a8d8853bb43d3369387002497c85ae9 Mon Sep 17 00:00:00 2001 From: HGSilveri Date: Thu, 13 Jul 2023 18:48:01 +0200 Subject: [PATCH 3/3] Remove expired deprecations in pulser-pasqal --- pulser-pasqal/pulser_pasqal/__init__.py | 1 - pulser-pasqal/pulser_pasqal/job_parameters.py | 65 ---------- pulser-pasqal/pulser_pasqal/pasqal_cloud.py | 87 +------------ tests/test_pasqal.py | 117 +----------------- 4 files changed, 2 insertions(+), 268 deletions(-) delete mode 100644 pulser-pasqal/pulser_pasqal/job_parameters.py diff --git a/pulser-pasqal/pulser_pasqal/__init__.py b/pulser-pasqal/pulser_pasqal/__init__.py index 6f9c57bf3..8f1020532 100644 --- a/pulser-pasqal/pulser_pasqal/__init__.py +++ b/pulser-pasqal/pulser_pasqal/__init__.py @@ -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 diff --git a/pulser-pasqal/pulser_pasqal/job_parameters.py b/pulser-pasqal/pulser_pasqal/job_parameters.py deleted file mode 100644 index d2ddb0a8b..000000000 --- a/pulser-pasqal/pulser_pasqal/job_parameters.py +++ /dev/null @@ -1,65 +0,0 @@ -# Copyright 2022 Pulser Development Team -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -"""Parameters to build a sequence sent to the PASQAL cloud plaftorm.""" -from __future__ import annotations - -import dataclasses -from typing import Dict, Mapping, Optional, Union - -from numpy.typing import ArrayLike - -from pulser.register import QubitId - -JobVariablesDict = Dict[str, Union[ArrayLike, Optional[Mapping[QubitId, int]]]] - - -class JobVariables: - """Variables to build the sequence.""" - - def __init__( - self, - qubits: Optional[Mapping[QubitId, int]] = None, - **vars: Union[ArrayLike, float, int], - ): - """Initializes the JobVariables class. - - Args: - qubits: A mapping between qubit IDs and trap IDs used to define - the register. Must only be provided when the sequence is - initialized with a MappableRegister. - vars: The values for all the variables declared in this Sequence - instance, indexed by the name given upon declaration. Check - ``Sequence.declared_variables`` to see all the variables. - """ - self._qubits = qubits - self._vars = vars - - def get_dict(self) -> JobVariablesDict: - """Creates a dictionary used by the Sequence building and the cloud.""" - return {"qubits": self._qubits, **self._vars} - - -@dataclasses.dataclass -class JobParameters: - """Parameters representing a job to build the sequence.""" - - runs: int - variables: JobVariables - - def get_dict(self) -> dict[str, Union[int, JobVariablesDict]]: - """Creates a dictionary to send to the cloud.""" - return dict( - runs=self.runs, - variables=self.variables.get_dict(), - ) diff --git a/pulser-pasqal/pulser_pasqal/pasqal_cloud.py b/pulser-pasqal/pulser_pasqal/pasqal_cloud.py index 1173e472d..5d385f4e1 100644 --- a/pulser-pasqal/pulser_pasqal/pasqal_cloud.py +++ b/pulser-pasqal/pulser_pasqal/pasqal_cloud.py @@ -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 @@ -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, @@ -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 - ) diff --git a/tests/test_pasqal.py b/tests/test_pasqal.py index ae670acf4..5124c2893 100644 --- a/tests/test_pasqal.py +++ b/tests/test_pasqal.py @@ -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 @@ -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, - )