qadence 1.6.3__tar.gz → 1.7.0__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.
Files changed (157) hide show
  1. {qadence-1.6.3 → qadence-1.7.0}/PKG-INFO +2 -2
  2. {qadence-1.6.3 → qadence-1.7.0}/mkdocs.yml +1 -0
  3. {qadence-1.6.3 → qadence-1.7.0}/pyproject.toml +62 -64
  4. {qadence-1.6.3 → qadence-1.7.0}/qadence/__init__.py +2 -2
  5. {qadence-1.6.3 → qadence-1.7.0}/qadence/backends/pyqtorch/convert_ops.py +4 -2
  6. {qadence-1.6.3 → qadence-1.7.0}/qadence/backends/utils.py +45 -4
  7. {qadence-1.6.3 → qadence-1.7.0}/qadence/blocks/matrix.py +1 -1
  8. {qadence-1.6.3 → qadence-1.7.0}/qadence/blocks/primitive.py +1 -1
  9. {qadence-1.6.3 → qadence-1.7.0}/qadence/constructors/__init__.py +2 -0
  10. {qadence-1.6.3 → qadence-1.7.0}/qadence/constructors/hamiltonians.py +38 -1
  11. {qadence-1.6.3 → qadence-1.7.0}/qadence/draw/utils.py +1 -1
  12. {qadence-1.6.3 → qadence-1.7.0}/qadence/ml_tools/__init__.py +11 -3
  13. qadence-1.7.0/qadence/ml_tools/config.py +347 -0
  14. qadence-1.7.0/qadence/ml_tools/constructors.py +774 -0
  15. qadence-1.6.3/qadence/models/qnn.py → qadence-1.7.0/qadence/ml_tools/models.py +183 -40
  16. {qadence-1.6.3 → qadence-1.7.0}/qadence/ml_tools/saveload.py +6 -6
  17. {qadence-1.6.3 → qadence-1.7.0}/qadence/ml_tools/train_grad.py +3 -7
  18. {qadence-1.6.3 → qadence-1.7.0}/qadence/ml_tools/utils.py +2 -8
  19. qadence-1.6.3/qadence/models/quantum_model.py → qadence-1.7.0/qadence/model.py +14 -8
  20. {qadence-1.6.3 → qadence-1.7.0}/qadence/overlap.py +1 -1
  21. {qadence-1.6.3 → qadence-1.7.0}/qadence/serialization.py +6 -6
  22. {qadence-1.6.3 → qadence-1.7.0}/qadence/types.py +42 -0
  23. qadence-1.6.3/qadence/finitediff.py +0 -47
  24. qadence-1.6.3/qadence/ml_tools/config.py +0 -72
  25. qadence-1.6.3/qadence/ml_tools/models.py +0 -320
  26. qadence-1.6.3/qadence/models/__init__.py +0 -7
  27. {qadence-1.6.3 → qadence-1.7.0}/.coveragerc +0 -0
  28. {qadence-1.6.3 → qadence-1.7.0}/.github/dependabot.yml +0 -0
  29. {qadence-1.6.3 → qadence-1.7.0}/.github/workflows/build_docs.yml +0 -0
  30. {qadence-1.6.3 → qadence-1.7.0}/.github/workflows/dependabot.yml +0 -0
  31. {qadence-1.6.3 → qadence-1.7.0}/.github/workflows/lint.yml +0 -0
  32. {qadence-1.6.3 → qadence-1.7.0}/.github/workflows/test_all.yml +0 -0
  33. {qadence-1.6.3 → qadence-1.7.0}/.github/workflows/test_examples.yml +0 -0
  34. {qadence-1.6.3 → qadence-1.7.0}/.github/workflows/test_fast.yml +0 -0
  35. {qadence-1.6.3 → qadence-1.7.0}/.gitignore +0 -0
  36. {qadence-1.6.3 → qadence-1.7.0}/.pre-commit-config.yaml +0 -0
  37. {qadence-1.6.3 → qadence-1.7.0}/LICENSE +0 -0
  38. {qadence-1.6.3 → qadence-1.7.0}/MANIFEST.in +0 -0
  39. {qadence-1.6.3 → qadence-1.7.0}/README.md +0 -0
  40. {qadence-1.6.3 → qadence-1.7.0}/qadence/analog/__init__.py +0 -0
  41. {qadence-1.6.3 → qadence-1.7.0}/qadence/analog/addressing.py +0 -0
  42. {qadence-1.6.3 → qadence-1.7.0}/qadence/analog/constants.py +0 -0
  43. {qadence-1.6.3 → qadence-1.7.0}/qadence/analog/device.py +0 -0
  44. {qadence-1.6.3 → qadence-1.7.0}/qadence/analog/hamiltonian_terms.py +0 -0
  45. {qadence-1.6.3 → qadence-1.7.0}/qadence/analog/parse_analog.py +0 -0
  46. {qadence-1.6.3 → qadence-1.7.0}/qadence/backend.py +0 -0
  47. {qadence-1.6.3 → qadence-1.7.0}/qadence/backends/__init__.py +0 -0
  48. {qadence-1.6.3 → qadence-1.7.0}/qadence/backends/api.py +0 -0
  49. {qadence-1.6.3 → qadence-1.7.0}/qadence/backends/braket/__init__.py +0 -0
  50. {qadence-1.6.3 → qadence-1.7.0}/qadence/backends/braket/backend.py +0 -0
  51. {qadence-1.6.3 → qadence-1.7.0}/qadence/backends/braket/config.py +0 -0
  52. {qadence-1.6.3 → qadence-1.7.0}/qadence/backends/braket/convert_ops.py +0 -0
  53. {qadence-1.6.3 → qadence-1.7.0}/qadence/backends/gpsr.py +0 -0
  54. {qadence-1.6.3 → qadence-1.7.0}/qadence/backends/horqrux/__init__.py +0 -0
  55. {qadence-1.6.3 → qadence-1.7.0}/qadence/backends/horqrux/backend.py +0 -0
  56. {qadence-1.6.3 → qadence-1.7.0}/qadence/backends/horqrux/config.py +0 -0
  57. {qadence-1.6.3 → qadence-1.7.0}/qadence/backends/horqrux/convert_ops.py +0 -0
  58. {qadence-1.6.3 → qadence-1.7.0}/qadence/backends/jax_utils.py +0 -0
  59. {qadence-1.6.3 → qadence-1.7.0}/qadence/backends/pulser/__init__.py +0 -0
  60. {qadence-1.6.3 → qadence-1.7.0}/qadence/backends/pulser/backend.py +0 -0
  61. {qadence-1.6.3 → qadence-1.7.0}/qadence/backends/pulser/channels.py +0 -0
  62. {qadence-1.6.3 → qadence-1.7.0}/qadence/backends/pulser/cloud.py +0 -0
  63. {qadence-1.6.3 → qadence-1.7.0}/qadence/backends/pulser/config.py +0 -0
  64. {qadence-1.6.3 → qadence-1.7.0}/qadence/backends/pulser/convert_ops.py +0 -0
  65. {qadence-1.6.3 → qadence-1.7.0}/qadence/backends/pulser/devices.py +0 -0
  66. {qadence-1.6.3 → qadence-1.7.0}/qadence/backends/pulser/pulses.py +0 -0
  67. {qadence-1.6.3 → qadence-1.7.0}/qadence/backends/pulser/waveforms.py +0 -0
  68. {qadence-1.6.3 → qadence-1.7.0}/qadence/backends/pyqtorch/__init__.py +0 -0
  69. {qadence-1.6.3 → qadence-1.7.0}/qadence/backends/pyqtorch/backend.py +0 -0
  70. {qadence-1.6.3 → qadence-1.7.0}/qadence/backends/pyqtorch/config.py +0 -0
  71. {qadence-1.6.3 → qadence-1.7.0}/qadence/blocks/__init__.py +0 -0
  72. {qadence-1.6.3 → qadence-1.7.0}/qadence/blocks/abstract.py +0 -0
  73. {qadence-1.6.3 → qadence-1.7.0}/qadence/blocks/analog.py +0 -0
  74. {qadence-1.6.3 → qadence-1.7.0}/qadence/blocks/block_to_tensor.py +0 -0
  75. {qadence-1.6.3 → qadence-1.7.0}/qadence/blocks/composite.py +0 -0
  76. {qadence-1.6.3 → qadence-1.7.0}/qadence/blocks/embedding.py +0 -0
  77. {qadence-1.6.3 → qadence-1.7.0}/qadence/blocks/manipulate.py +0 -0
  78. {qadence-1.6.3 → qadence-1.7.0}/qadence/blocks/utils.py +0 -0
  79. {qadence-1.6.3 → qadence-1.7.0}/qadence/circuit.py +0 -0
  80. {qadence-1.6.3 → qadence-1.7.0}/qadence/constructors/ansatze.py +0 -0
  81. {qadence-1.6.3 → qadence-1.7.0}/qadence/constructors/daqc/__init__.py +0 -0
  82. {qadence-1.6.3 → qadence-1.7.0}/qadence/constructors/daqc/daqc.py +0 -0
  83. {qadence-1.6.3 → qadence-1.7.0}/qadence/constructors/daqc/gen_parser.py +0 -0
  84. {qadence-1.6.3 → qadence-1.7.0}/qadence/constructors/daqc/utils.py +0 -0
  85. {qadence-1.6.3 → qadence-1.7.0}/qadence/constructors/feature_maps.py +0 -0
  86. {qadence-1.6.3 → qadence-1.7.0}/qadence/constructors/iia.py +0 -0
  87. {qadence-1.6.3 → qadence-1.7.0}/qadence/constructors/qft.py +0 -0
  88. {qadence-1.6.3 → qadence-1.7.0}/qadence/constructors/rydberg_feature_maps.py +0 -0
  89. {qadence-1.6.3 → qadence-1.7.0}/qadence/constructors/rydberg_hea.py +0 -0
  90. {qadence-1.6.3 → qadence-1.7.0}/qadence/constructors/utils.py +0 -0
  91. {qadence-1.6.3 → qadence-1.7.0}/qadence/decompose.py +0 -0
  92. {qadence-1.6.3 → qadence-1.7.0}/qadence/divergences.py +0 -0
  93. {qadence-1.6.3 → qadence-1.7.0}/qadence/draw/__init__.py +0 -0
  94. {qadence-1.6.3 → qadence-1.7.0}/qadence/draw/assets/dark/measurement.png +0 -0
  95. {qadence-1.6.3 → qadence-1.7.0}/qadence/draw/assets/dark/measurement.svg +0 -0
  96. {qadence-1.6.3 → qadence-1.7.0}/qadence/draw/assets/light/measurement.png +0 -0
  97. {qadence-1.6.3 → qadence-1.7.0}/qadence/draw/assets/light/measurement.svg +0 -0
  98. {qadence-1.6.3 → qadence-1.7.0}/qadence/draw/themes.py +0 -0
  99. {qadence-1.6.3 → qadence-1.7.0}/qadence/draw/vizbackend.py +0 -0
  100. {qadence-1.6.3 → qadence-1.7.0}/qadence/engines/__init__.py +0 -0
  101. {qadence-1.6.3 → qadence-1.7.0}/qadence/engines/differentiable_backend.py +0 -0
  102. {qadence-1.6.3 → qadence-1.7.0}/qadence/engines/jax/__init__.py +0 -0
  103. {qadence-1.6.3 → qadence-1.7.0}/qadence/engines/jax/differentiable_backend.py +0 -0
  104. {qadence-1.6.3 → qadence-1.7.0}/qadence/engines/jax/differentiable_expectation.py +0 -0
  105. {qadence-1.6.3 → qadence-1.7.0}/qadence/engines/torch/__init__.py +0 -0
  106. {qadence-1.6.3 → qadence-1.7.0}/qadence/engines/torch/differentiable_backend.py +0 -0
  107. {qadence-1.6.3 → qadence-1.7.0}/qadence/engines/torch/differentiable_expectation.py +0 -0
  108. {qadence-1.6.3 → qadence-1.7.0}/qadence/exceptions/__init__.py +0 -0
  109. {qadence-1.6.3 → qadence-1.7.0}/qadence/exceptions/exceptions.py +0 -0
  110. {qadence-1.6.3 → qadence-1.7.0}/qadence/execution.py +0 -0
  111. {qadence-1.6.3 → qadence-1.7.0}/qadence/extensions.py +0 -0
  112. {qadence-1.6.3 → qadence-1.7.0}/qadence/libs.py +0 -0
  113. {qadence-1.6.3 → qadence-1.7.0}/qadence/log_config.yaml +0 -0
  114. {qadence-1.6.3 → qadence-1.7.0}/qadence/logger.py +0 -0
  115. {qadence-1.6.3 → qadence-1.7.0}/qadence/measurements/__init__.py +0 -0
  116. {qadence-1.6.3 → qadence-1.7.0}/qadence/measurements/protocols.py +0 -0
  117. {qadence-1.6.3 → qadence-1.7.0}/qadence/measurements/samples.py +0 -0
  118. {qadence-1.6.3 → qadence-1.7.0}/qadence/measurements/shadow.py +0 -0
  119. {qadence-1.6.3 → qadence-1.7.0}/qadence/measurements/tomography.py +0 -0
  120. {qadence-1.6.3 → qadence-1.7.0}/qadence/measurements/utils.py +0 -0
  121. {qadence-1.6.3 → qadence-1.7.0}/qadence/mitigations/__init__.py +0 -0
  122. {qadence-1.6.3 → qadence-1.7.0}/qadence/mitigations/analog_zne.py +0 -0
  123. {qadence-1.6.3 → qadence-1.7.0}/qadence/mitigations/protocols.py +0 -0
  124. {qadence-1.6.3 → qadence-1.7.0}/qadence/mitigations/readout.py +0 -0
  125. {qadence-1.6.3 → qadence-1.7.0}/qadence/ml_tools/data.py +0 -0
  126. {qadence-1.6.3 → qadence-1.7.0}/qadence/ml_tools/optimize_step.py +0 -0
  127. {qadence-1.6.3 → qadence-1.7.0}/qadence/ml_tools/parameters.py +0 -0
  128. {qadence-1.6.3 → qadence-1.7.0}/qadence/ml_tools/printing.py +0 -0
  129. {qadence-1.6.3 → qadence-1.7.0}/qadence/ml_tools/tensors.py +0 -0
  130. {qadence-1.6.3 → qadence-1.7.0}/qadence/ml_tools/train_no_grad.py +0 -0
  131. {qadence-1.6.3 → qadence-1.7.0}/qadence/noise/__init__.py +0 -0
  132. {qadence-1.6.3 → qadence-1.7.0}/qadence/noise/protocols.py +0 -0
  133. {qadence-1.6.3 → qadence-1.7.0}/qadence/noise/readout.py +0 -0
  134. {qadence-1.6.3 → qadence-1.7.0}/qadence/operations/__init__.py +0 -0
  135. {qadence-1.6.3 → qadence-1.7.0}/qadence/operations/analog.py +0 -0
  136. {qadence-1.6.3 → qadence-1.7.0}/qadence/operations/control_ops.py +0 -0
  137. {qadence-1.6.3 → qadence-1.7.0}/qadence/operations/ham_evo.py +0 -0
  138. {qadence-1.6.3 → qadence-1.7.0}/qadence/operations/parametric.py +0 -0
  139. {qadence-1.6.3 → qadence-1.7.0}/qadence/operations/primitive.py +0 -0
  140. {qadence-1.6.3 → qadence-1.7.0}/qadence/parameters.py +0 -0
  141. {qadence-1.6.3 → qadence-1.7.0}/qadence/protocols.py +0 -0
  142. {qadence-1.6.3 → qadence-1.7.0}/qadence/py.typed +0 -0
  143. {qadence-1.6.3 → qadence-1.7.0}/qadence/qubit_support.py +0 -0
  144. {qadence-1.6.3 → qadence-1.7.0}/qadence/register.py +0 -0
  145. {qadence-1.6.3 → qadence-1.7.0}/qadence/serial_expr_grammar.peg +0 -0
  146. {qadence-1.6.3 → qadence-1.7.0}/qadence/states.py +0 -0
  147. {qadence-1.6.3 → qadence-1.7.0}/qadence/transpile/__init__.py +0 -0
  148. {qadence-1.6.3 → qadence-1.7.0}/qadence/transpile/apply_fn.py +0 -0
  149. {qadence-1.6.3 → qadence-1.7.0}/qadence/transpile/block.py +0 -0
  150. {qadence-1.6.3 → qadence-1.7.0}/qadence/transpile/circuit.py +0 -0
  151. {qadence-1.6.3 → qadence-1.7.0}/qadence/transpile/digitalize.py +0 -0
  152. {qadence-1.6.3 → qadence-1.7.0}/qadence/transpile/flatten.py +0 -0
  153. {qadence-1.6.3 → qadence-1.7.0}/qadence/transpile/invert.py +0 -0
  154. {qadence-1.6.3 → qadence-1.7.0}/qadence/transpile/transpile.py +0 -0
  155. {qadence-1.6.3 → qadence-1.7.0}/qadence/utils.py +0 -0
  156. {qadence-1.6.3 → qadence-1.7.0}/renovate.json +0 -0
  157. {qadence-1.6.3 → qadence-1.7.0}/setup.py +0 -0
