ketjet 0.1.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.
- ketjet-0.1.0/.gitignore +25 -0
- ketjet-0.1.0/CHANGELOG.md +44 -0
- ketjet-0.1.0/LICENSE +201 -0
- ketjet-0.1.0/PKG-INFO +199 -0
- ketjet-0.1.0/README.md +168 -0
- ketjet-0.1.0/changes/README.md +17 -0
- ketjet-0.1.0/conftest.py +6 -0
- ketjet-0.1.0/docs/examples/vqe-h2.md +106 -0
- ketjet-0.1.0/pyproject.toml +248 -0
- ketjet-0.1.0/src/ketjet/__init__.py +11 -0
- ketjet-0.1.0/src/ketjet/adjoint.py +115 -0
- ketjet-0.1.0/src/ketjet/backends/__init__.py +6 -0
- ketjet-0.1.0/src/ketjet/backends/base.py +101 -0
- ketjet-0.1.0/src/ketjet/backends/numpy_backend.py +107 -0
- ketjet-0.1.0/src/ketjet/circuit.py +560 -0
- ketjet-0.1.0/src/ketjet/gates.py +351 -0
- ketjet-0.1.0/src/ketjet/gradients.py +445 -0
- ketjet-0.1.0/src/ketjet/kernels.py +328 -0
- ketjet-0.1.0/src/ketjet/measurements.py +256 -0
- ketjet-0.1.0/src/ketjet/observables.py +436 -0
- ketjet-0.1.0/src/ketjet/operations.py +457 -0
- ketjet-0.1.0/src/ketjet/pennylane.py +584 -0
- ketjet-0.1.0/src/ketjet/py.typed +0 -0
- ketjet-0.1.0/src/ketjet/statevector.py +187 -0
- ketjet-0.1.0/tests/__init__.py +0 -0
- ketjet-0.1.0/tests/conftest.py +12 -0
- ketjet-0.1.0/tests/differential/__init__.py +0 -0
- ketjet-0.1.0/tests/differential/test_gradients_vs_default_qubit.py +81 -0
- ketjet-0.1.0/tests/differential/test_measurements_vs_default_qubit.py +99 -0
- ketjet-0.1.0/tests/differential/test_pennylane_matrices.py +76 -0
- ketjet-0.1.0/tests/differential/test_pennylane_observables.py +53 -0
- ketjet-0.1.0/tests/integration/__init__.py +0 -0
- ketjet-0.1.0/tests/integration/test_numpy_backend_vs_default_qubit.py +52 -0
- ketjet-0.1.0/tests/integration/test_optimization.py +36 -0
- ketjet-0.1.0/tests/integration/test_pennylane_conformance.py +175 -0
- ketjet-0.1.0/tests/integration/test_pennylane_decomposition.py +186 -0
- ketjet-0.1.0/tests/integration/test_pennylane_device.py +319 -0
- ketjet-0.1.0/tests/integration/test_pennylane_gradients.py +359 -0
- ketjet-0.1.0/tests/integration/test_readme.py +67 -0
- ketjet-0.1.0/tests/integration/test_vqe_h2.py +73 -0
- ketjet-0.1.0/tests/pennylane_support.py +90 -0
- ketjet-0.1.0/tests/random_circuits.py +50 -0
- ketjet-0.1.0/tests/regression/__init__.py +0 -0
- ketjet-0.1.0/tests/regression/circuits.py +73 -0
- ketjet-0.1.0/tests/regression/generate_golden.py +94 -0
- ketjet-0.1.0/tests/regression/golden/ghz5.json +186 -0
- ketjet-0.1.0/tests/regression/golden/gradient3.json +184 -0
- ketjet-0.1.0/tests/regression/golden/qft4_0110.json +241 -0
- ketjet-0.1.0/tests/regression/golden/qft5_10011.json +367 -0
- ketjet-0.1.0/tests/regression/test_golden.py +83 -0
- ketjet-0.1.0/tests/tolerances.py +48 -0
- ketjet-0.1.0/tests/unit/__init__.py +0 -0
- ketjet-0.1.0/tests/unit/test_adjoint.py +266 -0
- ketjet-0.1.0/tests/unit/test_circuit.py +242 -0
- ketjet-0.1.0/tests/unit/test_circuit_parameters.py +116 -0
- ketjet-0.1.0/tests/unit/test_gates.py +290 -0
- ketjet-0.1.0/tests/unit/test_gradients.py +181 -0
- ketjet-0.1.0/tests/unit/test_kernels.py +226 -0
- ketjet-0.1.0/tests/unit/test_measurements.py +190 -0
- ketjet-0.1.0/tests/unit/test_numpy_backend.py +80 -0
- ketjet-0.1.0/tests/unit/test_observables.py +262 -0
- ketjet-0.1.0/tests/unit/test_package.py +32 -0
- ketjet-0.1.0/tests/unit/test_parameter_shift.py +225 -0
- ketjet-0.1.0/tests/unit/test_sampling.py +195 -0
- ketjet-0.1.0/tests/unit/test_statevector.py +162 -0
- ketjet-0.1.0/tests/unit/test_structured_kernels.py +247 -0
- ketjet-0.1.0/tests/unit/test_vjp.py +144 -0
ketjet-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.egg-info/
|
|
5
|
+
build/
|
|
6
|
+
dist/
|
|
7
|
+
.venv/
|
|
8
|
+
|
|
9
|
+
# Tooling caches
|
|
10
|
+
.mypy_cache/
|
|
11
|
+
.ruff_cache/
|
|
12
|
+
.pytest_cache/
|
|
13
|
+
.hypothesis/
|
|
14
|
+
.coverage
|
|
15
|
+
.coverage.*
|
|
16
|
+
coverage.xml
|
|
17
|
+
htmlcov/
|
|
18
|
+
|
|
19
|
+
# Docs
|
|
20
|
+
site/
|
|
21
|
+
|
|
22
|
+
# Editors / OS
|
|
23
|
+
.vscode/
|
|
24
|
+
.idea/
|
|
25
|
+
.DS_Store
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented in this file.
|
|
4
|
+
|
|
5
|
+
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project adheres to
|
|
6
|
+
[Semantic Versioning](https://semver.org/spec/v2.0.0.html). Before v1.0.0, minor versions may contain
|
|
7
|
+
breaking changes; every break is listed here. Entries are generated from towncrier news fragments
|
|
8
|
+
(one per PR, see `changes/README.md`).
|
|
9
|
+
|
|
10
|
+
## [Unreleased]
|
|
11
|
+
|
|
12
|
+
Unreleased changes live as fragments in [`changes/`](changes/) and are compiled into this file when a version is
|
|
13
|
+
released.
|
|
14
|
+
|
|
15
|
+
<!-- towncrier release notes start -->
|
|
16
|
+
|
|
17
|
+
## [0.1.0] - 2026-11-11
|
|
18
|
+
|
|
19
|
+
The first release: the NumPy reference simulator, with exact gradients (adjoint, parameter-shift and finite
|
|
20
|
+
differences), as the PennyLane device `ketjet.qubit`. It passes PennyLane's own device test suite.
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
|
|
24
|
+
- Changelog entries are now written as towncrier fragments in `changes/` and checked in CI. ([#8](https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/issues/8))
|
|
25
|
+
- `ketjet.zero_state(n, dtype, max_bytes=...)` allocates the |0…0⟩ state in complex128 or complex64 with clear `MemoryError`s; `ketjet.state_nbytes` reports memory up front. ([#14](https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/issues/14))
|
|
26
|
+
- `ketjet.kernels.apply_matrix(state, matrix, wires)` applies any 2^k × 2^k matrix to k wires: pure, dtype-preserving, and validated against an independent dense reference. ([#15](https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/issues/15))
|
|
27
|
+
- Gate library: `ketjet.gates` registers 20 base gates with structure flags verified against their matrices; `ketjet.operations` provides immutable, self-validating operations, symbolic parameters, controlled gates (`CNOT`, `CZ`, `CRX`, `Toffoli`, `CSWAP`, `MultiControlledX`, `ctrl`) and inverses. Every matrix matches PennyLane. ([#16](https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/issues/16))
|
|
28
|
+
- Specialized kernels for diagonal and permutation gates (`kernels.apply_diagonal`, `kernels.apply_permutation`, `kernels.apply_structured`), used by `NumPyBackend` and adjoint differentiation: 2–10× faster than the dense kernel from 16 qubits up. `Operation.is_diagonal` and `Operation.is_permutation` expose the gate's structure. ([#17](https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/issues/17))
|
|
29
|
+
- `ketjet.backends` adds the typed `Backend` protocol and the `NumPyBackend` reference implementation; random circuits match PennyLane's `default.qubit`. ([#21](https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/issues/21))
|
|
30
|
+
- `ketjet.Circuit`: a fluent circuit builder (`Circuit(2).h(0).cnot(0, 1)`) with validation, immutable operation snapshots, `inverse()`, readable `repr` and a versioned JSON format. ([#23](https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/issues/23))
|
|
31
|
+
- `Circuit.parameters`, `Circuit.parameter_slots` and `Circuit.bind(...)` (by `Parameter`, name or keyword) for symbolic, re-bindable circuits; binding returns a new circuit. ([#24](https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/issues/24))
|
|
32
|
+
- `Circuit.state()`, `Circuit.probs(wires)`, `Circuit.expval(obs)` and `Circuit.var(obs)` run a circuit and return exact results in PennyLane's conventions; the `Backend` protocol gains read-only `probs`, `expval` and `var`; reference implementations live in `ketjet.measurements`. ([#25](https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/issues/25))
|
|
33
|
+
- Observables in `ketjet.observables`: Pauli strings (`Z(0) @ Z(1)`), `Hermitian` matrices, tensor products and real-weighted sums (`0.5 * Z(0) @ Z(1) - 0.2 * X(0)`). Pauli strings are applied matrix-free in O(2^n). ([#26](https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/issues/26))
|
|
34
|
+
- `Circuit.sample(shots, wires, seed=...)` and `Circuit.expval(obs, shots=..., seed=...)`: seeded, reproducible sampling (also on the `Backend` protocol) and shot-based expectation values via eigenbasis rotation. ([#27](https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/issues/27))
|
|
35
|
+
- `ketjet.gradients.grad` / `jacobian` and `Circuit.gradient`: gradients of expectation values with respect to circuit parameters (shared parameters handled by the chain rule); `method="finite-diff"` (central differences) also differentiates variances. ([#30](https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/issues/30))
|
|
36
|
+
- `method="parameter-shift"`: exact gradients from shift rules derived from each gate's generator spectrum, including the four-term rule for controlled rotations, and shot-based gradients with `shots=`/`seed=`. Gate specs declare `generator_eigvals`. ([#31](https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/issues/31))
|
|
37
|
+
- `method="adjoint"` (the default): exact adjoint differentiation of expectation values with memory independent of circuit depth, as one `Backend.adjoint_jacobian` call; analytic gate derivatives (`GateSpec.derivative`, `Operation.derivative_matrix`). ([#33](https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/issues/33))
|
|
38
|
+
- `ketjet.gradients.vjp` computes vector-Jacobian products. With the default adjoint method it is one backward pass, however many observables there are. ([#35](https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/issues/35))
|
|
39
|
+
- The PennyLane device `ketjet.qubit` (`pip install "ketjet[pennylane]"`, then `qml.device("ketjet.qubit", wires=n)`): PennyLane decomposes circuits into ketjet's gates, which run on a ketjet backend; `expval`, `var` and `probs` are computed by ketjet, with seeded shots, shot vectors and `c_dtype` precision. `import ketjet` doesn't import PennyLane. ([#38](https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/issues/38))
|
|
40
|
+
- `ketjet.qubit` runs every PennyLane operation that has a decomposition (templates, `QubitUnitary`, `StatePrep`, Ising and excitation gates, …) by decomposing it into ketjet's gates; operations without one raise a `DeviceError` naming the operation. ([#39](https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/issues/39))
|
|
41
|
+
- `diff_method="adjoint"` on `ketjet.qubit`: device Jacobians from one backend adjoint call per circuit, and vector-Jacobian products (`device_vjp=True`) in one backward pass however many expectation values a circuit returns. `diff_method="best"` picks adjoint for exact expectation values; PennyLane's parameter-shift and finite differences work too, with or without shots. ([#40](https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/issues/40))
|
|
42
|
+
- `ketjet.qubit` passes PennyLane's own device test suite (`pl-device-test`) in exact and shot mode, checked on every pull request; operations with a matrix but no decomposition (e.g. `DoubleExcitationPlus`, `BlockEncode`) now run too. New docs page: the PennyLane device. ([#41](https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/issues/41))
|
|
43
|
+
- Package skeleton: typed (PEP 561), Apache-2.0 licensed, tested on Linux, macOS and Windows with Python 3.12–3.15.
|
|
44
|
+
- Release pipeline: TestPyPI, an install smoke test on three OSes, then PyPI via Trusted Publishing.
|
ketjet-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
ketjet-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: ketjet
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A high-performance differentiable quantum statevector simulator, usable as a PennyLane device.
|
|
5
|
+
Project-URL: Homepage, https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator
|
|
6
|
+
Project-URL: Documentation, https://hasanahmed77.github.io/high-performance-differentiable-quantum-simulator/
|
|
7
|
+
Project-URL: Issues, https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/blob/main/CHANGELOG.md
|
|
9
|
+
Author: Mustakim Ahmed Hasan
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: autodiff,gpu,jax,pennylane,quantum,simulator,statevector
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: Operating System :: MacOS
|
|
16
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
17
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
24
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
25
|
+
Classifier: Typing :: Typed
|
|
26
|
+
Requires-Python: >=3.12
|
|
27
|
+
Requires-Dist: numpy>=2.1
|
|
28
|
+
Provides-Extra: pennylane
|
|
29
|
+
Requires-Dist: pennylane<0.46,>=0.44; extra == 'pennylane'
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# ketjet
|
|
33
|
+
|
|
34
|
+
**A high-performance differentiable quantum statevector simulator, usable as a PennyLane device.**
|
|
35
|
+
|
|
36
|
+
[](https://pypi.org/project/ketjet/)
|
|
37
|
+
[](https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/actions/workflows/ci.yml)
|
|
38
|
+
[](https://hasanahmed77.github.io/high-performance-differentiable-quantum-simulator/)
|
|
39
|
+
[](https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/blob/main/pyproject.toml)
|
|
40
|
+
[](https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/blob/main/LICENSE)
|
|
41
|
+
[](https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/blob/main/pyproject.toml)
|
|
42
|
+
|
|
43
|
+
> **Status: alpha (v0.1.0).** The NumPy reference simulator, with exact gradients, as a PennyLane device. The
|
|
44
|
+
> faster backends (JAX, C++, CUDA) come next; see the [roadmap](#roadmap) and the
|
|
45
|
+
> [project board](https://github.com/users/hasanahmed77/projects/2).
|
|
46
|
+
|
|
47
|
+
## Why
|
|
48
|
+
|
|
49
|
+
Quantum machine-learning research runs mostly on classical simulators. Training a parametrized circuit means
|
|
50
|
+
simulating it thousands of times and computing gradients each time. Researchers need a simulator that is:
|
|
51
|
+
|
|
52
|
+
- **differentiable**, with exact, memory-efficient gradients for deep circuits;
|
|
53
|
+
- **fast** on CPUs and GPUs, and **batched**, so many parameter sets run as one computation;
|
|
54
|
+
- **trustworthy**: verified against established tools, with honest performance numbers.
|
|
55
|
+
|
|
56
|
+
## Quickstart
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pip install "ketjet[pennylane]"
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Use it from PennyLane like any other device, here with ketjet's adjoint gradients:
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
import pennylane as qml
|
|
66
|
+
from pennylane import numpy as np
|
|
67
|
+
|
|
68
|
+
dev = qml.device("ketjet.qubit", wires=2)
|
|
69
|
+
|
|
70
|
+
@qml.qnode(dev, diff_method="adjoint")
|
|
71
|
+
def energy(theta):
|
|
72
|
+
qml.RY(theta[0], wires=0)
|
|
73
|
+
qml.CNOT(wires=[0, 1])
|
|
74
|
+
qml.RX(theta[1], wires=1)
|
|
75
|
+
return qml.expval(qml.PauliZ(0) @ qml.PauliZ(1) + 0.5 * qml.PauliX(0) @ qml.PauliX(1))
|
|
76
|
+
|
|
77
|
+
theta = np.array([0.3, 0.8], requires_grad=True)
|
|
78
|
+
print(f"{energy(theta):.6f}") # 0.844467
|
|
79
|
+
print(qml.grad(energy)(theta).round(6)) # [ 0.477668 -0.717356]
|
|
80
|
+
|
|
81
|
+
opt = qml.GradientDescentOptimizer(stepsize=0.2)
|
|
82
|
+
for _ in range(100):
|
|
83
|
+
theta = opt.step(energy, theta)
|
|
84
|
+
print(f"{energy(theta):.6f}") # -1.500000, the exact minimum
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Or use ketjet's own API, which needs nothing but NumPy:
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
import ketjet as kj
|
|
91
|
+
from ketjet import gradients
|
|
92
|
+
from ketjet.observables import X, Z
|
|
93
|
+
from ketjet.operations import Parameter
|
|
94
|
+
|
|
95
|
+
a, b = Parameter("a"), Parameter("b")
|
|
96
|
+
circuit = kj.Circuit(2).ry(a, 0).cnot(0, 1).rx(b, 1)
|
|
97
|
+
H = Z(0) @ Z(1) + 0.5 * X(0) @ X(1)
|
|
98
|
+
values = {"a": 0.3, "b": 0.8}
|
|
99
|
+
|
|
100
|
+
print(f"{circuit.bind(values).expval(H):.6f}") # 0.844467
|
|
101
|
+
print(gradients.grad(circuit, H, values).round(6)) # [ 0.477668 -0.717356]
|
|
102
|
+
print(gradients.grad(circuit, H, values, method="parameter-shift").round(6)) # [ 0.477668 -0.717356]
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## What you get
|
|
106
|
+
|
|
107
|
+
- **A PennyLane device**, `ketjet.qubit`: every PennyLane gate and template runs, by decomposition into ketjet's
|
|
108
|
+
gates. `expval`, `var` and `probs` are native; shots are seeded and reproducible.
|
|
109
|
+
[Device docs](https://hasanahmed77.github.io/high-performance-differentiable-quantum-simulator/pennylane/)
|
|
110
|
+
- **Exact gradients three ways:**
|
|
111
|
+
- **adjoint** (the default), with memory independent of circuit depth;
|
|
112
|
+
- **parameter-shift**, with exact rules derived from each gate's spectrum, including the four-term rule for
|
|
113
|
+
controlled rotations;
|
|
114
|
+
- **finite differences**, as a test oracle.
|
|
115
|
+
- **Vector-Jacobian products in one backward pass**, however many expectation values a circuit returns: the form
|
|
116
|
+
PennyLane and JAX ask for when training.
|
|
117
|
+
- **A small, typed Python API:** a fluent circuit builder, symbolic parameters, Pauli and Hermitian observables,
|
|
118
|
+
and both precisions (complex128 and complex64).
|
|
119
|
+
|
|
120
|
+
## Results
|
|
121
|
+
|
|
122
|
+
What is verified today, on every pull request across Linux, macOS and Windows and Python 3.12–3.15:
|
|
123
|
+
|
|
124
|
+
| Claim | Evidence |
|
|
125
|
+
|---|---|
|
|
126
|
+
| **Correct** | States, probabilities, expectation values, variances and Jacobians match PennyLane's `default.qubit` to 1e-10 (complex128) on random circuits |
|
|
127
|
+
| **Conformant** | PennyLane's own device suite passes: 380 tests in exact mode and 365 with shots, **0 failures**; every skip is [explained](https://hasanahmed77.github.io/high-performance-differentiable-quantum-simulator/pennylane/#conformance) |
|
|
128
|
+
| **Adjoint memory is independent of depth** | Peak memory is 5.1 to 5.35 statevectors from 20 to 4000 layers (14 qubits); storing every intermediate state would need one per gate |
|
|
129
|
+
| **Gradients are exact** | Adjoint, parameter-shift and PennyLane's backprop agree on random circuits, including through gates PennyLane decomposes |
|
|
130
|
+
| **One backward pass per VJP** | A VJP over 4 expectation values makes 1 backend call (checked by counting) |
|
|
131
|
+
| **Specialized kernels** | Diagonal and permutation gates run 2 to 10× faster than ketjet's dense kernel from 16 qubits up (Apple M2) |
|
|
132
|
+
| **A real problem** | A VQE on the H₂ molecule [reaches the exact ground-state energy](https://hasanahmed77.github.io/high-performance-differentiable-quantum-simulator/examples/vqe-h2/) to 1e-12 |
|
|
133
|
+
| **Tested** | 100% line and branch coverage today (CI requires at least 85%); 80 deliberately injected bugs caught, several only after a test was strengthened |
|
|
134
|
+
|
|
135
|
+
**Not yet measured: speed against other simulators.** This release is the NumPy *reference* backend, built to be
|
|
136
|
+
correct and readable, so that every faster backend can be checked against it. Benchmarks against `default.qubit`,
|
|
137
|
+
`lightning.qubit`, Qiskit Aer and Qulacs will be published with the faster backends, with reproducible scripts and
|
|
138
|
+
plots, **including the cases where ketjet loses**.
|
|
139
|
+
|
|
140
|
+
## Design
|
|
141
|
+
|
|
142
|
+
ketjet is layered so that every faster backend is checked against a simple, readable reference:
|
|
143
|
+
|
|
144
|
+
```
|
|
145
|
+
PennyLane device (ketjet.qubit) · Python API (Circuit, gradients)
|
|
146
|
+
│ circuit IR: an inspectable list of operations
|
|
147
|
+
Differentiation ── adjoint · parameter-shift · finite differences
|
|
148
|
+
│ one typed backend protocol
|
|
149
|
+
NumPy (reference, today) · JAX (jit, vmap, GPU) · C++ (SIMD, OpenMP) · CUDA
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Every significant decision is recorded with its alternatives in an architecture decision record:
|
|
153
|
+
[statevectors](https://hasanahmed77.github.io/high-performance-differentiable-quantum-simulator/adr/0001-statevector-representation/),
|
|
154
|
+
[circuit IR](https://hasanahmed77.github.io/high-performance-differentiable-quantum-simulator/adr/0002-circuit-ir/),
|
|
155
|
+
[measurements](https://hasanahmed77.github.io/high-performance-differentiable-quantum-simulator/adr/0003-measurements-and-observables/),
|
|
156
|
+
[differentiation](https://hasanahmed77.github.io/high-performance-differentiable-quantum-simulator/adr/0004-differentiation/)
|
|
157
|
+
and the
|
|
158
|
+
[PennyLane device](https://hasanahmed77.github.io/high-performance-differentiable-quantum-simulator/adr/0005-pennylane-device/).
|
|
159
|
+
|
|
160
|
+
## Installation
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
pip install ketjet # the simulator; needs only NumPy
|
|
164
|
+
pip install "ketjet[pennylane]" # plus the PennyLane device
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Requires Python 3.12–3.15 on Linux, macOS or Windows. To install the latest development version from source:
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
pip install "ketjet[pennylane] @ git+https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator.git"
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Roadmap
|
|
174
|
+
|
|
175
|
+
| Release | Adds |
|
|
176
|
+
|---|---|
|
|
177
|
+
| **v0.1.0** (released) | NumPy reference simulator, exact gradients, PennyLane device |
|
|
178
|
+
| v0.2.0 | JAX backend: jit, vmap batching, GPU, backprop and adjoint inside JAX; then the first benchmarks |
|
|
179
|
+
| v0.3.0 | Native C++ backend: SIMD and OpenMP, with prebuilt wheels |
|
|
180
|
+
| v0.4.0 | Gate fusion and autotuning, with a CPU roofline and a performance report |
|
|
181
|
+
| v0.5.0 | CUDA backend, with GPU adjoint |
|
|
182
|
+
| v1.0.0 | A stable API, complete docs and a technical write-up |
|
|
183
|
+
|
|
184
|
+
## Documentation
|
|
185
|
+
|
|
186
|
+
[hasanahmed77.github.io/high-performance-differentiable-quantum-simulator](https://hasanahmed77.github.io/high-performance-differentiable-quantum-simulator/):
|
|
187
|
+
getting started, the PennyLane device, the H₂ example, the API reference, design decisions and sprint reports.
|
|
188
|
+
|
|
189
|
+
## Contributing
|
|
190
|
+
|
|
191
|
+
Contributions are welcome. See
|
|
192
|
+
[CONTRIBUTING.md](https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/blob/main/CONTRIBUTING.md)
|
|
193
|
+
for setup, checks and workflow, and
|
|
194
|
+
[SECURITY.md](https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/blob/main/SECURITY.md)
|
|
195
|
+
for reporting vulnerabilities.
|
|
196
|
+
|
|
197
|
+
## License
|
|
198
|
+
|
|
199
|
+
[Apache License 2.0](https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/blob/main/LICENSE)
|
ketjet-0.1.0/README.md
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# ketjet
|
|
2
|
+
|
|
3
|
+
**A high-performance differentiable quantum statevector simulator, usable as a PennyLane device.**
|
|
4
|
+
|
|
5
|
+
[](https://pypi.org/project/ketjet/)
|
|
6
|
+
[](https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/actions/workflows/ci.yml)
|
|
7
|
+
[](https://hasanahmed77.github.io/high-performance-differentiable-quantum-simulator/)
|
|
8
|
+
[](https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/blob/main/pyproject.toml)
|
|
9
|
+
[](https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/blob/main/LICENSE)
|
|
10
|
+
[](https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/blob/main/pyproject.toml)
|
|
11
|
+
|
|
12
|
+
> **Status: alpha (v0.1.0).** The NumPy reference simulator, with exact gradients, as a PennyLane device. The
|
|
13
|
+
> faster backends (JAX, C++, CUDA) come next; see the [roadmap](#roadmap) and the
|
|
14
|
+
> [project board](https://github.com/users/hasanahmed77/projects/2).
|
|
15
|
+
|
|
16
|
+
## Why
|
|
17
|
+
|
|
18
|
+
Quantum machine-learning research runs mostly on classical simulators. Training a parametrized circuit means
|
|
19
|
+
simulating it thousands of times and computing gradients each time. Researchers need a simulator that is:
|
|
20
|
+
|
|
21
|
+
- **differentiable**, with exact, memory-efficient gradients for deep circuits;
|
|
22
|
+
- **fast** on CPUs and GPUs, and **batched**, so many parameter sets run as one computation;
|
|
23
|
+
- **trustworthy**: verified against established tools, with honest performance numbers.
|
|
24
|
+
|
|
25
|
+
## Quickstart
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install "ketjet[pennylane]"
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Use it from PennyLane like any other device, here with ketjet's adjoint gradients:
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
import pennylane as qml
|
|
35
|
+
from pennylane import numpy as np
|
|
36
|
+
|
|
37
|
+
dev = qml.device("ketjet.qubit", wires=2)
|
|
38
|
+
|
|
39
|
+
@qml.qnode(dev, diff_method="adjoint")
|
|
40
|
+
def energy(theta):
|
|
41
|
+
qml.RY(theta[0], wires=0)
|
|
42
|
+
qml.CNOT(wires=[0, 1])
|
|
43
|
+
qml.RX(theta[1], wires=1)
|
|
44
|
+
return qml.expval(qml.PauliZ(0) @ qml.PauliZ(1) + 0.5 * qml.PauliX(0) @ qml.PauliX(1))
|
|
45
|
+
|
|
46
|
+
theta = np.array([0.3, 0.8], requires_grad=True)
|
|
47
|
+
print(f"{energy(theta):.6f}") # 0.844467
|
|
48
|
+
print(qml.grad(energy)(theta).round(6)) # [ 0.477668 -0.717356]
|
|
49
|
+
|
|
50
|
+
opt = qml.GradientDescentOptimizer(stepsize=0.2)
|
|
51
|
+
for _ in range(100):
|
|
52
|
+
theta = opt.step(energy, theta)
|
|
53
|
+
print(f"{energy(theta):.6f}") # -1.500000, the exact minimum
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Or use ketjet's own API, which needs nothing but NumPy:
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
import ketjet as kj
|
|
60
|
+
from ketjet import gradients
|
|
61
|
+
from ketjet.observables import X, Z
|
|
62
|
+
from ketjet.operations import Parameter
|
|
63
|
+
|
|
64
|
+
a, b = Parameter("a"), Parameter("b")
|
|
65
|
+
circuit = kj.Circuit(2).ry(a, 0).cnot(0, 1).rx(b, 1)
|
|
66
|
+
H = Z(0) @ Z(1) + 0.5 * X(0) @ X(1)
|
|
67
|
+
values = {"a": 0.3, "b": 0.8}
|
|
68
|
+
|
|
69
|
+
print(f"{circuit.bind(values).expval(H):.6f}") # 0.844467
|
|
70
|
+
print(gradients.grad(circuit, H, values).round(6)) # [ 0.477668 -0.717356]
|
|
71
|
+
print(gradients.grad(circuit, H, values, method="parameter-shift").round(6)) # [ 0.477668 -0.717356]
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## What you get
|
|
75
|
+
|
|
76
|
+
- **A PennyLane device**, `ketjet.qubit`: every PennyLane gate and template runs, by decomposition into ketjet's
|
|
77
|
+
gates. `expval`, `var` and `probs` are native; shots are seeded and reproducible.
|
|
78
|
+
[Device docs](https://hasanahmed77.github.io/high-performance-differentiable-quantum-simulator/pennylane/)
|
|
79
|
+
- **Exact gradients three ways:**
|
|
80
|
+
- **adjoint** (the default), with memory independent of circuit depth;
|
|
81
|
+
- **parameter-shift**, with exact rules derived from each gate's spectrum, including the four-term rule for
|
|
82
|
+
controlled rotations;
|
|
83
|
+
- **finite differences**, as a test oracle.
|
|
84
|
+
- **Vector-Jacobian products in one backward pass**, however many expectation values a circuit returns: the form
|
|
85
|
+
PennyLane and JAX ask for when training.
|
|
86
|
+
- **A small, typed Python API:** a fluent circuit builder, symbolic parameters, Pauli and Hermitian observables,
|
|
87
|
+
and both precisions (complex128 and complex64).
|
|
88
|
+
|
|
89
|
+
## Results
|
|
90
|
+
|
|
91
|
+
What is verified today, on every pull request across Linux, macOS and Windows and Python 3.12–3.15:
|
|
92
|
+
|
|
93
|
+
| Claim | Evidence |
|
|
94
|
+
|---|---|
|
|
95
|
+
| **Correct** | States, probabilities, expectation values, variances and Jacobians match PennyLane's `default.qubit` to 1e-10 (complex128) on random circuits |
|
|
96
|
+
| **Conformant** | PennyLane's own device suite passes: 380 tests in exact mode and 365 with shots, **0 failures**; every skip is [explained](https://hasanahmed77.github.io/high-performance-differentiable-quantum-simulator/pennylane/#conformance) |
|
|
97
|
+
| **Adjoint memory is independent of depth** | Peak memory is 5.1 to 5.35 statevectors from 20 to 4000 layers (14 qubits); storing every intermediate state would need one per gate |
|
|
98
|
+
| **Gradients are exact** | Adjoint, parameter-shift and PennyLane's backprop agree on random circuits, including through gates PennyLane decomposes |
|
|
99
|
+
| **One backward pass per VJP** | A VJP over 4 expectation values makes 1 backend call (checked by counting) |
|
|
100
|
+
| **Specialized kernels** | Diagonal and permutation gates run 2 to 10× faster than ketjet's dense kernel from 16 qubits up (Apple M2) |
|
|
101
|
+
| **A real problem** | A VQE on the H₂ molecule [reaches the exact ground-state energy](https://hasanahmed77.github.io/high-performance-differentiable-quantum-simulator/examples/vqe-h2/) to 1e-12 |
|
|
102
|
+
| **Tested** | 100% line and branch coverage today (CI requires at least 85%); 80 deliberately injected bugs caught, several only after a test was strengthened |
|
|
103
|
+
|
|
104
|
+
**Not yet measured: speed against other simulators.** This release is the NumPy *reference* backend, built to be
|
|
105
|
+
correct and readable, so that every faster backend can be checked against it. Benchmarks against `default.qubit`,
|
|
106
|
+
`lightning.qubit`, Qiskit Aer and Qulacs will be published with the faster backends, with reproducible scripts and
|
|
107
|
+
plots, **including the cases where ketjet loses**.
|
|
108
|
+
|
|
109
|
+
## Design
|
|
110
|
+
|
|
111
|
+
ketjet is layered so that every faster backend is checked against a simple, readable reference:
|
|
112
|
+
|
|
113
|
+
```
|
|
114
|
+
PennyLane device (ketjet.qubit) · Python API (Circuit, gradients)
|
|
115
|
+
│ circuit IR: an inspectable list of operations
|
|
116
|
+
Differentiation ── adjoint · parameter-shift · finite differences
|
|
117
|
+
│ one typed backend protocol
|
|
118
|
+
NumPy (reference, today) · JAX (jit, vmap, GPU) · C++ (SIMD, OpenMP) · CUDA
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Every significant decision is recorded with its alternatives in an architecture decision record:
|
|
122
|
+
[statevectors](https://hasanahmed77.github.io/high-performance-differentiable-quantum-simulator/adr/0001-statevector-representation/),
|
|
123
|
+
[circuit IR](https://hasanahmed77.github.io/high-performance-differentiable-quantum-simulator/adr/0002-circuit-ir/),
|
|
124
|
+
[measurements](https://hasanahmed77.github.io/high-performance-differentiable-quantum-simulator/adr/0003-measurements-and-observables/),
|
|
125
|
+
[differentiation](https://hasanahmed77.github.io/high-performance-differentiable-quantum-simulator/adr/0004-differentiation/)
|
|
126
|
+
and the
|
|
127
|
+
[PennyLane device](https://hasanahmed77.github.io/high-performance-differentiable-quantum-simulator/adr/0005-pennylane-device/).
|
|
128
|
+
|
|
129
|
+
## Installation
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
pip install ketjet # the simulator; needs only NumPy
|
|
133
|
+
pip install "ketjet[pennylane]" # plus the PennyLane device
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Requires Python 3.12–3.15 on Linux, macOS or Windows. To install the latest development version from source:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
pip install "ketjet[pennylane] @ git+https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator.git"
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Roadmap
|
|
143
|
+
|
|
144
|
+
| Release | Adds |
|
|
145
|
+
|---|---|
|
|
146
|
+
| **v0.1.0** (released) | NumPy reference simulator, exact gradients, PennyLane device |
|
|
147
|
+
| v0.2.0 | JAX backend: jit, vmap batching, GPU, backprop and adjoint inside JAX; then the first benchmarks |
|
|
148
|
+
| v0.3.0 | Native C++ backend: SIMD and OpenMP, with prebuilt wheels |
|
|
149
|
+
| v0.4.0 | Gate fusion and autotuning, with a CPU roofline and a performance report |
|
|
150
|
+
| v0.5.0 | CUDA backend, with GPU adjoint |
|
|
151
|
+
| v1.0.0 | A stable API, complete docs and a technical write-up |
|
|
152
|
+
|
|
153
|
+
## Documentation
|
|
154
|
+
|
|
155
|
+
[hasanahmed77.github.io/high-performance-differentiable-quantum-simulator](https://hasanahmed77.github.io/high-performance-differentiable-quantum-simulator/):
|
|
156
|
+
getting started, the PennyLane device, the H₂ example, the API reference, design decisions and sprint reports.
|
|
157
|
+
|
|
158
|
+
## Contributing
|
|
159
|
+
|
|
160
|
+
Contributions are welcome. See
|
|
161
|
+
[CONTRIBUTING.md](https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/blob/main/CONTRIBUTING.md)
|
|
162
|
+
for setup, checks and workflow, and
|
|
163
|
+
[SECURITY.md](https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/blob/main/SECURITY.md)
|
|
164
|
+
for reporting vulnerabilities.
|
|
165
|
+
|
|
166
|
+
## License
|
|
167
|
+
|
|
168
|
+
[Apache License 2.0](https://github.com/hasanahmed77/high-performance-differentiable-quantum-simulator/blob/main/LICENSE)
|