qadence 1.5.0__tar.gz → 1.5.2__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.5.0 → qadence-1.5.2}/.pre-commit-config.yaml +1 -1
- {qadence-1.5.0 → qadence-1.5.2}/PKG-INFO +31 -30
- {qadence-1.5.0 → qadence-1.5.2}/README.md +27 -27
- qadence-1.5.2/mkdocs.yml +171 -0
- {qadence-1.5.0 → qadence-1.5.2}/pyproject.toml +4 -2
- {qadence-1.5.0 → qadence-1.5.2}/qadence/backend.py +1 -26
- {qadence-1.5.0 → qadence-1.5.2}/qadence/backends/braket/backend.py +1 -1
- {qadence-1.5.0 → qadence-1.5.2}/qadence/backends/horqrux/backend.py +1 -1
- {qadence-1.5.0 → qadence-1.5.2}/qadence/backends/pulser/backend.py +1 -1
- {qadence-1.5.0 → qadence-1.5.2}/qadence/backends/pyqtorch/backend.py +1 -1
- {qadence-1.5.0 → qadence-1.5.2}/qadence/ml_tools/models.py +17 -5
- {qadence-1.5.0 → qadence-1.5.2}/qadence/ml_tools/train_grad.py +16 -7
- {qadence-1.5.0 → qadence-1.5.2}/qadence/models/quantum_model.py +5 -2
- qadence-1.5.2/qadence/serial_expr_grammar.peg +11 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/serialization.py +190 -65
- {qadence-1.5.0 → qadence-1.5.2}/qadence/utils.py +8 -2
- qadence-1.5.0/mkdocs.yml +0 -161
- {qadence-1.5.0 → qadence-1.5.2}/.coveragerc +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/.github/dependabot.yml +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/.github/workflows/build_docs.yml +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/.github/workflows/dependabot.yml +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/.github/workflows/lint.yml +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/.github/workflows/test_all.yml +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/.github/workflows/test_examples.yml +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/.github/workflows/test_fast.yml +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/.gitignore +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/LICENSE +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/MANIFEST.in +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/__init__.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/analog/__init__.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/analog/addressing.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/analog/constants.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/analog/device.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/analog/hamiltonian_terms.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/analog/parse_analog.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/backends/__init__.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/backends/adjoint.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/backends/api.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/backends/braket/__init__.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/backends/braket/config.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/backends/braket/convert_ops.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/backends/gpsr.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/backends/horqrux/__init__.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/backends/horqrux/config.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/backends/horqrux/convert_ops.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/backends/jax_utils.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/backends/pulser/__init__.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/backends/pulser/channels.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/backends/pulser/cloud.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/backends/pulser/config.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/backends/pulser/convert_ops.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/backends/pulser/devices.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/backends/pulser/pulses.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/backends/pulser/waveforms.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/backends/pyqtorch/__init__.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/backends/pyqtorch/config.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/backends/pyqtorch/convert_ops.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/backends/utils.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/blocks/__init__.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/blocks/abstract.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/blocks/analog.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/blocks/block_to_tensor.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/blocks/composite.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/blocks/embedding.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/blocks/manipulate.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/blocks/matrix.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/blocks/primitive.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/blocks/utils.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/circuit.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/constructors/__init__.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/constructors/ansatze.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/constructors/daqc/__init__.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/constructors/daqc/daqc.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/constructors/daqc/gen_parser.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/constructors/daqc/utils.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/constructors/feature_maps.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/constructors/hamiltonians.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/constructors/iia.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/constructors/qft.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/constructors/rydberg_feature_maps.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/constructors/rydberg_hea.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/constructors/utils.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/decompose.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/divergences.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/draw/__init__.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/draw/assets/dark/measurement.png +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/draw/assets/dark/measurement.svg +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/draw/assets/light/measurement.png +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/draw/assets/light/measurement.svg +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/draw/themes.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/draw/utils.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/draw/vizbackend.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/engines/__init__.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/engines/differentiable_backend.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/engines/jax/__init__.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/engines/jax/differentiable_backend.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/engines/jax/differentiable_expectation.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/engines/torch/__init__.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/engines/torch/differentiable_backend.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/engines/torch/differentiable_expectation.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/exceptions/__init__.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/exceptions/exceptions.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/execution.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/extensions.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/finitediff.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/libs.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/logger.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/measurements/__init__.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/measurements/protocols.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/measurements/samples.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/measurements/shadow.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/measurements/tomography.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/measurements/utils.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/mitigations/__init__.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/mitigations/analog_zne.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/mitigations/protocols.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/mitigations/readout.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/ml_tools/__init__.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/ml_tools/config.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/ml_tools/data.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/ml_tools/optimize_step.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/ml_tools/parameters.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/ml_tools/printing.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/ml_tools/saveload.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/ml_tools/tensors.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/ml_tools/train_no_grad.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/ml_tools/utils.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/models/__init__.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/models/qnn.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/noise/__init__.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/noise/protocols.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/noise/readout.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/operations/__init__.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/operations/analog.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/operations/control_ops.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/operations/ham_evo.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/operations/parametric.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/operations/primitive.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/overlap.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/parameters.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/protocols.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/py.typed +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/qubit_support.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/register.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/states.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/transpile/__init__.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/transpile/apply_fn.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/transpile/block.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/transpile/circuit.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/transpile/digitalize.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/transpile/flatten.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/transpile/invert.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/transpile/transpile.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/qadence/types.py +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/renovate.json +0 -0
- {qadence-1.5.0 → qadence-1.5.2}/setup.py +0 -0
@@ -1,8 +1,8 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: qadence
|
3
|
-
Version: 1.5.
|
3
|
+
Version: 1.5.2
|
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>
|
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>
|
6
6
|
License: Apache 2.0
|
7
7
|
License-File: LICENSE
|
8
8
|
Classifier: License :: OSI Approved :: Apache Software License
|
@@ -14,6 +14,7 @@ Classifier: Programming Language :: Python :: 3.11
|
|
14
14
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
15
15
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
16
16
|
Requires-Python: <3.13,>=3.9
|
17
|
+
Requires-Dist: arpeggio==2.0.2
|
17
18
|
Requires-Dist: deepdiff
|
18
19
|
Requires-Dist: jsonschema
|
19
20
|
Requires-Dist: matplotlib
|
@@ -27,7 +28,7 @@ Requires-Dist: sympytorch>=0.1.2
|
|
27
28
|
Requires-Dist: tensorboard>=2.12.0
|
28
29
|
Requires-Dist: torch
|
29
30
|
Provides-Extra: all
|
30
|
-
Requires-Dist: amazon-braket-sdk; extra == 'all'
|
31
|
+
Requires-Dist: amazon-braket-sdk==1.71.0; extra == 'all'
|
31
32
|
Requires-Dist: graphviz; extra == 'all'
|
32
33
|
Requires-Dist: libs; extra == 'all'
|
33
34
|
Requires-Dist: protocols; extra == 'all'
|
@@ -53,19 +54,21 @@ Provides-Extra: visualization
|
|
53
54
|
Requires-Dist: graphviz; extra == 'visualization'
|
54
55
|
Description-Content-Type: text/markdown
|
55
56
|
|
56
|
-
<
|
57
|
-
<
|
58
|
-
|
59
|
-
|
60
|
-
|
57
|
+
<p align="center">
|
58
|
+
<picture>
|
59
|
+
<source media="(prefers-color-scheme: dark)" srcset="./docs/extras/assets/logo/qadence_logo_white.svg" width="75%">
|
60
|
+
<source media="(prefers-color-scheme: light)" srcset="./docs/extras/assets/logo/qadence_logo.svg" width="75%">
|
61
|
+
<img alt="Qadence logo" src="./docs/assets/logo/qadence_logo.svg" width="75%">
|
62
|
+
</picture>
|
63
|
+
</p>
|
64
|
+
|
65
|
+
**Qadence** is a Python package that provides a simple interface to build **digital-analog quantum
|
66
|
+
programs** with tunable qubit interactions and arbitrary register topologies realizable on neutral atom devices.
|
61
67
|
|
62
68
|
**For a high-level overview of Qadence features, [check out our white paper](https://arxiv.org/abs/2401.09915).**
|
63
69
|
|
64
70
|
**For more detailed information, [check out the documentation](https://pasqal-io.github.io/qadence/latest/).**
|
65
71
|
|
66
|
-
**Qadence** is a Python package that provides a simple interface to build _**digital-analog quantum
|
67
|
-
programs**_ with tunable qubit interaction defined on _**arbitrary register topologies**_ realizable on neutral atom devices.
|
68
|
-
|
69
72
|
[](https://github.com/pasqal-io/qadence/actions/workflows/lint.yml)
|
70
73
|
[](https://github.com/pasqal-io/qadence/actions/workflows/test_fast.yml)
|
71
74
|
[](https://pasqal-io.github.io/qadence/latest)
|
@@ -74,27 +77,26 @@ programs**_ with tunable qubit interaction defined on _**arbitrary register topo
|
|
74
77
|
|
75
78
|
## Feature highlights
|
76
79
|
|
77
|
-
<
|
78
|
-
<
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
80
|
+
<p align="center">
|
81
|
+
<picture>
|
82
|
+
<source media="(prefers-color-scheme: dark)" srcset="./docs/extras/assets/qadence_arch.svg" width="75%">
|
83
|
+
<source media="(prefers-color-scheme: light)" srcset="./docs/extras/assets/qadence_arch.svg" width="75%">
|
84
|
+
<img alt="Qadence architecture" src="./docs/assets/qadence_arch.svg" width="75%">
|
85
|
+
</picture>
|
86
|
+
<p align="center">
|
83
87
|
|
84
|
-
* A [block-based system](docs/
|
88
|
+
* A [block-based system](docs/content/block_system.md) for composing _**complex digital-analog
|
85
89
|
programs**_ in a flexible and scalable manner, inspired by the Julia quantum SDK
|
86
90
|
[Yao.jl](https://github.com/QuantumBFS/Yao.jl) and functional programming concepts.
|
87
91
|
|
88
|
-
*
|
89
|
-
using [arbitrary registers topologies](docs/tutorials/register.md).
|
90
|
-
|
91
|
-
* An intuitive [expression-based system](docs/tutorials/parameters.md) developed on top of the symbolic library [Sympy](https://www.sympy.org/en/index.html) to construct _**parametric quantum programs**_ easily.
|
92
|
-
|
93
|
-
* [High-order generalized parameter shift rules](docs/advanced_tutorials/differentiability.md) for _**differentiating parametrized quantum operations**_.
|
92
|
+
* An intuitive [expression-based system](docs/content/parameters.md) developed on top of the symbolic library [Sympy](https://www.sympy.org/en/index.html) to construct _**parametric quantum programs**_ easily.
|
94
93
|
|
95
94
|
* Out-of-the-box _**automatic differentiability**_ of quantum programs with [PyTorch](https://pytorch.org/) integration.
|
96
95
|
|
97
|
-
*
|
96
|
+
* [High-order generalized parameter shift rules](docs/tutorials/advanced_tutorials/differentiability.md) for _**differentiating parametrized quantum operations**_.
|
97
|
+
|
98
|
+
* A [simple interface](docs/tutorials/digital_analog_qc/analog-basics.md) to work with _**interacting neutral-atom qubit systems**_
|
99
|
+
using [arbitrary registers topologies](docs/content/register.md).
|
98
100
|
|
99
101
|
## Installation guide
|
100
102
|
|
@@ -106,11 +108,10 @@ pip install qadence
|
|
106
108
|
|
107
109
|
The default, pre-installed backend for Qadence is [PyQTorch](https://github.com/pasqal-io/pyqtorch), a differentiable state vector simulator for digital-analog simulation based on `PyTorch`. It is possible to install additional, `PyTorch` -based backends and the circuit visualization library using the following extras:
|
108
110
|
|
109
|
-
* `pulser`: The [Pulser](https://github.com/pasqal-io/Pulser) backend for composing, simulating and executing pulse sequences for neutral-atom quantum devices.
|
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.
|
111
111
|
* `visualization`: A visualization library to display quantum circuit diagrams.
|
112
112
|
* `protocols`: A collection of [protocols](https://github.com/pasqal-io/qadence-protocols) for error mitigation in Qadence.
|
113
113
|
* `libs`: A collection of [functionalities](https://github.com/pasqal-io/qadence-libs) for graph machine learning problems build on top of Qadence.
|
114
|
+
* `pulser`: The [Pulser](https://github.com/pasqal-io/Pulser) backend for composing, simulating and executing pulse sequences for neutral-atom quantum devices (experimental).
|
114
115
|
|
115
116
|
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).
|
116
117
|
|
@@ -118,7 +119,7 @@ Qadence also supports a `JAX` engine which is currently supporting the [Horqrux]
|
|
118
119
|
To install individual extras, use the following syntax (**IMPORTANT** Make sure to use quotes):
|
119
120
|
|
120
121
|
```bash
|
121
|
-
pip install "qadence[
|
122
|
+
pip install "qadence[pulser,visualization]"
|
122
123
|
```
|
123
124
|
|
124
125
|
To install all available extras, simply do:
|
@@ -144,10 +145,10 @@ conda install python-graphviz
|
|
144
145
|
|
145
146
|
## Contributing
|
146
147
|
|
147
|
-
Before making a contribution, please review our [code of conduct](docs/CODE_OF_CONDUCT.md).
|
148
|
+
Before making a contribution, please review our [code of conduct](docs/getting_started/CODE_OF_CONDUCT.md).
|
148
149
|
|
149
150
|
- **Submitting Issues:** To submit bug reports or feature requests, please use our [issue tracker](https://github.com/pasqal-io/qadence/issues).
|
150
|
-
- **Developing in qadence:** To learn more about how to develop within `qadence`, please refer to [contributing guidelines](docs/CONTRIBUTING.md).
|
151
|
+
- **Developing in qadence:** To learn more about how to develop within `qadence`, please refer to [contributing guidelines](docs/getting_started/CONTRIBUTING.md).
|
151
152
|
|
152
153
|
### Setting up qadence in development mode
|
153
154
|
|
@@ -1,16 +1,18 @@
|
|
1
|
-
<
|
2
|
-
<
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
<p align="center">
|
2
|
+
<picture>
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="./docs/extras/assets/logo/qadence_logo_white.svg" width="75%">
|
4
|
+
<source media="(prefers-color-scheme: light)" srcset="./docs/extras/assets/logo/qadence_logo.svg" width="75%">
|
5
|
+
<img alt="Qadence logo" src="./docs/assets/logo/qadence_logo.svg" width="75%">
|
6
|
+
</picture>
|
7
|
+
</p>
|
8
|
+
|
9
|
+
**Qadence** is a Python package that provides a simple interface to build **digital-analog quantum
|
10
|
+
programs** with tunable qubit interactions and arbitrary register topologies realizable on neutral atom devices.
|
6
11
|
|
7
12
|
**For a high-level overview of Qadence features, [check out our white paper](https://arxiv.org/abs/2401.09915).**
|
8
13
|
|
9
14
|
**For more detailed information, [check out the documentation](https://pasqal-io.github.io/qadence/latest/).**
|
10
15
|
|
11
|
-
**Qadence** is a Python package that provides a simple interface to build _**digital-analog quantum
|
12
|
-
programs**_ with tunable qubit interaction defined on _**arbitrary register topologies**_ realizable on neutral atom devices.
|
13
|
-
|
14
16
|
[](https://github.com/pasqal-io/qadence/actions/workflows/lint.yml)
|
15
17
|
[](https://github.com/pasqal-io/qadence/actions/workflows/test_fast.yml)
|
16
18
|
[](https://pasqal-io.github.io/qadence/latest)
|
@@ -19,27 +21,26 @@ programs**_ with tunable qubit interaction defined on _**arbitrary register topo
|
|
19
21
|
|
20
22
|
## Feature highlights
|
21
23
|
|
22
|
-
<
|
23
|
-
<
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
<p align="center">
|
25
|
+
<picture>
|
26
|
+
<source media="(prefers-color-scheme: dark)" srcset="./docs/extras/assets/qadence_arch.svg" width="75%">
|
27
|
+
<source media="(prefers-color-scheme: light)" srcset="./docs/extras/assets/qadence_arch.svg" width="75%">
|
28
|
+
<img alt="Qadence architecture" src="./docs/assets/qadence_arch.svg" width="75%">
|
29
|
+
</picture>
|
30
|
+
<p align="center">
|
28
31
|
|
29
|
-
* A [block-based system](docs/
|
32
|
+
* A [block-based system](docs/content/block_system.md) for composing _**complex digital-analog
|
30
33
|
programs**_ in a flexible and scalable manner, inspired by the Julia quantum SDK
|
31
34
|
[Yao.jl](https://github.com/QuantumBFS/Yao.jl) and functional programming concepts.
|
32
35
|
|
33
|
-
*
|
34
|
-
using [arbitrary registers topologies](docs/tutorials/register.md).
|
35
|
-
|
36
|
-
* An intuitive [expression-based system](docs/tutorials/parameters.md) developed on top of the symbolic library [Sympy](https://www.sympy.org/en/index.html) to construct _**parametric quantum programs**_ easily.
|
37
|
-
|
38
|
-
* [High-order generalized parameter shift rules](docs/advanced_tutorials/differentiability.md) for _**differentiating parametrized quantum operations**_.
|
36
|
+
* An intuitive [expression-based system](docs/content/parameters.md) developed on top of the symbolic library [Sympy](https://www.sympy.org/en/index.html) to construct _**parametric quantum programs**_ easily.
|
39
37
|
|
40
38
|
* Out-of-the-box _**automatic differentiability**_ of quantum programs with [PyTorch](https://pytorch.org/) integration.
|
41
39
|
|
42
|
-
*
|
40
|
+
* [High-order generalized parameter shift rules](docs/tutorials/advanced_tutorials/differentiability.md) for _**differentiating parametrized quantum operations**_.
|
41
|
+
|
42
|
+
* A [simple interface](docs/tutorials/digital_analog_qc/analog-basics.md) to work with _**interacting neutral-atom qubit systems**_
|
43
|
+
using [arbitrary registers topologies](docs/content/register.md).
|
43
44
|
|
44
45
|
## Installation guide
|
45
46
|
|
@@ -51,11 +52,10 @@ pip install qadence
|
|
51
52
|
|
52
53
|
The default, pre-installed backend for Qadence is [PyQTorch](https://github.com/pasqal-io/pyqtorch), a differentiable state vector simulator for digital-analog simulation based on `PyTorch`. It is possible to install additional, `PyTorch` -based backends and the circuit visualization library using the following extras:
|
53
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
|
-
* `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
55
|
* `visualization`: A visualization library to display quantum circuit diagrams.
|
57
56
|
* `protocols`: A collection of [protocols](https://github.com/pasqal-io/qadence-protocols) for error mitigation in Qadence.
|
58
57
|
* `libs`: A collection of [functionalities](https://github.com/pasqal-io/qadence-libs) for graph machine learning problems build on top of Qadence.
|
58
|
+
* `pulser`: The [Pulser](https://github.com/pasqal-io/Pulser) backend for composing, simulating and executing pulse sequences for neutral-atom quantum devices (experimental).
|
59
59
|
|
60
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).
|
61
61
|
|
@@ -63,7 +63,7 @@ Qadence also supports a `JAX` engine which is currently supporting the [Horqrux]
|
|
63
63
|
To install individual extras, use the following syntax (**IMPORTANT** Make sure to use quotes):
|
64
64
|
|
65
65
|
```bash
|
66
|
-
pip install "qadence[
|
66
|
+
pip install "qadence[pulser,visualization]"
|
67
67
|
```
|
68
68
|
|
69
69
|
To install all available extras, simply do:
|
@@ -89,10 +89,10 @@ conda install python-graphviz
|
|
89
89
|
|
90
90
|
## Contributing
|
91
91
|
|
92
|
-
Before making a contribution, please review our [code of conduct](docs/CODE_OF_CONDUCT.md).
|
92
|
+
Before making a contribution, please review our [code of conduct](docs/getting_started/CODE_OF_CONDUCT.md).
|
93
93
|
|
94
94
|
- **Submitting Issues:** To submit bug reports or feature requests, please use our [issue tracker](https://github.com/pasqal-io/qadence/issues).
|
95
|
-
- **Developing in qadence:** To learn more about how to develop within `qadence`, please refer to [contributing guidelines](docs/CONTRIBUTING.md).
|
95
|
+
- **Developing in qadence:** To learn more about how to develop within `qadence`, please refer to [contributing guidelines](docs/getting_started/CONTRIBUTING.md).
|
96
96
|
|
97
97
|
### Setting up qadence in development mode
|
98
98
|
|
qadence-1.5.2/mkdocs.yml
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
site_name: Qadence
|
2
|
+
repo_url: "https://github.com/pasqal-io/qadence/"
|
3
|
+
site_url: "https://pasqal-io.github.io/qadence/"
|
4
|
+
repo_name: "qadence"
|
5
|
+
|
6
|
+
nav:
|
7
|
+
- Home: index.md
|
8
|
+
|
9
|
+
- Getting started:
|
10
|
+
- Installation: getting_started/installation.md
|
11
|
+
- Development & Info:
|
12
|
+
- Contributing: getting_started/CONTRIBUTING.md
|
13
|
+
- Code of conduct: getting_started/CODE_OF_CONDUCT.md
|
14
|
+
- License: getting_started/LICENSE.md
|
15
|
+
|
16
|
+
- Contents:
|
17
|
+
- Block system: content/block_system.md
|
18
|
+
- Parametric programs: content/parameters.md
|
19
|
+
- Quantum models: content/quantummodels.md
|
20
|
+
- Quantum registers: content/register.md
|
21
|
+
- State initialization: content/state_init.md
|
22
|
+
- Arbitrary Hamiltonians: content/hamiltonians.md
|
23
|
+
- QML Constructors: content/qml_constructors.md
|
24
|
+
- Wavefunction overlaps: content/overlap.md
|
25
|
+
- Backends: content/backends.md
|
26
|
+
- Useful info:
|
27
|
+
- State conventions: content/state_conventions.md
|
28
|
+
- Serialization: content/serializ_and_prep.md
|
29
|
+
|
30
|
+
- Tutorials:
|
31
|
+
- tutorials/index.md
|
32
|
+
- Digital-analog quantum computing:
|
33
|
+
- tutorials/digital_analog_qc/index.md
|
34
|
+
- Basic operations on neutral-atoms: tutorials/digital_analog_qc/analog-basics.md
|
35
|
+
- Fitting a simple function: tutorials/digital_analog_qc/analog-qcl.md
|
36
|
+
- Restricted local addressability: tutorials/digital_analog_qc/semi-local-addressing.md
|
37
|
+
- Pulse-level programming with Pulser: tutorials/digital_analog_qc/pulser-basic.md
|
38
|
+
- Solve a QUBO problem: tutorials/digital_analog_qc/analog-qubo.md
|
39
|
+
- CNOT with interacting qubits: tutorials/digital_analog_qc/daqc-cnot.md
|
40
|
+
|
41
|
+
- Variational quantum algorithms:
|
42
|
+
- tutorials/qml/index.md
|
43
|
+
- Training tools: tutorials/qml/ml_tools.md
|
44
|
+
- Quantum circuit learning: tutorials/qml/qcl.md
|
45
|
+
- Solving MaxCut with QAOA: tutorials/qml/qaoa.md
|
46
|
+
- Solving a 1D ODE: tutorials/qml/dqc_1d.md
|
47
|
+
|
48
|
+
- Advanced Tutorials:
|
49
|
+
- tutorials/advanced_tutorials/index.md
|
50
|
+
- Quantum circuits differentiation: tutorials/advanced_tutorials/differentiability.md
|
51
|
+
- Custom quantum models: tutorials/advanced_tutorials/custom-models.md
|
52
|
+
- Projector blocks: tutorials/advanced_tutorials/projectors.md
|
53
|
+
|
54
|
+
- Realistic simulations:
|
55
|
+
- tutorials/realistic_sims/index.md
|
56
|
+
- Measurement protocols: tutorials/realistic_sims/measurements.md
|
57
|
+
- Simulated errors: tutorials/realistic_sims/noise.md
|
58
|
+
- Error mitigation: tutorials/realistic_sims/mitigation.md
|
59
|
+
|
60
|
+
- Development:
|
61
|
+
- Architecture and sharp bits: tutorials/development/architecture.md
|
62
|
+
- Drawing: tutorials/development/draw.md
|
63
|
+
|
64
|
+
- API:
|
65
|
+
- Block system: api/blocks.md
|
66
|
+
- Operations: api/operations.md
|
67
|
+
- Register: api/register.md
|
68
|
+
- QuantumCircuit: api/quantumcircuit.md
|
69
|
+
- Parameters: api/parameters.md
|
70
|
+
- State preparation: api/states.md
|
71
|
+
- Constructors: api/constructors.md
|
72
|
+
- Transpilation: api/transpile.md
|
73
|
+
- Execution: api/execution.md
|
74
|
+
- Quantum models: api/models.md
|
75
|
+
- QML tools: api/ml_tools.md
|
76
|
+
- Serialization: api/serialization.md
|
77
|
+
- Types: api/types.md
|
78
|
+
- Drawing: api/draw.md
|
79
|
+
|
80
|
+
- Backends:
|
81
|
+
- Abstract backend: api/backends/backend.md
|
82
|
+
- PyQTorch: api/backends/pyqtorch.md
|
83
|
+
- Amazon Braket: api/backends/braket.md
|
84
|
+
- Pulser: api/backends/pulser.md
|
85
|
+
- DifferentiableBackend: api/backends/differentiable.md
|
86
|
+
|
87
|
+
edit_uri: edit/main/docs/
|
88
|
+
|
89
|
+
theme:
|
90
|
+
name: material
|
91
|
+
custom_dir: docs/extras/overrides/
|
92
|
+
logo: extras/assets/logo/qadence_logo_small_white.svg
|
93
|
+
features:
|
94
|
+
- content.code.annotate
|
95
|
+
- navigation.tabs
|
96
|
+
- navigation.indexes
|
97
|
+
- navigation.sections
|
98
|
+
- content.code.copy
|
99
|
+
- content.code.annotate
|
100
|
+
|
101
|
+
palette:
|
102
|
+
- media: "(prefers-color-scheme: light)"
|
103
|
+
scheme: default
|
104
|
+
primary: custom
|
105
|
+
accent: custom
|
106
|
+
toggle:
|
107
|
+
icon: material/weather-sunny
|
108
|
+
name: Switch to dark mode
|
109
|
+
- media: "(prefers-color-scheme: dark)"
|
110
|
+
scheme: slate
|
111
|
+
primary: black
|
112
|
+
accent: custom
|
113
|
+
toggle:
|
114
|
+
icon: material/weather-night
|
115
|
+
name: Switch to light mode
|
116
|
+
|
117
|
+
markdown_extensions:
|
118
|
+
- admonition # for notes
|
119
|
+
- footnotes
|
120
|
+
- pymdownx.arithmatex: # for mathjax
|
121
|
+
generic: true
|
122
|
+
- pymdownx.highlight:
|
123
|
+
anchor_linenums: true
|
124
|
+
- pymdownx.inlinehilite
|
125
|
+
- pymdownx.snippets
|
126
|
+
- pymdownx.details
|
127
|
+
- pymdownx.superfences:
|
128
|
+
custom_fences:
|
129
|
+
- name: python
|
130
|
+
class: python
|
131
|
+
validator: "!!python/name:markdown_exec.validator"
|
132
|
+
format: "!!python/name:markdown_exec.formatter"
|
133
|
+
|
134
|
+
plugins:
|
135
|
+
- search
|
136
|
+
- section-index
|
137
|
+
- mkdocstrings:
|
138
|
+
default_handler: python
|
139
|
+
handlers:
|
140
|
+
python:
|
141
|
+
selection:
|
142
|
+
filters:
|
143
|
+
- "!^_" # exlude all members starting with _
|
144
|
+
- "^__init__$" # but always include __init__ modules and methods
|
145
|
+
- "^__new__$" # but always include __init__ modules and methods
|
146
|
+
options:
|
147
|
+
show_root_toc_entry: false
|
148
|
+
heading_level: 3
|
149
|
+
merge_init_into_class: true
|
150
|
+
docstring_section_style: spacy
|
151
|
+
|
152
|
+
- markdown-exec
|
153
|
+
|
154
|
+
extra:
|
155
|
+
version:
|
156
|
+
provider: mike
|
157
|
+
|
158
|
+
# To get nice tabs
|
159
|
+
extra_css:
|
160
|
+
- extras/css/mkdocstrings.css
|
161
|
+
- extras/css/colors.css
|
162
|
+
- extras/css/home.css
|
163
|
+
|
164
|
+
# For mathjax
|
165
|
+
extra_javascript:
|
166
|
+
- extras/javascripts/mathjax.js
|
167
|
+
- https://polyfill.io/v3/polyfill.min.js?features=es6
|
168
|
+
- https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js
|
169
|
+
|
170
|
+
watch:
|
171
|
+
- qadence
|
@@ -17,10 +17,11 @@ authors = [
|
|
17
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
|
+
{ name = "Eduardo Maschio", email = "eduardo.maschio@pasqal.com" },
|
20
21
|
]
|
21
22
|
requires-python = ">=3.9,<3.13"
|
22
23
|
license = {text = "Apache 2.0"}
|
23
|
-
version = "1.5.
|
24
|
+
version = "1.5.2"
|
24
25
|
classifiers=[
|
25
26
|
"License :: OSI Approved :: Apache Software License",
|
26
27
|
"Programming Language :: Python",
|
@@ -44,6 +45,7 @@ dependencies = [
|
|
44
45
|
"scipy",
|
45
46
|
"pyqtorch==1.1.0",
|
46
47
|
"matplotlib",
|
48
|
+
"Arpeggio==2.0.2",
|
47
49
|
]
|
48
50
|
|
49
51
|
[tool.hatch.metadata]
|
@@ -71,7 +73,7 @@ protocols = ["qadence-protocols"]
|
|
71
73
|
libs = ["qadence-libs"]
|
72
74
|
all = [
|
73
75
|
"pulser>=0.15.2",
|
74
|
-
"amazon-braket-sdk",
|
76
|
+
"amazon-braket-sdk==1.71.0",
|
75
77
|
"graphviz",
|
76
78
|
"protocols",
|
77
79
|
"libs",
|
@@ -26,7 +26,6 @@ from qadence.mitigations import Mitigations
|
|
26
26
|
from qadence.noise import Noise
|
27
27
|
from qadence.parameters import stringify
|
28
28
|
from qadence.types import ArrayLike, BackendName, DiffMode, Endianness, Engine, ParamDictType
|
29
|
-
from qadence.utils import validate_values_and_state
|
30
29
|
|
31
30
|
logger = get_logger(__file__)
|
32
31
|
|
@@ -259,29 +258,6 @@ class Backend(ABC):
|
|
259
258
|
"""
|
260
259
|
raise NotImplementedError
|
261
260
|
|
262
|
-
@abstractmethod
|
263
|
-
def _run(
|
264
|
-
self,
|
265
|
-
circuit: ConvertedCircuit,
|
266
|
-
param_values: dict[str, ArrayLike] = {},
|
267
|
-
state: ArrayLike | None = None,
|
268
|
-
endianness: Endianness = Endianness.BIG,
|
269
|
-
) -> ArrayLike:
|
270
|
-
"""Run a circuit and return the resulting wave function.
|
271
|
-
|
272
|
-
Arguments:
|
273
|
-
circuit: A converted circuit as returned by `backend.circuit`.
|
274
|
-
param_values: _**Already embedded**_ parameters of the circuit. See
|
275
|
-
[`embedding`][qadence.blocks.embedding.embedding] for more info.
|
276
|
-
state: Initial state.
|
277
|
-
endianness: Endianness of the resulting wavefunction.
|
278
|
-
|
279
|
-
Returns:
|
280
|
-
A list of Counter objects where each key represents a bitstring
|
281
|
-
and its value the number of times it has been sampled from the given wave function.
|
282
|
-
"""
|
283
|
-
raise NotImplementedError
|
284
|
-
|
285
261
|
def run(
|
286
262
|
self,
|
287
263
|
circuit: ConvertedCircuit,
|
@@ -304,8 +280,7 @@ class Backend(ABC):
|
|
304
280
|
A list of Counter objects where each key represents a bitstring
|
305
281
|
and its value the number of times it has been sampled from the given wave function.
|
306
282
|
"""
|
307
|
-
|
308
|
-
return self._run(circuit, param_values, state, endianness, *args, **kwargs)
|
283
|
+
raise NotImplementedError
|
309
284
|
|
310
285
|
@abstractmethod
|
311
286
|
def run_dm(
|
@@ -66,7 +66,7 @@ class Backend(BackendInterface):
|
|
66
66
|
hq_obs = convert_observable(block, n_qubits=n_qubits, config=self.config)
|
67
67
|
return ConvertedObservable(native=hq_obs, abstract=block, original=observable)
|
68
68
|
|
69
|
-
def
|
69
|
+
def run(
|
70
70
|
self,
|
71
71
|
circuit: ConvertedCircuit,
|
72
72
|
param_values: ParamDictType = {},
|
@@ -80,7 +80,7 @@ class Backend(BackendInterface):
|
|
80
80
|
(native,) = convert_observable(block, n_qubits=n_qubits, config=self.config)
|
81
81
|
return ConvertedObservable(native=native, abstract=block, original=observable)
|
82
82
|
|
83
|
-
def
|
83
|
+
def run(
|
84
84
|
self,
|
85
85
|
circuit: ConvertedCircuit,
|
86
86
|
param_values: dict[str, Tensor] = {},
|
@@ -289,11 +289,23 @@ class TransformedModule(torch.nn.Module):
|
|
289
289
|
def to(self, *args: Any, **kwargs: Any) -> TransformedModule:
|
290
290
|
try:
|
291
291
|
self.model = self.model.to(*args, **kwargs)
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
292
|
+
if isinstance(self.model, QuantumModel):
|
293
|
+
device = self.model._circuit.native.device
|
294
|
+
dtype = (
|
295
|
+
torch.float64
|
296
|
+
if self.model._circuit.native.dtype == torch.cdouble
|
297
|
+
else torch.float32
|
298
|
+
)
|
299
|
+
|
300
|
+
self._input_scaling = self._input_scaling.to(device=device, dtype=dtype)
|
301
|
+
self._input_shifting = self._input_shifting.to(device=device, dtype=dtype)
|
302
|
+
self._output_scaling = self._output_scaling.to(device=device, dtype=dtype)
|
303
|
+
self._output_shifting = self._output_shifting.to(device=device, dtype=dtype)
|
304
|
+
elif isinstance(self.model, torch.nn.Module):
|
305
|
+
self._input_scaling = self._input_scaling.to(*args, **kwargs)
|
306
|
+
self._input_shifting = self._input_shifting.to(*args, **kwargs)
|
307
|
+
self._output_scaling = self._output_scaling.to(*args, **kwargs)
|
308
|
+
self._output_shifting = self._output_shifting.to(*args, **kwargs)
|
297
309
|
logger.debug(f"Moved {self} to {args}, {kwargs}.")
|
298
310
|
except Exception as e:
|
299
311
|
logger.warning(f"Unable to move {self} to {args}, {kwargs} due to {e}.")
|
@@ -3,6 +3,7 @@ from __future__ import annotations
|
|
3
3
|
from typing import Callable, Union
|
4
4
|
|
5
5
|
from rich.progress import BarColumn, Progress, TaskProgressColumn, TextColumn, TimeRemainingColumn
|
6
|
+
from torch import complex128, float32, float64
|
6
7
|
from torch import device as torch_device
|
7
8
|
from torch import dtype as torch_dtype
|
8
9
|
from torch.nn import DataParallel, Module
|
@@ -110,17 +111,17 @@ def train(
|
|
110
111
|
train_with_grad(model, data, optimizer, config, loss_fn=loss_fn)
|
111
112
|
```
|
112
113
|
"""
|
114
|
+
# load available checkpoint
|
115
|
+
init_iter = 0
|
116
|
+
if config.folder:
|
117
|
+
model, optimizer, init_iter = load_checkpoint(config.folder, model, optimizer)
|
118
|
+
logger.debug(f"Loaded model and optimizer from {config.folder}")
|
113
119
|
|
114
120
|
# Move model to device before optimizer is loaded
|
115
121
|
if isinstance(model, DataParallel):
|
116
122
|
model = model.module.to(device=device, dtype=dtype)
|
117
123
|
else:
|
118
124
|
model = model.to(device=device, dtype=dtype)
|
119
|
-
# load available checkpoint
|
120
|
-
init_iter = 0
|
121
|
-
if config.folder:
|
122
|
-
model, optimizer, init_iter = load_checkpoint(config.folder, model, optimizer)
|
123
|
-
logger.debug(f"Loaded model and optimizer from {config.folder}")
|
124
125
|
# initialize tensorboard
|
125
126
|
writer = SummaryWriter(config.folder, purge_step=init_iter)
|
126
127
|
|
@@ -131,7 +132,9 @@ def train(
|
|
131
132
|
TaskProgressColumn(),
|
132
133
|
TimeRemainingColumn(elapsed_when_finished=True),
|
133
134
|
)
|
134
|
-
|
135
|
+
data_dtype = None
|
136
|
+
if dtype:
|
137
|
+
data_dtype = float64 if dtype == complex128 else float32
|
135
138
|
with progress:
|
136
139
|
dl_iter = iter(dataloader) if dataloader is not None else None
|
137
140
|
|
@@ -143,7 +146,12 @@ def train(
|
|
143
146
|
# which do not have classical input data (e.g. chemistry)
|
144
147
|
if dataloader is None:
|
145
148
|
loss, metrics = optimize_step(
|
146
|
-
model=model,
|
149
|
+
model=model,
|
150
|
+
optimizer=optimizer,
|
151
|
+
loss_fn=loss_fn,
|
152
|
+
xs=None,
|
153
|
+
device=device,
|
154
|
+
dtype=data_dtype,
|
147
155
|
)
|
148
156
|
loss = loss.item()
|
149
157
|
|
@@ -154,6 +162,7 @@ def train(
|
|
154
162
|
loss_fn=loss_fn,
|
155
163
|
xs=next(dl_iter), # type: ignore[arg-type]
|
156
164
|
device=device,
|
165
|
+
dtype=data_dtype,
|
157
166
|
)
|
158
167
|
|
159
168
|
else:
|
@@ -342,9 +342,10 @@ class QuantumModel(nn.Module):
|
|
342
342
|
return self.backend.assign_parameters(self._circuit, params)
|
343
343
|
|
344
344
|
def to(self, *args: Any, **kwargs: Any) -> QuantumModel:
|
345
|
+
from pyqtorch import QuantumCircuit as PyQCircuit
|
346
|
+
|
345
347
|
try:
|
346
|
-
if isinstance(self._circuit.native,
|
347
|
-
# Backends which are not torch-based cannot be moved to 'device'
|
348
|
+
if isinstance(self._circuit.native, PyQCircuit):
|
348
349
|
self._circuit.native = self._circuit.native.to(*args, **kwargs)
|
349
350
|
if self._observable is not None:
|
350
351
|
if isinstance(self._observable, ConvertedObservable):
|
@@ -359,6 +360,8 @@ class QuantumModel(nn.Module):
|
|
359
360
|
else torch.float32,
|
360
361
|
)
|
361
362
|
logger.debug(f"Moved {self} to {args}, {kwargs}.")
|
363
|
+
else:
|
364
|
+
logger.debug("QuantumModel.to only supports pyqtorch.QuantumCircuits.")
|
362
365
|
except Exception as e:
|
363
366
|
logger.warning(f"Unable to move {self} to {args}, {kwargs} due to {e}.")
|
364
367
|
return self
|