@@ -1,8 +1,8 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: qadence
3
- Version: 1.6.3
3
+ Version: 1.7.0
4
4
  Summary: Pasqal interface for circuit-based quantum computing SDKs
5
- Author-email: Aleksander Wennersteen <aleksander.wennersteen@pasqal.com>, Gert-Jan Both <gert-jan.both@pasqal.com>, Niklas Heim <niklas.heim@pasqal.com>, Mario Dagrada <mario.dagrada@pasqal.com>, Vincent Elfving <vincent.elfving@pasqal.com>, Dominik Seitz <dominik.seitz@pasqal.com>, Roland Guichard <roland.guichard@pasqal.com>, "Joao P. Moutinho" <joao.moutinho@pasqal.com>, Vytautas Abramavicius <vytautas.abramavicius@pasqal.com>, Gergana Velikova <gergana.velikova@pasqal.com>, Eduardo Maschio <eduardo.maschio@pasqal.com>
5
+ Author-email: Aleksander Wennersteen <aleksander.wennersteen@pasqal.com>, Gert-Jan Both <gert-jan.both@pasqal.com>, Niklas Heim <niklas.heim@pasqal.com>, Mario Dagrada <mario.dagrada@pasqal.com>, Vincent Elfving <vincent.elfving@pasqal.com>, Dominik Seitz <dominik.seitz@pasqal.com>, Roland Guichard <roland.guichard@pasqal.com>, "Joao P. Moutinho" <joao.moutinho@pasqal.com>, Vytautas Abramavicius <vytautas.abramavicius@pasqal.com>, Gergana Velikova <gergana.velikova@pasqal.com>, Eduardo Maschio <eduardo.maschio@pasqal.com>, Smit Chaudhary <smit.chaudhary@pasqal.com>
6
6
  License: Apache 2.0
