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.
Files changed (51) hide show
  1. qadence/analog/device.py +1 -1
  2. qadence/backend.py +3 -3
  3. qadence/backends/horqrux/backend.py +3 -3
  4. qadence/backends/pulser/backend.py +16 -17
  5. qadence/backends/pulser/convert_ops.py +2 -2
  6. qadence/backends/pyqtorch/backend.py +7 -7
  7. qadence/backends/pyqtorch/convert_ops.py +191 -240
  8. qadence/backends/utils.py +9 -1
  9. qadence/blocks/abstract.py +1 -1
  10. qadence/blocks/embedding.py +21 -11
  11. qadence/blocks/matrix.py +3 -1
  12. qadence/blocks/primitive.py +36 -11
  13. qadence/circuit.py +1 -1
  14. qadence/constructors/__init__.py +2 -1
  15. qadence/constructors/ansatze.py +176 -0
  16. qadence/engines/differentiable_backend.py +3 -3
  17. qadence/engines/jax/differentiable_backend.py +2 -2
  18. qadence/engines/jax/differentiable_expectation.py +2 -2
  19. qadence/engines/torch/differentiable_backend.py +2 -2
  20. qadence/engines/torch/differentiable_expectation.py +2 -2
  21. qadence/execution.py +14 -14
  22. qadence/extensions.py +1 -1
  23. qadence/measurements/shadow.py +4 -5
  24. qadence/measurements/tomography.py +2 -2
  25. qadence/measurements/utils.py +2 -2
  26. qadence/mitigations/analog_zne.py +8 -7
  27. qadence/mitigations/protocols.py +2 -2
  28. qadence/mitigations/readout.py +8 -5
  29. qadence/ml_tools/constructors.py +2 -2
  30. qadence/ml_tools/models.py +7 -7
  31. qadence/ml_tools/printing.py +2 -1
  32. qadence/model.py +5 -5
  33. qadence/noise/__init__.py +2 -2
  34. qadence/noise/protocols.py +216 -29
  35. qadence/operations/control_ops.py +37 -22
  36. qadence/operations/ham_evo.py +1 -0
  37. qadence/operations/parametric.py +32 -10
  38. qadence/operations/primitive.py +61 -29
  39. qadence/overlap.py +0 -6
  40. qadence/parameters.py +3 -2
  41. qadence/transpile/__init__.py +2 -1
  42. qadence/transpile/noise.py +46 -0
  43. qadence/types.py +26 -2
  44. {qadence-1.7.8.dist-info → qadence-1.8.0.dist-info}/METADATA +5 -8
  45. {qadence-1.7.8.dist-info → qadence-1.8.0.dist-info}/RECORD +47 -50
  46. qadence/backends/braket/__init__.py +0 -4
  47. qadence/backends/braket/backend.py +0 -234
  48. qadence/backends/braket/config.py +0 -22
  49. qadence/backends/braket/convert_ops.py +0 -116
  50. {qadence-1.7.8.dist-info → qadence-1.8.0.dist-info}/WHEEL +0 -0
  51. {qadence-1.7.8.dist-info → qadence-1.8.0.dist-info}/licenses/LICENSE +0 -0
qadence/analog/device.py CHANGED
@@ -49,7 +49,7 @@ class RydbergDevice:
49
49
  )
50
50
 
51
51
  def _to_dict(self) -> dict:
52
- device_dict = {}
52
+ device_dict = dict()
53
53
  for field in fields(self):
54
54
  if field.name != "pattern":
55
55
  device_dict[field.name] = getattr(self, field.name)
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 Noise
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: Noise | None = None,
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: Noise | None = None,
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 Noise
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: Noise | None = None,
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: Noise | None = None,
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 Noise
28
- from qadence.noise.protocols import apply_noise
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: Noise | None = None,
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: 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
- noise_probs = noise.options.get("noise_probs", None)
245
- if noise_probs is None:
246
- KeyError("A `noise probs` option should be passed to the <class QuantumModel>.")
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
- sim_config = {"noise": noise.protocol, noise.protocol + "_rate": noise_prob}
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: Noise | None = None,
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 = apply_noise(noise=noise, samples=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: Noise | None = None,
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 Noise
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: Noise | None = None,
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 Noise
26
- from qadence.noise.protocols import apply_noise
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: Noise | None = None,
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: Noise | None = None,
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: Noise | None = None,
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: Noise | None = None,
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 = apply_noise(noise=noise, samples=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.",