Skip to content

Commit

Permalink
Merge branch 'develop' into hs/remove-legacy-noise-model
Browse files Browse the repository at this point in the history
  • Loading branch information
HGSilveri authored Oct 8, 2024
2 parents a25fdd7 + 0f8d435 commit cbd769e
Show file tree
Hide file tree
Showing 17 changed files with 28 additions and 562 deletions.
4 changes: 1 addition & 3 deletions docs/source/apidoc/simulation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ QutipEmulator

:class:`QutipEmulator` is the class to simulate :class:`SequenceSamples`, that are samples of a :class:`Sequence`.
It is possible to simulate directly a :class:`Sequence` object by using the class method
``QutipEmulator.from_sequence``. Since version 0.14.0, the :class:`Simulation` class is deprecated
in favour of :class:`QutipEmulator`.
``QutipEmulator.from_sequence``.

.. autoclass:: pulser_simulation.simulation.QutipEmulator
:members:

.. autoclass:: pulser_simulation.simulation.Simulation

SimConfig
----------------------
Expand Down
78 changes: 2 additions & 76 deletions pulser-core/pulser/backend/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@
from __future__ import annotations

import typing
import warnings
from abc import ABC, abstractmethod
from collections.abc import Callable
from enum import Enum, auto
from functools import wraps
from types import TracebackType
from typing import Any, Mapping, Type, TypedDict, TypeVar, cast
from typing import Any, Mapping, Type, TypedDict, cast

from pulser.backend.abc import Backend
from pulser.devices import Device
Expand All @@ -37,23 +34,8 @@ class JobParams(TypedDict, total=False):
variables: dict[str, Any]


class SubmissionStatus(Enum):
"""Status of a remote submission."""

PENDING = auto()
RUNNING = auto()
DONE = auto()
CANCELED = auto()
TIMED_OUT = auto()
ERROR = auto()
PAUSED = auto()


class BatchStatus(Enum):
"""Status of a batch.
Same as SubmissionStatus, needed because we renamed Submission -> Batch.
"""
"""Status of a batch."""

PENDING = auto()
RUNNING = auto()
Expand Down Expand Up @@ -81,38 +63,9 @@ class RemoteResultsError(Exception):
pass


F = TypeVar("F", bound=Callable)


def _deprecate_submission_id(func: F) -> F:
@wraps(func)
def wrapper(self: RemoteResults, *args: Any, **kwargs: Any) -> Any:
if "submission_id" in kwargs:
# 'batch_id' is the first positional arg so if len(args) > 0,
# then it is being given
if "batch_id" in kwargs or args:
raise ValueError(
"'submission_id' and 'batch_id' cannot be simultaneously"
" specified. Please provide only the 'batch_id'."
)
warnings.warn(
"'submission_id' has been deprecated and replaced by "
"'batch_id'.",
category=DeprecationWarning,
stacklevel=3,
)
kwargs["batch_id"] = kwargs.pop("submission_id")
return func(self, *args, **kwargs)

return cast(F, wrapper)


class RemoteResults(Results):
"""A collection of results obtained through a remote connection.
Warns:
DeprecationWarning: If 'submission_id' is given instead of 'batch_id'.
Args:
batch_id: The ID that identifies the batch linked to the results.
connection: The remote connection over which to get the batch's
Expand All @@ -122,7 +75,6 @@ class RemoteResults(Results):
all jobs are included.
"""

