qadence 1.4.1__tar.gz → 1.5.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.
- {qadence-1.4.1 → qadence-1.5.0}/PKG-INFO +10 -5
- {qadence-1.4.1 → qadence-1.5.0}/README.md +2 -0
- {qadence-1.4.1 → qadence-1.5.0}/pyproject.toml +6 -4
- {qadence-1.4.1 → qadence-1.5.0}/qadence/__init__.py +1 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/backends/pyqtorch/backend.py +25 -22
- {qadence-1.4.1 → qadence-1.5.0}/qadence/backends/pyqtorch/convert_ops.py +25 -10
- {qadence-1.4.1 → qadence-1.5.0}/qadence/backends/utils.py +3 -2
- {qadence-1.4.1 → qadence-1.5.0}/qadence/engines/torch/differentiable_expectation.py +4 -164
- qadence-1.5.0/qadence/libs.py +15 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/ml_tools/data.py +11 -11
- {qadence-1.4.1 → qadence-1.5.0}/qadence/ml_tools/models.py +8 -8
- {qadence-1.4.1 → qadence-1.5.0}/qadence/ml_tools/optimize_step.py +2 -1
- {qadence-1.4.1 → qadence-1.5.0}/qadence/ml_tools/train_grad.py +4 -2
- {qadence-1.4.1 → qadence-1.5.0}/qadence/models/quantum_model.py +12 -7
- qadence-1.5.0/renovate.json +15 -0
- {qadence-1.4.1 → qadence-1.5.0}/.coveragerc +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/.github/dependabot.yml +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/.github/workflows/build_docs.yml +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/.github/workflows/dependabot.yml +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/.github/workflows/lint.yml +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/.github/workflows/test_all.yml +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/.github/workflows/test_examples.yml +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/.github/workflows/test_fast.yml +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/.gitignore +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/.pre-commit-config.yaml +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/LICENSE +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/MANIFEST.in +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/mkdocs.yml +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/analog/__init__.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/analog/addressing.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/analog/constants.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/analog/device.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/analog/hamiltonian_terms.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/analog/parse_analog.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/backend.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/backends/__init__.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/backends/adjoint.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/backends/api.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/backends/braket/__init__.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/backends/braket/backend.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/backends/braket/config.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/backends/braket/convert_ops.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/backends/gpsr.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/backends/horqrux/__init__.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/backends/horqrux/backend.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/backends/horqrux/config.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/backends/horqrux/convert_ops.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/backends/jax_utils.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/backends/pulser/__init__.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/backends/pulser/backend.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/backends/pulser/channels.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/backends/pulser/cloud.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/backends/pulser/config.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/backends/pulser/convert_ops.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/backends/pulser/devices.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/backends/pulser/pulses.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/backends/pulser/waveforms.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/backends/pyqtorch/__init__.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/backends/pyqtorch/config.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/blocks/__init__.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/blocks/abstract.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/blocks/analog.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/blocks/block_to_tensor.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/blocks/composite.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/blocks/embedding.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/blocks/manipulate.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/blocks/matrix.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/blocks/primitive.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/blocks/utils.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/circuit.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/constructors/__init__.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/constructors/ansatze.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/constructors/daqc/__init__.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/constructors/daqc/daqc.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/constructors/daqc/gen_parser.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/constructors/daqc/utils.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/constructors/feature_maps.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/constructors/hamiltonians.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/constructors/iia.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/constructors/qft.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/constructors/rydberg_feature_maps.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/constructors/rydberg_hea.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/constructors/utils.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/decompose.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/divergences.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/draw/__init__.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/draw/assets/dark/measurement.png +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/draw/assets/dark/measurement.svg +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/draw/assets/light/measurement.png +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/draw/assets/light/measurement.svg +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/draw/themes.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/draw/utils.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/draw/vizbackend.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/engines/__init__.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/engines/differentiable_backend.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/engines/jax/__init__.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/engines/jax/differentiable_backend.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/engines/jax/differentiable_expectation.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/engines/torch/__init__.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/engines/torch/differentiable_backend.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/exceptions/__init__.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/exceptions/exceptions.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/execution.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/extensions.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/finitediff.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/logger.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/measurements/__init__.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/measurements/protocols.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/measurements/samples.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/measurements/shadow.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/measurements/tomography.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/measurements/utils.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/mitigations/__init__.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/mitigations/analog_zne.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/mitigations/protocols.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/mitigations/readout.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/ml_tools/__init__.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/ml_tools/config.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/ml_tools/parameters.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/ml_tools/printing.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/ml_tools/saveload.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/ml_tools/tensors.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/ml_tools/train_no_grad.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/ml_tools/utils.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/models/__init__.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/models/qnn.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/noise/__init__.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/noise/protocols.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/noise/readout.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/operations/__init__.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/operations/analog.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/operations/control_ops.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/operations/ham_evo.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/operations/parametric.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/operations/primitive.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/overlap.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/parameters.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/protocols.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/py.typed +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/qubit_support.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/register.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/serialization.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/states.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/transpile/__init__.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/transpile/apply_fn.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/transpile/block.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/transpile/circuit.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/transpile/digitalize.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/transpile/flatten.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/transpile/invert.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/transpile/transpile.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/types.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/qadence/utils.py +0 -0
- {qadence-1.4.1 → qadence-1.5.0}/setup.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.3
|
2
2
|
Name: qadence
|
3
|
-
Version: 1.
|
3
|
+
Version: 1.5.0
|
4
4
|
Summary: Pasqal interface for circuit-based quantum computing SDKs
|
5
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>
|
6
6
|
License: Apache 2.0
|
@@ -13,14 +13,14 @@ Classifier: Programming Language :: Python :: 3.10
|
|
13
13
|
Classifier: Programming Language :: Python :: 3.11
|
14
14
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
15
15
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
16
|
-
Requires-Python: <3.
|
16
|
+
Requires-Python: <3.13,>=3.9
|
17
17
|
Requires-Dist: deepdiff
|
18
18
|
Requires-Dist: jsonschema
|
19
19
|
Requires-Dist: matplotlib
|
20
20
|
Requires-Dist: nevergrad
|
21
21
|
Requires-Dist: numpy
|
22
22
|
Requires-Dist: openfermion
|
23
|
-
Requires-Dist: pyqtorch==1.0
|
23
|
+
Requires-Dist: pyqtorch==1.1.0
|
24
24
|
Requires-Dist: rich
|
25
25
|
Requires-Dist: scipy
|
26
26
|
Requires-Dist: sympytorch>=0.1.2
|
@@ -29,10 +29,11 @@ Requires-Dist: torch
|
|
29
29
|
Provides-Extra: all
|
30
30
|
Requires-Dist: amazon-braket-sdk; extra == 'all'
|
31
31
|
Requires-Dist: graphviz; extra == 'all'
|
32
|
+
Requires-Dist: libs; extra == 'all'
|
32
33
|
Requires-Dist: protocols; extra == 'all'
|
33
34
|
Requires-Dist: pulser>=0.15.2; extra == 'all'
|
34
35
|
Provides-Extra: braket
|
35
|
-
Requires-Dist: amazon-braket-sdk; extra == 'braket'
|
36
|
+
Requires-Dist: amazon-braket-sdk==1.71.0; extra == 'braket'
|
36
37
|
Provides-Extra: horqrux
|
37
38
|
Requires-Dist: einops; extra == 'horqrux'
|
38
39
|
Requires-Dist: flax; extra == 'horqrux'
|
@@ -41,6 +42,8 @@ Requires-Dist: jax; extra == 'horqrux'
|
|
41
42
|
Requires-Dist: jaxopt; extra == 'horqrux'
|
42
43
|
Requires-Dist: optax; extra == 'horqrux'
|
43
44
|
Requires-Dist: sympy2jax; extra == 'horqrux'
|
45
|
+
Provides-Extra: libs
|
46
|
+
Requires-Dist: qadence-libs; extra == 'libs'
|
44
47
|
Provides-Extra: protocols
|
45
48
|
Requires-Dist: qadence-protocols; extra == 'protocols'
|
46
49
|
Provides-Extra: pulser
|
@@ -106,6 +109,8 @@ The default, pre-installed backend for Qadence is [PyQTorch](https://github.com/
|
|
106
109
|
* `pulser`: The [Pulser](https://github.com/pasqal-io/Pulser) backend for composing, simulating and executing pulse sequences for neutral-atom quantum devices.
|
107
110
|
* `braket`: The [Braket](https://github.com/amazon-braket/amazon-braket-sdk-python) backend, an open source library that provides a framework for interacting with quantum computing hardware devices through Amazon Braket.
|
108
111
|
* `visualization`: A visualization library to display quantum circuit diagrams.
|
112
|
+
* `protocols`: A collection of [protocols](https://github.com/pasqal-io/qadence-protocols) for error mitigation in Qadence.
|
113
|
+
* `libs`: A collection of [functionalities](https://github.com/pasqal-io/qadence-libs) for graph machine learning problems build on top of Qadence.
|
109
114
|
|
110
115
|
Qadence also supports a `JAX` engine which is currently supporting the [Horqrux](https://github.com/pasqal-io/horqrux) backend. `horqrux` is currently only available via the [low-level API](examples/backends/low_level/horqrux_backend.py).
|
111
116
|
|
@@ -54,6 +54,8 @@ The default, pre-installed backend for Qadence is [PyQTorch](https://github.com/
|
|
54
54
|
* `pulser`: The [Pulser](https://github.com/pasqal-io/Pulser) backend for composing, simulating and executing pulse sequences for neutral-atom quantum devices.
|
55
55
|
* `braket`: The [Braket](https://github.com/amazon-braket/amazon-braket-sdk-python) backend, an open source library that provides a framework for interacting with quantum computing hardware devices through Amazon Braket.
|
56
56
|
* `visualization`: A visualization library to display quantum circuit diagrams.
|
57
|
+
* `protocols`: A collection of [protocols](https://github.com/pasqal-io/qadence-protocols) for error mitigation in Qadence.
|
58
|
+
* `libs`: A collection of [functionalities](https://github.com/pasqal-io/qadence-libs) for graph machine learning problems build on top of Qadence.
|
57
59
|
|
58
60
|
Qadence also supports a `JAX` engine which is currently supporting the [Horqrux](https://github.com/pasqal-io/horqrux) backend. `horqrux` is currently only available via the [low-level API](examples/backends/low_level/horqrux_backend.py).
|
59
61
|
|
@@ -18,9 +18,9 @@ authors = [
|
|
18
18
|
{ name = "Vytautas Abramavicius", email = "vytautas.abramavicius@pasqal.com" },
|
19
19
|
{ name = "Gergana Velikova", email = "gergana.velikova@pasqal.com" },
|
20
20
|
]
|
21
|
-
requires-python = ">=3.9,<3.
|
21
|
+
requires-python = ">=3.9,<3.13"
|
22
22
|
license = {text = "Apache 2.0"}
|
23
|
-
version = "1.
|
23
|
+
version = "1.5.0"
|
24
24
|
classifiers=[
|
25
25
|
"License :: OSI Approved :: Apache Software License",
|
26
26
|
"Programming Language :: Python",
|
@@ -42,7 +42,7 @@ dependencies = [
|
|
42
42
|
"jsonschema",
|
43
43
|
"nevergrad",
|
44
44
|
"scipy",
|
45
|
-
"pyqtorch==1.0
|
45
|
+
"pyqtorch==1.1.0",
|
46
46
|
"matplotlib",
|
47
47
|
]
|
48
48
|
|
@@ -52,7 +52,7 @@ allow-ambiguous-features = true
|
|
52
52
|
|
53
53
|
[project.optional-dependencies]
|
54
54
|
pulser = ["pulser>=v0.15.2", "pasqal-cloud>=0.3.5"]
|
55
|
-
braket = ["amazon-braket-sdk"]
|
55
|
+
braket = ["amazon-braket-sdk==1.71.0"]
|
56
56
|
visualization = [
|
57
57
|
"graphviz",
|
58
58
|
# FIXME: will be needed once we support latex labels
|
@@ -68,11 +68,13 @@ horqrux = [
|
|
68
68
|
"einops",
|
69
69
|
"sympy2jax"]
|
70
70
|
protocols = ["qadence-protocols"]
|
71
|
+
libs = ["qadence-libs"]
|
71
72
|
all = [
|
72
73
|
"pulser>=0.15.2",
|
73
74
|
"amazon-braket-sdk",
|
74
75
|
"graphviz",
|
75
76
|
"protocols",
|
77
|
+
"libs",
|
76
78
|
# FIXME: will be needed once we support latex labels
|
77
79
|
# "latex2svg @ git+https://github.com/Moonbase59/latex2svg.git#egg=latex2svg",
|
78
80
|
# "scour",
|
@@ -32,6 +32,7 @@ DEFAULT_FLOAT_DTYPE = torchfloat64
|
|
32
32
|
DEFAULT_COMPLEX_DTYPE = cdouble
|
33
33
|
set_default_dtype(DEFAULT_FLOAT_DTYPE)
|
34
34
|
|
35
|
+
|
35
36
|
"""Fetch the functions defined in the __all__ of each sub-module.
|
36
37
|
|
37
38
|
Import to the qadence name space. Make sure each added submodule has the respective definition:
|
@@ -151,7 +151,9 @@ class Backend(BackendInterface):
|
|
151
151
|
if state is None:
|
152
152
|
from qadence.states import zero_state
|
153
153
|
|
154
|
-
state = zero_state(circuit.abstract.n_qubits, batch_size=1)
|
154
|
+
state = zero_state(circuit.abstract.n_qubits, batch_size=1).to(
|
155
|
+
dtype=circuit.native.dtype
|
156
|
+
)
|
155
157
|
if state.size(0) != 1:
|
156
158
|
raise ValueError(
|
157
159
|
"Looping expectation does not make sense with batched initial state. "
|
@@ -222,28 +224,29 @@ class Backend(BackendInterface):
|
|
222
224
|
}
|
223
225
|
)
|
224
226
|
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
_probs
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
if noise is not None:
|
239
|
-
samples = apply_noise(noise=noise, samples=samples)
|
240
|
-
if mitigation is not None:
|
241
|
-
logger.warning(
|
242
|
-
"Mitigation protocol is deprecated. Use qadence-protocols instead.",
|
227
|
+
with torch.no_grad():
|
228
|
+
wf = self.run(circuit=circuit, param_values=param_values, state=state)
|
229
|
+
probs = torch.abs(torch.pow(wf, 2))
|
230
|
+
samples = list(
|
231
|
+
map(
|
232
|
+
lambda _probs: _sample(
|
233
|
+
_probs=_probs,
|
234
|
+
n_shots=n_shots,
|
235
|
+
endianness=endianness,
|
236
|
+
n_qubits=circuit.abstract.n_qubits,
|
237
|
+
),
|
238
|
+
probs,
|
239
|
+
)
|
243
240
|
)
|
244
|
-
|
245
|
-
|
246
|
-
|
241
|
+
if noise is not None:
|
242
|
+
samples = apply_noise(noise=noise, samples=samples)
|
243
|
+
if mitigation is not None:
|
244
|
+
logger.warning(
|
245
|
+
"Mitigation protocol is deprecated. Use qadence-protocols instead.",
|
246
|
+
)
|
247
|
+
assert noise
|
248
|
+
samples = apply_mitigation(noise=noise, mitigation=mitigation, samples=samples)
|
249
|
+
return samples
|
247
250
|
|
248
251
|
def assign_parameters(self, circuit: ConvertedCircuit, param_values: dict[str, Tensor]) -> Any:
|
249
252
|
raise NotImplementedError
|
@@ -4,7 +4,7 @@ from functools import reduce
|
|
4
4
|
from itertools import chain as flatten
|
5
5
|
from math import prod
|
6
6
|
from operator import add
|
7
|
-
from typing import Sequence, Tuple
|
7
|
+
from typing import Any, Sequence, Tuple
|
8
8
|
|
9
9
|
import pyqtorch as pyq
|
10
10
|
import sympy
|
@@ -26,6 +26,7 @@ from torch import (
|
|
26
26
|
transpose,
|
27
27
|
)
|
28
28
|
from torch import device as torch_device
|
29
|
+
from torch import dtype as torch_dtype
|
29
30
|
from torch.nn import Module
|
30
31
|
|
31
32
|
from qadence.backends.utils import (
|
@@ -178,6 +179,7 @@ class PyQMatrixBlock(Module):
|
|
178
179
|
self.register_buffer("mat", block.matrix.unsqueeze(2))
|
179
180
|
self.mat: Tensor
|
180
181
|
self._device: torch_device = self.mat.device
|
182
|
+
self._dtype: torch_dtype = self.mat.dtype
|
181
183
|
|
182
184
|
def forward(self, state: Tensor, _: dict[str, Tensor] = None) -> Tensor:
|
183
185
|
return apply_operator(state, self.mat, self.qubits, self.n_qubits)
|
@@ -186,9 +188,10 @@ class PyQMatrixBlock(Module):
|
|
186
188
|
def device(self) -> torch_device:
|
187
189
|
return self._device
|
188
190
|
|
189
|
-
def to(self,
|
190
|
-
self.mat = self.mat.to(
|
191
|
-
self._device = device
|
191
|
+
def to(self, *args: Any, **kwargs: Any) -> PyQMatrixBlock:
|
192
|
+
self.mat = self.mat.to(*args, **kwargs)
|
193
|
+
self._device = self.mat.device
|
194
|
+
self._dtype = self.mat.dtype
|
192
195
|
return self
|
193
196
|
|
194
197
|
|
@@ -262,6 +265,7 @@ class PyQObservable(Module):
|
|
262
265
|
)
|
263
266
|
self._forward = lambda self, state, values: self.operation(state, values)
|
264
267
|
self._device = self.operation.device
|
268
|
+
self._dtype = self.operation.dtype
|
265
269
|
|
266
270
|
def run(self, state: Tensor, values: dict[str, Tensor]) -> Tensor:
|
267
271
|
return self._forward(self, state, values)
|
@@ -273,9 +277,14 @@ class PyQObservable(Module):
|
|
273
277
|
def device(self) -> torch_device:
|
274
278
|
return self._device
|
275
279
|
|
276
|
-
|
277
|
-
|
278
|
-
self.
|
280
|
+
@property
|
281
|
+
def dtype(self) -> torch_dtype:
|
282
|
+
return self._dtype
|
283
|
+
|
284
|
+
def to(self, *args: Any, **kwargs: Any) -> PyQObservable:
|
285
|
+
self.operation = self.operation.to(*args, **kwargs)
|
286
|
+
self._device = self.operation.device
|
287
|
+
self._dtype = self.operation.dtype
|
279
288
|
return self
|
280
289
|
|
281
290
|
|
@@ -338,6 +347,7 @@ class PyQHamiltonianEvolution(Module):
|
|
338
347
|
self._device: torch_device = (
|
339
348
|
self.hmat.device if hasattr(self, "hmat") else torch_device("cpu")
|
340
349
|
)
|
350
|
+
self._dtype: torch_dtype = self.hmat.dtype if hasattr(self, "hmat") else cdouble
|
341
351
|
|
342
352
|
def _unitary(self, hamiltonian: Tensor, time_evolution: Tensor) -> Tensor:
|
343
353
|
self.batch_size = max(hamiltonian.size()[2], len(time_evolution))
|
@@ -419,10 +429,15 @@ class PyQHamiltonianEvolution(Module):
|
|
419
429
|
def device(self) -> torch_device:
|
420
430
|
return self._device
|
421
431
|
|
422
|
-
|
432
|
+
@property
|
433
|
+
def dtype(self) -> torch_dtype:
|
434
|
+
return self._dtype
|
435
|
+
|
436
|
+
def to(self, *args: Any, **kwargs: Any) -> PyQHamiltonianEvolution:
|
423
437
|
if hasattr(self, "hmat"):
|
424
|
-
self.hmat = self.hmat.to(
|
425
|
-
|
438
|
+
self.hmat = self.hmat.to(*args, **kwargs)
|
439
|
+
self._device = self.hmat.device
|
440
|
+
self._dtype = self.hmat.dtype
|
426
441
|
return self
|
427
442
|
|
428
443
|
|
@@ -13,6 +13,7 @@ from pyqtorch.parametric import Parametric as PyQParametric
|
|
13
13
|
from torch import (
|
14
14
|
Tensor,
|
15
15
|
cat,
|
16
|
+
complex64,
|
16
17
|
complex128,
|
17
18
|
mean,
|
18
19
|
no_grad,
|
@@ -129,8 +130,8 @@ def is_pyq_shape(state: Tensor, n_qubits: int) -> bool:
|
|
129
130
|
|
130
131
|
def validate_state(state: Tensor, n_qubits: int) -> None:
|
131
132
|
"""Check if a custom initial state conforms to the qadence or the pyqtorch format."""
|
132
|
-
if state.dtype
|
133
|
-
raise TypeError(f"Expected
|
133
|
+
if state.dtype not in [complex128, complex64]:
|
134
|
+
raise TypeError(f"Expected complex dtype, got {state.dtype}")
|
134
135
|
elif len(state.size()) < 2:
|
135
136
|
raise ValueError(f"Invalid state shape. Got {state.shape}")
|
136
137
|
elif not is_qadence_shape(state, n_qubits) and not is_pyq_shape(state, n_qubits):
|
@@ -1,6 +1,6 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
|
3
|
-
from collections import
|
3
|
+
from collections import OrderedDict
|
4
4
|
from dataclasses import dataclass
|
5
5
|
from functools import partial
|
6
6
|
from typing import Any, Callable, Sequence
|
@@ -8,22 +8,19 @@ from typing import Any, Callable, Sequence
|
|
8
8
|
import torch
|
9
9
|
from torch import Tensor
|
10
10
|
from torch.autograd import Function
|
11
|
-
from torch.nn import Module
|
12
11
|
|
13
12
|
from qadence.backend import Backend as QuantumBackend
|
14
|
-
from qadence.backend import
|
13
|
+
from qadence.backend import ConvertedCircuit, ConvertedObservable
|
15
14
|
from qadence.backends.adjoint import AdjointExpectation
|
16
15
|
from qadence.backends.utils import infer_batchsize, is_pyq_shape, param_dict, pyqify, validate_state
|
17
16
|
from qadence.blocks.abstract import AbstractBlock
|
18
|
-
from qadence.blocks.
|
19
|
-
from qadence.blocks.utils import uuid_to_block, uuid_to_eigen
|
17
|
+
from qadence.blocks.utils import uuid_to_eigen
|
20
18
|
from qadence.circuit import QuantumCircuit
|
21
|
-
from qadence.extensions import get_gpsr_fns
|
22
19
|
from qadence.measurements import Measurements
|
23
20
|
from qadence.mitigations import Mitigations
|
24
21
|
from qadence.ml_tools import promote_to_tensor
|
25
22
|
from qadence.noise import Noise
|
26
|
-
from qadence.types import
|
23
|
+
from qadence.types import Endianness
|
27
24
|
|
28
25
|
|
29
26
|
class PSRExpectation(Function):
|
@@ -232,160 +229,3 @@ class DifferentiableExpectation:
|
|
232
229
|
# Since they are constants their gradients are 0.
|
233
230
|
param_to_psr[param_id] = lambda x: torch.tensor([0.0], requires_grad=False)
|
234
231
|
return param_to_psr
|
235
|
-
|
236
|
-
|
237
|
-
class DifferentiableBackend(Module):
|
238
|
-
"""A class to abstract the operations done by the autodiff engine.
|
239
|
-
|
240
|
-
Arguments:
|
241
|
-
backend: An instance of the QuantumBackend type perform execution.
|
242
|
-
diff_mode: A differentiable mode supported by the differentiation engine.
|
243
|
-
**psr_args: Arguments that will be passed on to `DifferentiableExpectation`.
|
244
|
-
"""
|
245
|
-
|
246
|
-
def __init__(
|
247
|
-
self,
|
248
|
-
backend: QuantumBackend,
|
249
|
-
diff_mode: DiffMode = DiffMode.AD,
|
250
|
-
**psr_args: int | float | None,
|
251
|
-
) -> None:
|
252
|
-
super().__init__()
|
253
|
-
|
254
|
-
self.backend = backend
|
255
|
-
self.diff_mode = diff_mode
|
256
|
-
self.psr_args = psr_args
|
257
|
-
# TODO: Add differentiable overlap calculation
|
258
|
-
self._overlap: Callable = None # type: ignore [assignment]
|
259
|
-
|
260
|
-
def run(
|
261
|
-
self,
|
262
|
-
circuit: ConvertedCircuit,
|
263
|
-
param_values: dict = {},
|
264
|
-
state: Tensor | None = None,
|
265
|
-
endianness: Endianness = Endianness.BIG,
|
266
|
-
) -> Tensor:
|
267
|
-
"""Run on the underlying backend."""
|
268
|
-
return self.backend.run(
|
269
|
-
circuit=circuit, param_values=param_values, state=state, endianness=endianness
|
270
|
-
)
|
271
|
-
|
272
|
-
def expectation(
|
273
|
-
self,
|
274
|
-
circuit: ConvertedCircuit,
|
275
|
-
observable: list[ConvertedObservable] | ConvertedObservable,
|
276
|
-
param_values: dict[str, Tensor] = {},
|
277
|
-
state: Tensor | None = None,
|
278
|
-
measurement: Measurements | None = None,
|
279
|
-
noise: Noise | None = None,
|
280
|
-
mitigation: Mitigations | None = None,
|
281
|
-
endianness: Endianness = Endianness.BIG,
|
282
|
-
) -> Tensor:
|
283
|
-
"""Compute the expectation value of a given observable.
|
284
|
-
|
285
|
-
Arguments:
|
286
|
-
circuit: A backend native quantum circuit to be executed.
|
287
|
-
observable: A backend native observable to compute the expectation value from.
|
288
|
-
param_values: A dict of values for symbolic substitution.
|
289
|
-
state: An initial state.
|
290
|
-
measurement: A shot-based measurement protocol.
|
291
|
-
endianness: Endianness of the state.
|
292
|
-
|
293
|
-
Returns:
|
294
|
-
A tensor of expectation values.
|
295
|
-
"""
|
296
|
-
observable = observable if isinstance(observable, list) else [observable]
|
297
|
-
differentiable_expectation = DifferentiableExpectation(
|
298
|
-
backend=self.backend,
|
299
|
-
circuit=circuit,
|
300
|
-
observable=observable,
|
301
|
-
param_values=param_values,
|
302
|
-
state=state,
|
303
|
-
measurement=measurement,
|
304
|
-
noise=noise,
|
305
|
-
mitigation=mitigation,
|
306
|
-
endianness=endianness,
|
307
|
-
)
|
308
|
-
|
309
|
-
if self.diff_mode == DiffMode.AD:
|
310
|
-
expectation = differentiable_expectation.ad
|
311
|
-
elif self.diff_mode == DiffMode.ADJOINT:
|
312
|
-
expectation = differentiable_expectation.adjoint
|
313
|
-
else:
|
314
|
-
try:
|
315
|
-
fns = get_gpsr_fns()
|
316
|
-
psr_fn = fns[self.diff_mode]
|
317
|
-
except KeyError:
|
318
|
-
raise ValueError(f"{self.diff_mode} differentiation mode is not supported")
|
319
|
-
expectation = partial(differentiable_expectation.psr, psr_fn=psr_fn, **self.psr_args)
|
320
|
-
return expectation()
|
321
|
-
|
322
|
-
def sample(
|
323
|
-
self,
|
324
|
-
circuit: ConvertedCircuit,
|
325
|
-
param_values: dict[str, Tensor],
|
326
|
-
n_shots: int = 1,
|
327
|
-
state: Tensor | None = None,
|
328
|
-
noise: Noise | None = None,
|
329
|
-
mitigation: Mitigations | None = None,
|
330
|
-
endianness: Endianness = Endianness.BIG,
|
331
|
-
) -> list[Counter]:
|
332
|
-
"""Sample bitstring from the registered circuit.
|
333
|
-
|
334
|
-
Arguments:
|
335
|
-
circuit: A backend native quantum circuit to be executed.
|
336
|
-
param_values: The values of the parameters after embedding
|
337
|
-
n_shots: The number of shots. Defaults to 1.
|
338
|
-
state: Initial state.
|
339
|
-
noise: A noise model to use.
|
340
|
-
mitigation: A mitigation protocol to apply to noisy samples.
|
341
|
-
endianness: Endianness of the resulting bitstrings.
|
342
|
-
|
343
|
-
Returns:
|
344
|
-
An iterable with all the sampled bitstrings
|
345
|
-
"""
|
346
|
-
with torch.no_grad():
|
347
|
-
return self.backend.sample(
|
348
|
-
circuit=circuit,
|
349
|
-
param_values=param_values,
|
350
|
-
n_shots=n_shots,
|
351
|
-
state=state,
|
352
|
-
noise=noise,
|
353
|
-
mitigation=mitigation,
|
354
|
-
endianness=endianness,
|
355
|
-
)
|
356
|
-
|
357
|
-
def circuit(self, circuit: QuantumCircuit) -> ConvertedCircuit:
|
358
|
-
parametrized_blocks = list(uuid_to_block(circuit.block).values())
|
359
|
-
non_prim_blocks = filter(lambda b: not isinstance(b, PrimitiveBlock), parametrized_blocks)
|
360
|
-
if len(list(non_prim_blocks)) > 0:
|
361
|
-
raise ValueError(
|
362
|
-
"The circuit contains non-primitive blocks that are currently not supported by the "
|
363
|
-
"PSR differentiable mode."
|
364
|
-
)
|
365
|
-
return self.backend.circuit(circuit)
|
366
|
-
|
367
|
-
def observable(self, observable: AbstractBlock, n_qubits: int) -> ConvertedObservable:
|
368
|
-
if observable is not None and observable.is_parametric:
|
369
|
-
raise ValueError("PSR cannot be applied to a parametric observable.")
|
370
|
-
return self.backend.observable(observable, n_qubits)
|
371
|
-
|
372
|
-
def convert(
|
373
|
-
self,
|
374
|
-
circuit: QuantumCircuit,
|
375
|
-
observable: list[AbstractBlock] | AbstractBlock | None = None,
|
376
|
-
) -> Converted:
|
377
|
-
if self.diff_mode != DiffMode.AD and observable is not None:
|
378
|
-
msg = (
|
379
|
-
f"Differentiation mode '{self.diff_mode}' does not support parametric observables."
|
380
|
-
)
|
381
|
-
if isinstance(observable, list):
|
382
|
-
for obs in observable:
|
383
|
-
if obs.is_parametric:
|
384
|
-
raise ValueError(msg)
|
385
|
-
else:
|
386
|
-
if observable.is_parametric:
|
387
|
-
raise ValueError(msg)
|
388
|
-
return self.backend.convert(circuit, observable)
|
389
|
-
|
390
|
-
def assign_parameters(self, circuit: ConvertedCircuit, param_values: dict[str, Tensor]) -> Any:
|
391
|
-
return self.backend.assign_parameters(circuit, param_values)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
import importlib
|
4
|
+
|
5
|
+
from qadence.logger import get_logger
|
6
|
+
|
7
|
+
logger = get_logger(__name__)
|
8
|
+
|
9
|
+
try:
|
10
|
+
module = importlib.import_module("qadence_libs.protocols")
|
11
|
+
available_libs = getattr(module, "available_libs")
|
12
|
+
except ModuleNotFoundError:
|
13
|
+
raise ModuleNotFoundError(
|
14
|
+
"The 'qadence_libs' module is not present." " Please install the 'qadence-libs' package."
|
15
|
+
)
|
@@ -82,34 +82,34 @@ def to_dataloader(*tensors: Tensor, batch_size: int = 1, infinite: bool = False)
|
|
82
82
|
|
83
83
|
|
84
84
|
@singledispatch
|
85
|
-
def data_to_device(xs: Any,
|
85
|
+
def data_to_device(xs: Any, *args: Any, **kwargs: Any) -> Any:
|
86
86
|
"""Utility method to move arbitrary data to 'device'."""
|
87
|
-
raise ValueError(f"
|
87
|
+
raise ValueError(f"Unable to move {type(xs)} with input args: {args} and kwargs: {kwargs}.")
|
88
88
|
|
89
89
|
|
90
90
|
@data_to_device.register
|
91
|
-
def _(xs: None,
|
91
|
+
def _(xs: None, *args: Any, **kwargs: Any) -> None:
|
92
92
|
return xs
|
93
93
|
|
94
94
|
|
95
95
|
@data_to_device.register(Tensor)
|
96
|
-
def _(xs: Tensor,
|
97
|
-
return xs.to(
|
96
|
+
def _(xs: Tensor, *args: Any, **kwargs: Any) -> Tensor:
|
97
|
+
return xs.to(*args, **kwargs)
|
98
98
|
|
99
99
|
|
100
100
|
@data_to_device.register(list)
|
101
|
-
def _(xs: list,
|
102
|
-
return [data_to_device(x,
|
101
|
+
def _(xs: list, *args: Any, **kwargs: Any) -> list:
|
102
|
+
return [data_to_device(x, *args, **kwargs) for x in xs]
|
103
103
|
|
104
104
|
|
105
105
|
@data_to_device.register(dict)
|
106
|
-
def _(xs: dict,
|
107
|
-
return {key: data_to_device(val,
|
106
|
+
def _(xs: dict, *args: Any, **kwargs: Any) -> dict:
|
107
|
+
return {key: data_to_device(val, *args, **kwargs) for key, val in xs.items()}
|
108
108
|
|
109
109
|
|
110
110
|
@data_to_device.register(DataLoader)
|
111
|
-
def _(xs: DataLoader,
|
112
|
-
return DataLoader(data_to_device(xs.dataset,
|
111
|
+
def _(xs: DataLoader, *args: Any, **kwargs: Any) -> DataLoader:
|
112
|
+
return DataLoader(data_to_device(xs.dataset, *args, **kwargs))
|
113
113
|
|
114
114
|
|
115
115
|
@data_to_device.register(DictDataLoader)
|
@@ -286,15 +286,15 @@ class TransformedModule(torch.nn.Module):
|
|
286
286
|
output_shifting=torch.tensor(d["_output_shifting"]),
|
287
287
|
)
|
288
288
|
|
289
|
-
def to(self,
|
289
|
+
def to(self, *args: Any, **kwargs: Any) -> TransformedModule:
|
290
290
|
try:
|
291
|
-
self.model = self.model.to(
|
292
|
-
self._input_scaling = self._input_scaling.to(
|
293
|
-
self._input_shifting = self._input_shifting.to(
|
294
|
-
self._output_scaling = self._output_scaling.to(
|
295
|
-
self._output_shifting = self._output_shifting.to(
|
291
|
+
self.model = self.model.to(*args, **kwargs)
|
292
|
+
self._input_scaling = self._input_scaling.to(*args, **kwargs)
|
293
|
+
self._input_shifting = self._input_shifting.to(*args, **kwargs)
|
294
|
+
self._output_scaling = self._output_scaling.to(*args, **kwargs)
|
295
|
+
self._output_shifting = self._output_shifting.to(*args, **kwargs)
|
296
296
|
|
297
|
-
logger.debug(f"Moved {self} to
|
297
|
+
logger.debug(f"Moved {self} to {args}, {kwargs}.")
|
298
298
|
except Exception as e:
|
299
|
-
logger.warning(f"Unable to move {self} to
|
299
|
+
logger.warning(f"Unable to move {self} to {args}, {kwargs} due to {e}.")
|
300
300
|
return self
|
@@ -15,6 +15,7 @@ def optimize_step(
|
|
15
15
|
loss_fn: Callable,
|
16
16
|
xs: dict | list | torch.Tensor | None,
|
17
17
|
device: torch.device = None,
|
18
|
+
dtype: torch.dtype = None,
|
18
19
|
) -> tuple[torch.Tensor | float, dict | None]:
|
19
20
|
"""Default Torch optimize step with closure.
|
20
21
|
|
@@ -35,7 +36,7 @@ def optimize_step(
|
|
35
36
|
"""
|
36
37
|
|
37
38
|
loss, metrics = None, {}
|
38
|
-
xs_to_device = data_to_device(xs, device)
|
39
|
+
xs_to_device = data_to_device(xs, device=device, dtype=dtype)
|
39
40
|
|
40
41
|
def closure() -> Any:
|
41
42
|
# NOTE: We need the nonlocal as we can't return a metric dict and
|
@@ -4,6 +4,7 @@ from typing import Callable, Union
|
|
4
4
|
|
5
5
|
from rich.progress import BarColumn, Progress, TaskProgressColumn, TextColumn, TimeRemainingColumn
|
6
6
|
from torch import device as torch_device
|
7
|
+
from torch import dtype as torch_dtype
|
7
8
|
from torch.nn import DataParallel, Module
|
8
9
|
from torch.optim import Optimizer
|
9
10
|
from torch.utils.data import DataLoader
|
@@ -28,6 +29,7 @@ def train(
|
|
28
29
|
device: torch_device = None,
|
29
30
|
optimize_step: Callable = optimize_step,
|
30
31
|
write_tensorboard: Callable = write_tensorboard,
|
32
|
+
dtype: torch_dtype = None,
|
31
33
|
) -> tuple[Module, Optimizer]:
|
32
34
|
"""Runs the training loop with gradient-based optimizer.
|
33
35
|
|
@@ -111,9 +113,9 @@ def train(
|
|
111
113
|
|
112
114
|
# Move model to device before optimizer is loaded
|
113
115
|
if isinstance(model, DataParallel):
|
114
|
-
model = model.module.to(device)
|
116
|
+
model = model.module.to(device=device, dtype=dtype)
|
115
117
|
else:
|
116
|
-
model = model.to(device)
|
118
|
+
model = model.to(device=device, dtype=dtype)
|
117
119
|
# load available checkpoint
|
118
120
|
init_iter = 0
|
119
121
|
if config.folder:
|
@@ -341,19 +341,24 @@ class QuantumModel(nn.Module):
|
|
341
341
|
params = self.embedding_fn(self._params, values)
|
342
342
|
return self.backend.assign_parameters(self._circuit, params)
|
343
343
|
|
344
|
-
def to(self,
|
344
|
+
def to(self, *args: Any, **kwargs: Any) -> QuantumModel:
|
345
345
|
try:
|
346
346
|
if isinstance(self._circuit.native, torch.nn.Module):
|
347
347
|
# Backends which are not torch-based cannot be moved to 'device'
|
348
|
-
self.
|
349
|
-
self._circuit.native = self._circuit.native.to(device)
|
348
|
+
self._circuit.native = self._circuit.native.to(*args, **kwargs)
|
350
349
|
if self._observable is not None:
|
351
350
|
if isinstance(self._observable, ConvertedObservable):
|
352
|
-
self._observable.native = self._observable.native.to(
|
351
|
+
self._observable.native = self._observable.native.to(*args, **kwargs)
|
353
352
|
elif isinstance(self._observable, list):
|
354
353
|
for obs in self._observable:
|
355
|
-
obs.native = obs.native.to(
|
356
|
-
|
354
|
+
obs.native = obs.native.to(*args, **kwargs)
|
355
|
+
self._params = self._params.to(
|
356
|
+
device=self._circuit.native.device,
|
357
|
+
dtype=torch.float64
|
358
|
+
if self._circuit.native.dtype == torch.cdouble
|
359
|
+
else torch.float32,
|
360
|
+
)
|
361
|
+
logger.debug(f"Moved {self} to {args}, {kwargs}.")
|
357
362
|
except Exception as e:
|
358
|
-
logger.warning(f"Unable to move {self} to
|
363
|
+
logger.warning(f"Unable to move {self} to {args}, {kwargs} due to {e}.")
|
359
364
|
return self
|