nudaq 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.
- nudaq-0.1.0/.gitignore +8 -0
- nudaq-0.1.0/CHANGELOG.md +11 -0
- nudaq-0.1.0/LICENSE +21 -0
- nudaq-0.1.0/PKG-INFO +157 -0
- nudaq-0.1.0/README.md +133 -0
- nudaq-0.1.0/pyproject.toml +47 -0
- nudaq-0.1.0/src/nudaq/__init__.py +74 -0
- nudaq-0.1.0/src/nudaq/__main__.py +22 -0
- nudaq-0.1.0/src/nudaq/_alias/cudaq/__init__.py +6 -0
- nudaq-0.1.0/src/nudaq/_core.py +737 -0
- nudaq-0.1.0/tests/test_package.py +98 -0
- nudaq-0.1.0/tests/test_simulator.py +510 -0
nudaq-0.1.0/.gitignore
ADDED
nudaq-0.1.0/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 (unreleased)
|
|
4
|
+
|
|
5
|
+
First release, split out of a course repository where it checked CUDA-Q notebooks on machines
|
|
6
|
+
without CUDA-Q.
|
|
7
|
+
|
|
8
|
+
- Eager numpy state-vector simulator following the CUDA-Q 0.17 Python API subset listed in the README.
|
|
9
|
+
- Kernel lint that rejects code the CUDA-Q kernel compiler would reject.
|
|
10
|
+
- `nudaq.install()`, `nudaq.alias_path()` and `python -m nudaq path` to run unchanged `import cudaq` code.
|
|
11
|
+
- Gate names are provided inside kernel bodies only; importing nudaq does not modify `builtins`.
|
nudaq-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Yongseok Yoo
|
|
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.
|
nudaq-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: nudaq
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A small numpy simulator that copies a subset of the CUDA-Q Python API, for running and testing CUDA-Q style code without CUDA-Q
|
|
5
|
+
Project-URL: Homepage, https://github.com/ssuai/nudaq
|
|
6
|
+
Project-URL: Issues, https://github.com/ssuai/nudaq/issues
|
|
7
|
+
Author-email: Yongseok Yoo <yyoo@ssu.ac.kr>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: cuda-q,education,quantum,quantum computing,simulator,testing
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Education
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
18
|
+
Classifier: Topic :: Software Development :: Testing
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Requires-Dist: numpy>=1.22
|
|
21
|
+
Provides-Extra: test
|
|
22
|
+
Requires-Dist: pytest>=7; extra == 'test'
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# nudaq
|
|
26
|
+
|
|
27
|
+
A small **numpy** state-vector simulator that copies a subset of the
|
|
28
|
+
[CUDA-Q](https://nvidia.github.io/cuda-quantum/) Python API. Use it to run and test CUDA-Q style code
|
|
29
|
+
where CUDA-Q cannot be installed: Intel Macs, Windows without WSL, lightweight CI runners, or a
|
|
30
|
+
course's test suite.
|
|
31
|
+
|
|
32
|
+
> nudaq is **not** CUDA-Q, and is not affiliated with or endorsed by NVIDIA. It reproduces only the API
|
|
33
|
+
> surface listed below, simulates at most a few dozen qubits (state vector in memory), and gives no
|
|
34
|
+
> performance or exact-behaviour guarantees. Before you rely on results, run your code once on the real
|
|
35
|
+
> CUDA-Q.
|
|
36
|
+
|
|
37
|
+
## Install
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install nudaq
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The only dependency is numpy. Python ≥ 3.10.
|
|
44
|
+
|
|
45
|
+
## Three ways to use it
|
|
46
|
+
|
|
47
|
+
**1. Write against nudaq directly**
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
import nudaq as cudaq
|
|
51
|
+
|
|
52
|
+
@cudaq.kernel
|
|
53
|
+
def bell():
|
|
54
|
+
q = cudaq.qvector(2)
|
|
55
|
+
h(q[0])
|
|
56
|
+
x.ctrl(q[0], q[1])
|
|
57
|
+
mz(q)
|
|
58
|
+
|
|
59
|
+
print(cudaq.sample(bell, shots_count=1000)) # {'00': ~500, '11': ~500}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**2. Make `import cudaq` return nudaq in the current process** (a test `conftest.py`, the first cell of
|
|
63
|
+
a notebook):
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
import nudaq
|
|
67
|
+
nudaq.install() # refuses if a real cudaq is already imported
|
|
68
|
+
import cudaq # -> nudaq
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**3. Run unchanged code that does `import cudaq`** (scripts, Jupyter kernels, test subprocesses):
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
PYTHONPATH="$(python -m nudaq path)" python my_cudaq_script.py
|
|
75
|
+
PYTHONPATH="$(python -m nudaq path)" jupyter nbconvert --execute --to notebook my.ipynb
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
`python -m nudaq path` (or the `nudaq path` command) prints a directory that holds a tiny `cudaq` package
|
|
79
|
+
forwarding to nudaq. `nudaq.alias_path()` returns the same directory from Python.
|
|
80
|
+
|
|
81
|
+
## Supported API (CUDA-Q 0.17 semantics)
|
|
82
|
+
|
|
83
|
+
**Kernels** (`@cudaq.kernel`):
|
|
84
|
+
- Allocation: `cudaq.qvector(n)`, `cudaq.qvector(amplitudes)` (normalised list, little-endian
|
|
85
|
+
order), `cudaq.qubit()`.
|
|
86
|
+
- Indexing: `q[i]`, slices `q[a:b]`, `q.size()`, `q.front()`, `q.back()`, `q.front(k)`, `q.back(k)`,
|
|
87
|
+
`for qb in q`.
|
|
88
|
+
- Gates: `h x y z s t sdg tdg rx ry rz r1 u3 swap`, and the controlled forms `cx cy cz ch crx cry crz cr1`.
|
|
89
|
+
One-qubit gates broadcast over a register (`h(q)`).
|
|
90
|
+
- `.ctrl(...)` with one or several controls, a register as control, and negated controls `~q[0]`.
|
|
91
|
+
`.adj(...)` for adjoints.
|
|
92
|
+
- Sub-kernels with `cudaq.qview` arguments; `cudaq.control(kernel, ctrl, ...)` and
|
|
93
|
+
`cudaq.adjoint(kernel, ...)`.
|
|
94
|
+
- Custom gates with `cudaq.register_operation(name, unitary)`.
|
|
95
|
+
- Measurement with `mz`, as the final operations of a kernel.
|
|
96
|
+
|
|
97
|
+
**Host functions:**
|
|
98
|
+
- `sample(kernel, *args, shots_count=...)` returns a dict-like result with `most_probable`,
|
|
99
|
+
`probability`, `count` and `get_total_shots`.
|
|
100
|
+
- `get_state(...)` returns a state usable as `np.array(state)`, with `amplitude`, `amplitudes` and
|
|
101
|
+
`overlap`.
|
|
102
|
+
- `observe(kernel, H, *args)` with `H` built from `cudaq.spin.x/y/z/i`.
|
|
103
|
+
- Also `draw` (plain text list of gates), `set_random_seed`, `get_target`, and `set_target` (accepted,
|
|
104
|
+
ignored).
|
|
105
|
+
|
|
106
|
+
**Conventions copied from CUDA-Q:**
|
|
107
|
+
- `sample` bitstrings and `state.amplitude("01")` labels put qubit 0 on the **left**.
|
|
108
|
+
- `np.array(state)` is **little-endian**: qubit 0 is the least significant bit of the index.
|
|
109
|
+
`cudaq.qvector(amplitudes)` takes the same order.
|
|
110
|
+
- `register_operation` matrices are in **MSB order**: the first target is the most significant.
|
|
111
|
+
- Gate matrices:
|
|
112
|
+
- `ry(θ)|0⟩ = cos(θ/2)|0⟩ + sin(θ/2)|1⟩`
|
|
113
|
+
- `rx(θ) = e^{-iθX/2}`
|
|
114
|
+
- `rz(θ) = diag(e^{-iθ/2}, e^{iθ/2})`
|
|
115
|
+
- `r1(λ) = diag(1, e^{iλ})`
|
|
116
|
+
|
|
117
|
+
**Kernel lint.** Kernels run eagerly as Python, so nudaq first checks each kernel body and rejects what
|
|
118
|
+
the CUDA-Q kernel compiler rejects:
|
|
119
|
+
- captured globals (pass values as arguments);
|
|
120
|
+
- missing or unsupported argument annotations;
|
|
121
|
+
- default arguments;
|
|
122
|
+
- list comprehensions, strings, nested functions, try/with;
|
|
123
|
+
- numpy calls other than scalar math (`sin cos tan arcsin arccos arctan sqrt exp log`, `pi`);
|
|
124
|
+
- module-level variables that shadow gate names;
|
|
125
|
+
- numpy arrays passed as kernel arguments (pass `arr.tolist()`).
|
|
126
|
+
|
|
127
|
+
Passing the lint makes it likely, not certain, that CUDA-Q compiles the kernel.
|
|
128
|
+
|
|
129
|
+
Allowed argument types: `int float bool complex list[int] list[float] list[bool] list[complex]
|
|
130
|
+
cudaq.qview cudaq.qvector cudaq.qubit`.
|
|
131
|
+
|
|
132
|
+
**Not supported:** `get_unitary`, `exp_pauli`, `reset`, mid-circuit measurement with classical
|
|
133
|
+
feed-forward, noise models, `cudaq.run`, `cudaq.vqe`/optimizers, the builder API (`make_kernel`), GPU
|
|
134
|
+
targets, multi-QPU execution. `cudaq.draw` prints a gate list, not CUDA-Q's ASCII circuit.
|
|
135
|
+
|
|
136
|
+
## Development
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
python -m venv .venv && source .venv/bin/activate
|
|
140
|
+
pip install -e ".[test]"
|
|
141
|
+
python -m pytest
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
The tests check nudaq against an independent Kronecker-product reference simulator, the CUDA-Q ordering
|
|
145
|
+
conventions, the lint rules, and the three ways of importing it.
|
|
146
|
+
|
|
147
|
+
## Release
|
|
148
|
+
|
|
149
|
+
1. Update `__version__` in `src/nudaq/__init__.py` and `CHANGELOG.md`.
|
|
150
|
+
2. `python -m build && python -m twine check dist/*`.
|
|
151
|
+
3. Publish: `python -m twine upload dist/*`, or publish a GitHub release. `.github/workflows/publish.yml`
|
|
152
|
+
then uploads it through PyPI trusted publishing.
|
|
153
|
+
|
|
154
|
+
## License
|
|
155
|
+
|
|
156
|
+
MIT. "CUDA-Q" and "NVIDIA" are trademarks of NVIDIA Corporation; they are used here only to describe
|
|
157
|
+
API compatibility.
|
nudaq-0.1.0/README.md
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# nudaq
|
|
2
|
+
|
|
3
|
+
A small **numpy** state-vector simulator that copies a subset of the
|
|
4
|
+
[CUDA-Q](https://nvidia.github.io/cuda-quantum/) Python API. Use it to run and test CUDA-Q style code
|
|
5
|
+
where CUDA-Q cannot be installed: Intel Macs, Windows without WSL, lightweight CI runners, or a
|
|
6
|
+
course's test suite.
|
|
7
|
+
|
|
8
|
+
> nudaq is **not** CUDA-Q, and is not affiliated with or endorsed by NVIDIA. It reproduces only the API
|
|
9
|
+
> surface listed below, simulates at most a few dozen qubits (state vector in memory), and gives no
|
|
10
|
+
> performance or exact-behaviour guarantees. Before you rely on results, run your code once on the real
|
|
11
|
+
> CUDA-Q.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install nudaq
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The only dependency is numpy. Python ≥ 3.10.
|
|
20
|
+
|
|
21
|
+
## Three ways to use it
|
|
22
|
+
|
|
23
|
+
**1. Write against nudaq directly**
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
import nudaq as cudaq
|
|
27
|
+
|
|
28
|
+
@cudaq.kernel
|
|
29
|
+
def bell():
|
|
30
|
+
q = cudaq.qvector(2)
|
|
31
|
+
h(q[0])
|
|
32
|
+
x.ctrl(q[0], q[1])
|
|
33
|
+
mz(q)
|
|
34
|
+
|
|
35
|
+
print(cudaq.sample(bell, shots_count=1000)) # {'00': ~500, '11': ~500}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**2. Make `import cudaq` return nudaq in the current process** (a test `conftest.py`, the first cell of
|
|
39
|
+
a notebook):
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
import nudaq
|
|
43
|
+
nudaq.install() # refuses if a real cudaq is already imported
|
|
44
|
+
import cudaq # -> nudaq
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**3. Run unchanged code that does `import cudaq`** (scripts, Jupyter kernels, test subprocesses):
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
PYTHONPATH="$(python -m nudaq path)" python my_cudaq_script.py
|
|
51
|
+
PYTHONPATH="$(python -m nudaq path)" jupyter nbconvert --execute --to notebook my.ipynb
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`python -m nudaq path` (or the `nudaq path` command) prints a directory that holds a tiny `cudaq` package
|
|
55
|
+
forwarding to nudaq. `nudaq.alias_path()` returns the same directory from Python.
|
|
56
|
+
|
|
57
|
+
## Supported API (CUDA-Q 0.17 semantics)
|
|
58
|
+
|
|
59
|
+
**Kernels** (`@cudaq.kernel`):
|
|
60
|
+
- Allocation: `cudaq.qvector(n)`, `cudaq.qvector(amplitudes)` (normalised list, little-endian
|
|
61
|
+
order), `cudaq.qubit()`.
|
|
62
|
+
- Indexing: `q[i]`, slices `q[a:b]`, `q.size()`, `q.front()`, `q.back()`, `q.front(k)`, `q.back(k)`,
|
|
63
|
+
`for qb in q`.
|
|
64
|
+
- Gates: `h x y z s t sdg tdg rx ry rz r1 u3 swap`, and the controlled forms `cx cy cz ch crx cry crz cr1`.
|
|
65
|
+
One-qubit gates broadcast over a register (`h(q)`).
|
|
66
|
+
- `.ctrl(...)` with one or several controls, a register as control, and negated controls `~q[0]`.
|
|
67
|
+
`.adj(...)` for adjoints.
|
|
68
|
+
- Sub-kernels with `cudaq.qview` arguments; `cudaq.control(kernel, ctrl, ...)` and
|
|
69
|
+
`cudaq.adjoint(kernel, ...)`.
|
|
70
|
+
- Custom gates with `cudaq.register_operation(name, unitary)`.
|
|
71
|
+
- Measurement with `mz`, as the final operations of a kernel.
|
|
72
|
+
|
|
73
|
+
**Host functions:**
|
|
74
|
+
- `sample(kernel, *args, shots_count=...)` returns a dict-like result with `most_probable`,
|
|
75
|
+
`probability`, `count` and `get_total_shots`.
|
|
76
|
+
- `get_state(...)` returns a state usable as `np.array(state)`, with `amplitude`, `amplitudes` and
|
|
77
|
+
`overlap`.
|
|
78
|
+
- `observe(kernel, H, *args)` with `H` built from `cudaq.spin.x/y/z/i`.
|
|
79
|
+
- Also `draw` (plain text list of gates), `set_random_seed`, `get_target`, and `set_target` (accepted,
|
|
80
|
+
ignored).
|
|
81
|
+
|
|
82
|
+
**Conventions copied from CUDA-Q:**
|
|
83
|
+
- `sample` bitstrings and `state.amplitude("01")` labels put qubit 0 on the **left**.
|
|
84
|
+
- `np.array(state)` is **little-endian**: qubit 0 is the least significant bit of the index.
|
|
85
|
+
`cudaq.qvector(amplitudes)` takes the same order.
|
|
86
|
+
- `register_operation` matrices are in **MSB order**: the first target is the most significant.
|
|
87
|
+
- Gate matrices:
|
|
88
|
+
- `ry(θ)|0⟩ = cos(θ/2)|0⟩ + sin(θ/2)|1⟩`
|
|
89
|
+
- `rx(θ) = e^{-iθX/2}`
|
|
90
|
+
- `rz(θ) = diag(e^{-iθ/2}, e^{iθ/2})`
|
|
91
|
+
- `r1(λ) = diag(1, e^{iλ})`
|
|
92
|
+
|
|
93
|
+
**Kernel lint.** Kernels run eagerly as Python, so nudaq first checks each kernel body and rejects what
|
|
94
|
+
the CUDA-Q kernel compiler rejects:
|
|
95
|
+
- captured globals (pass values as arguments);
|
|
96
|
+
- missing or unsupported argument annotations;
|
|
97
|
+
- default arguments;
|
|
98
|
+
- list comprehensions, strings, nested functions, try/with;
|
|
99
|
+
- numpy calls other than scalar math (`sin cos tan arcsin arccos arctan sqrt exp log`, `pi`);
|
|
100
|
+
- module-level variables that shadow gate names;
|
|
101
|
+
- numpy arrays passed as kernel arguments (pass `arr.tolist()`).
|
|
102
|
+
|
|
103
|
+
Passing the lint makes it likely, not certain, that CUDA-Q compiles the kernel.
|
|
104
|
+
|
|
105
|
+
Allowed argument types: `int float bool complex list[int] list[float] list[bool] list[complex]
|
|
106
|
+
cudaq.qview cudaq.qvector cudaq.qubit`.
|
|
107
|
+
|
|
108
|
+
**Not supported:** `get_unitary`, `exp_pauli`, `reset`, mid-circuit measurement with classical
|
|
109
|
+
feed-forward, noise models, `cudaq.run`, `cudaq.vqe`/optimizers, the builder API (`make_kernel`), GPU
|
|
110
|
+
targets, multi-QPU execution. `cudaq.draw` prints a gate list, not CUDA-Q's ASCII circuit.
|
|
111
|
+
|
|
112
|
+
## Development
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
python -m venv .venv && source .venv/bin/activate
|
|
116
|
+
pip install -e ".[test]"
|
|
117
|
+
python -m pytest
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
The tests check nudaq against an independent Kronecker-product reference simulator, the CUDA-Q ordering
|
|
121
|
+
conventions, the lint rules, and the three ways of importing it.
|
|
122
|
+
|
|
123
|
+
## Release
|
|
124
|
+
|
|
125
|
+
1. Update `__version__` in `src/nudaq/__init__.py` and `CHANGELOG.md`.
|
|
126
|
+
2. `python -m build && python -m twine check dist/*`.
|
|
127
|
+
3. Publish: `python -m twine upload dist/*`, or publish a GitHub release. `.github/workflows/publish.yml`
|
|
128
|
+
then uploads it through PyPI trusted publishing.
|
|
129
|
+
|
|
130
|
+
## License
|
|
131
|
+
|
|
132
|
+
MIT. "CUDA-Q" and "NVIDIA" are trademarks of NVIDIA Corporation; they are used here only to describe
|
|
133
|
+
API compatibility.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "nudaq"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "A small numpy simulator that copies a subset of the CUDA-Q Python API, for running and testing CUDA-Q style code without CUDA-Q"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
authors = [{ name = "Yongseok Yoo", email = "yyoo@ssu.ac.kr" }]
|
|
14
|
+
dependencies = ["numpy>=1.22"]
|
|
15
|
+
keywords = ["quantum", "quantum computing", "cuda-q", "simulator", "testing", "education"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 3 - Alpha",
|
|
18
|
+
"Intended Audience :: Education",
|
|
19
|
+
"Intended Audience :: Science/Research",
|
|
20
|
+
"Operating System :: OS Independent",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
23
|
+
"Topic :: Scientific/Engineering :: Physics",
|
|
24
|
+
"Topic :: Software Development :: Testing",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[project.optional-dependencies]
|
|
28
|
+
test = ["pytest>=7"]
|
|
29
|
+
|
|
30
|
+
[project.urls]
|
|
31
|
+
Homepage = "https://github.com/ssuai/nudaq"
|
|
32
|
+
Issues = "https://github.com/ssuai/nudaq/issues"
|
|
33
|
+
|
|
34
|
+
[project.scripts]
|
|
35
|
+
nudaq = "nudaq.__main__:main"
|
|
36
|
+
|
|
37
|
+
[tool.hatch.version]
|
|
38
|
+
path = "src/nudaq/__init__.py"
|
|
39
|
+
|
|
40
|
+
[tool.hatch.build.targets.wheel]
|
|
41
|
+
packages = ["src/nudaq"]
|
|
42
|
+
|
|
43
|
+
[tool.hatch.build.targets.sdist]
|
|
44
|
+
include = ["src/nudaq", "tests", "README.md", "LICENSE", "CHANGELOG.md", "pyproject.toml"]
|
|
45
|
+
|
|
46
|
+
[tool.pytest.ini_options]
|
|
47
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""nudaq: a small numpy simulator that copies a subset of the CUDA-Q Python API.
|
|
2
|
+
|
|
3
|
+
Use it to run and test CUDA-Q style code where CUDA-Q cannot be installed
|
|
4
|
+
(for example Intel Macs or plain CI runners). nudaq is not CUDA-Q and is not
|
|
5
|
+
affiliated with NVIDIA.
|
|
6
|
+
|
|
7
|
+
Three ways to use it:
|
|
8
|
+
|
|
9
|
+
import nudaq as cudaq # in your own code
|
|
10
|
+
|
|
11
|
+
import nudaq; nudaq.install() # make a later `import cudaq` return nudaq (this process only)
|
|
12
|
+
|
|
13
|
+
PYTHONPATH="$(python -m nudaq path)" python script.py # unchanged code that does `import cudaq`
|
|
14
|
+
"""
|
|
15
|
+
import os
|
|
16
|
+
import sys
|
|
17
|
+
|
|
18
|
+
from ._core import ( # noqa: F401
|
|
19
|
+
ObserveResult,
|
|
20
|
+
SampleResult,
|
|
21
|
+
SpinOperator,
|
|
22
|
+
State,
|
|
23
|
+
adjoint,
|
|
24
|
+
control,
|
|
25
|
+
draw,
|
|
26
|
+
get_state,
|
|
27
|
+
get_target,
|
|
28
|
+
get_unitary,
|
|
29
|
+
kernel,
|
|
30
|
+
observe,
|
|
31
|
+
qubit,
|
|
32
|
+
qview,
|
|
33
|
+
qvector,
|
|
34
|
+
register_operation,
|
|
35
|
+
reset,
|
|
36
|
+
sample,
|
|
37
|
+
set_random_seed,
|
|
38
|
+
set_target,
|
|
39
|
+
spin,
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
__version__ = "0.1.0"
|
|
43
|
+
|
|
44
|
+
#: The CUDA-Q release whose Python API nudaq follows.
|
|
45
|
+
CUDAQ_API_VERSION = "0.17"
|
|
46
|
+
|
|
47
|
+
__all__ = [
|
|
48
|
+
"CUDAQ_API_VERSION", "ObserveResult", "SampleResult", "SpinOperator", "State", "adjoint", "alias_path",
|
|
49
|
+
"control", "draw", "get_state", "get_target", "get_unitary", "install", "kernel", "observe", "qubit",
|
|
50
|
+
"qview", "qvector", "register_operation", "reset", "sample", "set_random_seed", "set_target", "spin",
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def install():
|
|
55
|
+
"""Register nudaq as the module ``cudaq`` in this interpreter.
|
|
56
|
+
|
|
57
|
+
After ``nudaq.install()``, ``import cudaq`` returns nudaq. Raises RuntimeError if a different
|
|
58
|
+
``cudaq`` module (for example the real CUDA-Q) is already imported.
|
|
59
|
+
"""
|
|
60
|
+
mod = sys.modules[__name__]
|
|
61
|
+
old = sys.modules.get("cudaq")
|
|
62
|
+
if old is not None and old is not mod:
|
|
63
|
+
raise RuntimeError("nudaq.install(): another 'cudaq' module is already imported")
|
|
64
|
+
sys.modules["cudaq"] = mod
|
|
65
|
+
return mod
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def alias_path():
|
|
69
|
+
"""Directory holding a ``cudaq`` package that forwards to nudaq.
|
|
70
|
+
|
|
71
|
+
Put it first on PYTHONPATH (or sys.path) to run unchanged code that does ``import cudaq``,
|
|
72
|
+
for example a Jupyter kernel or a test suite run in a subprocess.
|
|
73
|
+
"""
|
|
74
|
+
return os.path.join(os.path.dirname(os.path.abspath(__file__)), "_alias")
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""Command line: ``python -m nudaq path`` prints the directory to put on PYTHONPATH so that
|
|
2
|
+
``import cudaq`` loads nudaq; ``python -m nudaq version`` prints the versions."""
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
import nudaq
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def main(argv=None):
|
|
9
|
+
argv = sys.argv[1:] if argv is None else argv
|
|
10
|
+
cmd = argv[0] if argv else "help"
|
|
11
|
+
if cmd == "path":
|
|
12
|
+
print(nudaq.alias_path())
|
|
13
|
+
elif cmd == "version":
|
|
14
|
+
print(f"nudaq {nudaq.__version__} (CUDA-Q API {nudaq.CUDAQ_API_VERSION})")
|
|
15
|
+
else:
|
|
16
|
+
print(__doc__.strip())
|
|
17
|
+
return 0 if cmd in ("help", "-h", "--help") else 2
|
|
18
|
+
return 0
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
if __name__ == "__main__":
|
|
22
|
+
sys.exit(main())
|