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,39 +7,58 @@ import:
|
||||
cap: ext/quantum/_capability/index.mq.md
|
||||
---
|
||||
|
||||
State
|
||||
Pure states — compare, combine or partition a quantum state.
|
||||
|
||||
A pure quantum state on n qubits is a unit vector in a complex space of size
|
||||
two to the n. In this package each amplitude is a map with re and im fields.
|
||||
Qubit 0 is the rightmost bit in basis labels. Ideal simulation ignores teaching
|
||||
noise; sampled trajectories live under the simulate skill.
|
||||
Obtain a state with simulate.state. A state is a map with qubits, dim and a
|
||||
list of amplitudes, each carrying re and im. A raw amplitude list from
|
||||
simulate.simulate is not a state handle. fidelity and schmidt also accept a
|
||||
circuit and evolve its ideal state. kron requires two state handles for the
|
||||
state-vector branch; convert circuits with simulate.state first.
|
||||
|
||||
States often arrive as the result of simulate tools on a circuit. This module
|
||||
answers state-to-state questions: tensor products, fidelity, and Schmidt cuts.
|
||||
A self-contained tensor experiment
|
||||
|
||||
## For AI agents
|
||||
Two zero states make a two-qubit zero state. Its fidelity with itself is one.
|
||||
The first factor is the high-bit subsystem of the tensor product; the second
|
||||
factor occupies the low bits. For Schmidt, cut counts the low bits in A.
|
||||
|
||||
If you were given only this file, run state tools with marqdo call and --effects
|
||||
plugin. Example fidelity:
|
||||
```sh
|
||||
marqdo call ext/quantum/circuit/index.mq.md new qubits=1 --effects plugin --session handbook --toget qc --json
|
||||
marqdo call ext/quantum/simulate/index.mq.md state 'circuit=$qc' --effects plugin --session handbook --toget psi --json
|
||||
marqdo call ext/quantum/state/index.mq.md kron 'a=$psi' 'b=$psi' --effects plugin --session handbook --toget product --json
|
||||
marqdo call ext/quantum/state/index.mq.md fidelity 'a=$product' 'b=$product' --effects plugin --session handbook --json
|
||||
marqdo call ext/quantum/state/index.mq.md schmidt 'state=$product' cut=1 --effects plugin --session handbook --json
|
||||
```
|
||||
|
||||
Call example (plain text):
|
||||
marqdo call ext/quantum/state/index.mq.md fidelity a=$psi b=$phi --effects plugin --json
|
||||
fidelity is squared absolute overlap of equal-size pure states. schmidt returns
|
||||
coeffs, ua, ub, entropy, cut and qubits. Entropy uses natural logarithms (nats);
|
||||
a Bell pair has two coefficients near 1/√2 and entropy ln(2). Schmidt currently
|
||||
shares the density solver's six-qubit limit and requires 0 < cut < qubits.
|
||||
kron also accepts matrix factors and returns a matrix-bearing handle; this is
|
||||
an operator product, not an automatic conversion into a normalized pure state.
|
||||
|
||||
Tools: kron, fidelity, schmidt.
|
||||
Development route
|
||||
|
||||
Keep pure-state algebra here and mixed-state operations in
|
||||
[density](../density/index.mq.md). Mathematical implementations and independent
|
||||
numerical tests belong in plugins/quantum/src/linalg.rs, with exports in
|
||||
src/lib.rs. Add both language contracts and preserve tests/ext/quantum-linalg-smoke.mq.md.
|
||||
Use known orthogonal/product/entangled states as checks instead of comparing a
|
||||
new implementation only with itself. Draw a single wire through
|
||||
[viz.draw_bloch](../viz/index.mq.md) using its source circuit.
|
||||
|
||||
## kron
|
||||
|
||||
The Kronecker product of `a` and `b` builds a larger space from two smaller
|
||||
ones. For state vectors this writes product states; for matrices it enlarges
|
||||
operators.
|
||||
|
||||
| 参数 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| a | any | left factor state or matrix |
|
||||
| b | any | right factor state or matrix |
|
||||
|
||||
Pass handles the plugin already understands. Circuit and density objects may
|
||||
participate through their registered ABI shapes when the simulator accepts them.
|
||||
The Kronecker product of `a` and `b` builds a larger space from two smaller
|
||||
ones. For state vectors this writes product states; for matrices it enlarges
|
||||
operators.
|
||||
|
||||
Pass handles the plugin already understands. For a pure-state product, convert circuits with simulate.state first. Matrix
|
||||
factors take the operator branch; raw amplitude lists are not accepted as states.
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
@@ -50,16 +69,16 @@ participate through their registered ABI shapes when the simulator accepts them.
|
||||
|
||||
## fidelity
|
||||
|
||||
Pure-state fidelity between `a` and `b` is the squared absolute overlap. It is
|
||||
one when the states coincide and zero when they are orthogonal. You may pass a
|
||||
circuit handle; the plugin uses the ideal simulated state. Teaching noise is
|
||||
ignored.
|
||||
|
||||
| 参数 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| a | any | first pure state or circuit |
|
||||
| b | any | second pure state or circuit |
|
||||
|
||||
Pure-state fidelity between `a` and `b` is the squared absolute overlap. It is
|
||||
one when the states coincide and zero when they are orthogonal. You may pass a
|
||||
circuit handle; the plugin uses the ideal simulated state. Teaching noise is
|
||||
ignored.
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| result | number | fidelity in the unit interval |
|
||||
@@ -69,15 +88,15 @@ ignored.
|
||||
|
||||
## schmidt
|
||||
|
||||
Schmidt decomposition of `state` across a cut. Subsystem A owns the lowest
|
||||
`cut`=1 qubits by default. Qubit 0 is the rightmost bit. Singular values show
|
||||
entanglement across the bipartition.
|
||||
|
||||
| 参数 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| state | any | pure state or circuit |
|
||||
| cut | number | qubits in subsystem A low bits |
|
||||
|
||||
Schmidt decomposition of `state` across a cut. Subsystem A owns the lowest
|
||||
`cut`=1 qubits by default. Qubit 0 is the rightmost bit. Singular values show
|
||||
entanglement across the bipartition.
|
||||
|
||||
| 返回 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| result | any | singular values and factors |
|
||||
|
||||
Reference in new issue
Block a user