7
7
  License-File: LICENSE
8
8
  Classifier: License :: OSI Approved :: Apache Software License
@@ -41,6 +41,7 @@ nav:
41
41
  - Variational quantum algorithms:
42
42
  - tutorials/qml/index.md
43
43
  - Training tools: tutorials/qml/ml_tools.md
44
+ - Configuring a QNN: tutorials/qml/config_qnn.md
44
45
  - Quantum circuit learning: tutorials/qml/qcl.md
45
46
  - Solving MaxCut with QAOA: tutorials/qml/qaoa.md
46
47
  - Solving a 1D ODE: tutorials/qml/dqc_1d.md
@@ -14,15 +14,16 @@ authors = [
14
14
  { name = "Vincent Elfving", email = "vincent.elfving@pasqal.com" },
15
15
  { name = "Dominik Seitz", email = "dominik.seitz@pasqal.com" },
16
16
  { name = "Roland Guichard", email = "roland.guichard@pasqal.com" },
17
- { name = "Joao P. Moutinho", email = "joao.moutinho@pasqal.com"},
17
+ { name = "Joao P. Moutinho", email = "joao.moutinho@pasqal.com" },
18
18
  { name = "Vytautas Abramavicius", email = "vytautas.abramavicius@pasqal.com" },
19
19
  { name = "Gergana Velikova", email = "gergana.velikova@pasqal.com" },
20
20
  { name = "Eduardo Maschio", email = "eduardo.maschio@pasqal.com" },
21
+ { name = "Smit Chaudhary", email = "smit.chaudhary@pasqal.com" },
21
22
  ]
