qsengine 1.0.0__cp39-abi3-win_amd64.whl
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.
- qsengine/__init__.py +5 -0
- qsengine/__init__.pyi +45 -0
- qsengine/py.typed +0 -0
- qsengine/qsengine.pyd +0 -0
- qsengine-1.0.0.dist-info/METADATA +178 -0
- qsengine-1.0.0.dist-info/RECORD +9 -0
- qsengine-1.0.0.dist-info/WHEEL +4 -0
- qsengine-1.0.0.dist-info/licenses/LICENSE +21 -0
- qsengine-1.0.0.dist-info/sboms/qsengine.cyclonedx.json +4091 -0
qsengine/__init__.py
ADDED
qsengine/__init__.pyi
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""Type stub for the compiled `qsengine` extension (gives IDEs autocomplete and types).
|
|
2
|
+
|
|
3
|
+
Bit order: qubit 0 is the rightmost character of every bitstring and bit 0 of
|
|
4
|
+
every basis index, the same convention as Qiskit.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import Literal, Optional
|
|
8
|
+
|
|
9
|
+
__version__: str
|
|
10
|
+
|
|
11
|
+
Backend = Literal["auto", "cpu", "gpu"]
|
|
12
|
+
|
|
13
|
+
class QuantumCircuit:
|
|
14
|
+
"""A quantum circuit on a fixed number of qubits, starting in |0...0>."""
|
|
15
|
+
|
|
16
|
+
def __init__(self, num_qubits: int) -> None: ...
|
|
17
|
+
@property
|
|
18
|
+
def num_qubits(self) -> int: ...
|
|
19
|
+
def __len__(self) -> int:
|
|
20
|
+
"""Number of gates recorded so far."""
|
|
21
|
+
|
|
22
|
+
# Single-qubit gates
|
|
23
|
+
def x(self, qubit: int) -> None: ...
|
|
24
|
+
def y(self, qubit: int) -> None: ...
|
|
25
|
+
def z(self, qubit: int) -> None: ...
|
|
26
|
+
def h(self, qubit: int) -> None: ...
|
|
27
|
+
def s(self, qubit: int) -> None: ...
|
|
28
|
+
def t(self, qubit: int) -> None: ...
|
|
29
|
+
def rx(self, qubit: int, theta: float) -> None: ...
|
|
30
|
+
def ry(self, qubit: int, theta: float) -> None: ...
|
|
31
|
+
def rz(self, qubit: int, theta: float) -> None: ...
|
|
32
|
+
|
|
33
|
+
# Two-qubit gates
|
|
34
|
+
def cx(self, control: int, target: int) -> None: ...
|
|
35
|
+
def cz(self, control: int, target: int) -> None: ...
|
|
36
|
+
|
|
37
|
+
# Execution
|
|
38
|
+
def run(
|
|
39
|
+
self, shots: int = 1024, seed: Optional[int] = None, backend: Backend = "auto"
|
|
40
|
+
) -> dict[str, int]:
|
|
41
|
+
"""Measure all qubits `shots` times; returns {bitstring: count}."""
|
|
42
|
+
def statevector(self, backend: Backend = "auto") -> list[complex]:
|
|
43
|
+
"""Exact final amplitudes, length 2**num_qubits."""
|
|
44
|
+
def probabilities(self, backend: Backend = "auto") -> list[float]:
|
|
45
|
+
"""Exact final basis-state probabilities, length 2**num_qubits."""
|
qsengine/py.typed
ADDED
|
File without changes
|
qsengine/qsengine.pyd
ADDED
|
Binary file
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: qsengine
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
5
|
+
Classifier: Intended Audience :: Science/Research
|
|
6
|
+
Classifier: Intended Audience :: Education
|
|
7
|
+
Classifier: Intended Audience :: Developers
|
|
8
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
9
|
+
Classifier: Operating System :: MacOS
|
|
10
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
11
|
+
Classifier: Programming Language :: Rust
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
14
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
16
|
+
Classifier: Typing :: Typed
|
|
17
|
+
Requires-Dist: pytest ; extra == 'test'
|
|
18
|
+
Requires-Dist: numpy ; extra == 'test'
|
|
19
|
+
Provides-Extra: test
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Summary: A fast state-vector quantum simulator for Python, with a Rust core that runs on any CPU or GPU
|
|
22
|
+
Keywords: quantum,quantum computing,simulator,statevector,qubit,gpu,rust
|
|
23
|
+
Home-Page: https://qsengine.kaiwave.dev
|
|
24
|
+
Author: kaiwave
|
|
25
|
+
License-Expression: MIT
|
|
26
|
+
Requires-Python: >=3.9
|
|
27
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
28
|
+
Project-URL: Documentation, https://qsengine.kaiwave.dev/docs/
|
|
29
|
+
Project-URL: Homepage, https://qsengine.kaiwave.dev
|
|
30
|
+
Project-URL: Issues, https://github.com/kaiwave/qsengine/issues
|
|
31
|
+
Project-URL: Release notes, https://qsengine.kaiwave.dev/docs/release-notes/
|
|
32
|
+
Project-URL: Source, https://github.com/kaiwave/qsengine
|
|
33
|
+
|
|
34
|
+
# qsengine
|
|
35
|
+
|
|
36
|
+
A state-vector quantum simulator for Python. You build circuits in Python; a Rust core runs them on every CPU core or on any GPU, and hands back the results.
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install qsengine
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
import qsengine
|
|
44
|
+
|
|
45
|
+
qc = qsengine.QuantumCircuit(2)
|
|
46
|
+
qc.h(0)
|
|
47
|
+
qc.cx(0, 1)
|
|
48
|
+
|
|
49
|
+
print(qc.run(shots=1000, seed=1)) # {'00': 513, '11': 487}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**Documentation and guides:** [qsengine.kaiwave.dev](https://qsengine.kaiwave.dev)
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Why qsengine
|
|
57
|
+
|
|
58
|
+
- **Fast where it counts.** Small circuits run on the CPU with almost no per-call overhead; from 14 qubits up, the GPU takes over. On a 22-qubit benchmark qsengine's GPU backend is about 5 times faster than Qiskit Aer.
|
|
59
|
+
- **Any GPU, nothing to install.** The GPU backend uses [wgpu](https://wgpu.rs), so it runs on NVIDIA, AMD, Intel and Apple GPUs through Vulkan, DirectX 12 or Metal. No CUDA, no vendor toolkit.
|
|
60
|
+
- **Works everywhere.** Without a usable GPU the same code runs on the CPU, in full 64-bit precision.
|
|
61
|
+
- **Small, plain API.** One class, eleven gates, three ways to get a result. Mistakes raise a normal Python `ValueError` on the line that made them.
|
|
62
|
+
- **Built to learn with.** The website walks from bra-ket notation to a complete Deutsch-Jozsa run, and every example on it is real qsengine output.
|
|
63
|
+
|
|
64
|
+
## Install
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pip install qsengine
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
One wheel per platform covers CPython 3.9 and newer on Windows, macOS and Linux. A GPU is optional.
|
|
71
|
+
|
|
72
|
+
## Using it
|
|
73
|
+
|
|
74
|
+
A circuit has a fixed number of qubits, all starting in |0⟩. Gate methods record gates; nothing runs until you ask for a result.
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
import qsengine
|
|
78
|
+
|
|
79
|
+
qc = qsengine.QuantumCircuit(3)
|
|
80
|
+
qc.h(0)
|
|
81
|
+
qc.cx(0, 1)
|
|
82
|
+
qc.cx(1, 2)
|
|
83
|
+
|
|
84
|
+
qc.run(shots=1000) # measurement counts: {'000': ..., '111': ...}
|
|
85
|
+
qc.probabilities() # exact probabilities of all 8 basis states
|
|
86
|
+
qc.statevector() # exact complex amplitudes
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
| Gates | Methods |
|
|
90
|
+
| --- | --- |
|
|
91
|
+
| Single qubit | `x`, `y`, `z`, `h`, `s`, `t` |
|
|
92
|
+
| Rotations (radians) | `rx(q, theta)`, `ry(q, theta)`, `rz(q, theta)` |
|
|
93
|
+
| Two qubit | `cx(control, target)`, `cz(control, target)` |
|
|
94
|
+
|
|
95
|
+
Bitstrings put **qubit 0 on the right**, the same convention as Qiskit. Pass `seed` to `run()` for repeatable counts.
|
|
96
|
+
|
|
97
|
+
### Choosing a backend
|
|
98
|
+
|
|
99
|
+
Every method that runs a circuit takes `backend="auto"` (the default), `"cpu"` or `"gpu"`.
|
|
100
|
+
|
|
101
|
+
| | CPU | GPU | auto |
|
|
102
|
+
| --- | --- | --- | --- |
|
|
103
|
+
| Precision | 64-bit | 32-bit (within 1e-5 of the CPU) | 64-bit below 14 qubits, 32-bit from 14 |
|
|
104
|
+
| Runs on | every CPU core | any NVIDIA, AMD, Intel or Apple GPU | whichever is faster |
|
|
105
|
+
| Without a GPU | works | raises `RuntimeError` | falls back to the CPU |
|
|
106
|
+
|
|
107
|
+
The full API, every error message and a guide to each topic are in the [documentation](https://qsengine.kaiwave.dev/docs/).
|
|
108
|
+
|
|
109
|
+
## Performance
|
|
110
|
+
|
|
111
|
+
Each run simulates 5 layers of (H on every qubit, RZ on every qubit, CNOT chain) and samples 1000 shots. Best of several runs on a Ryzen 5 5500 with a Radeon RX 6600, Windows 10, Qiskit Aer 0.18.2.
|
|
112
|
+
|
|
113
|
+

|
|
114
|
+
|
|
115
|
+
| Qubits | Pure Python | qsengine CPU | qsengine GPU | Qiskit Aer |
|
|
116
|
+
| ---: | ---: | ---: | ---: | ---: |
|
|
117
|
+
| 6 | 2.2 ms | **0.11 ms** | 1.3 ms | 3.7 ms |
|
|
118
|
+
| 10 | 30 ms | **0.30 ms** | 1.2 ms | 5.8 ms |
|
|
119
|
+
| 14 | 740 ms | 2.4 ms | **1.3 ms** | 11.7 ms |
|
|
120
|
+
| 18 | 16.2 s | 25 ms | **4.9 ms** | 19 ms |
|
|
121
|
+
| 22 | not run | 1.03 s | **70 ms** | 367 ms |
|
|
122
|
+
|
|
123
|
+
Below 14 qubits the CPU backend is 7 to 60 times faster than Aer; from 14 qubits the GPU backend is 3 to 9 times faster. Above about 17 qubits the CPU backend is slower than Aer, which fuses multi-qubit gates. These are one machine's numbers: reproduce them with [`benchmarks/benchmark.py`](benchmarks/benchmark.py).
|
|
124
|
+
|
|
125
|
+
## Limitations
|
|
126
|
+
|
|
127
|
+
Version 1.0 measures every qubit at the end of the circuit. There is no SWAP gate and no mid-circuit measurement yet, so algorithms such as teleportation that branch on a measurement are not possible. A register holds at most 30 qubits (16 GiB of memory).
|
|
128
|
+
|
|
129
|
+
## Building from source
|
|
130
|
+
|
|
131
|
+
You need a recent Rust toolchain (tested with 1.88) and Python 3.9 or newer.
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
git clone https://github.com/kaiwave/qsengine
|
|
135
|
+
cd qsengine
|
|
136
|
+
python -m venv .venv
|
|
137
|
+
source .venv/bin/activate # Windows: .venv\Scripts\activate
|
|
138
|
+
pip install maturin pytest numpy
|
|
139
|
+
maturin develop --release # build and install into the venv
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Tests:
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
cargo test --release # Rust tests (GPU tests skip without a GPU)
|
|
146
|
+
pytest # Python tests, checked against a NumPy reference
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
To build without the GPU backend, use `cargo build --no-default-features` for Rust.
|
|
150
|
+
|
|
151
|
+
The website lives in `site/` (Next.js, static export, maths rendered with KaTeX at build time):
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
cd site
|
|
155
|
+
npm install
|
|
156
|
+
npm run dev # local preview
|
|
157
|
+
npm run build # static site in site/out/
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Project layout
|
|
161
|
+
|
|
162
|
+
```text
|
|
163
|
+
src/ Rust core and Python bindings
|
|
164
|
+
engine.rs CPU backend (64-bit, multithreaded with Rayon)
|
|
165
|
+
gpu.rs GPU backend (wgpu compute shader in shaders/)
|
|
166
|
+
circuit.rs QuantumCircuit: records gates, fuses them, runs them
|
|
167
|
+
python.rs PyO3 bindings for the qsengine Python module
|
|
168
|
+
qsengine.pyi Type hints for editors
|
|
169
|
+
tests/ Python tests against NumPy
|
|
170
|
+
benchmarks/ Benchmark script, results and plot
|
|
171
|
+
site/ Documentation and learning website
|
|
172
|
+
docs/RUST_GUIDE.md A guide to every Rust feature the engine uses
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Licence
|
|
176
|
+
|
|
177
|
+
MIT, see [LICENSE](LICENSE). Made by [kaiwave](https://kaiwave.dev).
|
|
178
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
qsengine/__init__.py,sha256=Im4Q0Sh68pf2dIxIpkDpwQrqcB27ua8LZnVcoaVmAxc,115
|
|
2
|
+
qsengine/__init__.pyi,sha256=jlfuOwfIjPz8s0nz_HJ2J3L0WpMF3EJJEjBh_EaQvsI,1718
|
|
3
|
+
qsengine/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
+
qsengine/qsengine.pyd,sha256=enq5K7EQ0LhGy4Z_gTRjyS7aBZt7pBwe3LwrAvYYhmE,5833216
|
|
5
|
+
qsengine-1.0.0.dist-info/METADATA,sha256=xGHJ45VfPGBY_QVtpAjPMPzqutzkYcPIbI5fUpYKkUY,7207
|
|
6
|
+
qsengine-1.0.0.dist-info/WHEEL,sha256=xe4_tbg8wYdeh4O7nLbnWckzIQtCR4nODDgwke_TKy8,95
|
|
7
|
+
qsengine-1.0.0.dist-info/licenses/LICENSE,sha256=6-tKeeTbXQ_AoDo4IK5dj9wO5tk4Z6f9js1w-oE4Zz0,1085
|
|
8
|
+
qsengine-1.0.0.dist-info/sboms/qsengine.cyclonedx.json,sha256=vid-pkEHbPL0BJAFVVmSLYJxj1pNfihBx9ZBmxvDJPc,128975
|
|
9
|
+
qsengine-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 kaiwave
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|