pyqit 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.
Files changed (81) hide show
  1. pyqit-0.1.0/LICENSE +191 -0
  2. pyqit-0.1.0/PKG-INFO +172 -0
  3. pyqit-0.1.0/README.md +104 -0
  4. pyqit-0.1.0/pyproject.toml +158 -0
  5. pyqit-0.1.0/pyqit/__init__.py +19 -0
  6. pyqit-0.1.0/pyqit/ansatzes/__init__.py +18 -0
  7. pyqit-0.1.0/pyqit/ansatzes/base.py +60 -0
  8. pyqit-0.1.0/pyqit/ansatzes/basic_entangler.py +46 -0
  9. pyqit-0.1.0/pyqit/ansatzes/cnot_ladder.py +45 -0
  10. pyqit-0.1.0/pyqit/ansatzes/hardware_efficient.py +101 -0
  11. pyqit-0.1.0/pyqit/ansatzes/sel.py +72 -0
  12. pyqit-0.1.0/pyqit/ansatzes/simplified_two_design.py +59 -0
  13. pyqit-0.1.0/pyqit/base/__init__.py +4 -0
  14. pyqit-0.1.0/pyqit/base/_tags.py +574 -0
  15. pyqit-0.1.0/pyqit/base/base_object.py +60 -0
  16. pyqit-0.1.0/pyqit/core/__init__.py +59 -0
  17. pyqit-0.1.0/pyqit/core/adapters/__init__.py +13 -0
  18. pyqit-0.1.0/pyqit/core/adapters/lightning.py +284 -0
  19. pyqit-0.1.0/pyqit/core/callbacks/__init__.py +14 -0
  20. pyqit-0.1.0/pyqit/core/callbacks/base.py +84 -0
  21. pyqit-0.1.0/pyqit/core/callbacks/checkpoint.py +368 -0
  22. pyqit-0.1.0/pyqit/core/callbacks/early_stopping.py +119 -0
  23. pyqit-0.1.0/pyqit/core/callbacks/history.py +45 -0
  24. pyqit-0.1.0/pyqit/core/config.py +92 -0
  25. pyqit-0.1.0/pyqit/core/embeddings.py +255 -0
  26. pyqit-0.1.0/pyqit/core/losses/__init__.py +15 -0
  27. pyqit-0.1.0/pyqit/core/losses/_registry.py +32 -0
  28. pyqit-0.1.0/pyqit/core/losses/base.py +78 -0
  29. pyqit-0.1.0/pyqit/core/losses/cross_entropy.py +75 -0
  30. pyqit-0.1.0/pyqit/core/losses/hinge.py +44 -0
  31. pyqit-0.1.0/pyqit/core/losses/mse.py +39 -0
  32. pyqit-0.1.0/pyqit/core/measurements.py +38 -0
  33. pyqit-0.1.0/pyqit/core/pipeline.py +561 -0
  34. pyqit-0.1.0/pyqit/core/trainer/__init__.py +13 -0
  35. pyqit-0.1.0/pyqit/core/trainer/_reporting.py +271 -0
  36. pyqit-0.1.0/pyqit/core/trainer/history.py +95 -0
  37. pyqit-0.1.0/pyqit/core/trainer/loops/__init__.py +14 -0
  38. pyqit-0.1.0/pyqit/core/trainer/loops/_registry.py +52 -0
  39. pyqit-0.1.0/pyqit/core/trainer/loops/base.py +151 -0
  40. pyqit-0.1.0/pyqit/core/trainer/loops/lightning_loop.py +126 -0
  41. pyqit-0.1.0/pyqit/core/trainer/loops/pennylane_loop.py +185 -0
  42. pyqit-0.1.0/pyqit/core/trainer/trainer.py +404 -0
  43. pyqit-0.1.0/pyqit/data/__init__.py +7 -0
  44. pyqit-0.1.0/pyqit/data/datamodule.py +796 -0
  45. pyqit-0.1.0/pyqit/models/__init__.py +21 -0
  46. pyqit-0.1.0/pyqit/models/base/__init__.py +6 -0
  47. pyqit-0.1.0/pyqit/models/base/base.py +168 -0
  48. pyqit-0.1.0/pyqit/models/base/quantum_model.py +138 -0
  49. pyqit-0.1.0/pyqit/models/classification/__init__.py +13 -0
  50. pyqit-0.1.0/pyqit/models/classification/classifier_mixin.py +112 -0
  51. pyqit-0.1.0/pyqit/models/classification/dressed.py +157 -0
  52. pyqit-0.1.0/pyqit/models/classification/reuploading.py +153 -0
  53. pyqit-0.1.0/pyqit/models/classification/vqc.py +128 -0
  54. pyqit-0.1.0/pyqit/models/layers/__init__.py +6 -0
  55. pyqit-0.1.0/pyqit/models/layers/dense.py +42 -0
  56. pyqit-0.1.0/pyqit/models/layers/stages.py +163 -0
  57. pyqit-0.1.0/pyqit/models/layers/vqc.py +118 -0
  58. pyqit-0.1.0/pyqit/models/regression/__init__.py +6 -0
  59. pyqit-0.1.0/pyqit/models/regression/regressor_mixin.py +15 -0
  60. pyqit-0.1.0/pyqit/models/regression/vqr.py +132 -0
  61. pyqit-0.1.0/pyqit/tests/__init__.py +0 -0
  62. pyqit-0.1.0/pyqit/tests/_fixture_generators.py +117 -0
  63. pyqit-0.1.0/pyqit/tests/scenarios.py +117 -0
  64. pyqit-0.1.0/pyqit/tests/test_all_ansatz.py +98 -0
  65. pyqit-0.1.0/pyqit/tests/test_all_embeddings.py +83 -0
  66. pyqit-0.1.0/pyqit/tests/test_all_layers.py +35 -0
  67. pyqit-0.1.0/pyqit/tests/test_all_losses.py +57 -0
  68. pyqit-0.1.0/pyqit/tests/test_all_models.py +146 -0
  69. pyqit-0.1.0/pyqit/tests/test_base.py +24 -0
  70. pyqit-0.1.0/pyqit/tests/test_datamodule.py +247 -0
  71. pyqit-0.1.0/pyqit/tests/test_pipeline.py +444 -0
  72. pyqit-0.1.0/pyqit/tests/test_trainer.py +603 -0
  73. pyqit-0.1.0/pyqit/utils/__init__.py +0 -0
  74. pyqit-0.1.0/pyqit/utils/diagnostic.py +472 -0
  75. pyqit-0.1.0/pyqit/utils/utils.py +133 -0
  76. pyqit-0.1.0/pyqit.egg-info/PKG-INFO +172 -0
  77. pyqit-0.1.0/pyqit.egg-info/SOURCES.txt +79 -0
  78. pyqit-0.1.0/pyqit.egg-info/dependency_links.txt +1 -0
  79. pyqit-0.1.0/pyqit.egg-info/requires.txt +45 -0
  80. pyqit-0.1.0/pyqit.egg-info/top_level.txt +1 -0
  81. pyqit-0.1.0/setup.cfg +4 -0
