rqm-core 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.
- rqm_core-0.1.0/LICENSE +21 -0
- rqm_core-0.1.0/PKG-INFO +353 -0
- rqm_core-0.1.0/README.md +301 -0
- rqm_core-0.1.0/pyproject.toml +55 -0
- rqm_core-0.1.0/setup.cfg +4 -0
- rqm_core-0.1.0/src/rqm_core/__init__.py +72 -0
- rqm_core-0.1.0/src/rqm_core/bloch.py +126 -0
- rqm_core-0.1.0/src/rqm_core/linalg.py +120 -0
- rqm_core-0.1.0/src/rqm_core/py.typed +0 -0
- rqm_core-0.1.0/src/rqm_core/quaternion.py +295 -0
- rqm_core-0.1.0/src/rqm_core/spinor.py +137 -0
- rqm_core-0.1.0/src/rqm_core/su2.py +149 -0
- rqm_core-0.1.0/src/rqm_core/types.py +18 -0
- rqm_core-0.1.0/src/rqm_core/utils.py +70 -0
- rqm_core-0.1.0/src/rqm_core/validation.py +128 -0
- rqm_core-0.1.0/src/rqm_core.egg-info/PKG-INFO +353 -0
- rqm_core-0.1.0/src/rqm_core.egg-info/SOURCES.txt +26 -0
- rqm_core-0.1.0/src/rqm_core.egg-info/dependency_links.txt +1 -0
- rqm_core-0.1.0/src/rqm_core.egg-info/requires.txt +5 -0
- rqm_core-0.1.0/src/rqm_core.egg-info/top_level.txt +1 -0
- rqm_core-0.1.0/tests/test_bloch.py +165 -0
- rqm_core-0.1.0/tests/test_linalg.py +169 -0
- rqm_core-0.1.0/tests/test_public_api.py +140 -0
- rqm_core-0.1.0/tests/test_quaternion.py +282 -0
- rqm_core-0.1.0/tests/test_spinor.py +154 -0
- rqm_core-0.1.0/tests/test_su2.py +146 -0
- rqm_core-0.1.0/tests/test_utils.py +126 -0
- rqm_core-0.1.0/tests/test_validation.py +175 -0
rqm_core-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 RQM Technologies
|
|
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.
|
rqm_core-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rqm-core
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Core quaternion, spinor, SU(2), and Bloch mathematics for the RQM Python ecosystem
|
|
5
|
+
Author: RQM Technologies
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 RQM Technologies
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://rqmtechnologies.com
|
|
29
|
+
Project-URL: Documentation, https://docs.rqmtechnologies.com
|
|
30
|
+
Project-URL: Source, https://github.com/RQM-Technologies-dev/rqm-core
|
|
31
|
+
Project-URL: Issues, https://github.com/RQM-Technologies-dev/rqm-core/issues
|
|
32
|
+
Keywords: quaternion,su2,bloch sphere,spinor,quantum,linear algebra,rotation,mathematics
|
|
33
|
+
Classifier: Development Status :: 4 - Beta
|
|
34
|
+
Classifier: Intended Audience :: Science/Research
|
|
35
|
+
Classifier: Intended Audience :: Developers
|
|
36
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
37
|
+
Classifier: Programming Language :: Python :: 3
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
41
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
42
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
43
|
+
Classifier: Typing :: Typed
|
|
44
|
+
Requires-Python: >=3.10
|
|
45
|
+
Description-Content-Type: text/markdown
|
|
46
|
+
License-File: LICENSE
|
|
47
|
+
Requires-Dist: numpy>=1.24
|
|
48
|
+
Provides-Extra: dev
|
|
49
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
50
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
51
|
+
Dynamic: license-file
|
|
52
|
+
|
|
53
|
+
# RQM Core
|
|
54
|
+
|
|
55
|
+
> Core quaternion, spinor, SU(2), and Bloch mathematics for the RQM Python ecosystem.
|
|
56
|
+
|
|
57
|
+
[](https://pypi.org/project/rqm-core/)
|
|
58
|
+
[](https://pypi.org/project/rqm-core/)
|
|
59
|
+
[](LICENSE)
|
|
60
|
+
[](https://docs.rqmtechnologies.com)
|
|
61
|
+
[](https://rqmtechnologies.com)
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## π RQM Platform
|
|
66
|
+
|
|
67
|
+
This repository is part of the RQM Technologies ecosystem.
|
|
68
|
+
|
|
69
|
+
β Website: https://rqmtechnologies.com
|
|
70
|
+
β Documentation: https://docs.rqmtechnologies.com
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## Install
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
pip install rqm-core
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
`rqm-core` is the mathematical foundation layer. It has no RQM-level dependencies β only `numpy` at runtime.
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## Where This Fits
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
rqm-core β rqm-compiler β rqm-qiskit / rqm-braket
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
`rqm-core` provides the canonical mathematical layer of the RQM ecosystem, including quaternion, spinor, Bloch, and SU(2) foundations. Higher-level packages (`rqm-compiler`, `rqm-qiskit`, `rqm-braket`) build on top of it.
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## Next Steps
|
|
95
|
+
|
|
96
|
+
- Documentation: https://docs.rqmtechnologies.com
|
|
97
|
+
- Website: https://rqmtechnologies.com
|
|
98
|
+
- Next package in the stack: [`rqm-compiler`](https://github.com/RQM-Technologies-dev/rqm-compiler)
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## Why This Package Exists
|
|
103
|
+
|
|
104
|
+
Higher-level RQM libraries (simulators, compilers, hardware adapters) all require a
|
|
105
|
+
common, reliable layer of linear algebra and quantum geometry. `rqm-core` is that layer.
|
|
106
|
+
|
|
107
|
+
It provides a single, versioned source of truth for the mathematical primitives shared
|
|
108
|
+
across the whole ecosystem: no duplication, no conflicting conventions, and no framework lock-in.
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## Design Principles
|
|
113
|
+
|
|
114
|
+
| Principle | What it means in practice |
|
|
115
|
+
|---|---|
|
|
116
|
+
| **Tiny** | Only implement primitives that are needed by β₯2 packages |
|
|
117
|
+
| **Stable** | Slow to change; breaking changes require a major version bump |
|
|
118
|
+
| **Dependency-light** | Only `numpy` at runtime |
|
|
119
|
+
| **Canonical** | One correct convention, clearly documented, used everywhere |
|
|
120
|
+
| **Well-tested** | Strong test coverage from the first commit |
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## What Is Included
|
|
125
|
+
|
|
126
|
+
- **Quaternion primitives** β Hamilton product, conjugate, inverse, axis-angle construction, SO(3) and SU(2) conversions
|
|
127
|
+
- **Spinor helpers** β normalization, norm, fidelity, spinorβquaternion/SU(2) mappings
|
|
128
|
+
- **SU(2) conversions** β construction from quaternions and axis-angle, validation, round-trips
|
|
129
|
+
- **Bloch sphere mappings** β stateβBloch, Blochβstate, quaternion rotation to Bloch vector
|
|
130
|
+
- **Matrix helpers** β trace, determinant, conjugate transpose (dagger), norm, closeness checks
|
|
131
|
+
- **Validation utilities** β axis, complex pair, matrix shape, real number, tolerance checks
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## Mathematical Conventions
|
|
136
|
+
|
|
137
|
+
The full reference lives in [`CONVENTIONS.md`](CONVENTIONS.md).
|
|
138
|
+
The five items every downstream package needs to know:
|
|
139
|
+
|
|
140
|
+
### 1 Β· SU(2) Convention
|
|
141
|
+
|
|
142
|
+
A unit quaternion `q = w + xi + yj + zk` maps to SU(2) as:
|
|
143
|
+
|
|
144
|
+
```
|
|
145
|
+
U(q) = [[ w β iz , βy β ix ],
|
|
146
|
+
[ y β ix , w + iz ]]
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Implemented in `Quaternion.to_su2_matrix()`; inverted by `su2_to_quaternion()`.
|
|
150
|
+
|
|
151
|
+
### 2 Β· Spinor Convention
|
|
152
|
+
|
|
153
|
+
States are written `|Οβ© = Ξ±|0β© + Ξ²|1β©` with `|0β©` as the north-pole
|
|
154
|
+
computational-basis ground state. Amplitudes are always passed as the ordered
|
|
155
|
+
pair `(alpha, beta)`. Functions that require unit norm normalize internally.
|
|
156
|
+
|
|
157
|
+
### 3 Β· Bloch Sphere Parameterization
|
|
158
|
+
|
|
159
|
+
```
|
|
160
|
+
|Οβ© = cos(ΞΈ/2)|0β© + e^{iΟ} sin(ΞΈ/2)|1β©
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
`theta` β `[0, Ο]` (polar/colatitude), `phi` β `[0, 2Ο)` (azimuthal).
|
|
164
|
+
`|0β©` β north pole `(0, 0, +1)`; `|1β©` β south pole `(0, 0, β1)`.
|
|
165
|
+
|
|
166
|
+
### 4 Β· Global Phase
|
|
167
|
+
|
|
168
|
+
`q` and `βq` represent the same rotation. `spinor_to_quaternion` encodes
|
|
169
|
+
the rotation up to global phase β never rely on the sign of the scalar part.
|
|
170
|
+
|
|
171
|
+
### 5 Β· Default Tolerance and Axis Labels
|
|
172
|
+
|
|
173
|
+
All closeness checks default to `atol = 1e-9` (absolute, no relative
|
|
174
|
+
component). Axis labels are `"x"`, `"y"`, `"z"` (case-insensitive);
|
|
175
|
+
all angles are in **radians**.
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## What Is Intentionally *Not* Included
|
|
180
|
+
|
|
181
|
+
- Qiskit / PennyLane / Cirq adapters
|
|
182
|
+
- Backend execution or hardware drivers
|
|
183
|
+
- Circuit transpilation or compilation
|
|
184
|
+
- Plotting or visualisation
|
|
185
|
+
- Cloud workflow integration
|
|
186
|
+
- Notebook tooling
|
|
187
|
+
- Algorithm frameworks or optimisation workflows
|
|
188
|
+
|
|
189
|
+
Those belong in higher-level packages.
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## Installation
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
pip install rqm-core
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Development install (includes `pytest` and `pytest-cov`):
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
pip install "rqm-core[dev]"
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## Ecosystem Role
|
|
208
|
+
|
|
209
|
+
`rqm-core` is the **spine** of the RQM Python ecosystem. It provides the
|
|
210
|
+
single canonical implementation of all shared mathematical primitives so that
|
|
211
|
+
downstream packages never need to re-implement or copy them.
|
|
212
|
+
|
|
213
|
+
**How downstream packages declare the dependency** (example `pyproject.toml` excerpt):
|
|
214
|
+
|
|
215
|
+
```toml
|
|
216
|
+
[project]
|
|
217
|
+
dependencies = [
|
|
218
|
+
"rqm-core>=0.1.0",
|
|
219
|
+
]
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
**How downstream packages import:**
|
|
223
|
+
|
|
224
|
+
```python
|
|
225
|
+
# rqm-qiskit, rqm-circuits, rqm-compiler, etc.
|
|
226
|
+
from rqm_core import Quaternion, axis_angle_to_su2, state_to_bloch
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
**Contract for downstream maintainers:**
|
|
230
|
+
|
|
231
|
+
- All conventions are defined in [`CONVENTIONS.md`](CONVENTIONS.md) and must
|
|
232
|
+
not be re-defined or overridden locally.
|
|
233
|
+
- Breaking changes to `rqm-core` require a **major version bump** (`1.0.0`, β¦).
|
|
234
|
+
- Any primitive needed by two or more packages belongs here, not in the
|
|
235
|
+
individual packages.
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## Quickstart
|
|
240
|
+
|
|
241
|
+
```python
|
|
242
|
+
from rqm_core import Quaternion, state_to_bloch, axis_angle_to_su2
|
|
243
|
+
import math
|
|
244
|
+
|
|
245
|
+
# 90Β° rotation around Y
|
|
246
|
+
q = Quaternion.from_axis_angle("y", math.pi / 2)
|
|
247
|
+
print(q)
|
|
248
|
+
# Quaternion(0.7071..., 0.0, 0.7071..., 0.0)
|
|
249
|
+
|
|
250
|
+
# SU(2) matrix directly from axis-angle
|
|
251
|
+
print(axis_angle_to_su2("y", math.pi / 2))
|
|
252
|
+
|
|
253
|
+
# |+β© state on the Bloch sphere β equator at (1, 0, 0)
|
|
254
|
+
c = 1 / math.sqrt(2)
|
|
255
|
+
x, y, z = state_to_bloch(c, c)
|
|
256
|
+
print(x, y, z) # 1.0 0.0 0.0
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
---
|
|
260
|
+
|
|
261
|
+
## Package Structure
|
|
262
|
+
|
|
263
|
+
```
|
|
264
|
+
rqm-core/
|
|
265
|
+
CONVENTIONS.md β canonical mathematical conventions reference
|
|
266
|
+
pyproject.toml β package metadata and build config
|
|
267
|
+
src/rqm_core/
|
|
268
|
+
__init__.py β canonical public API (import everything from here)
|
|
269
|
+
py.typed β PEP 561 marker (enables type checking in downstream packages)
|
|
270
|
+
quaternion.py β Quaternion class (Hamilton algebra, SO(3)/SU(2) conversions)
|
|
271
|
+
spinor.py β spinor normalization, fidelity, spinorβquaternion/SU(2)
|
|
272
|
+
su2.py β SU(2) construction, validation, quaternion round-trips
|
|
273
|
+
bloch.py β Bloch sphere mappings and validation
|
|
274
|
+
linalg.py β matrix helpers (dagger, trace, determinant, closeness)
|
|
275
|
+
validation.py β shared validation helpers (axis, matrix shape, tolerances)
|
|
276
|
+
types.py β shared type aliases (ComplexVector2, BlochVector, SU2Matrix, β¦)
|
|
277
|
+
utils.py β small math utilities (angle_wrap, safe_norm, is_finite_*)
|
|
278
|
+
|
|
279
|
+
tests/
|
|
280
|
+
test_quaternion.py
|
|
281
|
+
test_spinor.py
|
|
282
|
+
test_su2.py
|
|
283
|
+
test_bloch.py
|
|
284
|
+
test_linalg.py
|
|
285
|
+
test_utils.py
|
|
286
|
+
test_validation.py
|
|
287
|
+
test_public_api.py
|
|
288
|
+
|
|
289
|
+
examples/
|
|
290
|
+
quaternion_basics.py β quaternion construction, composition, conversion
|
|
291
|
+
spinor_basics.py β spinor normalization, Bloch mapping, fidelity
|
|
292
|
+
su2_bloch_demo.py β axis-angle β SU(2) β Bloch pipeline
|
|
293
|
+
bloch_mapping_demo.py β canonical Bloch vectors and round-trip checks
|
|
294
|
+
su2_rotation_demo.py β SU(2) construction and quaternion round-trip
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
---
|
|
298
|
+
|
|
299
|
+
## Testing
|
|
300
|
+
|
|
301
|
+
```bash
|
|
302
|
+
# Install the package in editable mode with test dependencies
|
|
303
|
+
pip install -e ".[dev]"
|
|
304
|
+
|
|
305
|
+
# Run the full test suite
|
|
306
|
+
pytest
|
|
307
|
+
|
|
308
|
+
# Run with coverage report
|
|
309
|
+
pytest --cov=rqm_core --cov-report=term-missing
|
|
310
|
+
|
|
311
|
+
# Run a single test file
|
|
312
|
+
pytest tests/test_quaternion.py -v
|
|
313
|
+
|
|
314
|
+
# Run only the public-API contract tests
|
|
315
|
+
pytest tests/test_public_api.py -v
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
---
|
|
319
|
+
|
|
320
|
+
## Architectural Notes
|
|
321
|
+
|
|
322
|
+
- **`su2.is_unitary` is a thin domain-scoped shim** over `linalg.is_unitary`.
|
|
323
|
+
Both exist intentionally: `linalg.is_unitary` is the general-purpose helper;
|
|
324
|
+
`su2.is_unitary` is the public entry point for SU(2)-context callers and is
|
|
325
|
+
what `rqm_core.is_unitary` resolves to in the top-level API.
|
|
326
|
+
|
|
327
|
+
- **`q` and `βq` represent the same rotation.** Round-trip conversions
|
|
328
|
+
`q β SU(2) β q` are tested against both `q` and `βq`. Downstream code
|
|
329
|
+
must never compare quaternion scalar parts for sign equality.
|
|
330
|
+
|
|
331
|
+
- **The `src/` layout** means `rqm_core` is only importable after installation
|
|
332
|
+
(`pip install -e .`). Running tests directly without installing first will
|
|
333
|
+
produce `ModuleNotFoundError`.
|
|
334
|
+
|
|
335
|
+
- **`py.typed`** is included in the installed wheel (via `[tool.setuptools.package-data]`),
|
|
336
|
+
enabling `mypy` and `pyright` in any package that depends on `rqm-core`.
|
|
337
|
+
|
|
338
|
+
---
|
|
339
|
+
|
|
340
|
+
## Roadmap
|
|
341
|
+
|
|
342
|
+
`rqm-core` is intended to remain **small and stable** while higher-level packages evolve around it.
|
|
343
|
+
|
|
344
|
+
Planned additions for future minor versions:
|
|
345
|
+
|
|
346
|
+
- [ ] Quaternion SLERP (spherical linear interpolation)
|
|
347
|
+
- [ ] SO(3) rotation-matrix β quaternion round-trip helpers
|
|
348
|
+
- [ ] Mixed-state density matrix utilities
|
|
349
|
+
- [ ] SU(2) Lie-algebra generators and exponential map
|
|
350
|
+
- [ ] Type stub files (`.pyi`) for IDE completions
|
|
351
|
+
|
|
352
|
+
No Qiskit or framework dependencies will ever be added to this package.
|
|
353
|
+
|
rqm_core-0.1.0/README.md
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
# RQM Core
|
|
2
|
+
|
|
3
|
+
> Core quaternion, spinor, SU(2), and Bloch mathematics for the RQM Python ecosystem.
|
|
4
|
+
|
|
5
|
+
[](https://pypi.org/project/rqm-core/)
|
|
6
|
+
[](https://pypi.org/project/rqm-core/)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
[](https://docs.rqmtechnologies.com)
|
|
9
|
+
[](https://rqmtechnologies.com)
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## π RQM Platform
|
|
14
|
+
|
|
15
|
+
This repository is part of the RQM Technologies ecosystem.
|
|
16
|
+
|
|
17
|
+
β Website: https://rqmtechnologies.com
|
|
18
|
+
β Documentation: https://docs.rqmtechnologies.com
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Install
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install rqm-core
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`rqm-core` is the mathematical foundation layer. It has no RQM-level dependencies β only `numpy` at runtime.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Where This Fits
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
rqm-core β rqm-compiler β rqm-qiskit / rqm-braket
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
`rqm-core` provides the canonical mathematical layer of the RQM ecosystem, including quaternion, spinor, Bloch, and SU(2) foundations. Higher-level packages (`rqm-compiler`, `rqm-qiskit`, `rqm-braket`) build on top of it.
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Next Steps
|
|
43
|
+
|
|
44
|
+
- Documentation: https://docs.rqmtechnologies.com
|
|
45
|
+
- Website: https://rqmtechnologies.com
|
|
46
|
+
- Next package in the stack: [`rqm-compiler`](https://github.com/RQM-Technologies-dev/rqm-compiler)
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## Why This Package Exists
|
|
51
|
+
|
|
52
|
+
Higher-level RQM libraries (simulators, compilers, hardware adapters) all require a
|
|
53
|
+
common, reliable layer of linear algebra and quantum geometry. `rqm-core` is that layer.
|
|
54
|
+
|
|
55
|
+
It provides a single, versioned source of truth for the mathematical primitives shared
|
|
56
|
+
across the whole ecosystem: no duplication, no conflicting conventions, and no framework lock-in.
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Design Principles
|
|
61
|
+
|
|
62
|
+
| Principle | What it means in practice |
|
|
63
|
+
|---|---|
|
|
64
|
+
| **Tiny** | Only implement primitives that are needed by β₯2 packages |
|
|
65
|
+
| **Stable** | Slow to change; breaking changes require a major version bump |
|
|
66
|
+
| **Dependency-light** | Only `numpy` at runtime |
|
|
67
|
+
| **Canonical** | One correct convention, clearly documented, used everywhere |
|
|
68
|
+
| **Well-tested** | Strong test coverage from the first commit |
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## What Is Included
|
|
73
|
+
|
|
74
|
+
- **Quaternion primitives** β Hamilton product, conjugate, inverse, axis-angle construction, SO(3) and SU(2) conversions
|
|
75
|
+
- **Spinor helpers** β normalization, norm, fidelity, spinorβquaternion/SU(2) mappings
|
|
76
|
+
- **SU(2) conversions** β construction from quaternions and axis-angle, validation, round-trips
|
|
77
|
+
- **Bloch sphere mappings** β stateβBloch, Blochβstate, quaternion rotation to Bloch vector
|
|
78
|
+
- **Matrix helpers** β trace, determinant, conjugate transpose (dagger), norm, closeness checks
|
|
79
|
+
- **Validation utilities** β axis, complex pair, matrix shape, real number, tolerance checks
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Mathematical Conventions
|
|
84
|
+
|
|
85
|
+
The full reference lives in [`CONVENTIONS.md`](CONVENTIONS.md).
|
|
86
|
+
The five items every downstream package needs to know:
|
|
87
|
+
|
|
88
|
+
### 1 Β· SU(2) Convention
|
|
89
|
+
|
|
90
|
+
A unit quaternion `q = w + xi + yj + zk` maps to SU(2) as:
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
U(q) = [[ w β iz , βy β ix ],
|
|
94
|
+
[ y β ix , w + iz ]]
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Implemented in `Quaternion.to_su2_matrix()`; inverted by `su2_to_quaternion()`.
|
|
98
|
+
|
|
99
|
+
### 2 Β· Spinor Convention
|
|
100
|
+
|
|
101
|
+
States are written `|Οβ© = Ξ±|0β© + Ξ²|1β©` with `|0β©` as the north-pole
|
|
102
|
+
computational-basis ground state. Amplitudes are always passed as the ordered
|
|
103
|
+
pair `(alpha, beta)`. Functions that require unit norm normalize internally.
|
|
104
|
+
|
|
105
|
+
### 3 Β· Bloch Sphere Parameterization
|
|
106
|
+
|
|
107
|
+
```
|
|
108
|
+
|Οβ© = cos(ΞΈ/2)|0β© + e^{iΟ} sin(ΞΈ/2)|1β©
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
`theta` β `[0, Ο]` (polar/colatitude), `phi` β `[0, 2Ο)` (azimuthal).
|
|
112
|
+
`|0β©` β north pole `(0, 0, +1)`; `|1β©` β south pole `(0, 0, β1)`.
|
|
113
|
+
|
|
114
|
+
### 4 Β· Global Phase
|
|
115
|
+
|
|
116
|
+
`q` and `βq` represent the same rotation. `spinor_to_quaternion` encodes
|
|
117
|
+
the rotation up to global phase β never rely on the sign of the scalar part.
|
|
118
|
+
|
|
119
|
+
### 5 Β· Default Tolerance and Axis Labels
|
|
120
|
+
|
|
121
|
+
All closeness checks default to `atol = 1e-9` (absolute, no relative
|
|
122
|
+
component). Axis labels are `"x"`, `"y"`, `"z"` (case-insensitive);
|
|
123
|
+
all angles are in **radians**.
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## What Is Intentionally *Not* Included
|
|
128
|
+
|
|
129
|
+
- Qiskit / PennyLane / Cirq adapters
|
|
130
|
+
- Backend execution or hardware drivers
|
|
131
|
+
- Circuit transpilation or compilation
|
|
132
|
+
- Plotting or visualisation
|
|
133
|
+
- Cloud workflow integration
|
|
134
|
+
- Notebook tooling
|
|
135
|
+
- Algorithm frameworks or optimisation workflows
|
|
136
|
+
|
|
137
|
+
Those belong in higher-level packages.
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## Installation
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
pip install rqm-core
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Development install (includes `pytest` and `pytest-cov`):
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
pip install "rqm-core[dev]"
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## Ecosystem Role
|
|
156
|
+
|
|
157
|
+
`rqm-core` is the **spine** of the RQM Python ecosystem. It provides the
|
|
158
|
+
single canonical implementation of all shared mathematical primitives so that
|
|
159
|
+
downstream packages never need to re-implement or copy them.
|
|
160
|
+
|
|
161
|
+
**How downstream packages declare the dependency** (example `pyproject.toml` excerpt):
|
|
162
|
+
|
|
163
|
+
```toml
|
|
164
|
+
[project]
|
|
165
|
+
dependencies = [
|
|
166
|
+
"rqm-core>=0.1.0",
|
|
167
|
+
]
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
**How downstream packages import:**
|
|
171
|
+
|
|
172
|
+
```python
|
|
173
|
+
# rqm-qiskit, rqm-circuits, rqm-compiler, etc.
|
|
174
|
+
from rqm_core import Quaternion, axis_angle_to_su2, state_to_bloch
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
**Contract for downstream maintainers:**
|
|
178
|
+
|
|
179
|
+
- All conventions are defined in [`CONVENTIONS.md`](CONVENTIONS.md) and must
|
|
180
|
+
not be re-defined or overridden locally.
|
|
181
|
+
- Breaking changes to `rqm-core` require a **major version bump** (`1.0.0`, β¦).
|
|
182
|
+
- Any primitive needed by two or more packages belongs here, not in the
|
|
183
|
+
individual packages.
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## Quickstart
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
from rqm_core import Quaternion, state_to_bloch, axis_angle_to_su2
|
|
191
|
+
import math
|
|
192
|
+
|
|
193
|
+
# 90Β° rotation around Y
|
|
194
|
+
q = Quaternion.from_axis_angle("y", math.pi / 2)
|
|
195
|
+
print(q)
|
|
196
|
+
# Quaternion(0.7071..., 0.0, 0.7071..., 0.0)
|
|
197
|
+
|
|
198
|
+
# SU(2) matrix directly from axis-angle
|
|
199
|
+
print(axis_angle_to_su2("y", math.pi / 2))
|
|
200
|
+
|
|
201
|
+
# |+β© state on the Bloch sphere β equator at (1, 0, 0)
|
|
202
|
+
c = 1 / math.sqrt(2)
|
|
203
|
+
x, y, z = state_to_bloch(c, c)
|
|
204
|
+
print(x, y, z) # 1.0 0.0 0.0
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
## Package Structure
|
|
210
|
+
|
|
211
|
+
```
|
|
212
|
+
rqm-core/
|
|
213
|
+
CONVENTIONS.md β canonical mathematical conventions reference
|
|
214
|
+
pyproject.toml β package metadata and build config
|
|
215
|
+
src/rqm_core/
|
|
216
|
+
__init__.py β canonical public API (import everything from here)
|
|
217
|
+
py.typed β PEP 561 marker (enables type checking in downstream packages)
|
|
218
|
+
quaternion.py β Quaternion class (Hamilton algebra, SO(3)/SU(2) conversions)
|
|
219
|
+
spinor.py β spinor normalization, fidelity, spinorβquaternion/SU(2)
|
|
220
|
+
su2.py β SU(2) construction, validation, quaternion round-trips
|
|
221
|
+
bloch.py β Bloch sphere mappings and validation
|
|
222
|
+
linalg.py β matrix helpers (dagger, trace, determinant, closeness)
|
|
223
|
+
validation.py β shared validation helpers (axis, matrix shape, tolerances)
|
|
224
|
+
types.py β shared type aliases (ComplexVector2, BlochVector, SU2Matrix, β¦)
|
|
225
|
+
utils.py β small math utilities (angle_wrap, safe_norm, is_finite_*)
|
|
226
|
+
|
|
227
|
+
tests/
|
|
228
|
+
test_quaternion.py
|
|
229
|
+
test_spinor.py
|
|
230
|
+
test_su2.py
|
|
231
|
+
test_bloch.py
|
|
232
|
+
test_linalg.py
|
|
233
|
+
test_utils.py
|
|
234
|
+
test_validation.py
|
|
235
|
+
test_public_api.py
|
|
236
|
+
|
|
237
|
+
examples/
|
|
238
|
+
quaternion_basics.py β quaternion construction, composition, conversion
|
|
239
|
+
spinor_basics.py β spinor normalization, Bloch mapping, fidelity
|
|
240
|
+
su2_bloch_demo.py β axis-angle β SU(2) β Bloch pipeline
|
|
241
|
+
bloch_mapping_demo.py β canonical Bloch vectors and round-trip checks
|
|
242
|
+
su2_rotation_demo.py β SU(2) construction and quaternion round-trip
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## Testing
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
# Install the package in editable mode with test dependencies
|
|
251
|
+
pip install -e ".[dev]"
|
|
252
|
+
|
|
253
|
+
# Run the full test suite
|
|
254
|
+
pytest
|
|
255
|
+
|
|
256
|
+
# Run with coverage report
|
|
257
|
+
pytest --cov=rqm_core --cov-report=term-missing
|
|
258
|
+
|
|
259
|
+
# Run a single test file
|
|
260
|
+
pytest tests/test_quaternion.py -v
|
|
261
|
+
|
|
262
|
+
# Run only the public-API contract tests
|
|
263
|
+
pytest tests/test_public_api.py -v
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
---
|
|
267
|
+
|
|
268
|
+
## Architectural Notes
|
|
269
|
+
|
|
270
|
+
- **`su2.is_unitary` is a thin domain-scoped shim** over `linalg.is_unitary`.
|
|
271
|
+
Both exist intentionally: `linalg.is_unitary` is the general-purpose helper;
|
|
272
|
+
`su2.is_unitary` is the public entry point for SU(2)-context callers and is
|
|
273
|
+
what `rqm_core.is_unitary` resolves to in the top-level API.
|
|
274
|
+
|
|
275
|
+
- **`q` and `βq` represent the same rotation.** Round-trip conversions
|
|
276
|
+
`q β SU(2) β q` are tested against both `q` and `βq`. Downstream code
|
|
277
|
+
must never compare quaternion scalar parts for sign equality.
|
|
278
|
+
|
|
279
|
+
- **The `src/` layout** means `rqm_core` is only importable after installation
|
|
280
|
+
(`pip install -e .`). Running tests directly without installing first will
|
|
281
|
+
produce `ModuleNotFoundError`.
|
|
282
|
+
|
|
283
|
+
- **`py.typed`** is included in the installed wheel (via `[tool.setuptools.package-data]`),
|
|
284
|
+
enabling `mypy` and `pyright` in any package that depends on `rqm-core`.
|
|
285
|
+
|
|
286
|
+
---
|
|
287
|
+
|
|
288
|
+
## Roadmap
|
|
289
|
+
|
|
290
|
+
`rqm-core` is intended to remain **small and stable** while higher-level packages evolve around it.
|
|
291
|
+
|
|
292
|
+
Planned additions for future minor versions:
|
|
293
|
+
|
|
294
|
+
- [ ] Quaternion SLERP (spherical linear interpolation)
|
|
295
|
+
- [ ] SO(3) rotation-matrix β quaternion round-trip helpers
|
|
296
|
+
- [ ] Mixed-state density matrix utilities
|
|
297
|
+
- [ ] SU(2) Lie-algebra generators and exponential map
|
|
298
|
+
- [ ] Type stub files (`.pyi`) for IDE completions
|
|
299
|
+
|
|
300
|
+
No Qiskit or framework dependencies will ever be added to this package.
|
|
301
|
+
|