emu-base 1.2.3__py3-none-any.whl → 1.2.5__py3-none-any.whl

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.
emu_base/__init__.py CHANGED
@@ -44,4 +44,4 @@ __all__ = [
44
44
  "DEFAULT_MAX_KRYLOV_DIM",
45
45
  ]
46
46
 
47
- __version__ = "1.2.3"
47
+ __version__ = "1.2.5"
@@ -3,6 +3,11 @@ from pulser.noise_model import NoiseModel
3
3
  import logging
4
4
  import sys
5
5
  import pathlib
6
+ from typing import TYPE_CHECKING
7
+ import torch
8
+
9
+ if TYPE_CHECKING:
10
+ from emu_base.base_classes.callback import Callback
6
11
 
7
12
 
8
13
  class BackendConfig:
@@ -30,8 +35,7 @@ class BackendConfig:
30
35
  def __init__(
31
36
  self,
32
37
  *,
33
- # "Callback" is a forward type reference because of the circular import otherwise.
34
- observables: list["Callback"] | None = None, # type: ignore # noqa: F821
38
+ observables: list[Callback] | None = None,
35
39
  with_modulation: bool = False,
36
40
  noise_model: NoiseModel = None,
37
41
  interaction_matrix: list[list[float]] | None = None,
@@ -47,29 +51,36 @@ class BackendConfig:
47
51
  self.with_modulation = with_modulation
48
52
  self.noise_model = noise_model
49
53
 
50
- if interaction_matrix is not None and (
51
- not isinstance(interaction_matrix, list)
52
- or not isinstance(interaction_matrix[0], list)
54
+ if interaction_matrix is not None and not (
55
+ isinstance(interaction_matrix, list)
56
+ and isinstance(interaction_matrix[0], list)
57
+ and isinstance(interaction_matrix[0][0], float)
53
58
  ):
54
59
  raise ValueError(
55
60
  "Interaction matrix must be provided as a Python list of lists of floats"
56
61
  )
57
62
 
63
+ if interaction_matrix is not None:
64
+ int_mat = torch.tensor(interaction_matrix)
65
+ tol = 1e-10
66
+ if not (
67
+ int_mat.numel() != 0
68
+ and torch.all(torch.isreal(int_mat))
69
+ and int_mat.dim() == 2
70
+ and int_mat.shape[0] == int_mat.shape[1]
71
+ and torch.allclose(int_mat, int_mat.T, atol=tol)
72
+ and torch.norm(torch.diag(int_mat)) < tol
73
+ ):
74
+ raise ValueError("Interaction matrix is not symmetric and zero diag")
75
+
58
76
  self.interaction_matrix = interaction_matrix
59
77
  self.interaction_cutoff = interaction_cutoff
60
78
  self.logger = logging.getLogger("global_logger")
61
- if log_file is None:
62
- logging.basicConfig(
63
- level=log_level, format="%(message)s", stream=sys.stdout, force=True
64
- ) # default to stream = sys.stderr
65
- else:
66
- logging.basicConfig(
67
- level=log_level,
68
- format="%(message)s",
69
- filename=str(log_file),
70
- filemode="w",
71
- force=True,
72
- )
79
+ self.log_file = log_file
80
+ self.log_level = log_level
81
+
82
+ self.init_logging()
83
+
73
84
  if noise_model is not None and (
74
85
  noise_model.runs != 1
75
86
  or noise_model.samples_per_run != 1
@@ -79,3 +90,17 @@ class BackendConfig:
79
90
  self.logger.warning(
80
91
  "Warning: The runs and samples_per_run values of the NoiseModel are ignored!"
81
92
  )
93
+
94
+ def init_logging(self) -> None:
95
+ if self.log_file is None:
96
+ logging.basicConfig(
97
+ level=self.log_level, format="%(message)s", stream=sys.stdout, force=True
98
+ ) # default to stream = sys.stderr
99
+ else:
100
+ logging.basicConfig(
101
+ level=self.log_level,
102
+ format="%(message)s",
103
+ filename=str(self.log_file),
104
+ filemode="w",
105
+ force=True,
106
+ )
@@ -21,7 +21,7 @@ class KrylovExpResult:
21
21
 
22
22
 
23
23
  def krylov_exp_impl(
24
- op: Callable,
24
+ op: Callable[[torch.Tensor], torch.Tensor],
25
25
  v: torch.Tensor,
26
26
  is_hermitian: bool, # note: complex-proportional to its adjoint is enough
27
27
  exp_tolerance: float,
@@ -103,7 +103,7 @@ def krylov_exp_impl(
103
103
 
104
104
 
105
105
  def krylov_exp(
106
- op: torch.Tensor,
106
+ op: Callable[[torch.Tensor], torch.Tensor],
107
107
  v: torch.Tensor,
108
108
  exp_tolerance: float,
109
109
  norm_tolerance: float,
@@ -62,7 +62,7 @@ def _xy_interaction(sequence: pulser.Sequence) -> torch.Tensor:
62
62
  qubit_positions = _get_qubit_positions(sequence.register)
63
63
  interaction_matrix = torch.zeros(num_qubits, num_qubits)
64
64
  mag_field = torch.tensor(sequence.magnetic_field) # by default [0.0,0.0,30.0]
65
- mag_norm = torch.norm(mag_field)
65
+ mag_norm = torch.linalg.norm(mag_field)
66
66
 
67
67
  for numi in range(len(qubit_positions)):
68
68
  for numj in range(numi + 1, len(qubit_positions)):
@@ -70,7 +70,10 @@ def _xy_interaction(sequence: pulser.Sequence) -> torch.Tensor:
70
70
  if mag_norm >= 1e-8: # selected by hand
71
71
  cosine = torch.dot(
72
72
  (qubit_positions[numi] - qubit_positions[numj]), mag_field
73
- ) / (torch.norm(qubit_positions[numi] - qubit_positions[numj]) * mag_norm)
73
+ ) / (
74
+ torch.linalg.norm(qubit_positions[numi] - qubit_positions[numj])
75
+ * mag_norm
76
+ )
74
77
 
75
78
  interaction_matrix[numi][numj] = (
76
79
  c3 # check this value with pulser people
@@ -155,17 +158,26 @@ def _extract_omega_delta_phi(
155
158
  global_times |= set(i for i in range(slot.ti, slot.tf))
156
159
 
157
160
  step = 0
158
- t = int((step + 1 / 2) * dt)
161
+ t = (step + 1 / 2) * dt
159
162
 
160
163
  while t < max_duration:
161
164
  for q_pos, q_id in enumerate(sequence.register.qubit_ids):
162
- omega[step, q_pos] = locals_a_d_p[q_id]["amp"][t]
163
- delta[step, q_pos] = locals_a_d_p[q_id]["det"][t]
164
- phi[step, q_pos] = locals_a_d_p[q_id]["phase"][t]
165
+ omega[step, q_pos] = (
166
+ locals_a_d_p[q_id]["amp"][math.floor(t)]
167
+ + locals_a_d_p[q_id]["amp"][math.ceil(t)]
168
+ ) / 2.0
169
+ delta[step, q_pos] = (
170
+ locals_a_d_p[q_id]["det"][math.floor(t)]
171
+ + locals_a_d_p[q_id]["det"][math.ceil(t)]
172
+ ) / 2.0
173
+ phi[step, q_pos] = (
174
+ locals_a_d_p[q_id]["phase"][math.floor(t)]
175
+ + locals_a_d_p[q_id]["phase"][math.ceil(t)]
176
+ ) / 2.0
165
177
  if t in global_times:
166
178
  omega[step] *= waist_factors
167
179
  step += 1
168
- t = int((step + 1 / 2) * dt)
180
+ t = (step + 1 / 2) * dt
169
181
 
170
182
  return omega, delta, phi
171
183
 
emu_base/utils.py CHANGED
@@ -1,9 +1,9 @@
1
1
  import torch
2
2
 
3
3
 
4
- def dist2(left: torch.tensor, right: torch.tensor) -> torch.Tensor:
5
- return torch.norm(left - right) ** 2
4
+ def dist2(left: torch.Tensor, right: torch.Tensor) -> float:
5
+ return torch.dist(left, right).item() ** 2
6
6
 
7
7
 
8
- def dist3(left: torch.tensor, right: torch.tensor) -> torch.Tensor:
9
- return torch.norm(left - right) ** 3
8
+ def dist3(left: torch.Tensor, right: torch.Tensor) -> float:
9
+ return torch.dist(left, right).item() ** 3
@@ -0,0 +1,102 @@
1
+ Metadata-Version: 2.4
2
+ Name: emu-base
3
+ Version: 1.2.5
4
+ Summary: Pasqal base classes for emulators
5
+ Author-email: Anton Quelle <anton.quelle@pasqal.com>, Mauro Mendizabal <mauro.mendizabal-pico@pasqal.com>, Stefano Grava <stefano.grava@pasqal.com>, Pablo Le Henaff <pablo.le-henaff@pasqal.com>
6
+ License: PASQAL OPEN-SOURCE SOFTWARE LICENSE AGREEMENT (MIT-derived)
7
+
8
+ The author of the License is:
9
+ Pasqal, a Société par Actions Simplifiée (Simplified Joint Stock Company) registered under number 849 441 522 at the Registre du commerce et des sociétés (Trade and Companies Register) of Evry – France, headquartered at 7 rue Leonard de Vinci – 91300 – Massy – France, duly represented by its Président, M. Georges-Olivier REYMOND,
10
+
11
+ Hereafter referred to as « the Licensor »
12
+
13
+ - Permission is hereby granted, free of charge, to any person obtaining a copy of this software (the “Licensee”) and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
14
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. The Software is “as is”, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and non-infringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise arising from, out of or in connection with the Software or the use or other dealings in the Software.
15
+
16
+ - If use of the Software leads to the necessary use of any patent of the Licensor and/or any of its Affiliates (defined as a company owned or controlled by the Licensor), the Licensee is granted a royalty-free license, in any country where such patent is in force, to use the object of such patent; or use the process covered by such patent,
17
+
18
+ - Such a patent license is granted for internal research or academic use of the Licensee's, which includes use by employees and students of the Licensee, acting on behalf of the Licensee, for research purposes only.
19
+
20
+ - The License is governed by the laws of France. Any dispute relating to the License, notably its execution, performance and/or termination shall be brought to, heard and tried by the Tribunal Judiciaire de Paris, regardless of the rules of jurisdiction in the matter.
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: Implementation :: CPython
23
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
24
+ Requires-Python: >=3.10
25
+ Requires-Dist: pulser-core==1.3.*
26
+ Requires-Dist: torch==2.5.0
27
+ Description-Content-Type: text/markdown
28
+
29
+ <div align="center">
30
+ <img src="docs/logos/LogoTaglineSoftGreen.svg">
31
+
32
+ # Emu-MPS
33
+ </div>
34
+
35
+ **Emu-mps** is a backend for the [Pulser low-level Quantum Programming toolkit](https://pulser.readthedocs.io) that lets you run Quantum Algorithms on a simulated device, using GPU acceleration if available. More in depth, emu-mps is designed to **emu**late the dynamics of programmable arrays of neutral atoms, with matrix product states (**mps**). While benchmarking is incomplete as of this writing, early results suggest that this design makes emu-mps faster and more memory-efficient than previous generations of quantum emulators at running simulations with large numbers of qubits.
36
+
37
+ As of this writing, Emu-MPS is provided for Linux and macOS but will not work under Windows.
38
+
39
+ ## Installation
40
+
41
+ **Warning:** installing emu-mps will update pulser-core
42
+
43
+ ### Using `hatch`, `uv` or any pyproject-compatible Python manager
44
+
45
+ To add `emu-mps` to your project, edit your `pyproject.toml` to add the line
46
+
47
+ ```toml
48
+ "emu-mps"
49
+ ```
50
+
51
+ to the list of `dependencies`.
52
+
53
+
54
+ ### Using `pip` or `pipx`
55
+ To install the `pipy` package using `pip` or `pipx`
56
+
57
+ 1. Create a `venv` if that's not done yet
58
+
59
+ ```sh
60
+ $ python -m venv venv
61
+
62
+ ```
63
+
64
+ 2. Enter the venv
65
+
66
+ If you're running Unix:
67
+
68
+ ```sh
69
+ $ . venv/bin/activate
70
+ ```
71
+
72
+ If you're running Windows:
73
+
74
+ ```sh
75
+ C:\> /path/to/new/virtual/environment/Scripts/activate
76
+ ```
77
+
78
+ 3. Install the package
79
+
80
+ ```sh
81
+ $ pip install emu-mps
82
+ # or
83
+ $ pipx install emu-mps
84
+ ```
85
+
86
+
87
+ Join us on [Slack](https://pasqalworkspace.slack.com/archives/C07MUV5K7EU) or by [e-mail](mailto:emulation@pasqal.com) to give us feedback about how you plan to use Emu-MPS or if you require specific feature-upgrades.
88
+
89
+ ## Usage
90
+
91
+ For the time being, the easiest way to learn how to use this package is to look
92
+ at the [examples](examples/emu_mps_examples) and [notebooks](https://pasqal-io.github.io/emulators/latest/).
93
+
94
+ See also the [full documentation](https://github.com/pasqal-io/emulators/blob/main/docs/index.md) for
95
+ the API, information about contributing, benchmarks, etc.
96
+
97
+
98
+ ## Getting in touch
99
+
100
+ - [Pasqal Community Portal](https://community.pasqal.com/) (forums, chat, tutorials, examples, code library).
101
+ - [GitHub Repository](https://github.com/pasqal-io/quantum-evolution-kernel) (source code, issue tracker).
102
+ - [Professional Support](https://www.pasqal.com/contact-us/) (if you need tech support, custom licenses, a variant of this library optimized for your workload, your own QPU, remote access to a QPU, ...)
@@ -1,19 +1,19 @@
1
- emu_base/__init__.py,sha256=SzA_qsfvzoNa6H1nsRR_o8HEDG6mt8hgX2dWXt-MIVI,1130
1
+ emu_base/__init__.py,sha256=5X57qf5fo0zv8vmeaDbrW9ThsAEIjy5HPsCpQEIL8iI,1130
2
2
  emu_base/lindblad_operators.py,sha256=eXkXsLt_fV7jhF31EkxzYFU04rOJV3uWXsl6t1aTAqs,1562
3
- emu_base/pulser_adapter.py,sha256=AjBT9CM0HX5vh8JaU1wRZq1QgXVAryAsYMNKmtPk9x4,8730
4
- emu_base/utils.py,sha256=YCi7UngUzZYSOONhecUdFSB_OkH_aadMTvixzqHYYAc,235
3
+ emu_base/pulser_adapter.py,sha256=vnIiOpjJBXEwMmuWqOdRIlHmkkYnvvPmsSfRNPzBi2k,9118
4
+ emu_base/utils.py,sha256=RM8O0qfPAJfcdqqAojwEEKV7I3ZfVDklnTisTGhUg5k,233
5
5
  emu_base/base_classes/__init__.py,sha256=Su6fHtjCyg0fw-7y7e7nbMfDASppNRQs8iGaAOkO3c4,570
6
6
  emu_base/base_classes/aggregators.py,sha256=bcvoGfZCkPKv-CI29gTma6HBphGh7bjBq2Ome77eRJM,1840
7
7
  emu_base/base_classes/backend.py,sha256=7tnwb9MnRbwRN1_JTqliYftjqExuOE-Rrwz9AU2Pc4c,1645
8
8
  emu_base/base_classes/callback.py,sha256=JXah_ZDNM8iyPWy7IOwW481qRFyqVvlSM-0OkjBzV0A,3055
9
- emu_base/base_classes/config.py,sha256=e7ZRNcBBTEfD_TrODZqCRncvOTUs07TivH04dKaiXrI,3333
9
+ emu_base/base_classes/config.py,sha256=Dg2CwC9sc5HYwszQAJSVjkSd3wuQrv6aEZGYBRnFl48,4098
10
10
  emu_base/base_classes/default_callbacks.py,sha256=F44kkuwWdVcvMGZ9vJ2q7ug-_P8IQyJv-SVxSVWHW_w,9940
11
11
  emu_base/base_classes/operator.py,sha256=MJjuDUTwJLbaSJzSNCKDWGvmGCGAEIEWISLoPSSzNsU,3501
12
12
  emu_base/base_classes/results.py,sha256=7-Mz3jmFy19hd3PIA5idK610mC3b5jOf3EKBmV14Jv4,5569
13
13
  emu_base/base_classes/state.py,sha256=7iIyZmBqqJ6G4SyYZ3kyylWjAqiYIx0aW5B0T74EPZI,2707
14
14
  emu_base/math/__init__.py,sha256=6BbIytYV5uC-e5jLMtIErkcUl_PvfSNnhmVFY9Il8uQ,97
15
15
  emu_base/math/brents_root_finding.py,sha256=AVx6L1Il6rpPJWrLJ7cn6oNmJyZOPRgEaaZaubC9lsU,3711
16
- emu_base/math/krylov_exp.py,sha256=TKvlByRKfCNZdS_YcfCtTk4D7YGhJ-2eIylLVT-X7i4,3784
17
- emu_base-1.2.3.dist-info/METADATA,sha256=f5VhLnKJDOGLnCqeQcUc91uf-o0oS7DhAlX05eFXH2A,4220
18
- emu_base-1.2.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
19
- emu_base-1.2.3.dist-info/RECORD,,
16
+ emu_base/math/krylov_exp.py,sha256=UCFNeq-j2ukgBsOPC9_Jiv1aqpy88SrslDLiCxIGBwk,3840
17
+ emu_base-1.2.5.dist-info/METADATA,sha256=wD4pmz4VvisVEZmM3Z44CC_fiwB6SMw-O9fFKPHvb7w,5576
18
+ emu_base-1.2.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
19
+ emu_base-1.2.5.dist-info/RECORD,,
@@ -1,134 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: emu-base
3
- Version: 1.2.3
4
- Summary: Pasqal base classes for emulators
5
- Author-email: Anton Quelle <anton.quelle@pasqal.com>, Mauro Mendizabal <mauro.mendizabal-pico@pasqal.com>, Stefano Grava <stefano.grava@pasqal.com>, Pablo Le Henaff <pablo.le-henaff@pasqal.com>
6
- License: Proprietary
7
- Classifier: License :: Other/Proprietary License
8
- Classifier: Programming Language :: Python :: 3.10
9
- Classifier: Programming Language :: Python :: Implementation :: CPython
10
- Classifier: Programming Language :: Python :: Implementation :: PyPy
11
- Requires-Python: >=3.10
12
- Requires-Dist: pulser-core==1.1.*
13
- Requires-Dist: torch==2.5.0
14
- Description-Content-Type: text/markdown
15
-
16
- <div align="center">
17
- <img src="docs/logos/LogoTaglineSoftGreen.svg">
18
-
19
- # Emu-MPS
20
- </div>
21
-
22
- **EMU-MPS** is a Pulser backend, designed to **EMU**late the dynamics of programmable arrays of neutral atoms, with matrix product states (**MPS**). It allows users to increase the number of qubits and reduce computation time.
23
-
24
- Join us on [Slack](https://pasqalworkspace.slack.com/archives/C07MUV5K7EU) or by [e-mail](mailto:emulation@pasqal.com) to give us feedback about how you plan to use Emu-MPS or if you require specific feature-upgrades.
25
-
26
-
27
- ## Getting started
28
-
29
- You can install from source, or download the package from the private pypi registry that pasqal maintains in gitlab.
30
- For developers, we recommend installing from source, for users we recommend installing from the registry.
31
-
32
- **Warning:** installing emu-mps will update pulser-core
33
-
34
- We always recommend using a virtual environment.
35
-
36
- <details>
37
- <summary>Click me to see how it is done</summary>
38
-
39
- #### Create a virtual environment using python
40
-
41
- ```
42
- python -m venv .venv
43
- ```
44
-
45
- Or
46
-
47
- ```
48
- python -m venv /path/to/new/virtual/environment
49
- ```
50
-
51
- Replace `/path/to/new/virtual/environment` with your desired directory path.
52
-
53
- Then activate the environment On linux or MacOS
54
-
55
- ```
56
- source /path/to/new/virtual/environment/bin/activate
57
- ```
58
-
59
- While on Windows it's
60
-
61
- ```
62
- C:\> /path/to/new/virtual/environment/Scripts/activate
63
- ```
64
-
65
- Remember to replace `/path/to/new/virtual/environment` with the actual path to your virtual environment. Once the environment is activated, you can clone emu_mps and install it using
66
-
67
- </details>
68
-
69
- ### installing from the registry
70
-
71
- When pip is configured to know about the pasqal registry, Emu-MPS installs as
72
-
73
- ```bash
74
- pip install emu-mps
75
- ```
76
- When pip is not already configured, the easiest way to do so, is to add a file `~/.config/pip/pip.conf` containing:
77
-
78
- ```
79
- [global]
80
- extra-index-url=https://gitlab.pasqal.com/api/v4/projects/597/packages/pypi/simple
81
- possible.other.urls
82
- ```
83
-
84
- As this shows, it is also possible to have multiple extra repositories configured. Note that the order is not important.
85
-
86
- It is also possible to add the `extra-index-url` to the `pip install` command directly, if you somehow don't want to create a `pip.conf` file.
87
-
88
- ### installing from source
89
- git clone this [repository ](https://gitlab.pasqal.com/emulation/rydberg-atoms/emu-ct) or download
90
-
91
-
92
- Then, `cd` into the root folder of the repo and type
93
-
94
- ```bash
95
- pip install -e .
96
- ```
97
-
98
- <details>
99
- <summary>Guidelines for developers </summary>
100
- We recommend using an environment, git clone the repository, then inside the `emu_mps` folder
101
-
102
- ```bash
103
- pip install -e .
104
- ```
105
-
106
- Also, the installation of pytest, nbmake, pre-commit.
107
-
108
- Do not forget to run the unit test suite by simply running `pytest` command.
109
-
110
- Another way can be using hatch.
111
-
112
- #### virtual environment with `hatch`
113
-
114
- ```bash
115
- python -m pip install hatch
116
- python -m hatch -v shell
117
- ```
118
-
119
- When inside the shell with development dependencies, install first the pre-commit hook:
120
- ```
121
- pre-commit install
122
- ```
123
- </details>
124
-
125
- ## Check the tutorial notebooks and example scripts
126
-
127
- For more information, you can check the tutorials and examples located in the [examples folder](https://gitlab.pasqal.com/emulation/rydberg-atoms/emu-ct/-/tree/main/examples?ref_type=heads)
128
-
129
- ## Documentation
130
-
131
- Please check the [documentation](./docs/index.md) page for more info about contributing, the API, benchmarks, etc.
132
-
133
-
134
- ![Code Coverage](https://img.shields.io/badge/Coverage-95%25-brightgreen.svg)