spatial-computing 0.6.0__py3-none-any.whl → 0.7.0__py3-none-any.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.
- spatial/__init__.py +1 -1
- spatial/q/backends/__init__.py +3 -3
- spatial/q/sim.py +24 -1
- {spatial_computing-0.6.0.dist-info → spatial_computing-0.7.0.dist-info}/METADATA +2 -2
- {spatial_computing-0.6.0.dist-info → spatial_computing-0.7.0.dist-info}/RECORD +9 -9
- {spatial_computing-0.6.0.dist-info → spatial_computing-0.7.0.dist-info}/WHEEL +0 -0
- {spatial_computing-0.6.0.dist-info → spatial_computing-0.7.0.dist-info}/entry_points.txt +0 -0
- {spatial_computing-0.6.0.dist-info → spatial_computing-0.7.0.dist-info}/licenses/LICENSE +0 -0
- {spatial_computing-0.6.0.dist-info → spatial_computing-0.7.0.dist-info}/top_level.txt +0 -0
spatial/__init__.py
CHANGED
spatial/q/backends/__init__.py
CHANGED
|
@@ -25,8 +25,8 @@ class StateVectorBackend(Backend):
|
|
|
25
25
|
"""Built-in NumPy simulator."""
|
|
26
26
|
name = "statevector"
|
|
27
27
|
|
|
28
|
-
def sample(self, c, shots, seed=None, noise: float = 0.0):
|
|
29
|
-
return sim.sample(c, shots, seed, noise=noise)
|
|
28
|
+
def sample(self, c, shots, seed=None, noise: float = 0.0, readout=None):
|
|
29
|
+
return sim.sample(c, shots, seed, noise=noise, readout=readout)
|
|
30
30
|
|
|
31
31
|
def expectation(self, c, pauli):
|
|
32
32
|
return sim.expectation(c, pauli)
|
|
@@ -147,9 +147,9 @@ class QpuBackend(Backend):
|
|
|
147
147
|
raise BackendUnavailable(f"IBM Quantum refused the account: {type(e).__name__}: {str(e)[:200]}")
|
|
148
148
|
|
|
149
149
|
def sample(self, c, shots, seed=None):
|
|
150
|
+
svc = self._service() # raises BackendUnavailable first if the package/token is missing
|
|
150
151
|
from qiskit import transpile
|
|
151
152
|
from qiskit_ibm_runtime import SamplerV2
|
|
152
|
-
svc = self._service()
|
|
153
153
|
try:
|
|
154
154
|
backend = svc.least_busy(operational=True, simulator=False, min_num_qubits=c.n_qubits)
|
|
155
155
|
except Exception as e:
|
spatial/q/sim.py
CHANGED
|
@@ -105,6 +105,19 @@ def is_static(c: Circuit) -> bool:
|
|
|
105
105
|
return all(o.name not in ("measure", "reset") and not o.cond for o in c.ops)
|
|
106
106
|
|
|
107
107
|
|
|
108
|
+
def apply_readout(v: np.ndarray, n: int, p01: float, p10: float) -> np.ndarray:
|
|
109
|
+
"""Readout (measurement) error on an outcome distribution `v` of length 2^n.
|
|
110
|
+
p01 = P(read 1 | qubit was 0), p10 = P(read 0 | qubit was 1), independent per qubit.
|
|
111
|
+
Superconducting devices typically have p10 > p01 (the excited state decays while being read)."""
|
|
112
|
+
if not (0 <= p01 <= 1 and 0 <= p10 <= 1):
|
|
113
|
+
raise ValueError("readout probabilities must be in [0, 1]")
|
|
114
|
+
M = np.array([[1 - p01, p10], [p01, 1 - p10]])
|
|
115
|
+
t = v.reshape((2,) * n)
|
|
116
|
+
for ax in range(n):
|
|
117
|
+
t = np.moveaxis(np.tensordot(M, t, axes=(1, ax)), 0, ax)
|
|
118
|
+
return t.reshape(-1)
|
|
119
|
+
|
|
120
|
+
|
|
108
121
|
_NOISE_PAULIS = ("x", "y", "z")
|
|
109
122
|
|
|
110
123
|
|
|
@@ -174,7 +187,7 @@ def branch_distribution(c: Circuit, max_branches: int = 4096) -> np.ndarray | No
|
|
|
174
187
|
|
|
175
188
|
|
|
176
189
|
def sample(c: Circuit, shots: int, seed: int | None = None, dynamic: str = "branch",
|
|
177
|
-
noise: float = 0.0) -> dict[str, int]:
|
|
190
|
+
noise: float = 0.0, readout: tuple[float, float] | None = None) -> dict[str, int]:
|
|
178
191
|
"""dynamic="branch": exact branch enumeration then one multinomial draw (fast);
|
|
179
192
|
dynamic="shots" : one full simulation per shot (reference implementation)."""
|
|
180
193
|
rng = np.random.default_rng(seed)
|
|
@@ -190,6 +203,8 @@ def sample(c: Circuit, shots: int, seed: int | None = None, dynamic: str = "bran
|
|
|
190
203
|
p = branch_distribution(c)
|
|
191
204
|
if p is not None:
|
|
192
205
|
p = p / p.sum()
|
|
206
|
+
if readout: # the readout channel acts on the outcome distribution
|
|
207
|
+
p = apply_readout(p, n, *readout)
|
|
193
208
|
draws = rng.multinomial(shots, p)
|
|
194
209
|
return {format(i, f"0{n}b"): int(k) for i, k in enumerate(draws) if k}
|
|
195
210
|
counts: dict[str, int] = {}
|
|
@@ -198,6 +213,14 @@ def sample(c: Circuit, shots: int, seed: int | None = None, dynamic: str = "bran
|
|
|
198
213
|
i = int(rng.choice(len(p), p=p / p.sum()))
|
|
199
214
|
key = format(i, f"0{n}b")
|
|
200
215
|
counts[key] = counts.get(key, 0) + 1
|
|
216
|
+
if readout: # trajectory path: flip bits of each recorded shot
|
|
217
|
+
flipped: dict[str, int] = {}
|
|
218
|
+
for key, k in counts.items():
|
|
219
|
+
for _ in range(k):
|
|
220
|
+
bits = "".join(("1" if rng.random() < readout[0] else "0") if b == "0" else
|
|
221
|
+
("0" if rng.random() < readout[1] else "1") for b in key)
|
|
222
|
+
flipped[bits] = flipped.get(bits, 0) + 1
|
|
223
|
+
counts = flipped
|
|
201
224
|
return counts
|
|
202
225
|
|
|
203
226
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: spatial-computing
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.0
|
|
4
4
|
Summary: Spatial Computing: open-source infrastructure efficiency toolkit. Measure, decide, prove (compute, tiered memory, runtime routing, hybrid quantum language)
|
|
5
5
|
Author: Spatial Computing contributors
|
|
6
6
|
License-Expression: Apache-2.0
|
|
@@ -37,7 +37,7 @@ Dynamic: license-file
|
|
|
37
37
|
|
|
38
38
|
Spatial Computing chooses where and how a workload should run from measurements, and claims a gain only when it is measured. It does not add RAM, cores or GPUs: it compares execution strategies on the hardware you have, trades one resource for another in numbers, and says plainly what it cannot do.
|
|
39
39
|
|
|
40
|
-
> **Status: v0.
|
|
40
|
+
> **Status: v0.7.0, early-stage open-source toolkit.** Everything here was built and measured on a single 2017 MacBook Pro (Intel i7-7660U, 2 cores, 16 GB). Nothing has been proven on a second machine, a data-center GPU or a real quantum computer. See [Limitations](docs/LIMITATIONS.md) and the [site](https://spatial-computing-ecru.vercel.app).
|
|
41
41
|
|
|
42
42
|
[Français](README.fr.md)
|
|
43
43
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
spatial/__init__.py,sha256=
|
|
1
|
+
spatial/__init__.py,sha256=jXXZSAhbQX0VXwHotl6_9oHXZFYg5i-HkqLzNTGVXGM,207
|
|
2
2
|
spatial/cli.py,sha256=qpQA41C9Va3SQ9AX7bPOBXGXrbWhgt05qUoLqDD-EFs,5288
|
|
3
3
|
spatial/ai/__init__.py,sha256=qrQZBRNCGwnMp_Rx7HNblvGfgmLApVrdIAPcYVmZdCg,926
|
|
4
4
|
spatial/ai/kvcache.py,sha256=7xrNI3zBKSoLA9ZjI1U2TZQ7GdXMZDzZq50qBrbWAWY,4054
|
|
@@ -36,8 +36,8 @@ spatial/q/lexer.py,sha256=duWOYLPwNZ4Je1gYza0dF6uro8WD-PXIFIUUr-PmGE4,1777
|
|
|
36
36
|
spatial/q/parser.py,sha256=Jp0qpiualGxmS6_cJ9rCrsCOSJ2DQow1L-KeFQVtUjA,11589
|
|
37
37
|
spatial/q/qir.py,sha256=2pweJv4Z1wu8pNwBfbU4BF4qeT-jLl7ki-ImIaWgQKA,5866
|
|
38
38
|
spatial/q/runtime.py,sha256=VspmpauZECTo60OeE_gp2-JKfq920BbsL8RTP4ouiJ4,12176
|
|
39
|
-
spatial/q/sim.py,sha256=
|
|
40
|
-
spatial/q/backends/__init__.py,sha256=
|
|
39
|
+
spatial/q/sim.py,sha256=9JO1alh55sh0kF_GBETbmUWyvCP5piXZCokrnM9Kb3Y,9443
|
|
40
|
+
spatial/q/backends/__init__.py,sha256=VbnulaOR-hRD58-rtKb0gz18DGEQfzEqs-BPlCOeUXY,6092
|
|
41
41
|
spatial/runtime/__init__.py,sha256=EaQrxHSP2fhYRDi5HCzzstPbt7qyrJMN_sxKLt9YeMw,195
|
|
42
42
|
spatial/runtime/envs.py,sha256=_k9pImrL25-vHHr6Bcn6Ab8wjPBec026MRpQK-0PeVA,3496
|
|
43
43
|
spatial/runtime/inspect.py,sha256=avluvbij6Kc0_1zo32LIm9ciKwRN35ggqR48oL6_Sqg,2387
|
|
@@ -50,9 +50,9 @@ spatial/scientific/jobs.py,sha256=KFNfzEwH-gipiq16i3pNUHbb6ov-0b_ge--egyktyC0,29
|
|
|
50
50
|
spatial/simulation/__init__.py,sha256=HqJB3WHViehwrHSoMf9TzLekGvrHs6e-I2p62TeVX5A,331
|
|
51
51
|
spatial/simulation/heat.py,sha256=g3ShRBNOwkb3UNIGMmsVxmsz1K0zISp4ftyM6BWtJFE,1594
|
|
52
52
|
spatial/simulation/nbody.py,sha256=WcvcrQ1f4c7wjDsLRyxUFMkMTT1HfJ-Es3kT0uf80Og,1094
|
|
53
|
-
spatial_computing-0.
|
|
54
|
-
spatial_computing-0.
|
|
55
|
-
spatial_computing-0.
|
|
56
|
-
spatial_computing-0.
|
|
57
|
-
spatial_computing-0.
|
|
58
|
-
spatial_computing-0.
|
|
53
|
+
spatial_computing-0.7.0.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
54
|
+
spatial_computing-0.7.0.dist-info/METADATA,sha256=_XjBUp3_J0YoS19BLKzlBYSqynYfpwj6zPwvaascgdU,5973
|
|
55
|
+
spatial_computing-0.7.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
56
|
+
spatial_computing-0.7.0.dist-info/entry_points.txt,sha256=UIFCHJL01u7PIPej7EUHRI7rWEY8uBhufZ-_ulXUPRk,79
|
|
57
|
+
spatial_computing-0.7.0.dist-info/top_level.txt,sha256=ZHke8hWgy4qIqEGq7omus3O-T7AhmPoc-cqr7JdGGxQ,8
|
|
58
|
+
spatial_computing-0.7.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|