emu-base 2.4.3__py3-none-any.whl → 2.5.0__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 +3 -2
- emu_base/jump_lindblad_operators.py +21 -6
- emu_base/pulser_adapter.py +7 -3
- emu_base/utils.py +21 -0
- {emu_base-2.4.3.dist-info → emu_base-2.5.0.dist-info}/METADATA +1 -1
- {emu_base-2.4.3.dist-info → emu_base-2.5.0.dist-info}/RECORD +7 -7
- {emu_base-2.4.3.dist-info → emu_base-2.5.0.dist-info}/WHEEL +0 -0
emu_base/__init__.py
CHANGED
|
@@ -4,7 +4,7 @@ from .math.brents_root_finding import find_root_brents
|
|
|
4
4
|
from .math.krylov_exp import krylov_exp, DEFAULT_MAX_KRYLOV_DIM
|
|
5
5
|
from .jump_lindblad_operators import compute_noise_from_lindbladians
|
|
6
6
|
from .math.matmul import matmul_2x2_with_batched
|
|
7
|
-
from .utils import get_max_rss, apply_measurement_errors, unix_like
|
|
7
|
+
from .utils import get_max_rss, apply_measurement_errors, unix_like, init_logging
|
|
8
8
|
|
|
9
9
|
__all__ = [
|
|
10
10
|
"__version__",
|
|
@@ -19,6 +19,7 @@ __all__ = [
|
|
|
19
19
|
"DEVICE_COUNT",
|
|
20
20
|
"apply_measurement_errors",
|
|
21
21
|
"unix_like",
|
|
22
|
+
"init_logging",
|
|
22
23
|
]
|
|
23
24
|
|
|
24
|
-
__version__ = "2.
|
|
25
|
+
__version__ = "2.5.0"
|
|
@@ -6,7 +6,11 @@ dtype = torch.complex128
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
def get_lindblad_operators(
|
|
9
|
-
*,
|
|
9
|
+
*,
|
|
10
|
+
noise_type: str,
|
|
11
|
+
noise_model: NoiseModel,
|
|
12
|
+
interact_type: str = "ising",
|
|
13
|
+
dim: int = 2,
|
|
10
14
|
) -> list[torch.Tensor]:
|
|
11
15
|
|
|
12
16
|
assert noise_type in noise_model.noise_types
|
|
@@ -19,7 +23,9 @@ def get_lindblad_operators(
|
|
|
19
23
|
|
|
20
24
|
if noise_type == "dephasing":
|
|
21
25
|
if noise_model.hyperfine_dephasing_rate != 0.0:
|
|
22
|
-
raise NotImplementedError(
|
|
26
|
+
raise NotImplementedError(
|
|
27
|
+
"hyperfine_dephasing_rate is supported only in the digital basis"
|
|
28
|
+
)
|
|
23
29
|
|
|
24
30
|
c = math.sqrt(noise_model.dephasing_rate / 2)
|
|
25
31
|
dephasing = torch.zeros(dim, dim, dtype=dtype)
|
|
@@ -51,15 +57,24 @@ def get_lindblad_operators(
|
|
|
51
57
|
for op in noise_model.eff_noise_opers
|
|
52
58
|
):
|
|
53
59
|
raise ValueError(
|
|
54
|
-
"Only
|
|
60
|
+
f"Only {dim} by {dim} effective noise operator matrices are "
|
|
61
|
+
"supported and it should be given as torch tensors "
|
|
55
62
|
)
|
|
56
63
|
|
|
57
|
-
|
|
58
|
-
math.sqrt(rate)
|
|
59
|
-
* torch.flip(op if isinstance(op, torch.Tensor) else torch.tensor(op), (0, 1))
|
|
64
|
+
lindblad_ops = [ # lindblad operators with XY pulser basis are fine
|
|
65
|
+
math.sqrt(rate) * torch.as_tensor(op)
|
|
60
66
|
for rate, op in zip(noise_model.eff_noise_rates, noise_model.eff_noise_opers)
|
|
61
67
|
]
|
|
62
68
|
|
|
69
|
+
# pulser ising basis changing to emu-mps ising basis
|
|
70
|
+
if interact_type == "ising":
|
|
71
|
+
for tensor in lindblad_ops:
|
|
72
|
+
tensor[:2, :2] = torch.flip(tensor[:2, :2], (0, 1))
|
|
73
|
+
|
|
74
|
+
return lindblad_ops
|
|
75
|
+
if noise_type == "leakage": # leakage operators are eff_noise
|
|
76
|
+
return []
|
|
77
|
+
|
|
63
78
|
raise ValueError(f"Unknown noise type: {noise_type}")
|
|
64
79
|
|
|
65
80
|
|
emu_base/pulser_adapter.py
CHANGED
|
@@ -20,7 +20,7 @@ _NON_LINDBLADIAN_NOISE = {"SPAM", "doppler", "amplitude", "detuning", "register"
|
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
def _get_all_lindblad_noise_operators(
|
|
23
|
-
noise_model: NoiseModel | None, dim: int = 2
|
|
23
|
+
noise_model: NoiseModel | None, dim: int = 2, interact_type: str = "ising"
|
|
24
24
|
) -> list[torch.Tensor]:
|
|
25
25
|
if noise_model is None:
|
|
26
26
|
return []
|
|
@@ -30,7 +30,10 @@ def _get_all_lindblad_noise_operators(
|
|
|
30
30
|
for noise_type in noise_model.noise_types
|
|
31
31
|
if noise_type not in _NON_LINDBLADIAN_NOISE
|
|
32
32
|
for op in get_lindblad_operators(
|
|
33
|
-
noise_type=noise_type,
|
|
33
|
+
noise_type=noise_type,
|
|
34
|
+
noise_model=noise_model,
|
|
35
|
+
dim=dim,
|
|
36
|
+
interact_type=interact_type,
|
|
34
37
|
)
|
|
35
38
|
]
|
|
36
39
|
|
|
@@ -150,6 +153,7 @@ class PulserData:
|
|
|
150
153
|
self.omega, self.delta, self.phi = _extract_omega_delta_phi(
|
|
151
154
|
self.hamiltonian.noisy_samples, self.qubit_ids, self.target_times
|
|
152
155
|
)
|
|
156
|
+
self.eigenstates = self.hamiltonian.eigenbasis
|
|
153
157
|
|
|
154
158
|
int_type = self.hamiltonian.interaction_type
|
|
155
159
|
self.dim = self.hamiltonian.dim
|
|
@@ -161,7 +165,7 @@ class PulserData:
|
|
|
161
165
|
raise ValueError(f"Unsupported basis: {int_type}")
|
|
162
166
|
|
|
163
167
|
self.lindblad_ops = _get_all_lindblad_noise_operators(
|
|
164
|
-
config.noise_model, dim=self.dim
|
|
168
|
+
config.noise_model, dim=self.dim, interact_type=int_type
|
|
165
169
|
)
|
|
166
170
|
self.has_lindblad_noise: bool = self.lindblad_ops != []
|
|
167
171
|
|
emu_base/utils.py
CHANGED
|
@@ -2,12 +2,33 @@ from collections import Counter
|
|
|
2
2
|
import random
|
|
3
3
|
import torch
|
|
4
4
|
import os
|
|
5
|
+
import logging
|
|
6
|
+
import sys
|
|
7
|
+
from pathlib import Path
|
|
5
8
|
|
|
6
9
|
unix_like = os.name != "nt"
|
|
7
10
|
if unix_like:
|
|
8
11
|
from resource import RUSAGE_SELF, getrusage
|
|
9
12
|
|
|
10
13
|
|
|
14
|
+
def init_logging(log_level: int, log_file: Path | None) -> logging.Logger:
|
|
15
|
+
logger = logging.getLogger("emulators")
|
|
16
|
+
logger.propagate = False
|
|
17
|
+
|
|
18
|
+
handler: logging.Handler
|
|
19
|
+
if log_file is None:
|
|
20
|
+
handler = logging.StreamHandler(sys.stdout)
|
|
21
|
+
else:
|
|
22
|
+
handler = logging.FileHandler(log_file, mode="w")
|
|
23
|
+
|
|
24
|
+
handler.setLevel(log_level)
|
|
25
|
+
handler.setFormatter(logging.Formatter("%(message)s"))
|
|
26
|
+
for h in logger.handlers:
|
|
27
|
+
logger.removeHandler(h)
|
|
28
|
+
logger.addHandler(handler)
|
|
29
|
+
return logger
|
|
30
|
+
|
|
31
|
+
|
|
11
32
|
def deallocate_tensor(t: torch.Tensor) -> None:
|
|
12
33
|
"""
|
|
13
34
|
Free the memory used by a tensor. This is done regardless of the
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
emu_base/__init__.py,sha256=
|
|
1
|
+
emu_base/__init__.py,sha256=0gT5wd46vY1MykuZ-E1-h9Ev1fOXE_tu59FzRDH9PCM,759
|
|
2
2
|
emu_base/constants.py,sha256=41LYkKLUCz-oxPbd-j7nUDZuhIbUrnez6prT0uR0jcE,56
|
|
3
|
-
emu_base/jump_lindblad_operators.py,sha256=
|
|
4
|
-
emu_base/pulser_adapter.py,sha256=
|
|
5
|
-
emu_base/utils.py,sha256=
|
|
3
|
+
emu_base/jump_lindblad_operators.py,sha256=F_C-1aruXY_SLzw0m_HD5loqRGdjgsLHEzttlMzWNEw,3015
|
|
4
|
+
emu_base/pulser_adapter.py,sha256=o30fm2soOXr7y2hvoZKLC24oi-FW0_6RmSgrsSWu_y4,7274
|
|
5
|
+
emu_base/utils.py,sha256=kXfRFq31r_dfLbBC0SHiPpvf7Wll4behd2vqQJsTrVo,3553
|
|
6
6
|
emu_base/math/__init__.py,sha256=6BbIytYV5uC-e5jLMtIErkcUl_PvfSNnhmVFY9Il8uQ,97
|
|
7
7
|
emu_base/math/brents_root_finding.py,sha256=AVx6L1Il6rpPJWrLJ7cn6oNmJyZOPRgEaaZaubC9lsU,3711
|
|
8
8
|
emu_base/math/double_krylov.py,sha256=X16dyCbyzdP7fFK-hmKS03Q-DJtC6TZ8sJrGTJ6akIc,3708
|
|
9
9
|
emu_base/math/krylov_energy_min.py,sha256=iR4hmE0eXptbAg3opikd5d4Zv7dhnDrawH-n_4KG-cc,4009
|
|
10
10
|
emu_base/math/krylov_exp.py,sha256=mGFddVQ8mEbwypbZtnlRPFpi4Nf8JZT6OKLHloIwCDQ,3934
|
|
11
11
|
emu_base/math/matmul.py,sha256=lEAnV0b5z_f1xEA-9p-WXxA8bM3QbShiHdXQ3ZkZFcQ,877
|
|
12
|
-
emu_base-2.
|
|
13
|
-
emu_base-2.
|
|
14
|
-
emu_base-2.
|
|
12
|
+
emu_base-2.5.0.dist-info/METADATA,sha256=U1_pInFyZ7gjemxHzZjX1F4y3hfhkw174NjuPVw47gI,3604
|
|
13
|
+
emu_base-2.5.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
14
|
+
emu_base-2.5.0.dist-info/RECORD,,
|
|
File without changes
|