22
23
  requires-python = ">=3.9"
23
- license = {text = "Apache 2.0"}
24
- version = "1.6.3"
25
- classifiers=[
24
+ license = { text = "Apache 2.0" }
25
+ version = "1.7.0"
26
+ classifiers = [
26
27
  "License :: OSI Approved :: Apache Software License",
27
28
  "Programming Language :: Python",
28
29
  "Programming Language :: Python :: 3",
@@ -55,13 +56,17 @@ allow-direct-references = true
55
56
  allow-ambiguous-features = true
56
57
 
57
58
  [project.optional-dependencies]
58
- pulser = ["pulser-core==0.18.1", "pulser-simulation==0.18.1","pasqal-cloud==0.10.1"]
59
+ pulser = [
60
+ "pulser-core==0.18.1",
61
+ "pulser-simulation==0.18.1",
62
+ "pasqal-cloud==0.10.1",
63
+ ]
59
64
  braket = ["amazon-braket-sdk<1.71.2"]
60
65
  visualization = [
61
- "graphviz",
62
- # FIXME: will be needed once we support latex labels
63
- # "latex2svg @ git+https://github.com/Moonbase59/latex2svg.git#egg=latex2svg",
64
- # "scour",
66
+ "graphviz",
67
+ # FIXME: will be needed once we support latex labels
68
+ # "latex2svg @ git+https://github.com/Moonbase59/latex2svg.git#egg=latex2svg",
69
+ # "scour",
65
70
  ]
66
71
  horqrux = [
67
72
  "horqrux==0.6.0",
@@ -70,35 +75,30 @@ horqrux = [
70
75
  "optax",
71
76
  "jaxopt",
72
77
  "einops",
73
- "sympy2jax"]
78
+ "sympy2jax",
79
+ ]
74
80
  protocols = ["qadence-protocols"]
75
81
  libs = ["qadence-libs"]
76
82
  dlprof = ["nvidia-pyindex", "nvidia-dlprof[pytorch]"]
77
- all = [
78
- "pulser",
79
- "braket",
80
- "visualization",
81
- "protocols",
82
- "libs",
83
- ]
83
+ all = ["pulser", "braket", "visualization", "protocols", "libs"]
84
84
 
85
85
  [tool.hatch.envs.default]
86
86
  dependencies = [
87
- "flaky",
88
- "hypothesis",
89
- "pytest",
90
- "pytest-cov",
91
- "pytest-mypy",
92
- "pytest-xdist",
93
- "types-PyYAML",
94
- "ipykernel",
95
- "pre-commit",
96
- "black",
97
- "isort",
98
- "ruff",
99
- "pydocstringformatter",
87
+ "flaky",
88
+ "hypothesis",
89
+ "pytest",
90
+ "pytest-cov",
91
+ "pytest-mypy",
92
+ "pytest-xdist",
93
+ "types-PyYAML",
94
+ "ipykernel",
95
+ "pre-commit",
96
+ "black",
97
+ "isort",
98
+ "ruff",
99
+ "pydocstringformatter",
100
100
  ]
101
- features = ["pulser", "braket","visualization", "horqrux"]
101
+ features = ["pulser", "braket", "visualization", "horqrux"]
102
102
 
103
103
  [tool.hatch.envs.default.scripts]
104
104
  test = "pytest -n auto --cov-report lcov --cov-config=pyproject.toml --cov=qadence --cov=tests --ignore=./tests/test_examples.py {args}"
@@ -108,34 +108,32 @@ test-docs = "mkdocs build --clean --strict"
108
108
  test-all = "pytest -n auto {args} && mkdocs build --clean --strict"
109
109
 
110
110
  [tool.pytest.ini_options]
111
- markers = [
112
- "slow: marks tests as slow (deselect with '-m \"not slow\"')",
113
- ]
111
+ markers = ["slow: marks tests as slow (deselect with '-m \"not slow\"')"]
114
112
  testpaths = ["tests"]
115
113
  addopts = """-vvv"""
116
114
  xfail_strict = true
117
115
  filterwarnings = [
118
- "ignore:Call to deprecated create function FieldDescriptor",
119
- "ignore:Call to deprecated create function Descriptor",
120
- "ignore:Call to deprecated create function EnumDescriptor",
121
- "ignore:Call to deprecated create function EnumValueDescriptor",
122
- "ignore:Call to deprecated create function FileDescriptor",
123
- "ignore:Call to deprecated create function OneofDescriptor",
124
- "ignore:distutils Version classes are deprecated.",
125
- "ignore::DeprecationWarning"
116
+ "ignore:Call to deprecated create function FieldDescriptor",
117
+ "ignore:Call to deprecated create function Descriptor",
118
+ "ignore:Call to deprecated create function EnumDescriptor",
119
+ "ignore:Call to deprecated create function EnumValueDescriptor",
120
+ "ignore:Call to deprecated create function FileDescriptor",
121
+ "ignore:Call to deprecated create function OneofDescriptor",
122
+ "ignore:distutils Version classes are deprecated.",
123
+ "ignore::DeprecationWarning",
126
124
  ]
127
125
 
128
126
 
129
127
  [tool.hatch.envs.docs]
130
128
  dependencies = [
131
- "mkdocs",
132
- "mkdocs-material",
133
- "mkdocstrings",
134
- "mkdocstrings-python",
135
- "mkdocs-section-index",
136
- "mkdocs-exclude",
137
- "markdown-exec",
138
- "mike",
129
+ "mkdocs",
130
+ "mkdocs-material",
131
+ "mkdocstrings",
132
+ "mkdocstrings-python",
133
+ "mkdocs-section-index",
134
+ "mkdocs-exclude",
135
+ "markdown-exec",
136
+ "mike",
139
137
  ]
140
138
  features = ["pulser", "braket", "horqrux", "visualization"]
141
139
 
@@ -151,12 +149,12 @@ features = ["all"]
151
149
 
152
150
  [tool.hatch.build.targets.sdist]
153
151
  exclude = [
154
- "/.gitignore",
155
- "/.gitlab-ci-yml",
156
- "/.pre-commit-config.yml",
157
- "/tests",
158
- "/docs",
159
- "/examples",
152
+ "/.gitignore",
153
+ "/.gitlab-ci-yml",
154
+ "/.pre-commit-config.yml",
155
+ "/tests",
156
+ "/docs",
157
+ "/examples",
160
158
  ]
161
159
 
162
160
  [tool.hatch.build.targets.wheel]
@@ -167,15 +165,11 @@ branch = true
167
165
  parallel = true
168
166
 
169
167
  [tool.coverage.report]
170
- exclude_lines = [
171
- "no cov",
172
- "if __name__ == .__main__.:",
173
- "if TYPE_CHECKING:",
174
- ]
168
+ exclude_lines = ["no cov", "if __name__ == .__main__.:", "if TYPE_CHECKING:"]
175
169
 
176
170
  [tool.ruff]
177
171
  select = ["E", "F", "I", "Q"]
178
- extend-ignore = ["F841","F403"]
172
+ extend-ignore = ["F841", "F403"]
179
173
  line-length = 100
180
174
 
181
175
  [tool.ruff.isort]
@@ -183,8 +177,12 @@ required-imports = ["from __future__ import annotations"]
183
177
 
184
178
  [tool.ruff.per-file-ignores]
185
179
  "__init__.py" = ["F401", "E402"]
186
- "qadence/operations/primitive.py" = ["E742"] # Avoid ambiguous class name warning for identity.
187
- "qadence/backends/horqrux/convert_ops.py" = ["E741"] # Avoid ambiguous class name warning for 0.
180
+ "qadence/operations/primitive.py" = [
181
+ "E742",
182
+ ] # Avoid ambiguous class name warning for identity.
183
+ "qadence/backends/horqrux/convert_ops.py" = [
184
+ "E741",
185
+ ] # Avoid ambiguous class name warning for 0.
188
186
  "examples/*" = ["E402"] # Allow torch seed to be set before qadence imports
189
187
 
190
188
  [tool.ruff.mccabe]
@@ -49,7 +49,7 @@ from .exceptions import *
49
49
  from .execution import *
50
50
  from .measurements import *
51
51
  from .ml_tools import *
52
- from .models import *
52
+ from .model import *
53
53
  from .noise import *
54
54
  from .operations import *
55
55
  from .overlap import *
@@ -82,7 +82,7 @@ list_of_submodules = [
82
82
  ".execution",
83
83
  ".measurements",
84
84
  ".ml_tools",
85
- ".models",
85
+ ".model",
86
86
  ".operations",
87
87
  ".overlap",
88
88
  ".parameters",
@@ -253,7 +253,8 @@ class PyQHamiltonianEvolution(Module):
253
253
  """Approximate jacobian of the evolved operator with respect to time evolution."""
254
254
  return finitediff(
255
255
  lambda t: self._unitary(time_evolution=t, hamiltonian=self._hamiltonian(self, values)),
256
- values[self.param_names[0]],
256
+ values[self.param_names[0]].reshape(-1, 1),
257
+ (0,),
257
258
  )
258
259
 
259
260
  def jacobian_generator(self, values: dict[str, Tensor]) -> Tensor:
@@ -280,7 +281,8 @@ class PyQHamiltonianEvolution(Module):
280
281
  lambda v: self._unitary(
281
282
  time_evolution=self._time_evolution(values), hamiltonian=_generator(v)
282
283
  ),
283
- values[self.param_names[1]],
284
+ values[self.param_names[1]].reshape(-1, 1),
285
+ (0,),
284
286
  )
285
287
 
286
288
  def dagger(self, values: dict[str, Tensor]) -> Tensor:
@@ -20,8 +20,8 @@ from torch import (
20
20
  rand,
21
21
  )
22
22
 
23
- from qadence.types import ParamDictType
24
- from qadence.utils import Endianness, int_to_basis, is_qadence_shape
23
+ from qadence.types import Endianness, ParamDictType
24
+ from qadence.utils import int_to_basis, is_qadence_shape
25
25
 
26
26
  FINITE_DIFF_EPS = 1e-06
27
27
  # Dict of NumPy dtype -> torch dtype (when the correspondence exists)
@@ -152,8 +152,49 @@ def infer_batchsize(param_values: ParamDictType = None) -> int:
152
152
  # native 'jacobian' methods.
153
153
 
154
154
 
155
- def finitediff(f: Callable, x: Tensor, eps: float = FINITE_DIFF_EPS) -> Tensor:
156
- return (f(x + eps) - f(x - eps)) / (2 * eps) # type: ignore
155
+ def finitediff(
156
+ f: Callable,
157
+ x: Tensor,
158
+ derivative_indices: tuple[int, ...],
159
+ eps: float = None,
160
+ ) -> Tensor:
161
+ """
162
+ Compute the finite difference of a function at a point.
163
+
164
+ Args:
165
+ f: The function to differentiate.
166
+ x: Input of size `(batch_size, input_size)`.
167
+ derivative_indices: Which *input* to differentiate (i.e. which variable x[:,i])
168
+ eps: finite difference spacing (uses `torch.finfo(x.dtype).eps ** (1 / (2 + order))`
169
+ as default)
170
+
171
+ Returns:
172
+ (Tensor): The finite difference of the function at the point `x`.
173
+ """
174
+
175
+ if eps is None:
176
+ order = len(derivative_indices)
177
+ eps = torch.finfo(x.dtype).eps ** (1 / (2 + order))
178
+
179
+ # compute derivative direction vector(s)
180
+ eps = torch.as_tensor(eps, dtype=x.dtype)
181
+ _eps = 1 / eps # type: ignore[operator]
182
+ ev = torch.zeros_like(x)
183
+ i = derivative_indices[0]
184
+ ev[:, i] += eps
185
+
186
+ # recursive finite differencing for higher order than 3 / mixed derivatives
187
+ if len(derivative_indices) > 3 or len(set(derivative_indices)) > 1:
188
+ di = derivative_indices[1:]
189
+ return (finitediff(f, x + ev, di) - finitediff(f, x - ev, di)) * _eps / 2
190
+ elif len(derivative_indices) == 3:
191
+ return (f(x + 2 * ev) - 2 * f(x + ev) + 2 * f(x - ev) - f(x - 2 * ev)) * _eps**3 / 2
192
+ elif len(derivative_indices) == 2:
193
+ return (f(x + ev) + f(x - ev) - 2 * f(x)) * _eps**2
194
+ elif len(derivative_indices) == 1:
195
+ return (f(x + ev) - f(x - ev)) * _eps / 2
196
+ else:
197
+ raise ValueError("If you see this error there is a bug in the `finitediff` function.")
157
198
 
158
199
 
159
200
  def finitediff_sampling(
@@ -27,7 +27,7 @@ class MatrixBlock(PrimitiveBlock):
27
27
  from qadence.circuit import QuantumCircuit
28
28
  from qadence.types import BackendName, DiffMode
29
29
  from qadence.blocks.matrix import MatrixBlock
30
- from qadence.models import QuantumModel
30
+ from qadence.model import QuantumModel
31
31
  from qadence.operations import X, Z
32
32
  from qadence.states import random_state
33
33
 
@@ -27,7 +27,7 @@ class PrimitiveBlock(AbstractBlock):
27
27
  Primitive blocks represent elementary unitary operations.
28
28
 
29
29
  Examples are single/multi-qubit gates or Hamiltonian evolution.
30
- See [`qadence.operations`](/qadence/operations.md) for a full list of
30
+ See [`qadence.operations`](operations.md) for a full list of
31
31
  primitive blocks.
32
32
  """
33
33
 
@@ -14,6 +14,7 @@ from .daqc import daqc_transform
14
14
  from .hamiltonians import (
15
15
  hamiltonian_factory,
16
16
  ising_hamiltonian,
17
+ ObservableConfig,
17
18
  total_magnetization,
18
19
  zz_hamiltonian,
19
20
  )
@@ -31,6 +32,7 @@ __all__ = [
31
32
  "identity_initialized_ansatz",
32
33
  "hamiltonian_factory",
33
34
  "ising_hamiltonian",
35
+ "ObservableConfig",
34
36
  "total_magnetization",
35
37
  "zz_hamiltonian",
36
38
  "qft",
@@ -1,15 +1,17 @@
1
1
  from __future__ import annotations
2
2
 
3
+ from dataclasses import dataclass
3
4
  from logging import getLogger
4
5
  from typing import Callable, List, Type, Union
5
6
 
6
7
  import numpy as np
7
8
  from torch import Tensor, double, ones, rand
9
+ from typing_extensions import Any
8
10
 
9
11
  from qadence.blocks import AbstractBlock, add, block_is_qubit_hamiltonian
10
12
  from qadence.operations import N, X, Y, Z
11
13
  from qadence.register import Register
12
- from qadence.types import Interaction, TArray
14
+ from qadence.types import Interaction, ObservableTransform, TArray, TParameter
13
15
 
14
16
  logger = getLogger(__name__)
15
17
 
@@ -229,3 +231,38 @@ def ising_hamiltonian(
229
231
  zz_ham = zz_hamiltonian(n_qubits, z_terms=z_terms, zz_terms=zz_terms)
230
232
  x_ham = hamiltonian_factory(n_qubits, detuning=X, detuning_strength=x_terms)
231
233
  return zz_ham + x_ham
234
+
235
+
236
+ def is_numeric(x: Any) -> bool:
237
+ return type(x) in (int, float, complex, np.int64, np.float64)
238
+
239
+
240
+ @dataclass
241
+ class ObservableConfig:
242
+ detuning: TDetuning
243
+ """
244
+ Single qubit detuning of the observable Hamiltonian.
245
+
246
+ Accepts single-qubit operator N, X, Y, or Z.
247
+ """
248
+ scale: TParameter = 1.0
249
+ """The scale by which to multiply the output of the observable."""
250
+ shift: TParameter = 0.0
251
+ """The shift to add to the output of the observable."""
252
+ transformation_type: ObservableTransform = ObservableTransform.NONE # type: ignore[assignment]
253
+ """The type of transformation."""
254
+ trainable_transform: bool | None = None
255
+ """
256
+ Whether to have a trainable transformation on the output of the observable.
257
+
258
+ If None, the scale and shift are numbers.
259
+ If True, the scale and shift are VariationalParameter.
260
+ If False, the scale and shift are FeatureParameter.
261
+ """
262
+
263
+ def __post_init__(self) -> None:
264
+ if is_numeric(self.scale) and is_numeric(self.shift):
265
+ assert (
266
+ self.trainable_transform is None
267
+ ), f"If scale and shift are numbers, trainable_transform must be None. \
268
+ But got: {self.trainable_transform}"
@@ -23,7 +23,7 @@ from qadence.blocks import (
23
23
  )
24
24
  from qadence.blocks.analog import ConstantAnalogRotation, InteractionBlock
25
25
  from qadence.circuit import QuantumCircuit
26
- from qadence.models import QuantumModel
26
+ from qadence.model import QuantumModel
27
27
  from qadence.operations import RX, RY, RZ, SWAP, HamEvo, I
28
28
  from qadence.transpile.block import fill_identities
29
29
  from qadence.utils import format_parameter
@@ -1,7 +1,9 @@
1
1
  from __future__ import annotations
2
2
 
3
- from .config import TrainConfig
3
+ from .config import AnsatzConfig, FeatureMapConfig, TrainConfig
4
+ from .constructors import create_ansatz, create_fm_blocks, observable_from_config
4
5
  from .data import DictDataLoader, InfiniteTensorDataset, to_dataloader
6
+ from .models import QNN
5
7
  from .optimize_step import optimize_step as default_optimize_step
6
8
  from .parameters import get_parameters, num_parameters, set_parameters
7
9
  from .printing import print_metrics, write_tensorboard
@@ -12,10 +14,16 @@ from .train_no_grad import train as train_gradient_free
12
14
 
13
15
  # Modules to be automatically added to the qadence namespace
14
16
  __all__ = [
15
- "TrainConfig",
17
+ "AnsatzConfig",
18
+ "create_ansatz",
19
+ "create_fm_blocks",
16
20
  "DictDataLoader",
21
+ "FeatureMapConfig",
22
+ "load_checkpoint",
23
+ "observable_from_config",
24
+ "QNN",
25
+ "TrainConfig",
17
26
  "train_with_grad",
18
27
  "train_gradient_free",
19
- "load_checkpoint",
20
28
  "write_checkpoint",
21
29
  ]