qadence 1.7.8__py3-none-any.whl → 1.8.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.
- qadence/analog/device.py +1 -1
- qadence/backend.py +3 -3
- qadence/backends/horqrux/backend.py +3 -3
- qadence/backends/pulser/backend.py +16 -17
- qadence/backends/pulser/convert_ops.py +2 -2
- qadence/backends/pyqtorch/backend.py +7 -7
- qadence/backends/pyqtorch/convert_ops.py +191 -240
- qadence/backends/utils.py +9 -1
- qadence/blocks/abstract.py +1 -1
- qadence/blocks/embedding.py +21 -11
- qadence/blocks/matrix.py +3 -1
- qadence/blocks/primitive.py +36 -11
- qadence/circuit.py +1 -1
- qadence/constructors/__init__.py +2 -1
- qadence/constructors/ansatze.py +176 -0
- qadence/engines/differentiable_backend.py +3 -3
- qadence/engines/jax/differentiable_backend.py +2 -2
- qadence/engines/jax/differentiable_expectation.py +2 -2
- qadence/engines/torch/differentiable_backend.py +2 -2
- qadence/engines/torch/differentiable_expectation.py +2 -2
- qadence/execution.py +14 -14
- qadence/extensions.py +1 -1
- qadence/measurements/shadow.py +4 -5
- qadence/measurements/tomography.py +2 -2
- qadence/measurements/utils.py +2 -2
- qadence/mitigations/analog_zne.py +8 -7
- qadence/mitigations/protocols.py +2 -2
- qadence/mitigations/readout.py +8 -5
- qadence/ml_tools/constructors.py +2 -2
- qadence/ml_tools/models.py +7 -7
- qadence/ml_tools/printing.py +2 -1
- qadence/model.py +5 -5
- qadence/noise/__init__.py +2 -2
- qadence/noise/protocols.py +216 -29
- qadence/operations/control_ops.py +37 -22
- qadence/operations/ham_evo.py +1 -0
- qadence/operations/parametric.py +32 -10
- qadence/operations/primitive.py +61 -29
- qadence/overlap.py +0 -6
- qadence/parameters.py +3 -2
- qadence/transpile/__init__.py +2 -1
- qadence/transpile/noise.py +46 -0
- qadence/types.py +26 -2
- {qadence-1.7.8.dist-info → qadence-1.8.0.dist-info}/METADATA +5 -8
- {qadence-1.7.8.dist-info → qadence-1.8.0.dist-info}/RECORD +47 -50
- qadence/backends/braket/__init__.py +0 -4
- qadence/backends/braket/backend.py +0 -234
- qadence/backends/braket/config.py +0 -22
- qadence/backends/braket/convert_ops.py +0 -116
- {qadence-1.7.8.dist-info → qadence-1.8.0.dist-info}/WHEEL +0 -0
- {qadence-1.7.8.dist-info → qadence-1.8.0.dist-info}/licenses/LICENSE +0 -0
qadence/analog/device.py
CHANGED
qadence/backend.py
CHANGED
@@ -23,7 +23,7 @@ from qadence.blocks.analog import ConstantAnalogRotation, InteractionBlock
|
|
23
23
|
from qadence.circuit import QuantumCircuit
|
24
24
|
from qadence.measurements import Measurements
|
25
25
|
from qadence.mitigations import Mitigations
|
26
|
-
from qadence.noise import
|
26
|
+
from qadence.noise import NoiseHandler
|
27
27
|
from qadence.parameters import stringify
|
28
28
|
from qadence.types import ArrayLike, BackendName, DiffMode, Endianness, Engine, ParamDictType
|
29
29
|
|
@@ -240,7 +240,7 @@ class Backend(ABC):
|
|
240
240
|
param_values: dict[str, Tensor] = {},
|
241
241
|
n_shots: int = 1000,
|
242
242
|
state: ArrayLike | None = None,
|
243
|
-
noise:
|
243
|
+
noise: NoiseHandler | None = None,
|
244
244
|
mitigation: Mitigations | None = None,
|
245
245
|
endianness: Endianness = Endianness.BIG,
|
246
246
|
) -> list[Counter]:
|
@@ -290,7 +290,7 @@ class Backend(ABC):
|
|
290
290
|
param_values: ParamDictType = {},
|
291
291
|
state: ArrayLike | None = None,
|
292
292
|
measurement: Measurements | None = None,
|
293
|
-
noise:
|
293
|
+
noise: NoiseHandler | None = None,
|
294
294
|
mitigation: Mitigations | None = None,
|
295
295
|
endianness: Endianness = Endianness.BIG,
|
296
296
|
) -> ArrayLike:
|
@@ -21,7 +21,7 @@ from qadence.blocks import AbstractBlock
|
|
21
21
|
from qadence.circuit import QuantumCircuit
|
22
22
|
from qadence.measurements import Measurements
|
23
23
|
from qadence.mitigations import Mitigations
|
24
|
-
from qadence.noise import
|
24
|
+
from qadence.noise import NoiseHandler
|
25
25
|
from qadence.transpile import flatten, scale_primitive_blocks_only, transpile
|
26
26
|
from qadence.types import BackendName, Endianness, Engine, ParamDictType
|
27
27
|
from qadence.utils import int_to_basis
|
@@ -114,7 +114,7 @@ class Backend(BackendInterface):
|
|
114
114
|
param_values: ParamDictType = {},
|
115
115
|
state: ArrayLike | None = None,
|
116
116
|
measurement: Measurements | None = None,
|
117
|
-
noise:
|
117
|
+
noise: NoiseHandler | None = None,
|
118
118
|
mitigation: Mitigations | None = None,
|
119
119
|
endianness: Endianness = Endianness.BIG,
|
120
120
|
) -> ArrayLike:
|
@@ -163,7 +163,7 @@ class Backend(BackendInterface):
|
|
163
163
|
param_values: ParamDictType = {},
|
164
164
|
n_shots: int = 1,
|
165
165
|
state: ArrayLike | None = None,
|
166
|
-
noise:
|
166
|
+
noise: NoiseHandler | None = None,
|
167
167
|
mitigation: Mitigations | None = None,
|
168
168
|
endianness: Endianness = Endianness.BIG,
|
169
169
|
) -> list[Counter]:
|
@@ -24,12 +24,12 @@ from qadence.circuit import QuantumCircuit
|
|
24
24
|
from qadence.measurements import Measurements
|
25
25
|
from qadence.mitigations import Mitigations
|
26
26
|
from qadence.mitigations.protocols import apply_mitigation
|
27
|
-
from qadence.noise import
|
28
|
-
from qadence.noise.protocols import
|
27
|
+
from qadence.noise import NoiseHandler
|
28
|
+
from qadence.noise.protocols import apply_readout_noise
|
29
29
|
from qadence.overlap import overlap_exact
|
30
30
|
from qadence.register import Register
|
31
31
|
from qadence.transpile import transpile
|
32
|
-
from qadence.types import BackendName, DeviceType, Endianness, Engine
|
32
|
+
from qadence.types import BackendName, DeviceType, Endianness, Engine, NoiseProtocol
|
33
33
|
|
34
34
|
from .channels import GLOBAL_CHANNEL, LOCAL_CHANNEL
|
35
35
|
from .cloud import get_client
|
@@ -187,7 +187,7 @@ class Backend(BackendInterface):
|
|
187
187
|
param_values: dict[str, Tensor] = {},
|
188
188
|
state: Tensor | None = None,
|
189
189
|
endianness: Endianness = Endianness.BIG,
|
190
|
-
noise:
|
190
|
+
noise: NoiseHandler | None = None,
|
191
191
|
) -> Tensor:
|
192
192
|
vals = to_list_of_dicts(param_values)
|
193
193
|
|
@@ -235,27 +235,26 @@ class Backend(BackendInterface):
|
|
235
235
|
def _run_noisy(
|
236
236
|
self,
|
237
237
|
circuit: ConvertedCircuit,
|
238
|
-
noise:
|
238
|
+
noise: NoiseHandler,
|
239
239
|
param_values: dict[str, Tensor] = dict(),
|
240
240
|
state: Tensor | None = None,
|
241
241
|
endianness: Endianness = Endianness.BIG,
|
242
242
|
) -> Tensor:
|
243
243
|
vals = to_list_of_dicts(param_values)
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
if not (isinstance(noise_probs, float) or isinstance(noise_probs, Iterable)):
|
248
|
-
KeyError(
|
249
|
-
"A single or a range of noise probabilities"
|
250
|
-
" should be passed. Got {type(noise_probs)}."
|
251
|
-
)
|
244
|
+
if not isinstance(noise.protocol[-1], NoiseProtocol.ANALOG):
|
245
|
+
raise TypeError("Noise must be of type `NoiseProtocol.ANALOG`.")
|
246
|
+
noise_probs = noise.options[-1].get("noise_probs", None)
|
252
247
|
|
253
248
|
def run_noisy_sim(noise_prob: float) -> Tensor:
|
254
249
|
batched_dm = np.zeros(
|
255
250
|
(len(vals), 2**circuit.abstract.n_qubits, 2**circuit.abstract.n_qubits),
|
256
251
|
dtype=np.complex128,
|
257
252
|
)
|
258
|
-
|
253
|
+
# pulser requires lower letters
|
254
|
+
sim_config = {
|
255
|
+
"noise": noise.protocol[-1].lower(),
|
256
|
+
noise.protocol[-1].lower() + "_rate": noise_prob,
|
257
|
+
}
|
259
258
|
self.config.sim_config = SimConfig(**sim_config)
|
260
259
|
|
261
260
|
for i, param_values_el in enumerate(vals):
|
@@ -289,7 +288,7 @@ class Backend(BackendInterface):
|
|
289
288
|
param_values: dict[str, Tensor] = {},
|
290
289
|
n_shots: int = 1,
|
291
290
|
state: Tensor | None = None,
|
292
|
-
noise:
|
291
|
+
noise: NoiseHandler | None = None,
|
293
292
|
mitigation: Mitigations | None = None,
|
294
293
|
endianness: Endianness = Endianness.BIG,
|
295
294
|
) -> list[Counter]:
|
@@ -313,7 +312,7 @@ class Backend(BackendInterface):
|
|
313
312
|
|
314
313
|
samples = invert_endianness(samples)
|
315
314
|
if noise is not None:
|
316
|
-
samples =
|
315
|
+
samples = apply_readout_noise(noise=noise, samples=samples)
|
317
316
|
if mitigation is not None:
|
318
317
|
logger.warning(
|
319
318
|
"Mitigation protocol is deprecated. Use qadence-protocols instead.",
|
@@ -329,7 +328,7 @@ class Backend(BackendInterface):
|
|
329
328
|
param_values: dict[str, Tensor] = {},
|
330
329
|
state: Tensor | None = None,
|
331
330
|
measurement: Measurements | None = None,
|
332
|
-
noise:
|
331
|
+
noise: NoiseHandler | None = None,
|
333
332
|
mitigation: Mitigations | None = None,
|
334
333
|
endianness: Endianness = Endianness.BIG,
|
335
334
|
) -> Tensor:
|
@@ -5,7 +5,7 @@ from typing import Sequence
|
|
5
5
|
import torch
|
6
6
|
from torch.nn import Module
|
7
7
|
|
8
|
-
from qadence import
|
8
|
+
from qadence import NoiseHandler
|
9
9
|
from qadence.blocks import (
|
10
10
|
AbstractBlock,
|
11
11
|
)
|
@@ -40,7 +40,7 @@ class PulserObservable(Module):
|
|
40
40
|
state: torch.Tensor,
|
41
41
|
values: dict[str, torch.Tensor] = dict(),
|
42
42
|
qubit_support: tuple | None = None,
|
43
|
-
noise:
|
43
|
+
noise: NoiseHandler | None = None,
|
44
44
|
endianness: Endianness = Endianness.BIG,
|
45
45
|
) -> torch.Tensor:
|
46
46
|
if not self.block.is_parametric:
|
@@ -22,8 +22,8 @@ from qadence.blocks import AbstractBlock
|
|
22
22
|
from qadence.circuit import QuantumCircuit
|
23
23
|
from qadence.measurements import Measurements
|
24
24
|
from qadence.mitigations.protocols import Mitigations, apply_mitigation
|
25
|
-
from qadence.noise import
|
26
|
-
from qadence.noise.protocols import
|
25
|
+
from qadence.noise import NoiseHandler
|
26
|
+
from qadence.noise.protocols import apply_readout_noise
|
27
27
|
from qadence.transpile import (
|
28
28
|
chain_single_qubit_ops,
|
29
29
|
flatten,
|
@@ -113,7 +113,7 @@ class Backend(BackendInterface):
|
|
113
113
|
param_values: dict[str, Tensor] = {},
|
114
114
|
state: Tensor | None = None,
|
115
115
|
measurement: Measurements | None = None,
|
116
|
-
noise:
|
116
|
+
noise: NoiseHandler | None = None,
|
117
117
|
endianness: Endianness = Endianness.BIG,
|
118
118
|
) -> Tensor:
|
119
119
|
state = self.run(
|
@@ -138,7 +138,7 @@ class Backend(BackendInterface):
|
|
138
138
|
param_values: dict[str, Tensor] = {},
|
139
139
|
state: Tensor | None = None,
|
140
140
|
measurement: Measurements | None = None,
|
141
|
-
noise:
|
141
|
+
noise: NoiseHandler | None = None,
|
142
142
|
endianness: Endianness = Endianness.BIG,
|
143
143
|
) -> Tensor:
|
144
144
|
if state is None:
|
@@ -169,7 +169,7 @@ class Backend(BackendInterface):
|
|
169
169
|
param_values: dict[str, Tensor] = {},
|
170
170
|
state: Tensor | None = None,
|
171
171
|
measurement: Measurements | None = None,
|
172
|
-
noise:
|
172
|
+
noise: NoiseHandler | None = None,
|
173
173
|
mitigation: Mitigations | None = None,
|
174
174
|
endianness: Endianness = Endianness.BIG,
|
175
175
|
) -> Tensor:
|
@@ -196,7 +196,7 @@ class Backend(BackendInterface):
|
|
196
196
|
param_values: dict[str, Tensor] = {},
|
197
197
|
n_shots: int = 1,
|
198
198
|
state: Tensor | None = None,
|
199
|
-
noise:
|
199
|
+
noise: NoiseHandler | None = None,
|
200
200
|
mitigation: Mitigations | None = None,
|
201
201
|
endianness: Endianness = Endianness.BIG,
|
202
202
|
pyqify_state: bool = True,
|
@@ -211,7 +211,7 @@ class Backend(BackendInterface):
|
|
211
211
|
)
|
212
212
|
samples = invert_endianness(samples) if endianness != Endianness.BIG else samples
|
213
213
|
if noise is not None:
|
214
|
-
samples =
|
214
|
+
samples = apply_readout_noise(noise=noise, samples=samples)
|
215
215
|
if mitigation is not None:
|
216
216
|
logger.warning(
|
217
217
|
"Mitigation protocol is deprecated. Use qadence-protocols instead.",
|