pulser-pasqal 0.20.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,2 @@
1
+ include README.md
2
+ include LICENSE
@@ -0,0 +1,50 @@
1
+ Metadata-Version: 2.2
2
+ Name: pulser-pasqal
3
+ Version: 0.20.2
4
+ Summary: A Pulser extension to execute pulse-level sequences on Pasqal backends.
5
+ Home-page: https://github.com/pasqal-io/pasqal-cloud
6
+ Author: Pulser Development Team
7
+ Maintainer: Pasqal Cloud Services
8
+ Maintainer-email: pcs@pasqal.io
9
+ License: Apache 2.0
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Programming Language :: Python :: 3
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: pasqal-cloud==0.20.2
16
+ Requires-Dist: pulser-core>=1.3
17
+ Requires-Dist: backoff~=2.2
18
+ Dynamic: author
19
+ Dynamic: classifier
20
+ Dynamic: description
21
+ Dynamic: description-content-type
22
+ Dynamic: home-page
23
+ Dynamic: license
24
+ Dynamic: maintainer
25
+ Dynamic: maintainer-email
26
+ Dynamic: requires-dist
27
+ Dynamic: requires-python
28
+ Dynamic: summary
29
+
30
+ # pulser-pasqal
31
+
32
+ [Pulser](https://pypi.org/project/pulser/) is a framework for composing, simulating and executing **pulse** sequences for neutral-atom quantum devices.
33
+
34
+ This is the `pulser-pasqal` extension, which provides the functionalities needed to execute `pulser` sequences on [Pasqal](https://portal.pasqal.cloud/)'s backends.
35
+
36
+ ## Installation
37
+
38
+ The standard Pulser installation,
39
+
40
+ ```bash
41
+ pip install pulser
42
+ ```
43
+
44
+ will automatically install `pulser-pasqal`. If you wish to install it on its own, you can also run
45
+
46
+ ```bash
47
+ pip install pulser-pasqal
48
+ ```
49
+
50
+ Note that `pulser-core` is a requirement of `pulser-pasqal`, so it will be installed if it hasn't been already.
@@ -0,0 +1,21 @@
1
+ # pulser-pasqal
2
+
3
+ [Pulser](https://pypi.org/project/pulser/) is a framework for composing, simulating and executing **pulse** sequences for neutral-atom quantum devices.
4
+
5
+ This is the `pulser-pasqal` extension, which provides the functionalities needed to execute `pulser` sequences on [Pasqal](https://portal.pasqal.cloud/)'s backends.
6
+
7
+ ## Installation
8
+
9
+ The standard Pulser installation,
10
+
11
+ ```bash
12
+ pip install pulser
13
+ ```
14
+
15
+ will automatically install `pulser-pasqal`. If you wish to install it on its own, you can also run
16
+
17
+ ```bash
18
+ pip install pulser-pasqal
19
+ ```
20
+
21
+ Note that `pulser-core` is a requirement of `pulser-pasqal`, so it will be installed if it hasn't been already.
@@ -0,0 +1,22 @@
1
+ # Copyright 2022 Pulser Development Team
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ """Classes for interfacing with Pasqal backends."""
15
+
16
+ from pasqal_cloud import BaseConfig, EmulatorType, Endpoints # noqa: F401
17
+
18
+ from pulser_pasqal._version import __version__ as __version__
19
+ from pulser_pasqal.backends import EmuFreeBackend, EmuTNBackend
20
+ from pulser_pasqal.pasqal_cloud import PasqalCloud
21
+
22
+ __all__ = ["EmuFreeBackend", "EmuTNBackend", "PasqalCloud"]
@@ -0,0 +1 @@
1
+ __version__ = '0.20.2'
@@ -0,0 +1,164 @@
1
+ # Copyright 2023 Pulser Development Team
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ """Defines Pasqal specific backends."""
15
+
16
+ from __future__ import annotations
17
+
18
+ from dataclasses import fields
19
+ from typing import Any, ClassVar
20
+
21
+ import pasqal_cloud
22
+ import pulser
23
+ from pulser.backend.config import EmulatorConfig
24
+ from pulser.backend.remote import JobParams, RemoteBackend, RemoteResults
25
+
26
+ from pulser_pasqal.pasqal_cloud import PasqalCloud
27
+
28
+ DEFAULT_CONFIG_EMU_TN = EmulatorConfig(evaluation_times="Final", sampling_rate=0.1)
29
+ DEFAULT_CONFIG_EMU_FREE = EmulatorConfig(evaluation_times="Final", sampling_rate=0.25)
30
+
31
+
32
+ class PasqalEmulator(RemoteBackend):
33
+ """The base class for a Pasqal emulator backend."""
34
+
35
+ emulator: ClassVar[pasqal_cloud.EmulatorType]
36
+ default_config: ClassVar[EmulatorConfig] = EmulatorConfig()
37
+ configurable_fields: ClassVar[tuple[str, ...]] = ("backend_options",)
38
+
39
+ def __init__(
40
+ self,
41
+ sequence: pulser.Sequence,
42
+ connection: PasqalCloud,
43
+ config: EmulatorConfig | None = None,
44
+ mimic_qpu: bool = False,
45
+ ) -> None:
46
+ """Initializes a new Pasqal emulator backend."""
47
+ super().__init__(sequence, connection, mimic_qpu=mimic_qpu)
48
+ config_ = config or self.default_config
49
+ self._validate_config(config_)
50
+ self._config = config_
51
+ if not isinstance(self._connection, PasqalCloud):
52
+ raise TypeError(
53
+ "The connection to the remote backend must be done"
54
+ " through a 'PasqalCloud' instance."
55
+ )
56
+
57
+ def run(
58
+ self, job_params: list[JobParams] | None = None, wait: bool = False
59
+ ) -> RemoteResults:
60
+ """Executes on the emulator backend through the Pasqal Cloud.
61
+
62
+ Args:
63
+ job_params: A list of parameters for each job to execute. Each
64
+ mapping must contain a defined 'runs' field specifying
65
+ the number of times to run the same sequence. If the sequence
66
+ is parametrized, the values for all the variables necessary
67
+ to build the sequence must be given in it's own mapping, for
68
+ each job, under the 'variables' field.
69
+ wait: Whether to wait until the results of the jobs become
70
+ available. If set to False, the call is non-blocking and the
71
+ obtained results' status can be checked using their `status`
72
+ property.
73
+
74
+ Returns:
75
+ The results, which can be accessed once all sequences have been
76
+ successfully executed.
77
+
78
+ """
79
+ suffix = f" when executing a sequence on {self.__class__.__name__}."
80
+ if not job_params:
81
+ raise ValueError("'job_params' must be specified" + suffix)
82
+ self._type_check_job_params(job_params)
83
+ if any("runs" not in j for j in job_params):
84
+ raise ValueError(
85
+ "All elements of 'job_params' must specify 'runs'" + suffix
86
+ )
87
+
88
+ return super().run(job_params, wait)
89
+
90
+ def _submit_kwargs(self) -> dict[str, Any]:
91
+ """Keyword arguments given to any call to RemoteConnection.submit()."""
92
+ return {
93
+ "batch_id": self._batch_id,
94
+ "emulator": self.emulator,
95
+ "config": self._config,
96
+ "mimic_qpu": self._mimic_qpu,
97
+ }
98
+
99
+ def _validate_config(self, config: EmulatorConfig) -> None:
100
+ if not isinstance(config, EmulatorConfig):
101
+ raise TypeError(
102
+ f"'config' must be of type 'EmulatorConfig', not {type(config)}."
103
+ )
104
+ for field in fields(config):
105
+ if field.name in self.configurable_fields:
106
+ continue
107
+ default_value = getattr(self.default_config, field.name)
108
+ if getattr(config, field.name) != default_value:
109
+ raise NotImplementedError(
110
+ f"'EmulatorConfig.{field.name}' is not configurable in "
111
+ "this backend. It should not be changed from its default "
112
+ f"value of '{default_value}'."
113
+ )
114
+
115
+
116
+ class EmuTNBackend(PasqalEmulator):
117
+ """An emulator backend using tensor network simulation.
118
+
119
+ Configurable fields in EmulatorConfig:
120
+ - sampling_rate: Defaults to 0.1. This value must remain low to use
121
+ this backend efficiently.
122
+ - backend_options:
123
+ - precision (str): The precision of the simulation. Can be "low",
124
+ "normal" or "high". Defaults to "normal".
125
+ - max_bond_dim (int): The maximum bond dimension of the Matrix
126
+ Product State (MPS). Defaults to 500.
127
+
128
+ All other parameters should not be changed from their default values.
129
+
130
+ Args:
131
+ sequence: The sequence to send to the backend.
132
+ connection: An open PasqalCloud connection.
133
+ config: An EmulatorConfig to configure the backend. If not provided,
134
+ the default configuration is used.
135
+ mimic_qpu: Whether to mimic the validations necessary for
136
+ execution on a QPU.
137
+ """
138
+
139
+ emulator = pasqal_cloud.EmulatorType.EMU_TN
140
+ default_config = DEFAULT_CONFIG_EMU_TN
141
+ configurable_fields = ("backend_options", "sampling_rate")
142
+
143
+
144
+ class EmuFreeBackend(PasqalEmulator):
145
+ """An emulator backend using free Hamiltonian time evolution.
146
+
147
+ Configurable fields in EmulatorConfig:
148
+ - backend_options:
149
+ - with_noise (bool): Whether to add noise to the simulation.
150
+ Defaults to False.
151
+
152
+ All other parameters should not be changed from their default values.
153
+
154
+ Args:
155
+ sequence: The sequence to send to the backend.
156
+ connection: An open PasqalCloud connection.
157
+ config: An EmulatorConfig to configure the backend. If not provided,
158
+ the default configuration is used.
159
+ mimic_qpu: Whether to mimic the validations necessary for
160
+ execution on a QPU.
161
+ """
162
+
163
+ emulator = pasqal_cloud.EmulatorType.EMU_FREE
164
+ default_config = DEFAULT_CONFIG_EMU_FREE
@@ -0,0 +1,247 @@
1
+ # Copyright 2022 Pulser Development Team
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ """Allows to connect to PASQAL's cloud platform to run sequences."""
15
+
16
+ from __future__ import annotations
17
+
18
+ from dataclasses import fields
19
+ from typing import Any, Mapping, Type, cast
20
+
21
+ import backoff
22
+ import pasqal_cloud
23
+ from pasqal_cloud.device.configuration import (
24
+ BaseConfig,
25
+ EmuFreeConfig,
26
+ EmuTNConfig,
27
+ )
28
+
29
+ from pulser import Sequence
30
+ from pulser.backend.config import EmulatorConfig
31
+ from pulser.backend.qpu import QPUBackend
32
+ from pulser.backend.remote import (
33
+ BatchStatus,
34
+ JobParams,
35
+ JobStatus,
36
+ RemoteConnection,
37
+ RemoteResults,
38
+ RemoteResultsError,
39
+ )
40
+ from pulser.devices import Device
41
+ from pulser.json.abstract_repr.deserializer import deserialize_device
42
+ from pulser.json.utils import make_json_compatible
43
+ from pulser.result import Result, SampledResult
44
+
45
+ EMU_TYPE_TO_CONFIG: dict[pasqal_cloud.EmulatorType, Type[BaseConfig]] = {
46
+ pasqal_cloud.EmulatorType.EMU_FREE: EmuFreeConfig,
47
+ pasqal_cloud.EmulatorType.EMU_TN: EmuTNConfig,
48
+ }
49
+
50
+ MAX_CLOUD_ATTEMPTS = 5
51
+
52
+ backoff_decorator = backoff.on_exception(
53
+ backoff.fibo, Exception, max_tries=MAX_CLOUD_ATTEMPTS, max_value=60
54
+ )
55
+
56
+
57
+ class PasqalCloud(RemoteConnection):
58
+ """Manager of the connection to PASQAL's cloud platform.
59
+
60
+ The cloud connection enables to run sequences on simulators or on real
61
+ QPUs.
62
+
63
+ Args:
64
+ username: Your username in the PASQAL cloud platform.
65
+ password: The password for your PASQAL cloud platform account.
66
+ project_id: The project ID associated to the account.
67
+ kwargs: Additional arguments to provide to the pasqal_cloud.SDK()
68
+ """
69
+
70
+ def __init__(
71
+ self,
72
+ username: str = "",
73
+ password: str = "",
74
+ project_id: str = "",
75
+ **kwargs: Any,
76
+ ):
77
+ """Initializes a connection to the Pasqal cloud platform."""
78
+ self._sdk_connection = pasqal_cloud.SDK(
79
+ username=username,
80
+ password=password,
81
+ project_id=project_id,
82
+ **kwargs,
83
+ )
84
+
85
+ def submit(
86
+ self,
87
+ sequence: Sequence,
88
+ wait: bool = False,
89
+ open: bool = False,
90
+ batch_id: str | None = None,
91
+ **kwargs: Any,
92
+ ) -> RemoteResults:
93
+ """Submits the sequence for execution on a remote Pasqal backend."""
94
+ sequence = self._add_measurement_to_sequence(sequence)
95
+ emulator = kwargs.get("emulator", None)
96
+ job_params: list[JobParams] = make_json_compatible(kwargs.get("job_params", []))
97
+ mimic_qpu: bool = kwargs.get("mimic_qpu", False)
98
+ if emulator is None or mimic_qpu:
99
+ sequence = self.update_sequence_device(sequence)
100
+ QPUBackend.validate_job_params(job_params, sequence.device.max_runs)
101
+
102
+ if sequence.is_parametrized() or sequence.is_register_mappable():
103
+ for params in job_params:
104
+ vars = params.get("variables", {})
105
+ sequence.build(**vars)
106
+
107
+ configuration = self._convert_configuration(
108
+ config=kwargs.get("config", None),
109
+ emulator=emulator,
110
+ strict_validation=mimic_qpu,
111
+ )
112
+
113
+ # If batch_id is not empty, then we can submit new jobs to a
114
+ # batch we just created otherwise, create a new one with
115
+ # _sdk_connection.create_batch()
116
+ if batch_id:
117
+ submit_jobs_fn = backoff_decorator(self._sdk_connection.add_jobs)
118
+ old_job_ids = self._get_job_ids(batch_id)
119
+ batch = submit_jobs_fn(
120
+ batch_id,
121
+ jobs=job_params or [], # type: ignore[arg-type]
122
+ )
123
+ new_job_ids = [
124
+ job_id
125
+ for job_id in self._get_job_ids(batch_id)
126
+ if job_id not in old_job_ids
127
+ ]
128
+ else:
129
+ create_batch_fn = backoff_decorator(self._sdk_connection.create_batch)
130
+ batch = create_batch_fn(
131
+ serialized_sequence=sequence.to_abstract_repr(),
132
+ jobs=job_params or [], # type: ignore[arg-type]
133
+ emulator=emulator,
134
+ configuration=configuration,
135
+ wait=wait,
136
+ open=open,
137
+ )
138
+ new_job_ids = self._get_job_ids(batch.id)
139
+ return RemoteResults(batch.id, self, job_ids=new_job_ids)
140
+
141
+ @backoff_decorator
142
+ def fetch_available_devices(self) -> dict[str, Device]:
143
+ """Fetches the devices available through this connection."""
144
+ abstract_devices = self._sdk_connection.get_device_specs_dict()
145
+ return {
146
+ name: cast(Device, deserialize_device(dev_str))
147
+ for name, dev_str in abstract_devices.items()
148
+ }
149
+
150
+ def _fetch_result(
151
+ self, batch_id: str, job_ids: list[str] | None
152
+ ) -> tuple[Result, ...]:
153
+ # For now, the results are always sampled results
154
+ jobs = self._query_job_progress(batch_id)
155
+
156
+ if job_ids is None:
157
+ job_ids = list(jobs.keys())
158
+
159
+ results: list[Result] = []
160
+ for id in job_ids:
161
+ status, result = jobs[id]
162
+ if status in {JobStatus.PENDING, JobStatus.RUNNING}:
163
+ raise RemoteResultsError(
164
+ f"The results are not yet available, job {id} status is {status}."
165
+ )
166
+ if result is None:
167
+ raise RemoteResultsError(f"No results found for job {id}.")
168
+ results.append(result)
169
+
170
+ return tuple(results)
171
+
172
+ def _query_job_progress(
173
+ self, batch_id: str
174
+ ) -> Mapping[str, tuple[JobStatus, Result | None]]:
175
+ get_batch_fn = backoff_decorator(self._sdk_connection.get_batch)
176
+ batch = get_batch_fn(id=batch_id)
177
+
178
+ assert isinstance(batch.sequence_builder, str)
179
+ seq_builder = Sequence.from_abstract_repr(batch.sequence_builder)
180
+ reg = seq_builder.get_register(include_mappable=True)
181
+ all_qubit_ids = reg.qubit_ids
182
+ meas_basis = seq_builder.get_measurement_basis()
183
+
184
+ results: dict[str, tuple[JobStatus, Result | None]] = {}
185
+
186
+ for job in batch.ordered_jobs:
187
+ vars = job.variables
188
+ size: int | None = None
189
+ if vars and "qubits" in vars:
190
+ size = len(vars["qubits"])
191
+ if job.result is None:
192
+ results[job.id] = (JobStatus[job.status], None)
193
+ else:
194
+ results[job.id] = (
195
+ JobStatus[job.status],
196
+ SampledResult(
197
+ atom_order=all_qubit_ids[slice(size)],
198
+ meas_basis=meas_basis,
199
+ bitstring_counts=job.result,
200
+ ),
201
+ )
202
+ return results
203
+
204
+ @backoff_decorator
205
+ def _get_batch_status(self, batch_id: str) -> BatchStatus:
206
+ """Gets the status of a batch from its ID."""
207
+ batch = self._sdk_connection.get_batch(id=batch_id)
208
+ return BatchStatus[batch.status]
209
+
210
+ @backoff_decorator
211
+ def _get_job_ids(self, batch_id: str) -> list[str]:
212
+ """Gets all the job IDs within a batch."""
213
+ batch = self._sdk_connection.get_batch(id=batch_id)
214
+ return [job.id for job in batch.ordered_jobs]
215
+
216
+ def _convert_configuration(
217
+ self,
218
+ config: EmulatorConfig | None,
219
+ emulator: pasqal_cloud.EmulatorType | None,
220
+ strict_validation: bool = False,
221
+ ) -> pasqal_cloud.BaseConfig | None:
222
+ """Converts a backend configuration into a pasqal_cloud.BaseConfig."""
223
+ if emulator is None or config is None:
224
+ return None
225
+ emu_cls = EMU_TYPE_TO_CONFIG[emulator]
226
+ backend_options = config.backend_options.copy()
227
+ pasqal_config_kwargs = {}
228
+ for field in fields(emu_cls):
229
+ pasqal_config_kwargs[field.name] = backend_options.pop(
230
+ field.name, field.default
231
+ )
232
+ # We pass the remaining backend options to "extra_config"
233
+ if backend_options:
234
+ pasqal_config_kwargs["extra_config"] = backend_options
235
+ if emulator == pasqal_cloud.EmulatorType.EMU_TN:
236
+ pasqal_config_kwargs["dt"] = 1.0 / config.sampling_rate
237
+
238
+ pasqal_config_kwargs["strict_validation"] = strict_validation
239
+ return emu_cls(**pasqal_config_kwargs)
240
+
241
+ def supports_open_batch(self) -> bool:
242
+ """Flag to confirm this class can support creating an open batch."""
243
+ return True
244
+
245
+ def _close_batch(self, batch_id: str) -> None:
246
+ """Closes the batch on pasqal cloud associated with the batch ID."""
247
+ self._sdk_connection.close_batch(batch_id)
File without changes
@@ -0,0 +1,50 @@
1
+ Metadata-Version: 2.2
2
+ Name: pulser-pasqal
3
+ Version: 0.20.2
4
+ Summary: A Pulser extension to execute pulse-level sequences on Pasqal backends.
5
+ Home-page: https://github.com/pasqal-io/pasqal-cloud
6
+ Author: Pulser Development Team
7
+ Maintainer: Pasqal Cloud Services
8
+ Maintainer-email: pcs@pasqal.io
9
+ License: Apache 2.0
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Programming Language :: Python :: 3
12
+ Requires-Python: >=3.8
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: pasqal-cloud==0.20.2
16
+ Requires-Dist: pulser-core>=1.3
17
+ Requires-Dist: backoff~=2.2
18
+ Dynamic: author
19
+ Dynamic: classifier
20
+ Dynamic: description
21
+ Dynamic: description-content-type
22
+ Dynamic: home-page
23
+ Dynamic: license
24
+ Dynamic: maintainer
25
+ Dynamic: maintainer-email
26
+ Dynamic: requires-dist
27
+ Dynamic: requires-python
28
+ Dynamic: summary
29
+
30
+ # pulser-pasqal
31
+
32
+ [Pulser](https://pypi.org/project/pulser/) is a framework for composing, simulating and executing **pulse** sequences for neutral-atom quantum devices.
33
+
34
+ This is the `pulser-pasqal` extension, which provides the functionalities needed to execute `pulser` sequences on [Pasqal](https://portal.pasqal.cloud/)'s backends.
35
+
36
+ ## Installation
37
+
38
+ The standard Pulser installation,
39
+
40
+ ```bash
41
+ pip install pulser
42
+ ```
43
+
44
+ will automatically install `pulser-pasqal`. If you wish to install it on its own, you can also run
45
+
46
+ ```bash
47
+ pip install pulser-pasqal
48
+ ```
49
+
50
+ Note that `pulser-core` is a requirement of `pulser-pasqal`, so it will be installed if it hasn't been already.
@@ -0,0 +1,15 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ pyproject.toml
5
+ setup.py
6
+ pulser_pasqal/__init__.py
7
+ pulser_pasqal/_version.py
8
+ pulser_pasqal/backends.py
9
+ pulser_pasqal/pasqal_cloud.py
10
+ pulser_pasqal/py.typed
11
+ pulser_pasqal.egg-info/PKG-INFO
12
+ pulser_pasqal.egg-info/SOURCES.txt
13
+ pulser_pasqal.egg-info/dependency_links.txt
14
+ pulser_pasqal.egg-info/requires.txt
15
+ pulser_pasqal.egg-info/top_level.txt
@@ -0,0 +1,3 @@
1
+ pasqal-cloud==0.20.2
2
+ pulser-core>=1.3
3
+ backoff~=2.2
@@ -0,0 +1 @@
1
+ pulser_pasqal
@@ -0,0 +1,8 @@
1
+ [build-system]
2
+ requires = ["setuptools>=42", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [tool.ruff]
6
+ [tool.ruff.lint.isort]
7
+
8
+ known-third-party = ["pasqal-cloud"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,68 @@
1
+ # Copyright 2022 Pulser Development Team
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ import os
15
+ from pathlib import Path
16
+
17
+ from setuptools import find_packages, setup
18
+
19
+ distribution_name = "pulser-pasqal" # The name on PyPI
20
+ package_name = "pulser_pasqal" # The main module name
21
+ description = "A Pulser extension to execute pulse-level sequences on Pasqal backends."
22
+ current_directory = Path(__file__).parent
23
+
24
+ # Reads the version from the VERSION.txt file
25
+ with open(current_directory.parent / "VERSION.txt", "r", encoding="utf-8") as f:
26
+ __version__ = f.read().strip()
27
+
28
+ # Changes to the directory where setup.py is
29
+ os.chdir(current_directory)
30
+
31
+ # Stashes the source code for the local version file
32
+ local_version_fpath = Path(package_name) / "_version.py"
33
+ with open(local_version_fpath, "r", encoding="utf-8") as f:
34
+ stashed_version_source = f.read()
35
+
36
+ # Overwrites the _version.py for the source distribution (reverted at the end)
37
+ with open(local_version_fpath, "w", encoding="utf-8") as f:
38
+ f.write(f"__version__ = '{__version__}'\n")
39
+
40
+ setup(
41
+ name=distribution_name,
42
+ version=__version__,
43
+ packages=find_packages(),
44
+ package_data={package_name: ["py.typed"]},
45
+ include_package_data=True,
46
+ description=description,
47
+ long_description=open("README.md", "r", encoding="utf-8").read(),
48
+ long_description_content_type="text/markdown",
49
+ author="Pulser Development Team",
50
+ maintainer="Pasqal Cloud Services",
51
+ maintainer_email="pcs@pasqal.io",
52
+ python_requires=">=3.8",
53
+ license="Apache 2.0",
54
+ classifiers=[
55
+ "Development Status :: 3 - Alpha",
56
+ "Programming Language :: Python :: 3",
57
+ ],
58
+ url="https://github.com/pasqal-io/pasqal-cloud",
59
+ install_requires=[
60
+ f"pasqal-cloud == {__version__}",
61
+ "pulser-core >= 1.3",
62
+ "backoff ~= 2.2",
63
+ ],
64
+ )
65
+
66
+ # Restores the original source code of _version.py
67
+ with open(local_version_fpath, "w", encoding="utf-8") as f:
68
+ f.write(stashed_version_source)