pyqit-0.1.0/LICENSE ADDED
@@ -0,0 +1,191 @@
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
+
179
+ Copyright (c) 2026, Aryan Saini
180
+
181
+ Licensed under the Apache License, Version 2.0 (the "License");
182
+ you may not use this file except in compliance with the License.
183
+ You may obtain a copy of the License at
184
+
185
+ http://www.apache.org/licenses/LICENSE-2.0
186
+
187
+ Unless required by applicable law or agreed to in writing, software
188
+ distributed under the License is distributed on an "AS IS" BASIS,
189
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
+ See the License for the specific language governing permissions and
191
+ limitations under the License.
pyqit-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,172 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyqit
3
+ Version: 0.1.0
4
+ Summary: A high-level orchestration and pipeline framework for quantum machine learning
5
+ Author: Aryan Saini
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/phoeenniixx/pyQit
8
+ Project-URL: Documentation, https://pyqit.readthedocs.io/en/stable/
9
+ Project-URL: Source, https://github.com/phoeenniixx/pyQit
10
+ Project-URL: Changelog, https://github.com/phoeenniixx/pyQit/blob/main/CHANGELOG.md
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Classifier: Topic :: Scientific/Engineering
20
+ Classifier: Topic :: Scientific/Engineering :: Physics
21
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
22
+ Classifier: Topic :: Software Development
23
+ Classifier: Topic :: Software Development :: Libraries
24
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
25
+ Requires-Python: <3.15,>=3.10
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ Requires-Dist: pennylane<0.46.0,>=0.42.0
29
+ Requires-Dist: numpy<3.0.0
30
+ Requires-Dist: pandas<3.1.0,>=2.3.3
31
+ Requires-Dist: scikit-learn<2.0,>=1.7.2
32
+ Requires-Dist: scikit-base<1.2.0
33
+ Provides-Extra: all-extras
34
+ Requires-Dist: torch!=2.0.1,<3.0.0,>=2.11.0; extra == "all-extras"
35
+ Requires-Dist: lightning; extra == "all-extras"
36
+ Requires-Dist: matplotlib; extra == "all-extras"
37
+ Requires-Dist: rich; extra == "all-extras"
38
+ Provides-Extra: pytorch
39
+ Requires-Dist: torch!=2.0.1,<3.0.0,>=2.11.0; extra == "pytorch"
40
+ Requires-Dist: lightning; extra == "pytorch"
41
+ Provides-Extra: qiskit
42
+ Requires-Dist: pennylane-qiskit; extra == "qiskit"
43
+ Provides-Extra: dev
44
+ Requires-Dist: pydocstyle; extra == "dev"
45
+ Requires-Dist: pre-commit; extra == "dev"
46
+ Requires-Dist: ruff; extra == "dev"
47
+ Requires-Dist: pytest; extra == "dev"
48
+ Requires-Dist: pytest-xdist; extra == "dev"
49
+ Requires-Dist: ipykernel; extra == "dev"
50
+ Requires-Dist: nbconvert; extra == "dev"
51
+ Requires-Dist: sphinx; extra == "dev"
52
+ Requires-Dist: pydata-sphinx-theme; extra == "dev"
53
+ Requires-Dist: nbsphinx; extra == "dev"
54
+ Requires-Dist: myst-parser; extra == "dev"
55
+ Requires-Dist: ipywidgets<9.0.0,>=8.1.8; extra == "dev"
56
+ Requires-Dist: pytest-dotenv<1.0.0,>=0.5.2; extra == "dev"
57
+ Provides-Extra: docs
58
+ Requires-Dist: sphinx<9.1.1,>3.2; extra == "docs"
59
+ Requires-Dist: pydata-sphinx-theme; extra == "docs"
60
+ Requires-Dist: nbsphinx; extra == "docs"
61
+ Requires-Dist: nbconvert; extra == "docs"
62
+ Requires-Dist: ipywidgets<9.0.0,>=8.1.8; extra == "docs"
63
+ Requires-Dist: myst-parser; extra == "docs"
64
+ Requires-Dist: docutils; extra == "docs"
65
+ Provides-Extra: github-actions
66
+ Requires-Dist: pytest-github-actions-annotate-failures; extra == "github-actions"
67
+ Dynamic: license-file
68
+
69
+ <p align="center">
70
+ <img src="docs/_static/pyqit-banner.png" alt="PyQit" width="320">
71
+ </p>
72
+
73
+ [![PyPI](https://img.shields.io/pypi/v/pyqit.svg)](https://pypi.org/project/pyqit/)
74
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
75
+ ![Status: Active Development](https://img.shields.io/badge/status-active_development-orange.svg)
76
+ [![Docs](https://app.readthedocs.org/projects/pyqit/badge/?version=stable)](https://pyqit.readthedocs.io/en/stable/)
77
+ [![Code style: ruff](https://img.shields.io/badge/code%20style-ruff-261230.svg)](https://github.com/astral-sh/ruff)
78
+ [![Build Status](https://img.shields.io/github/actions/workflow/status/phoeenniixx/pyQit/test.yml)](https://github.com/phoeenniixx/pyqit/actions)
79
+
80
+ PyQit is a quantum machine learning framework built on
81
+ [PennyLane](https://docs.pennylane.ai/en/stable/). It puts a Trainer, a
82
+ DataModule and model classes on top of PennyLane QNodes, so training a variational
83
+ circuit is a `fit` call rather than an optimizer loop you write yourself.
84
+ [PyTorch](https://pytorch.org/docs/stable/) and
85
+ [PyTorch Lightning](https://lightning.ai/docs/pytorch/stable/) are optional. Install
86
+ them and the same code trains through PyTorch Lightning instead of autograd. That is the
87
+ PyTorch project, not PennyLane's `lightning.qubit` simulator, which is a device and works
88
+ on either backend.
89
+
90
+ Version `0.1.0`.
91
+
92
+ The [documentation](https://pyqit.readthedocs.io/en/stable/) has the tutorials, the API
93
+ reference and the design notes. This page is the short version.
94
+
95
+ ## Installation
96
+
97
+ ```bash
98
+ pip install pyqit # pennylane and numpy
99
+ pip install "pyqit[pytorch]" # adds torch and pytorch lightning
100
+ pip install "pyqit[all_extras]" # adds matplotlib and rich as well
101
+ pip install "pyqit[qiskit]" # adds the PennyLane-Qiskit plugin
102
+ ```
103
+
104
+ With uv, `uv add pyqit` or `uv pip install "pyqit[pytorch]"` takes the same extras. There
105
+ is no conda package. Inside a conda environment, use pip.
106
+
107
+ `all_extras` covers torch, lightning, matplotlib and rich. The Qiskit plugin is not part
108
+ of it, because it needs Python 3.11 or newer. Install it through the `qiskit` extra on
109
+ its own.
110
+
111
+ ## Quickstart
112
+
113
+ ```python
114
+ from sklearn.datasets import make_moons
115
+
116
+ import pyqit
117
+ from pyqit.ansatzes import SELAnsatz
118
+ from pyqit.core import AngleEmbedding
119
+ from pyqit.models import VQCClassifier
120
+
121
+ pyqit.set_seed(42)
122
+
123
+ X, y = make_moons(n_samples=200, noise=0.1, random_state=0)
124
+
125
+ # Nothing is split, normalized or prescaled until the Trainer calls setup().
126
+ dm = pyqit.DataModule(X, y, normalize="minmax", batch_size=16)
127
+
128
+ model = VQCClassifier(
129
+ n_qubits=4,
130
+ n_layers=3,
131
+ ansatz=SELAnsatz,
132
+ encoder=AngleEmbedding,
133
+ )
134
+
135
+ trainer = pyqit.Trainer(max_epochs=30, learning_rate=0.05)
136
+ history = trainer.fit(model, dm)
137
+
138
+ print(history.best_epoch, history.best_score) # 22 0.0947
139
+ preds = trainer.predict(model, dm) # runs on the test split
140
+ ```
141
+
142
+ `fit` returns a `TrainingHistory` with one entry per epoch for train and validation loss
143
+ and accuracy. The model draws its weights and reads the backend in `__init__`, so seed
144
+ and pick the backend before you build it.
145
+
146
+ ## What is in the box
147
+
148
+ Each item links to its page in the docs.
149
+
150
+ - [Backends](https://pyqit.readthedocs.io/en/stable/api/trainer.html). `pyqit.set_backend("torch")` moves training to PyTorch Lightning. Same model, same callbacks, same history. PyTorch Lightning settings go through `Trainer(backend_kwargs=...)`.
151
+ - [DataModule](https://pyqit.readthedocs.io/en/stable/api/datamodule.html). Nothing runs until the Trainer asks. It splits, fits normalization on the train split only, and prescales inputs for the model's embedding.
152
+ - [Callbacks](https://pyqit.readthedocs.io/en/stable/api/callbacks.html). `EarlyStopping` and `ModelCheckpoint` work on both backends. Your own is a `BaseCallback` with up to three methods.
153
+ - [Losses](https://pyqit.readthedocs.io/en/stable/api/losses.html). `mse`, `hinge`, `cross_entropy`, or any callable.
154
+ - [Barren-plateau check](https://pyqit.readthedocs.io/en/stable/api/diagnostics.html). `Trainer(check_bp=True)` samples gradients at random weights before training and tells you whether their variance sits above the theoretical floor.
155
+ - [Pipelines](https://pyqit.readthedocs.io/en/stable/api/pipeline.html). `QuantumPipeline` chains models or runs them as an ensemble.
156
+ - [Devices](https://pyqit.readthedocs.io/en/stable/api/models.html#devices). `device=` takes any PennyLane device name, plugins included. The [PennyLane-Qiskit](https://docs.pennylane.ai/projects/qiskit/en/stable/) plugin is tested, and `Trainer(verbose=2)` prints which differentiation method a device gets.
157
+
158
+ Tutorials walk through a [VQC end to end](https://pyqit.readthedocs.io/en/stable/tutorials/vqc.html),
159
+ [callbacks and checkpoints](https://pyqit.readthedocs.io/en/stable/tutorials/callbacks.html)
160
+ and [barren plateaus](https://pyqit.readthedocs.io/en/stable/tutorials/barren_plateau.html).
161
+
162
+ ## Contributing
163
+
164
+ Issues and pull requests are welcome. The
165
+ [contributing guide](https://pyqit.readthedocs.io/en/stable/contributing.html) has the
166
+ conventions.
167
+
168
+ ```bash
169
+ pip install -e ".[dev,all_extras]"
170
+ python -m pytest -n auto
171
+ pre-commit run --all-files
172
+ ```
pyqit-0.1.0/README.md ADDED
@@ -0,0 +1,104 @@
1
+ <p align="center">
2
+ <img src="docs/_static/pyqit-banner.png" alt="PyQit" width="320">
3
+ </p>
4
+
5
+ [![PyPI](https://img.shields.io/pypi/v/pyqit.svg)](https://pypi.org/project/pyqit/)
6
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
7
+ ![Status: Active Development](https://img.shields.io/badge/status-active_development-orange.svg)
8
+ [![Docs](https://app.readthedocs.org/projects/pyqit/badge/?version=stable)](https://pyqit.readthedocs.io/en/stable/)
9
+ [![Code style: ruff](https://img.shields.io/badge/code%20style-ruff-261230.svg)](https://github.com/astral-sh/ruff)
10
+ [![Build Status](https://img.shields.io/github/actions/workflow/status/phoeenniixx/pyQit/test.yml)](https://github.com/phoeenniixx/pyqit/actions)
11
+
12
+ PyQit is a quantum machine learning framework built on
13
+ [PennyLane](https://docs.pennylane.ai/en/stable/). It puts a Trainer, a
14
+ DataModule and model classes on top of PennyLane QNodes, so training a variational
15
+ circuit is a `fit` call rather than an optimizer loop you write yourself.
16
+ [PyTorch](https://pytorch.org/docs/stable/) and
17
+ [PyTorch Lightning](https://lightning.ai/docs/pytorch/stable/) are optional. Install
18
+ them and the same code trains through PyTorch Lightning instead of autograd. That is the
19
+ PyTorch project, not PennyLane's `lightning.qubit` simulator, which is a device and works
20
+ on either backend.
21
+
22
+ Version `0.1.0`.
23
+
24
+ The [documentation](https://pyqit.readthedocs.io/en/stable/) has the tutorials, the API
25
+ reference and the design notes. This page is the short version.
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ pip install pyqit # pennylane and numpy
31
+ pip install "pyqit[pytorch]" # adds torch and pytorch lightning
32
+ pip install "pyqit[all_extras]" # adds matplotlib and rich as well
33
+ pip install "pyqit[qiskit]" # adds the PennyLane-Qiskit plugin
34
+ ```
35
+
36
+ With uv, `uv add pyqit` or `uv pip install "pyqit[pytorch]"` takes the same extras. There
37
+ is no conda package. Inside a conda environment, use pip.
38
+
39
+ `all_extras` covers torch, lightning, matplotlib and rich. The Qiskit plugin is not part
40
+ of it, because it needs Python 3.11 or newer. Install it through the `qiskit` extra on
41
+ its own.
42
+
43
+ ## Quickstart
44
+
45
+ ```python
46
+ from sklearn.datasets import make_moons
47
+
48
+ import pyqit
49
+ from pyqit.ansatzes import SELAnsatz
50
+ from pyqit.core import AngleEmbedding
51
+ from pyqit.models import VQCClassifier
52
+
53
+ pyqit.set_seed(42)
54
+
55
+ X, y = make_moons(n_samples=200, noise=0.1, random_state=0)
56
+
57
+ # Nothing is split, normalized or prescaled until the Trainer calls setup().
58
+ dm = pyqit.DataModule(X, y, normalize="minmax", batch_size=16)
59
+
60
+ model = VQCClassifier(
61
+ n_qubits=4,
62
+ n_layers=3,
63
+ ansatz=SELAnsatz,
64
+ encoder=AngleEmbedding,
65
+ )
66
+
67
+ trainer = pyqit.Trainer(max_epochs=30, learning_rate=0.05)
68
+ history = trainer.fit(model, dm)
69
+
70
+ print(history.best_epoch, history.best_score) # 22 0.0947
71
+ preds = trainer.predict(model, dm) # runs on the test split
72
+ ```
73
+
74
+ `fit` returns a `TrainingHistory` with one entry per epoch for train and validation loss
75
+ and accuracy. The model draws its weights and reads the backend in `__init__`, so seed
76
+ and pick the backend before you build it.
77
+
78
+ ## What is in the box
79
+
80
+ Each item links to its page in the docs.
81
+
82
+ - [Backends](https://pyqit.readthedocs.io/en/stable/api/trainer.html). `pyqit.set_backend("torch")` moves training to PyTorch Lightning. Same model, same callbacks, same history. PyTorch Lightning settings go through `Trainer(backend_kwargs=...)`.
83
+ - [DataModule](https://pyqit.readthedocs.io/en/stable/api/datamodule.html). Nothing runs until the Trainer asks. It splits, fits normalization on the train split only, and prescales inputs for the model's embedding.
84
+ - [Callbacks](https://pyqit.readthedocs.io/en/stable/api/callbacks.html). `EarlyStopping` and `ModelCheckpoint` work on both backends. Your own is a `BaseCallback` with up to three methods.
85
+ - [Losses](https://pyqit.readthedocs.io/en/stable/api/losses.html). `mse`, `hinge`, `cross_entropy`, or any callable.
86
+ - [Barren-plateau check](https://pyqit.readthedocs.io/en/stable/api/diagnostics.html). `Trainer(check_bp=True)` samples gradients at random weights before training and tells you whether their variance sits above the theoretical floor.
87
+ - [Pipelines](https://pyqit.readthedocs.io/en/stable/api/pipeline.html). `QuantumPipeline` chains models or runs them as an ensemble.
88
+ - [Devices](https://pyqit.readthedocs.io/en/stable/api/models.html#devices). `device=` takes any PennyLane device name, plugins included. The [PennyLane-Qiskit](https://docs.pennylane.ai/projects/qiskit/en/stable/) plugin is tested, and `Trainer(verbose=2)` prints which differentiation method a device gets.
89
+
90
+ Tutorials walk through a [VQC end to end](https://pyqit.readthedocs.io/en/stable/tutorials/vqc.html),
91
+ [callbacks and checkpoints](https://pyqit.readthedocs.io/en/stable/tutorials/callbacks.html)
92
+ and [barren plateaus](https://pyqit.readthedocs.io/en/stable/tutorials/barren_plateau.html).
93
+
94
+ ## Contributing
95
+
96
+ Issues and pull requests are welcome. The
97
+ [contributing guide](https://pyqit.readthedocs.io/en/stable/contributing.html) has the
98
+ conventions.
99
+
100
+ ```bash
101
+ pip install -e ".[dev,all_extras]"
102
+ python -m pytest -n auto
103
+ pre-commit run --all-files
104
+ ```
@@ -0,0 +1,158 @@
1
+ [project]
2
+ name = "pyqit"
3
+ readme = "README.md" # Markdown files are supported
4
+ version = "0.1.0"
5
+
6
+ authors = [
7
+ {name = "Aryan Saini"},
8
+ ]
9
+ requires-python = ">=3.10,<3.15"
10
+ license = "Apache-2.0"
11
+ license-files = ["LICENSE"]
12
+ classifiers = [
13
+ "Intended Audience :: Developers",
14
+ "Intended Audience :: Science/Research",
15
+ "Programming Language :: Python :: 3",
16
+ "Programming Language :: Python :: 3.10",
17
+ "Programming Language :: Python :: 3.11",
18
+ "Programming Language :: Python :: 3.12",
19
+ "Programming Language :: Python :: 3.13",
20
+ "Programming Language :: Python :: 3.14",
21
+ "Topic :: Scientific/Engineering",
22
+ "Topic :: Scientific/Engineering :: Physics",
23
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
24
+ "Topic :: Software Development",
25
+ "Topic :: Software Development :: Libraries",
26
+ "Topic :: Software Development :: Libraries :: Python Modules",
27
+ ]
28
+ description = "A high-level orchestration and pipeline framework for quantum machine learning"
29
+
30
+ dependencies = [
31
+ "pennylane >=0.42.0, <0.46.0",
32
+ "numpy <3.0.0",
33
+ "pandas >=2.3.3,<3.1.0",
34
+ "scikit-learn >=1.7.2,<2.0",
35
+ "scikit-base <1.2.0",
36
+ ]
37
+
38
+ [project.urls]
39
+ Homepage = "https://github.com/phoeenniixx/pyQit"
40
+ Documentation = "https://pyqit.readthedocs.io/en/stable/"
41
+ Source = "https://github.com/phoeenniixx/pyQit"
42
+ Changelog = "https://github.com/phoeenniixx/pyQit/blob/main/CHANGELOG.md"
43
+
44
+ [project.optional-dependencies]
45
+ all_extras = [
46
+ "torch !=2.0.1,>=2.11.0,<3.0.0",
47
+ "lightning",
48
+ "matplotlib",
49
+ "rich"
50
+ ]
51
+
52
+ pytorch = [
53
+ "torch !=2.0.1,>=2.11.0,<3.0.0",
54
+ "lightning",
55
+ ]
56
+
57
+ qiskit = [
58
+ "pennylane-qiskit",
59
+ ]
60
+
61
+ dev = [
62
+ "pydocstyle",
63
+ # checks and make tools
64
+ "pre-commit",
65
+ "ruff",
66
+ # pytest
67
+ "pytest",
68
+ "pytest-xdist",
69
+ # jupyter notebook
70
+ "ipykernel",
71
+ "nbconvert",
72
+ # documentatation
73
+ "sphinx",
74
+ "pydata-sphinx-theme",
75
+ "nbsphinx",
76
+ "myst-parser",
77
+ "ipywidgets>=8.1.8,<9.0.0",
78
+ "pytest-dotenv>=0.5.2,<1.0.0",
79
+ ]
80
+
81
+ # docs - dependencies for building the documentation
82
+ docs = [
83
+ "sphinx>3.2,<9.1.1",
84
+ "pydata-sphinx-theme",
85
+ "nbsphinx",
86
+ "nbconvert",
87
+ "ipywidgets>=8.1.8,<9.0.0",
88
+ "myst-parser",
89
+ "docutils",
90
+ ]
91
+
92
+ github-actions = ["pytest-github-actions-annotate-failures"]
93
+
94
+ [tool.setuptools.packages.find]
95
+ exclude = ["build_tools"]
96
+ include = ["pyqit", "pyqit*"]
97
+
98
+ [build-system]
99
+ build-backend = "setuptools.build_meta"
100
+ requires = [
101
+ "setuptools>=82.0.1",
102
+ ]
103
+
104
+ [tool.pytest.ini_options]
105
+ addopts = "-v"
106
+
107
+ [tool.ruff]
108
+ line-length = 88
109
+ exclude = [
110
+ "node_modules/",
111
+ "venv/",
112
+ ".venv/",
113
+ ".git/",
114
+ ".history/",
115
+ ]
116
+ target-version = "py310"
117
+
118
+ [tool.ruff.format]
119
+ # Enable formatting
120
+ quote-style = "double"
121
+ indent-style = "space"
122
+ skip-magic-trailing-comma = false
123
+ line-ending = "auto"
124
+
125
+ [tool.ruff.lint]
126
+ select = ["E", "F", "W", "C4", "S"]
127
+ extend-select = [
128
+ "I", # isort
129
+ "UP", # pyupgrade
130
+ "C4", # https://pypi.org/project/flake8-comprehensions
131
+ ]
132
+ extend-ignore = [
133
+ "E203", # space before : (needed for how black formats slicing)
134
+ "E402", # module level import not at top of file
135
+ "E731", # do not assign a lambda expression, use a def
136
+ "E741", # ignore not easy to read variables like i l I etc.
137
+ "C406", # Unnecessary list literal - rewrite as a dict literal.
138
+ "C408", # Unnecessary dict call - rewrite as a literal.
139
+ "C409", # Unnecessary list passed to tuple() - rewrite as a tuple literal.
140
+ "S101", # use of assert
141
+ "UP038", # isinstance(x, (a, b)) is not allowed
142
+ ]
143
+
144
+ [tool.ruff.lint.per-file-ignores]
145
+ "__init__.py" = ["F401"]
146
+ "build_tools/changelog.py" = ["S603", "S607"]
147
+
148
+ [tool.ruff.lint.isort]
149
+ known-first-party = ["pyqit"]
150
+ combine-as-imports = true
151
+ force-sort-within-sections = true
152
+
153
+ [tool.nbqa.mutate]
154
+ ruff = 1
155
+ black = 1
156
+
157
+ [tool.ruff.lint.pydocstyle]
158
+ convention = "numpy"
@@ -0,0 +1,19 @@
1
+ from importlib.metadata import version as _version
2
+ import logging
3
+
4
+ __version__ = _version("pyqit")
5
+
6
+ logging.getLogger("pyqit").addHandler(logging.NullHandler())
7
+
8
+ from pyqit.core.config import get_backend, set_backend, set_seed
9
+ from pyqit.core.trainer import Trainer
10
+ from pyqit.data.datamodule import DataModule
11
+
12
+ __all__ = [
13
+ "DataModule",
14
+ "Trainer",
15
+ "__version__",
16
+ "get_backend",
17
+ "set_backend",
18
+ "set_seed",
19
+ ]
@@ -0,0 +1,18 @@
1
+ """A module for quantum ansatzes."""
2
+
3
+ from pyqit.ansatzes.base import BaseAnsatz
4
+ from pyqit.ansatzes.basic_entangler import BasicEntanglerAnsatz
5
+ from pyqit.ansatzes.cnot_ladder import CNOTLadderAnsatz
6
+ from pyqit.ansatzes.hardware_efficient import EfficientSU2Ansatz, RealAmplitudesAnsatz
7
+ from pyqit.ansatzes.sel import SELAnsatz
8
+ from pyqit.ansatzes.simplified_two_design import SimplifiedTwoDesignAnsatz
9
+
10
+ __all__ = [
11
+ "BaseAnsatz",
12
+ "BasicEntanglerAnsatz",
13
+ "CNOTLadderAnsatz",
14
+ "EfficientSU2Ansatz",
15
+ "RealAmplitudesAnsatz",
16
+ "SELAnsatz",
17
+ "SimplifiedTwoDesignAnsatz",
18
+ ]