@_deprecate_submission_id
def __init__(
self,
batch_id: str,
Expand All @@ -147,17 +99,6 @@ def results(self) -> tuple[Result, ...]:
"""The actual results, obtained after execution is done."""
return self._results

@property
def _submission_id(self) -> str:
"""The same as the batch ID, kept for backwards compatibility."""
warnings.warn(
"'RemoteResults._submission_id' has been deprecated, please use"
"'RemoteResults.batch_id' instead.",
category=DeprecationWarning,
stacklevel=2,
)
return self._batch_id

@property
def batch_id(self) -> str:
"""The ID of the batch containing these results."""
Expand All @@ -170,21 +111,6 @@ def job_ids(self) -> list[str]:
return self._connection._get_job_ids(self._batch_id)
return self._job_ids

def get_status(self) -> SubmissionStatus:
"""Gets the status of the remote submission.
Warning:
This method has been deprecated, please use
`RemoteResults.get_batch_status()` instead.
"""
warnings.warn(
"'RemoteResults.get_status()' has been deprecated, please use"
"'RemoteResults.get_batch_status()' instead.",
category=DeprecationWarning,
stacklevel=2,
)
return SubmissionStatus[self.get_batch_status().name]

def get_batch_status(self) -> BatchStatus:
"""Gets the status of the batch linked to these results."""
return self._connection._get_batch_status(self._batch_id)
Expand Down
6 changes: 0 additions & 6 deletions pulser-core/pulser/devices/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,13 @@
from pulser.devices._device_datacls import Device, VirtualDevice
from pulser.devices._devices import (
AnalogDevice,
Chadoq2,
DigitalAnalogDevice,
IroiseMVP,
)
from pulser.devices._mock_device import MockDevice

# Registers which devices can be used to avoid definition of custom devices
_mock_devices: tuple[VirtualDevice, ...] = (MockDevice,)
_valid_devices: tuple[Device, ...] = (
Chadoq2,
IroiseMVP,
AnalogDevice,
DigitalAnalogDevice,
)
Expand All @@ -41,6 +37,4 @@
"AnalogDevice",
"DigitalAnalogDevice",
"MockDevice",
"Chadoq2",
"IroiseMVP",
]
32 changes: 0 additions & 32 deletions pulser-core/pulser/devices/_devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Examples of realistic devices."""
import dataclasses

import numpy as np

from pulser.channels import DMM, Raman, Rydberg
Expand Down Expand Up @@ -99,33 +97,3 @@
),
pre_calibrated_layouts=(TriangularLatticeLayout(61, 5),),
)

# Legacy devices (deprecated, should not be used in new sequences)

Chadoq2 = dataclasses.replace(DigitalAnalogDevice, name="Chadoq2")

IroiseMVP = Device(
name="IroiseMVP",
dimensions=2,
rydberg_level=60,
max_atom_num=100,
max_radial_distance=60,
min_atom_distance=5,
channel_objects=(
Rydberg.Global(
max_abs_detuning=2 * np.pi * 4,
max_amp=2 * np.pi * 3,
clock_period=4,
min_duration=16,
max_duration=2**26,
mod_bandwidth=4,
eom_config=RydbergEOM(
limiting_beam=RydbergBeam.RED,
max_limiting_amp=40 * 2 * np.pi,
intermediate_detuning=700 * 2 * np.pi,
mod_bandwidth=24,
controlled_beams=(RydbergBeam.BLUE,),
),
),
),
)
2 changes: 1 addition & 1 deletion pulser-core/pulser/sampler/samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ def to_nested_dict(
) -> dict:
"""Format in the nested dictionary form.
This is the format expected by `pulser_simulation.Simulation()`.
This is the format expected by `pulser_simulation.QutipEmulator()`.
Args:
all_local: Forces all samples to be distributed by their
Expand Down
2 changes: 1 addition & 1 deletion pulser-core/pulser/sequence/_seq_drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ def phase_str(phi: Any) -> str:
alpha=0.3,
hatch="////",
)
else:
else: # pragma: no cover
ax.plot(
t,
ys_mod[i][:total_duration],
Expand Down
95 changes: 2 additions & 93 deletions pulser-core/pulser/sequence/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
from numpy.typing import ArrayLike

import pulser
import pulser.devices as devices
import pulser.math as pm
import pulser.sequence._decorators as seq_decorators
from pulser.channels.base_channel import Channel, States, get_states_from_bases
Expand Down Expand Up @@ -124,25 +123,6 @@ def __init__(
f"'device' must be of type 'BaseDevice', not {type(device)}."
)

with warnings.catch_warnings():
warnings.simplefilter("always")
if device == devices.Chadoq2:
warnings.warn(
"The 'Chadoq2' device has been deprecated. For a "
"similar device combining global and local addressing, "
"consider using `DigitalAnalogDevice`.",
category=DeprecationWarning,
stacklevel=2,
)

if device == devices.IroiseMVP:
warnings.warn(
"The 'IroiseMVP' device has been deprecated. For a "
"similar analog device consider using `AnalogDevice`.",
category=DeprecationWarning,
stacklevel=2,
)

# Checks if register is compatible with the device
if isinstance(register, MappableRegister):
device.validate_layout(register.layout)
Expand Down Expand Up @@ -1625,39 +1605,6 @@ def build(

return seq

def serialize(self, **kwargs: Any) -> str:
"""Serializes the Sequence into a JSON formatted string.
Other Parameters:
kwargs: Valid keyword-arguments for ``json.dumps()``, except for
``cls``.
Returns:
The sequence encoded in a JSON formatted string.
Warning:
This method has been deprecated and is scheduled for removal
in Pulser v1.0.0. For sequence serialization and deserialization,
use ``Sequence.to_abstract_repr()`` and
``Sequence.from_abstract_repr()`` instead.
See Also:
``json.dumps``: Built-in function for serialization to a JSON
formatted string.
"""
with warnings.catch_warnings():
warnings.simplefilter("always")
warnings.warn(
DeprecationWarning(
"`Sequence.serialize()` and `Sequence.deserialize()` have "
"been deprecated and will be removed in Pulser v1.0.0. "
"Use `Sequence.to_abstract_repr()` and "
"`Sequence.from_abstract_repr()` instead."
)
)

return self._serialize(**kwargs)

def _serialize(self, **kwargs: Any) -> str:
"""Serializes the Sequence into a JSON formatted string.
Expand Down Expand Up @@ -1728,44 +1675,6 @@ def to_abstract_repr(
) from e
raise e # pragma: no cover

@staticmethod
def deserialize(obj: str, **kwargs: Any) -> Sequence:
"""Deserializes a JSON formatted string.
Args:
obj: The JSON formatted string to deserialize, coming from
the serialization of a ``Sequence`` through
``Sequence.serialize()``.
Other Parameters:
kwargs: Valid keyword-arguments for ``json.loads()``, except for
``cls`` and ``object_hook``.
Returns:
The deserialized Sequence object.
Warning:
This method has been deprecated and is scheduled for removal
in Pulser v1.0.0. For sequence serialization and deserialization,
use ``Sequence.to_abstract_repr()`` and
``Sequence.from_abstract_repr()`` instead.
See Also:
``json.loads``: Built-in function for deserialization from a JSON
formatted string.
"""
with warnings.catch_warnings():
warnings.simplefilter("always")
warnings.warn(
DeprecationWarning(
"`Sequence.serialize()` and `Sequence.deserialize()` have "
"been deprecated and will be removed in Pulser v1.0.0. "
"Use `Sequence.to_abstract_repr()` and "
"`Sequence.from_abstract_repr()` instead."
)
)
return Sequence._deserialize(obj, **kwargs)

@staticmethod
def _deserialize(obj: str, **kwargs: Any) -> Sequence:
"""Deserializes a JSON formatted string.
Expand Down Expand Up @@ -1886,8 +1795,8 @@ def draw(
need to set this flag to False.
See Also:
Simulation.draw(): Draws the provided sequence and the one used by
the solver.
QutipEmulator.draw(): Draws the provided sequence and the one used
by the solver.
"""
valid_modes = ("input", "output", "input+output")
if mode not in valid_modes:
Expand Down
37 changes: 0 additions & 37 deletions pulser-core/pulser/simulation/__init__.py

This file was deleted.

Loading

0 comments on commit cbd769e

Please sign in to comment.