Make Quantum an executable handbook with verified experiments
This commit is contained in:
1 parent
bb06dad134
commit
cc5277d2b5
23 files changed
+2990
-696
No files matched your search
@@ -7,32 +7,57 @@ import:
|
||||
cap: ext/quantum/_capability/index.mq.md
|
||||
---
|
||||
|
||||
Simulate
|
||||
Simulation — choose the observable before choosing the execution path.
|
||||
|
||||
Simulation answers what a circuit does. Ideal paths (simulate, state,
|
||||
probabilities) ignore teaching noise. The run tool draws computational-basis
|
||||
shots and applies circuit noise when noise was attached. The simulator refuses
|
||||
circuits wider than the plugin limit instead of silently truncating.
|
||||
What are the amplitudes? Use simulate (noise: no); returns list of maps with re, im.
|
||||
|
||||
## For AI agents
|
||||
Need a state for tensor/fidelity work? Use state (noise: no); returns quantum_state with qubits, dim, amplitudes.
|
||||
|
||||
If you were given only this file, you need a circuit handle from
|
||||
ext/quantum/circuit/index.mq.md (usually via --toget). Then:
|
||||
What are the exact basis weights? Use probabilities (noise: no); returns basis label → probability.
|
||||
|
||||
Call example (plain text):
|
||||
marqdo call ext/quantum/simulate/index.mq.md probabilities circuit=$qc --effects plugin --session s --json
|
||||
What would repeated readout produce? Use run (noise: yes); returns qubits, shots, seed, counts, measure; noise when set.
|
||||
|
||||
Other tools: simulate, state, run, noise. Always --effects plugin.
|
||||
Attach one teaching noise channel Use noise (noise: later in run); returns new circuit.
|
||||
|
||||
Noise is bitflip, depolarizing or amplitude_damping, with probability in [0,1].
|
||||
It acts after each unitary on that operation's participating wires. Attaching
|
||||
noise replaces the previous channel; it does not append a gate or change the
|
||||
ideal state. This is a teaching trajectory model, not a hardware backend.
|
||||
Measurement marks select sampled wires without collapsing ideal amplitudes.
|
||||
|
||||
A complete noise experiment
|
||||
|
||||
First create a circuit through the [circuit module](../circuit/index.mq.md).
|
||||
The ideal state after X is one. Full bit-flip noise after X makes every sampled
|
||||
outcome zero; exact probabilities still describe one. Repeating run with the
|
||||
same circuit, seed and shots is deterministic for this simulator version.
|
||||
|
||||
```sh
|
||||
marqdo call ext/quantum/circuit/index.mq.md new qubits=1 --effects plugin --session handbook --toget qc --json
|
||||
marqdo call ext/quantum/circuit/index.mq.md x 'circuit=$qc' --effects plugin --session handbook --toget qc --json
|
||||
marqdo call ext/quantum/simulate/index.mq.md noise 'circuit=$qc' 'kind="bitflip"' p=1 --effects plugin --session handbook --toget noisy --json
|
||||
marqdo call ext/quantum/simulate/index.mq.md probabilities 'circuit=$noisy' --effects plugin --session handbook --json
|
||||
marqdo call ext/quantum/simulate/index.mq.md run 'circuit=$noisy' shots=32 seed=7 --effects plugin --session handbook --json
|
||||
```
|
||||
|
||||
Development route
|
||||
|
||||
Put new readouts here rather than duplicating circuit construction. Numerical
|
||||
evolution and seeded sampling live in plugins/quantum/src/sim.rs; exports live
|
||||
in src/lib.rs beside it. Preserve ideal/noisy separation in both language trees
|
||||
and validate tests/ext/quantum-noise-smoke.mq.md plus amplitude-damping golds.
|
||||
For entanglement go to [state](../state/index.mq.md); for mixed states use
|
||||
[density](../density/index.mq.md), which currently describes ideal evolution.
|
||||
|
||||
## simulate
|
||||
|
||||
Return ideal state-vector amplitudes for `circuit` as re/im entries. Noise
|
||||
channels attached to the circuit are ignored here.
|
||||
|
||||
| 参数 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| circuit | any | circuit to evolve |
|
||||
|
||||
Return ideal state-vector amplitudes for `circuit` as re/im entries. Noise
|
||||
channels attached to the circuit are ignored here.
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| result | any | amplitude list |
|
||||
@@ -42,13 +67,13 @@ channels attached to the circuit are ignored here.
|
||||
|
||||
## state
|
||||
|
||||
Same ideal amplitudes as simulate for `circuit`, packaged as the plugin state
|
||||
object. Prefer this when later fidelity or density tools expect a state handle.
|
||||
|
||||
| 参数 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| circuit | any | circuit to evolve |
|
||||
|
||||
Same ideal amplitudes as simulate for `circuit`, packaged as the plugin state
|
||||
object. Prefer this when later fidelity or density tools expect a state handle.
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| result | any | ideal state |
|
||||
@@ -58,13 +83,13 @@ object. Prefer this when later fidelity or density tools expect a state handle.
|
||||
|
||||
## probabilities
|
||||
|
||||
Map basis label to probability for the ideal state of `circuit`. Labels use
|
||||
qubit 0 as the rightmost bit. Noise is ignored.
|
||||
|
||||
| 参数 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| circuit | any | circuit to read |
|
||||
|
||||
Map basis label to probability for the ideal state of `circuit`. Labels use
|
||||
qubit 0 as the rightmost bit. Noise is ignored.
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| result | any | probability map |
|
||||
@@ -74,15 +99,15 @@ qubit 0 as the rightmost bit. Noise is ignored.
|
||||
|
||||
## run
|
||||
|
||||
Sample computational-basis outcomes from `circuit`. Defaults are `shots`=1024
|
||||
and `seed`=1 so replays are deterministic. Teaching noise is applied when set.
|
||||
|
||||
| 参数 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| circuit | any | circuit to sample |
|
||||
| shots | number | sample count |
|
||||
| seed | number | RNG seed |
|
||||
|
||||
Sample computational-basis outcomes from `circuit`. Defaults are `shots`=1024
|
||||
and `seed`=1 so replays are deterministic. Teaching noise is applied when set.
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| result | any | counts or shot result |
|
||||
@@ -92,16 +117,16 @@ and `seed`=1 so replays are deterministic. Teaching noise is applied when set.
|
||||
|
||||
## noise
|
||||
|
||||
Attach teaching noise of kind `kind` with strength `p` on `circuit`. Ideal
|
||||
simulate and probability tools ignore it. Keep p small unless demonstrating
|
||||
decoherence. Supported kinds include bitflip, depolarizing, and amplitude_damping.
|
||||
|
||||
| 参数 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| circuit | any | circuit to annotate |
|
||||
| kind | text | noise family name |
|
||||
| p | number | strength in the unit interval |
|
||||
|
||||
Attach teaching noise of kind `kind` with strength `p` on `circuit`. Ideal
|
||||
simulate and probability tools ignore it. Keep p small unless demonstrating
|
||||
decoherence. Supported kinds include bitflip, depolarizing, and amplitude_damping.
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| result | any | circuit with noise metadata |
|
||||
|
||||
Reference in new issue
Block a user