quantum-forge 2.7.1 → 3.0.0
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.
- package/QUANTUM_FORGE.md +203 -207
- package/README.md +54 -38
- package/dist/lib/quantum.d.ts +674 -61
- package/dist/lib/quantum.js +1054 -4
- package/dist/lib/quantum.js.map +1 -1
- package/dist/quantum-forge-qubit/quantum-forge-web-esm.wasm +0 -0
- package/dist/quantum-forge-web-esm.wasm +0 -0
- package/package.json +3 -2
- package/quantum-forge-sw.js +1 -1
- package/dist/quantum-forge-web-0.3.0.tgz +0 -0
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Real quantum mechanics for game developers. Superposition, entanglement, and interference powered by a compiled C++ quantum simulator running via WebAssembly.
|
|
4
4
|
|
|
5
|
-
This is the core package: WASM loader, quantum property
|
|
5
|
+
This is the core package: WASM loader, quantum property handles, and Vite plugin. For the full game framework (engine, rendering, input, audio, and more), install [`quantum-forge-engine`](https://www.npmjs.com/package/quantum-forge-engine) instead. It depends on this package, so one install gets both.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -26,46 +26,52 @@ export default defineConfig({
|
|
|
26
26
|
|
|
27
27
|
> **ESM note:** If using `vite.config.js` (not `.ts` or `.mjs`), add `"type": "module"` to your `package.json`.
|
|
28
28
|
|
|
29
|
-
### 2.
|
|
29
|
+
### 2. Declare a quantum property
|
|
30
30
|
|
|
31
31
|
```typescript
|
|
32
|
-
import { ensureLoaded,
|
|
32
|
+
import { ensureLoaded, quantum } from "quantum-forge/quantum";
|
|
33
33
|
|
|
34
|
-
await ensureLoaded(); // once, before
|
|
34
|
+
await ensureLoaded(); // once, before the first quantum() call
|
|
35
35
|
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const qubit = qpm.acquireProperty(); // |0⟩, from the pool
|
|
40
|
-
m.hadamard(qubit); // equal superposition
|
|
36
|
+
const color = quantum(["red", "green", "blue"]); // a qutrit, starts "red"
|
|
37
|
+
color.superpose(); // equal superposition (alias for hadamard())
|
|
41
38
|
|
|
42
39
|
// Read without collapsing
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
color.probability("green"); // 1/3
|
|
41
|
+
color.probabilities();
|
|
42
|
+
// [{ value: "red", probability: 1/3 }, { value: "green", ... }, { value: "blue", ... }]
|
|
45
43
|
|
|
46
|
-
// Measure (collapses to
|
|
47
|
-
const
|
|
44
|
+
// Measure (collapses to one value)
|
|
45
|
+
const seen = color.measure(); // "red", "green" or "blue"
|
|
48
46
|
|
|
49
|
-
//
|
|
50
|
-
|
|
47
|
+
// End its life. dispose() measures, then frees the qudit for the next quantum() call.
|
|
48
|
+
color.dispose();
|
|
51
49
|
```
|
|
52
50
|
|
|
53
|
-
|
|
51
|
+
A property is declared by the values it can take, and the dimension is how many there are.
|
|
52
|
+
`quantum(3)` is the numeric form, with values `0`, `1`, `2`. A property needs at least two
|
|
53
|
+
values. A `using` declaration disposes the handle at the end of the scope; it needs TypeScript
|
|
54
|
+
5.2 or newer with `"ESNext.Disposable"` in the tsconfig `lib`. Code that never writes `using`
|
|
55
|
+
needs neither.
|
|
54
56
|
|
|
55
57
|
### 3. Entanglement
|
|
56
58
|
|
|
59
|
+
Entanglement is what an interaction leaves behind. A gate that touches two properties is an
|
|
60
|
+
interaction:
|
|
61
|
+
|
|
57
62
|
```typescript
|
|
58
|
-
|
|
59
|
-
const b = qpm.acquireProperty();
|
|
63
|
+
import { quantum, measure } from "quantum-forge/quantum";
|
|
60
64
|
|
|
61
|
-
|
|
62
|
-
|
|
65
|
+
const a = quantum([false, true]).flip(); // a = true
|
|
66
|
+
const b = quantum([false, true]); // b = false
|
|
67
|
+
a.iSwap(b, 0.5); // half iSwap: exactly one of the pair ends up true
|
|
63
68
|
|
|
64
|
-
const [va, vb] =
|
|
65
|
-
// va
|
|
69
|
+
const [va, vb] = measure(a, b); // one step, both collapse
|
|
70
|
+
// va !== vb, every time
|
|
66
71
|
```
|
|
67
72
|
|
|
68
|
-
|
|
73
|
+
So is a gate whose predicate reads another property. `b.flip({ when: [a.is(true)] })` is a
|
|
74
|
+
CNOT: `b` flips only where `a` is `true`. `a.is(1)` builds the same predicate by index.
|
|
69
75
|
|
|
70
76
|
## Editions
|
|
71
77
|
|
|
@@ -103,26 +109,36 @@ Node 22 or newer.
|
|
|
103
109
|
|
|
104
110
|
| Export | Contents |
|
|
105
111
|
|--------|----------|
|
|
106
|
-
| `quantum-forge/quantum` | `
|
|
112
|
+
| `quantum-forge/quantum` | `quantum`, `Quantum`, `measure`, `forcedMeasure`, `probabilities`, `densityMatrix`, `measureWhen`, `forcedMeasureWhen`, `probabilityWhen`, `phaseRotate`, `isQuantum`, `observeQuantum`, `clearQuantumCache`, `QuantumRecorder`, `ensureLoaded`, `startBackgroundLoad`, `isReady`, `useQuantumForgeBuild`, `setWasmBasePath`, `getVersion`, `getMaxDimension`, `getMaxQudits`, `getMaxStateSize`, `getAttribution`, `registerServiceWorker`, `OP` |
|
|
107
113
|
| `quantum-forge/logging` | `Logger` |
|
|
108
114
|
| `quantum-forge/vite-plugin` | `quantumForgeVitePlugin` |
|
|
109
115
|
|
|
110
116
|
## Gates
|
|
111
117
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
| `
|
|
118
|
-
| `
|
|
119
|
-
| `
|
|
120
|
-
| `
|
|
121
|
-
| `
|
|
122
|
-
| `
|
|
123
|
-
| `
|
|
124
|
-
|
|
125
|
-
|
|
118
|
+
Gates are methods on the handle. Each alias runs exactly the same gate as the physics name
|
|
119
|
+
beside it.
|
|
120
|
+
|
|
121
|
+
| Gate | Alias | Qudits | Description |
|
|
122
|
+
|------|-------|--------|-------------|
|
|
123
|
+
| `hadamard` | `superpose` | 1 | Equal superposition |
|
|
124
|
+
| `inverseHadamard` | | 1 | Undoes `hadamard` |
|
|
125
|
+
| `cycle` | `next`, and `flip` on qubits | 1 | \|0⟩→\|1⟩→\|2⟩→\|0⟩ (a NOT at dimension 2) |
|
|
126
|
+
| `shift` | `previous` | 1 | Inverse of cycle; same as cycle at dimension 2 |
|
|
127
|
+
| `clock` | `phase` | 1 | Phase rotation |
|
|
128
|
+
| `x`, `z` | | 1 | Pauli X (same as `shift`) and Pauli Z (same as `clock`) |
|
|
129
|
+
| `y` | | 1 | Pauli Y, dimension 2 only |
|
|
130
|
+
| `iSwap(other, fraction)` | | 2 | Entangling swap; `fraction` is required |
|
|
131
|
+
| `swap(other)` | | 2 | Value swap |
|
|
132
|
+
| `phaseRotate(angle, { when })` | | any | Free function: phase on the part of the state where the predicates hold |
|
|
133
|
+
|
|
134
|
+
Every gate except `inverseHadamard`, `swap` and `iSwap` takes an optional fraction first. An
|
|
135
|
+
omitted fraction, or exactly 1, is the discrete gate; any other number is the continuous
|
|
136
|
+
version, and 0.5 is the square root of the gate. Predicates go last, in `{ when: [...] }`.
|
|
137
|
+
|
|
138
|
+
Measurement: `prop.measure()`, `measure(...props)`, `measureWhen(preds)`, and the forced
|
|
139
|
+
variants for replays and tests, which throw if the forced value has zero probability.
|
|
140
|
+
Read-only: `prop.probability(value)`, `prop.probabilities()`,
|
|
141
|
+
`probabilities(...props)`, `probabilityWhen(preds)`, `densityMatrix(...props)`.
|
|
126
142
|
|
|
127
143
|
## Documentation
|
|
128
144
|
|