Refactor executable library handbooks and improve document reading

This commit is contained in:
cflmy committed 2026-11-08 22:19:11 +08:00
1 parent 16c44588d5
commit c50c515c4a
191 files changed
+29572 -7816

No files matched your search

+9 -9
View File
@@ -30,6 +30,10 @@ and tests/call_cli.rs before returning to [circuit](../circuit/index.mq.md).
## load
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | null after a successful load |
Locate the ABI v2 quantum shared library through plugin.native_path, then
plugin.load it. If the library is missing, print a short install hint and exit
non-zero so CI and agents fail loudly. After a successful load, later quantum
@@ -39,14 +43,10 @@ start of each tool that needs the simulator.
This tool takes no parameters.
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | null after a successful load |
**p = > plugin.native_path name="quantum"**
We retain **`p` = [Locate the installed native plugin](plugin.native_path(name="quantum"))**.
1. `p`
> plugin.load path=`p`
We **[Load the native plugin required by this operation](plugin.load(path=`p`))**.
2. *
> print text=ext/quantum: native quantum plugin not found (build marqdo_plugin_quantum or marqdo ext add quantum)
> sys.exit code=1
****
We **[Print the prepared message](print(text="ext/quantum: native quantum plugin not found (build marqdo_plugin_quantum or marqdo ext add quantum)"))**.
We **[End this run with the selected exit status](sys.exit(code=1))**.
Return *None*.
File diff suppressed because it is too large. Load diff
+97 -83
View File
@@ -46,142 +46,156 @@ independent matrices in tests/ext/quantum-linalg-smoke.mq.md.
## from_state
| 参数 | 类型 | 说明 |
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| state | any | required | pure state or circuit |
| 返回 | 类型 | 说明 |
|------|------|------|
| state | any | pure state or circuit |
| result | any | density handle |
Use `state` as the inputs for this operation.
Form rho as the outer product of a pure `state` (or the ideal state of a
circuit). Use this when you trust the pure-state picture and want mixed-state
tools without writing a matrix by hand.
We **[Load the native plugin required by this operation](cap.load())**.
Return *[Form rho as the outer product of a pure state (or the ideal state of a circuit)](quantum_density_from_state(state=`state`))*.
## from_matrix
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| matrix | any | required | Hermitian matrix |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | density handle |
> cap.load
*> quantum_density_from_state state=`state`*
## from_matrix
| 参数 | 类型 | 说明 |
|------|------|------|
| matrix | any | Hermitian matrix |
Use `matrix` as the inputs for this operation.
Build rho from an explicit Hermitian `matrix`. Pair with formula blocks in the
lecture so the matrix on the page is the matrix in the simulator. Size is
limited by the plugin.
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | density handle |
> cap.load
*> quantum_density_from_matrix matrix=`matrix`*
We **[Load the native plugin required by this operation](cap.load())**.
Return *[Build rho from an explicit Hermitian matrix](quantum_density_from_matrix(matrix=`matrix`))*.
## purity
| 参数 | 类型 | 说明 |
|------|------|------|
| density | any | density operator |
Compute the trace of rho squared for `density`. Values near one mean nearly
pure; lower values mean classical mixing or traced-out entanglement.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| density | any | required | density operator |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | number | purity |
> cap.load
*> quantum_density_purity density=`density`*
Use `density` as the inputs for this operation.
Compute the trace of rho squared for `density`. Values near one mean nearly
pure; lower values mean classical mixing or traced-out entanglement.
We **[Load the native plugin required by this operation](cap.load())**.
Return *[Compute the trace of rho squared for density. Values near one mean nearly pure; lower values mean classical mixing or traced-out entanglement.](quantum_density_purity(density=`density`))*.
## partial_trace
| 参数 | 类型 | 说明 |
|------|------|------|
| density | any | joint density |
| keep | any | qubit index list to keep |
Keep listed qubits in `keep` and trace out the rest of `density`. Indices use
LSB equals zero. The result is generally mixed even when the joint state was
pure.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| keep | any | required | qubit index list to keep |
| density | any | required | joint density |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | reduced density |
> cap.load
*> quantum_density_partial_trace density=`density` keep=`keep`*
Use `keep`, `density` as the inputs for this operation.
Keep listed qubits in `keep` and trace out the rest of `density`. Indices use
LSB equals zero. The result is generally mixed even when the joint state was
pure.
We **[Load the native plugin required by this operation](cap.load())**.
Return *[Keep listed qubits in keep and trace out the rest of density](quantum_density_partial_trace(density=`density`, keep=`keep`))*.
## expect
| 参数 | 类型 | 说明 |
|------|------|------|
| density | any | density operator |
| obs | any | Pauli string or matrix |
Expectation of observable `obs` on `density`. Pauli strings use left equals
high bit. Pass a matrix when the observable is not a Pauli product.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| obs | any | required | Pauli string or matrix |
| density | any | required | density operator |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | number | expectation value |
> cap.load
*> quantum_density_expect density=`density` obs=`obs`*
Use `obs`, `density` as the inputs for this operation.
Expectation of observable `obs` on `density`. Pauli strings use left equals
high bit. Pass a matrix when the observable is not a Pauli product.
We **[Load the native plugin required by this operation](cap.load())**.
Return *[Expectation of observable obs on density. Pauli strings use left equals high bit. Pass a matrix when the observable is not a Pauli product.](quantum_density_expect(density=`density`, obs=`obs`))*.
## eig
| 参数 | 类型 | 说明 |
|------|------|------|
| density | any | Hermitian density |
Hermitian spectrum of `density` as eigenvalues and eigenvectors. Useful when a
lecture needs the eigenbasis of rho.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| density | any | required | Hermitian density |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | eigenvalues and eigenvectors |
> cap.load
*> quantum_density_eig density=`density`*
Use `density` as the inputs for this operation.
Hermitian spectrum of `density` as eigenvalues and eigenvectors. Useful when a
lecture needs the eigenbasis of rho.
We **[Load the native plugin required by this operation](cap.load())**.
Return *[Hermitian spectrum of density as eigenvalues and eigenvectors. Useful when a lecture needs the eigenbasis of rho.](quantum_density_eig(density=`density`))*.
## matrix
| 参数 | 类型 | 说明 |
|------|------|------|
| density | any | Density handle / 密度句柄 |
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| density | any | required | Density handle / 密度句柄 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | Nested complex entries with re and im |
Use `density` as the inputs for this operation.
Export the explicit nested complex matrix of `density`. Reading entries does not
change the density operator. Use the exported entries for an independent trace
check or further linear algebra; the caller remains responsible for physicality.
> cap.load
*> quantum_density_matrix density=`density`*
We **[Load the native plugin required by this operation](cap.load())**.
Return *[Export the explicit nested complex matrix of density](quantum_density_matrix(density=`density`))*.
# density
| 参数 | 类型 | 说明 |
|------|------|------|
| state | any | Default None |
| matrix | any | Default None |
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| state | any | None | Default None |
| matrix | any | None | Default None |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | Returned value |
Inputs: `state`=None, `matrix`=None (input).
Use `state`=None, `matrix`=None as the inputs for this operation.
Construct a density operator from a pure state or circuit (state=) or from an explicit Hermitian matrix=. Density operations support at most six qubits. Pure and mixed states share this object surface for purity, partial trace, and expectation.
> cap.load
We **[Load the native plugin required by this operation](cap.load())**.
1. `matrix`
*> quantum_density_from_matrix matrix=`matrix`*
Return *[Construct a density operator from a pure state or circuit (state=) or from an explicit Hermitian matrix=](quantum_density_from_matrix(matrix=`matrix`))*.
2. *
*> quantum_density_from_state state=`state`*
Return *[Construct a density operator from a pure state or circuit (state=) or from an explicit Hermitian matrix=](quantum_density_from_state(state=`state`))*.
## matrix
@@ -191,7 +205,7 @@ Construct a density operator from a pure state or circuit (state=) or from an ex
Return the explicit matrix of this density operator so authors can inspect entries or hand the array to further linear-algebra steps outside the quantum package.
*> quantum_density_matrix density=`self`*
Return *[Return the explicit matrix of this density operator so authors can inspect entries or hand the array to further linear-algebra steps outside the quantum package](quantum_density_matrix(density=`self`))*.
## purity
@@ -201,23 +215,23 @@ Return the explicit matrix of this density operator so authors can inspect entri
Compute Tr(ρ²). Values near one mean a pure state; mixed states are strictly less than one. Use this as a quick entanglement or decoherence check after a partial trace.
*> quantum_density_purity density=`self`*
Return *[Compute Tr(ρ²)](quantum_density_purity(density=`self`))*.
## partial_trace
| 参数 | 类型 | 说明 |
|------|------|------|
| keep | any | Required |
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| keep | any | required | Required |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | Density operator handle |
Inputs: `keep` (input).
Use `keep` as the inputs for this operation.
Trace out every qubit except those listed in keep (LSB index 0). Returns the reduced density on the kept subsystem for entanglement lectures and purity checks.
*> quantum_density_partial_trace density=`self` keep=`keep`*
Return *[Trace out every qubit except those listed in keep (LSB index 0). Returns the reduced density on the kept subsystem for entanglement lectures and purity checks.](quantum_density_partial_trace(density=`self`, keep=`keep`))*.
## eig
@@ -227,37 +241,37 @@ Trace out every qubit except those listed in keep (LSB index 0). Returns the red
Compute the Hermitian spectrum of this density operator as eigenvalues and eigenvectors. Handy for lecture plots and for verifying that a constructed rho is physical.
*> quantum_density_eig density=`self`*
Return *[Compute the Hermitian spectrum of this density operator as eigenvalues and eigenvectors](quantum_density_eig(density=`self`))*.
## expect
| 参数 | 类型 | 说明 |
|------|------|------|
| obs | any | Required |
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| obs | any | required | Required |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | number | Scalar observation |
Inputs: `obs` (input).
Use `obs` as the inputs for this operation.
Expectation value of observable obs on this density. obs may be a Pauli string with the left end as the high bit, or an explicit matrix matching the density dimension.
*> quantum_density_expect density=`self` obs=`obs`*
Return *[Expectation value of observable obs on this density](quantum_density_expect(density=`self`, obs=`obs`))*.
## draw
| 参数 | 类型 | 说明 |
|------|------|------|
| path | any | Default None |
| kind | any | Default hinton |
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | any | None | Default None |
| kind | any | "hinton" | Default hinton |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | quantum_svg with kind and svg |
Inputs: `path`=None, `kind`="hinton" (input).
Use `path`=None, `kind`="hinton" as the inputs for this operation.
Draw a Hinton diagram, city plot, density grid, or Pauli vector for this density. Optional path writes SVG; kind selects which visual metaphor the lecture uses.
*> quantum_density_draw density=`self` path=`path` kind=`kind`*
Return *[Draw a Hinton diagram, city plot, density grid, or Pauli vector for this density](quantum_density_draw(density=`self`, path=`path`, kind=`kind`))*.
+86 -77
View File
@@ -45,6 +45,10 @@ which binds the Hadamard formula directly into the author gate constructor.
## hadamard
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | Hadamard gate handle |
The Hadamard gate creates equal superposition from computational basis states.
Its matrix in the computational basis is one over square-root two times the
matrix with ones on the first row and one then minus one on the second row.
@@ -53,43 +57,43 @@ equal minus combination. This tool returns a named gate handle for later apply.
This tool takes no parameters.
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | Hadamard gate handle |
> cap.load
*> quantum_gate_new name="H" theta=None matrix=None*
We **[Load the native plugin required by this operation](cap.load())**.
Return *[The Hadamard gate creates equal superposition from computational basis states](quantum_gate_new(name="H", theta=None, matrix=None))*.
## pauli_x
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | Pauli X handle |
Pauli X is the bit-flip gate: a two-by-two matrix that swaps ket-zero and
ket-one. Use it when a lecture needs an explicit NOT on the computational basis.
This tool takes no parameters.
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | Pauli X handle |
> cap.load
*> quantum_gate_new name="X" theta=None matrix=None*
We **[Load the native plugin required by this operation](cap.load())**.
Return *[Pauli X is the bit-flip gate: a two-by-two matrix that swaps ket-zero and ket-one](quantum_gate_new(name="X", theta=None, matrix=None))*.
## pauli_z
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | Pauli Z handle |
Pauli Z applies a phase of minus one to ket-one while leaving ket-zero alone.
Its diagonal matrix is the standard computational-basis Z.
This tool takes no parameters.
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | Pauli Z handle |
> cap.load
*> quantum_gate_new name="Z" theta=None matrix=None*
We **[Load the native plugin required by this operation](cap.load())**.
Return *[Pauli Z applies a phase of minus one to ket-one while leaving ket-zero alone](quantum_gate_new(name="Z", theta=None, matrix=None))*.
## cnot
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | CNOT gate handle |
The controlled-NOT on two qubits flips the target when the control is ket-one.
Wire order and bit-endianness follow the package convention where qubit 0 is the
rightmost label bit. Prefer applying via circuit tools with explicit control and
@@ -97,103 +101,108 @@ target indices when building lectures step by step.
This tool takes no parameters.
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | CNOT gate handle |
> cap.load
*> quantum_gate_new name="CX" theta=None matrix=None*
We **[Load the native plugin required by this operation](cap.load())**.
Return *[The controlled-NOT on two qubits flips the target when the control is ket-one](quantum_gate_new(name="CX", theta=None, matrix=None))*.
## custom
| 参数 | 类型 | 说明 |
|------|------|------|
| matrix | any | unitary matrix formula or list |
| name | text | optional label defaulting to U |
Build a gate from an explicit unitary given as `matrix`. Authors usually bind a
formula matrix first, then pass that binding. Optional label `name`="U" marks
drawings when the caller omits a name.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| matrix | any | required | unitary matrix formula or list |
| name | text | "U" | optional label defaulting to U |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | custom gate handle |
> cap.load
*> quantum_gate_new name=`name` theta=None matrix=`matrix`*
Use `matrix`, `name`="U" as the inputs for this operation.
Build a gate from an explicit unitary given as `matrix`. Authors usually bind a
formula matrix first, then pass that binding. Optional label `name`="U" marks
drawings when the caller omits a name.
We **[Load the native plugin required by this operation](cap.load())**.
Return *[Build a gate from an explicit unitary given as matrix](quantum_gate_new(name=`name`, theta=None, matrix=`matrix`))*.
## matches
| 参数 | 类型 | 说明 |
|------|------|------|
| gate | any | gate handle to test |
| matrix | any | expected unitary |
| tol | number | absolute tolerance |
Teaching check: does `gate` match expected `matrix` within absolute tolerance
`tol`=0.000000001 ? Use after defining a formula so the lecture and the simulator
cannot drift apart.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| gate | any | required | gate handle to test |
| matrix | any | required | expected unitary |
| tol | number | 0.000000001 | absolute tolerance |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | bool | True when matrices match |
> cap.load
*> quantum_gate_matches_matrix gate=`gate` matrix=`matrix` tol=`tol`*
Use `gate`, `matrix`, `tol`=0.000000001 as the inputs for this operation.
Teaching check: does `gate` match expected `matrix` within absolute tolerance
`tol`=0.000000001 ? Use after defining a formula so the lecture and the simulator
cannot drift apart.
We **[Load the native plugin required by this operation](cap.load())**.
Return *[Teaching check: does gate match expected matrix within absolute tolerance cannot drift apart.](quantum_gate_matches_matrix(gate=`gate`, matrix=`matrix`, tol=`tol`))*.
## named
| 参数 | 类型 | 说明 |
|------|------|------|
| name | text | Built-in gate name |
| theta | any | Rotation angle or None |
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| name | text | "H" | Built-in gate name |
| theta | any | None | Rotation angle or None |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | Gate handle for circuit.apply |
Use `name`="H", `theta`=None as the inputs for this operation.
Construct built-in `name`="H" with optional `theta`=None . Rx, Ry and Rz require
a numeric angle in radians. The returned gate can be passed to circuit.apply;
creating it never changes a circuit. Supported names are listed above.
> cap.load
*> quantum_gate_new name=`name` theta=`theta` matrix=None*
We **[Load the native plugin required by this operation](cap.load())**.
Return *[Construct built-in name="H" with optional theta=None ](quantum_gate_new(name=`name`, theta=`theta`, matrix=None))*.
## matrix
| 参数 | 类型 | 说明 |
|------|------|------|
| gate | any | Gate handle |
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| gate | any | required | Gate handle |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | Nested complex entries with re and im |
Use `gate` as the inputs for this operation.
Export the explicit unitary of `gate`. Each complex entry has re and im fields.
Use this to compare a formula with independent expected entries. Reading a gate
matrix neither modifies its handle nor applies the operator to any circuit.
> cap.load
*> quantum_gate_matrix gate=`gate`*
We **[Load the native plugin required by this operation](cap.load())**.
Return *[Export the explicit unitary of gate](quantum_gate_matrix(gate=`gate`))*.
# gate
| 参数 | 类型 | 说明 |
|------|------|------|
| name | any | Default None |
| theta | number | Default None |
| matrix | any | Default None |
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| name | any | None | Default None |
| theta | number | None | Default None |
| matrix | any | None | Default None |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | Gate handle for circuit.apply |
Inputs: `name`=None, `theta`=None, `matrix`=None (input).
Use `name`=None, `theta`=None, `matrix`=None as the inputs for this operation.
Named built-in gate (name=H) or a custom unitary defined by matrix= (nested lists or a formula matrix fence). Custom gates may set name= (default U). Authors and call-style tools share this object surface.
> cap.load
*> quantum_gate_new name=`name` theta=`theta` matrix=`matrix`*
We **[Load the native plugin required by this operation](cap.load())**.
Return *[Named built-in gate (name=H) or a custom unitary defined by matrix= (nested lists or a formula matrix fence)](quantum_gate_new(name=`name`, theta=`theta`, matrix=`matrix`))*.
## matrix
@@ -203,38 +212,38 @@ Named built-in gate (name=H) or a custom unitary defined by matrix= (nested list
Return the explicit unitary matrix of this gate handle. Use it to inspect entries or to feed matches_matrix after constructing a gate from a formula.
*> quantum_gate_matrix gate=`self`*
Return *[Return the explicit unitary matrix of this gate handle. Use it to inspect entries or to feed matches_matrix after constructing a gate from a formula.](quantum_gate_matrix(gate=`self`))*.
## matches_matrix
| 参数 | 类型 | 说明 |
|------|------|------|
| matrix | any | Required |
| tol | any | Default 0.000000001 |
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| matrix | any | required | Required |
| tol | any | 0.000000001 | Default 0.000000001 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | bool | Match within absolute tolerance |
Inputs: `matrix`, `tol`=0.000000001 (input).
Use `matrix`, `tol`=0.000000001 as the inputs for this operation.
Check whether this gate matches the given matrix within absolute tolerance tol. Typical after building a custom gate from a Markdown formula fence in a lecture notebook.
*> quantum_gate_matches_matrix gate=`self` matrix=`matrix` tol=`tol`*
Return *[Check whether this gate matches the given matrix within absolute tolerance tol](quantum_gate_matches_matrix(gate=`self`, matrix=`matrix`, tol=`tol`))*.
## draw
| 参数 | 类型 | 说明 |
|------|------|------|
| path | any | Default None |
| kind | any | Default gate |
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| path | any | None | Default None |
| kind | any | "gate" | Default gate |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | quantum_svg with kind and svg |
Inputs: `path`=None, `kind`="gate" (input).
Use `path`=None, `kind`="gate" as the inputs for this operation.
Draw a gate symbol or a complex-matrix heatmap (kind=gate or matrix). Optional path writes SVG to disk; plots also enter view/CLI through record_plot for the session.
*> quantum_gate_draw gate=`self` path=`path` kind=`kind`*
Return *[Draw a gate symbol or a complex-matrix heatmap (kind=gate or matrix)](quantum_gate_draw(gate=`self`, path=`path`, kind=`kind`))*.
+15 -14
View File
@@ -219,12 +219,12 @@ control the other. The resulting amplitudes correlate 00 with 11.
Return the circuit so a caller can apply another gate, attach noise, draw it
or independently test entanglement. Every step keeps the returned new value.
**qc = circuit.new qubits=2 steps=None**
We retain **`qc` = [New](circuit.new(qubits=2, steps=None))**.
Make two equal paths on the low wire, then propagate the path label to the other wire.
**qc = circuit.hadamard circuit=`qc` qubit=0**
*> circuit.cnot circuit=`qc` control=0 target=1*
We retain **`qc` = [Hadamard](circuit.hadamard(circuit=`qc`, qubit=0))**.
Return *[Cnot](circuit.cnot(circuit=`qc`, control=0, target=1))*.
## bell_phi_plus
@@ -237,8 +237,8 @@ returns only ideal probabilities. Expect equal weights on 00 and 11 and zero
elsewhere. Computational-basis correlation alone does not prove entanglement;
use bell_analysis for reduced purity, ZZ expectation and Schmidt evidence.
**qc = > bell_circuit**
*> simulate.probabilities circuit=`qc`*
We retain **`qc` = [Bell circuit](bell_circuit())**.
Return *[Probabilities](simulate.probabilities(circuit=`qc`))*.
## bell_analysis
@@ -253,23 +253,24 @@ or persistent session for the intermediate observations. Expect joint purity
one, reduced purity one-half, ZZ one and Schmidt entropy ln(2), within 1e-9.
All paths here describe ideal evolution rather than noisy trajectory averages.
**qc = > bell_circuit**
**probs = simulate.probabilities circuit=`qc`**
We retain **`qc` = [Bell circuit](bell_circuit())**.
We retain **`probs` = [Probabilities](simulate.probabilities(circuit=`qc`))**.
Build the joint density and compute purity. A pure joint state need not
have pure subsystems. Keep only the low wire and test the mixedness that
appears when information about the other wire is discarded.
**rho = density.from_state state=`qc`**
**whole = density.purity density=`rho`**
We retain **`rho` = [From state](density.from_state(state=`qc`))**.
We retain **`whole` = [Purity](density.purity(density=`rho`))**.
`kept` =
| qubit |
|-------|
| 0 |
**reduced = density.partial_trace density=`rho` keep=`kept`**
**local = density.purity density=`reduced`**
We retain **`reduced` = [Partial trace](density.partial_trace(density=`rho`, keep=`kept`))**.
We retain **`local` = [Purity](density.purity(density=`reduced`))**.
ZZ measures correlation and is not an entanglement witness by itself.
The Schmidt decomposition supplies pure-state coefficients and entropy.
@@ -277,8 +278,8 @@ Together these observations distinguish a Bell pure state from a classical
mixture with identical basis probabilities. Keep the measured values in the
return table rather than hiding them behind a pass label with an implicit threshold.
**correlation = density.expect density=`rho` obs="ZZ"**
**split = state.schmidt state=`qc` cut=1**
We retain **`correlation` = [Expect](density.expect(density=`rho`, obs="ZZ"))**.
We retain **`split` = [Schmidt](state.schmidt(state=`qc`, cut=1))**.
`report` =
@@ -286,4 +287,4 @@ return table rather than hiding them behind a pass label with an implicit thresh
|---------------|--------|----------------|----|---------|
| `probs` | `whole` | `local` | `correlation` | `split` |
*report*
Return *report*.
+55 -45
View File
@@ -51,85 +51,95 @@ For entanglement go to [state](../state/index.mq.md); for mixed states use
## simulate
| 参数 | 类型 | 说明 |
|------|------|------|
| 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.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| circuit | any | required | circuit to evolve |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | amplitude list |
> cap.load
*> quantum_simulate circuit=`circuit`*
Use `circuit` as the inputs for this operation.
Return ideal state-vector amplitudes for `circuit` as re/im entries. Noise
channels attached to the circuit are ignored here.
We **[Load the native plugin required by this operation](cap.load())**.
Return *[Return ideal state-vector amplitudes for circuit as re/im entries. Noise channels attached to the circuit are ignored here.](quantum_simulate(circuit=`circuit`))*.
## state
| 参数 | 类型 | 说明 |
|------|------|------|
| 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.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| circuit | any | required | circuit to evolve |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | ideal state |
> cap.load
*> quantum_state circuit=`circuit`*
Use `circuit` as the inputs for this operation.
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.
We **[Load the native plugin required by this operation](cap.load())**.
Return *[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.](quantum_state(circuit=`circuit`))*.
## probabilities
| 参数 | 类型 | 说明 |
|------|------|------|
| 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.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| circuit | any | required | circuit to read |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | probability map |
> cap.load
*> quantum_probabilities circuit=`circuit`*
Use `circuit` as the inputs for this operation.
Map basis label to probability for the ideal state of `circuit`. Labels use
qubit 0 as the rightmost bit. Noise is ignored.
We **[Load the native plugin required by this operation](cap.load())**.
Return *[Map basis label to probability for the ideal state of circuit. Labels use qubit 0 as the rightmost bit. Noise is ignored.](quantum_probabilities(circuit=`circuit`))*.
## run
| 参数 | 类型 | 说明 |
|------|------|------|
| 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.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| circuit | any | required | circuit to sample |
| shots | number | 1024 | sample count |
| seed | number | 1 | RNG seed |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | counts or shot result |
> cap.load
*> quantum_run circuit=`circuit` shots=`shots` seed=`seed`*
Use `circuit`, `shots`=1024, `seed`=1 as the inputs for this operation.
Sample computational-basis outcomes from `circuit`. Defaults are `shots`=1024
and `seed`=1 so replays are deterministic. Teaching noise is applied when set.
We **[Load the native plugin required by this operation](cap.load())**.
Return *[Sample computational-basis outcomes from circuit. Defaults are shots=1024 and seed=1 so replays are deterministic. Teaching noise is applied when set.](quantum_run(circuit=`circuit`, shots=`shots`, seed=`seed`))*.
## noise
| 参数 | 类型 | 说明 |
|------|------|------|
| 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.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| kind | text | required | noise family name |
| p | number | required | strength in the unit interval |
| circuit | any | required | circuit to annotate |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | circuit with noise metadata |
> cap.load
*> quantum_noise circuit=`circuit` kind=`kind` p=`p`*
Use `kind`, `p`, `circuit` as the inputs for this operation.
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.
We **[Load the native plugin required by this operation](cap.load())**.
Return *[Attach teaching noise of kind kind with strength p on circuit](quantum_noise(circuit=`circuit`, kind=`kind`, p=`p`))*.
+35 -28
View File
@@ -48,10 +48,16 @@ new implementation only with itself. Draw a single wire through
## kron
| 参数 | 类型 | 说明 |
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| a | any | required | left factor state or matrix |
| b | any | required | right factor state or matrix |
| 返回 | 类型 | 说明 |
|------|------|------|
| a | any | left factor state or matrix |
| b | any | right factor state or matrix |
| result | any | tensor product |
Use `a`, `b` as the inputs for this operation.
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
@@ -60,46 +66,47 @@ 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.
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | tensor product |
> cap.load
*> quantum_kron a=`a` b=`b`*
We **[Load the native plugin required by this operation](cap.load())**.
Return *[The Kronecker product of a and b builds a larger space from two smaller ones](quantum_kron(a=`a`, b=`b`))*.
## fidelity
| 参数 | 类型 | 说明 |
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| a | any | required | first pure state or circuit |
| b | any | required | second pure state or circuit |
| 返回 | 类型 | 说明 |
|------|------|------|
| a | any | first pure state or circuit |
| b | any | second pure state or circuit |
| result | number | fidelity in the unit interval |
Use `a`, `b` as the inputs for this operation.
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 |
> cap.load
*> quantum_fidelity a=`a` b=`b`*
We **[Load the native plugin required by this operation](cap.load())**.
Return *[Pure-state fidelity between a and b is the squared absolute overlap](quantum_fidelity(a=`a`, b=`b`))*.
## schmidt
| 参数 | 类型 | 说明 |
|------|------|------|
| 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.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| state | any | required | pure state or circuit |
| cut | number | 1 | qubits in subsystem A low bits |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | singular values and factors |
> cap.load
*> quantum_schmidt state=`state` cut=`cut`*
Use `state`, `cut`=1 as the inputs for this operation.
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.
We **[Load the native plugin required by this operation](cap.load())**.
Return *[Schmidt decomposition of state across a cut. Subsystem A owns the lowest entanglement across the bipartition.](quantum_schmidt(state=`state`, cut=`cut`))*.
+75 -62
View File
@@ -62,107 +62,124 @@ For input preparation follow [circuit](../circuit/index.mq.md),
## draw_circuit
| 参数 | 类型 | 说明 |
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| circuit | any | required | circuit to render |
| theme | text | "dark" | dark light or bw |
| path | any | None | optional output path or None |
| 返回 | 类型 | 说明 |
|------|------|------|
| circuit | any | circuit to render |
| path | any | optional output path or None |
| theme | text | dark light or bw |
| result | any | drawing result |
Use `circuit`, `theme`="dark", `path`=None as the inputs for this operation.
Render `circuit` as gate rails and barriers. Choose `theme`="dark" by default;
light and bw preserve the same geometry. Optional `path`=None returns SVG
without a file. A nonempty path is available to author programs under run.
We **[Load the native plugin required by this operation](cap.load())**.
Return *[Render circuit as gate rails and barriers](quantum_draw_circuit(circuit=`circuit`, path=`path`, kind="circuit", qubit=0, theme=`theme`))*.
## draw_probs
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| circuit | any | required | circuit to render |
| theme | text | "dark" | dark light or bw |
| path | any | None | optional output path or None |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | drawing result |
> cap.load
*> quantum_draw_circuit circuit=`circuit` path=`path` kind="circuit" qubit=0 theme=`theme`*
## draw_probs
| 参数 | 类型 | 说明 |
|------|------|------|
| circuit | any | circuit to render |
| path | any | optional output path or None |
| theme | text | dark light or bw |
Use `circuit`, `theme`="dark", `path`=None as the inputs for this operation.
Plot ideal basis probabilities of `circuit`. Default `theme`="dark" supports
light and bw alternatives. Optional `path`=None returns SVG without a file.
The bars ignore teaching noise, just like simulate.probabilities.
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | drawing result |
> cap.load
*> quantum_draw_circuit circuit=`circuit` path=`path` kind="probs" qubit=0 theme=`theme`*
We **[Load the native plugin required by this operation](cap.load())**.
Return *[Plot ideal basis probabilities of circuit](quantum_draw_circuit(circuit=`circuit`, path=`path`, kind="probs", qubit=0, theme=`theme`))*.
## draw_bloch
| 参数 | 类型 | 说明 |
|------|------|------|
| circuit | any | circuit source |
| path | any | optional output path or None |
| qubit | number | which wire |
| theme | text | dark light or bw |
Show the reduced Bloch sphere of wire `qubit`=0 from `circuit`. Default
`theme`="dark"; optional `path`=None returns SVG without a file. A multi-qubit
circuit still produces one reduced wire picture, not a joint-state sphere.
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| qubit | number | 0 | which wire |
| circuit | any | required | circuit source |
| theme | text | "dark" | dark light or bw |
| path | any | None | optional output path or None |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | drawing result |
> cap.load
*> quantum_draw_circuit circuit=`circuit` path=`path` kind="bloch" qubit=`qubit` theme=`theme`*
Use `qubit`=0, `circuit`, `theme`="dark", `path`=None as the inputs for this operation.
Show the reduced Bloch sphere of wire `qubit`=0 from `circuit`. Default
`theme`="dark"; optional `path`=None returns SVG without a file. A multi-qubit
circuit still produces one reduced wire picture, not a joint-state sphere.
We **[Load the native plugin required by this operation](cap.load())**.
Return *[Show the reduced Bloch sphere of wire qubit=0 from circuit. Default circuit still produces one reduced wire picture, not a joint-state sphere.](quantum_draw_circuit(circuit=`circuit`, path=`path`, kind="bloch", qubit=`qubit`, theme=`theme`))*.
## draw_density
| 参数 | 类型 | 说明 |
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| density | any | required | density operator |
| kind | text | "hinton" | hinton city density or paulivec |
| path | any | None | optional output path or None |
| 返回 | 类型 | 说明 |
|------|------|------|
| density | any | density operator |
| path | any | optional output path or None |
| kind | text | hinton city density or paulivec |
| result | any | drawing result |
Use `density`, `kind`="hinton", `path`=None as the inputs for this operation.
Plot `density` using `kind`="hinton" by default. Alternatives are city,
density and paulivec. Optional `path`=None returns SVG without a file.
Use the density module to construct the mixed-state input before drawing.
We **[Load the native plugin required by this operation](cap.load())**.
Return *[Plot density using kind="hinton" by default](quantum_density_draw(density=`density`, path=`path`, kind=`kind`))*.
## draw_gate
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| gate | any | required | gate handle |
| kind | text | "gate" | gate or matrix |
| path | any | None | optional output path or None |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | drawing result |
> cap.load
*> quantum_density_draw density=`density` path=`path` kind=`kind`*
## draw_gate
| 参数 | 类型 | 说明 |
|------|------|------|
| gate | any | gate handle |
| path | any | optional output path or None |
| kind | text | gate or matrix |
Use `gate`, `kind`="gate", `path`=None as the inputs for this operation.
Plot `gate` using `kind`="gate" by default. Choose matrix for a complex-entry
heatmap. Optional `path`=None returns SVG without a file. This observes the
operator rather than applying it or changing any circuit.
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | drawing result |
> cap.load
*> quantum_gate_draw gate=`gate` path=`path` kind=`kind`*
We **[Load the native plugin required by this operation](cap.load())**.
Return *[Plot gate using kind="gate" by default](quantum_gate_draw(gate=`gate`, path=`path`, kind=`kind`))*.
## draw_state
| 参数 | 类型 | 说明 |
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| circuit | any | required | Circuit evolved ideally |
| kind | text | "qsphere" | qsphere or multibloch |
| path | any | None | SVG output path or None |
| 返回 | 类型 | 说明 |
|------|------|------|
| circuit | any | Circuit evolved ideally |
| kind | text | qsphere or multibloch |
| path | any | SVG output path or None |
| result | any | quantum_svg with kind and svg |
Use `circuit`, `kind`="qsphere", `path`=None as the inputs for this operation.
Observe the ideal state of `circuit` as a basis-amplitude/phase sphere or one
reduced Bloch sphere per wire. Default `kind`="qsphere"; use multibloch for the
@@ -171,9 +188,5 @@ local Bloch vectors alone cannot certify joint entanglement. Both advanced
figures currently use fixed styling; theme support remains Q8c work and is
not offered as a nonfunctional parameter here.
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | quantum_svg with kind and svg |
> cap.load
*> quantum_draw_circuit circuit=`circuit` path=`path` kind=`kind` qubit=0 theme="dark"*
We **[Load the native plugin required by this operation](cap.load())**.
Return *[Observe the ideal state of circuit as a basis-amplitude/phase sphere or one reduced Bloch sphere per wire](quantum_draw_circuit(circuit=`circuit`, path=`path`, kind=`kind`, qubit=0, theme="dark"))*.
+73 -61
View File
@@ -55,116 +55,128 @@ record_plot 桥接。新增图类时同步本页和英文入口,别把文件
## 画电路
| 参数 | 类型 | 说明 |
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 电路 | any | 必填 | 调用方提供的电路 |
| 主题 | text | "dark" | dark light 或 bw |
| 路径 | any | None | 可选输出路径或 None |
| 返回 | 类型 | 说明 |
|------|------|------|
| 电路 | any | 电路 |
| 路径 | any | 可选输出路径或 None |
| 主题 | text | dark light 或 bw |
| result | any | 绘图结果 |
这里使用`电路`、`主题`="dark"、`路径`=None。
把 `电路` 的门和屏障画成轨线。默认 `主题`="dark",也可选择 light 或 bw。
可选 `路径`=None 只返回 SVG,不写文件;非空路径供 run 下的作者程序使用。
主题选择只改变配色,不改变线路几何与计算含义。
这里**[调用 加载](能力.加载())**。
完成后返回*[把 电路 的门和屏障画成轨线。默认 主题="dark",也可选择 light 或 bw。 可选 路径=None 只返回 SVG,不写文件;非空路径供 run 下的作者程序使用。 主题选择只改变配色,不改变线路几何与计算含义。](quantum_draw_circuit(circuit=`电路`, path=`路径`, kind="circuit", qubit=0, theme=`主题`))*。
## 画概率
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 电路 | any | 必填 | 调用方提供的电路 |
| 主题 | text | "dark" | dark light 或 bw |
| 路径 | any | None | 可选路径或 None |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 绘图结果 |
> 能力.加载
*> quantum_draw_circuit circuit=`电路` path=`路径` kind="circuit" qubit=0 theme=`主题`*
## 画概率
| 参数 | 类型 | 说明 |
|------|------|------|
| 电路 | any | 电路 |
| 路径 | any | 可选路径或 None |
| 主题 | text | dark light 或 bw |
这里使用`电路`、`主题`="dark"、`路径`=None。
绘制 `电路` 的理想基矢概率条。默认 `主题`="dark",可改为 light 或 bw。
可选 `路径`=None 只返回 SVG,不写文件。图中权重与模拟模块的理想概率一致,
忽略已附加的教学噪声,不能用它替代含噪采样结果。
这里**[调用 加载](能力.加载())**。
完成后返回*[绘制 电路 的理想基矢概率条。默认 主题="dark",可改为 light 或 bw。 可选 路径=None 只返回 SVG,不写文件。图中权重与模拟模块的理想概率一致, 忽略已附加的教学噪声,不能用它替代含噪采样结果。](quantum_draw_circuit(circuit=`电路`, path=`路径`, kind="probs", qubit=0, theme=`主题`))*。
## 画布洛赫
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 电路 | any | 必填 | 调用方提供的电路 |
| 比特 | number | 0 | 哪一根线 |
| 主题 | text | "dark" | dark light 或 bw |
| 路径 | any | None | 可选路径或 None |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 绘图结果 |
> 能力.加载
*> quantum_draw_circuit circuit=`电路` path=`路径` kind="probs" qubit=0 theme=`主题`*
## 画布洛赫
| 参数 | 类型 | 说明 |
|------|------|------|
| 电路 | any | 电路 |
| 路径 | any | 可选路径或 None |
| 比特 | number | 哪一根线 |
| 主题 | text | dark light 或 bw |
这里使用`电路`、`比特`=0、`主题`="dark"、`路径`=None。
绘制 `电路` 上 `比特`=0 的约化布洛赫球。默认 `主题`="dark"。
可选 `路径`=None 只返回 SVG,不写文件。多比特线路也只显示所选一条线的约化态,
不能把这张图解释为整个多比特纯态的完整表示。
这里**[调用 加载](能力.加载())**。
完成后返回*[绘制 电路 上 比特=0 的约化布洛赫球。默认 主题="dark"。 可选 路径=None 只返回 SVG,不写文件。多比特线路也只显示所选一条线的约化态, 不能把这张图解释为整个多比特纯态的完整表示。](quantum_draw_circuit(circuit=`电路`, path=`路径`, kind="bloch", qubit=`比特`, theme=`主题`))*。
## 画密度
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 密度 | any | 必填 | 密度算符 |
| 种类 | text | "hinton" | hinton city density 或 paulivec |
| 路径 | any | None | 可选路径或 None |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 绘图结果 |
> 能力.加载
*> quantum_draw_circuit circuit=`电路` path=`路径` kind="bloch" qubit=`比特` theme=`主题`*
## 画密度
| 参数 | 类型 | 说明 |
|------|------|------|
| 密度 | any | 密度算符 |
| 路径 | any | 可选路径或 None |
| 种类 | text | hinton city density 或 paulivec |
这里使用`密度`、`种类`="hinton"、`路径`=None。
绘制 `密度`,默认 `种类`="hinton",也可选 city、density 或 paulivec。
可选 `路径`=None 只返回 SVG,不写文件。先在密度模块构造或约化输入,
再按需要选择图类,本操作不改变密度矩阵或补做物理性认证。
这里**[调用 加载](能力.加载())**。
完成后返回*[绘制 密度,默认 种类="hinton",也可选 city、density 或 paulivec。 可选 路径=None 只返回 SVG,不写文件。先在密度模块构造或约化输入, 再按需要选择图类,本操作不改变密度矩阵或补做物理性认证。](quantum_density_draw(density=`密度`, path=`路径`, kind=`种类`))*。
## 画门
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 门 | any | 必填 | 门句柄 |
| 种类 | text | "gate" | gate 或 matrix |
| 路径 | any | None | 可选路径或 None |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 绘图结果 |
> 能力.加载
*> quantum_density_draw density=`密度` path=`路径` kind=`种类`*
## 画门
| 参数 | 类型 | 说明 |
|------|------|------|
| 门 | any | 门句柄 |
| 路径 | any | 可选路径或 None |
| 种类 | text | gate 或 matrix |
这里使用`门`、`种类`="gate"、`路径`=None。
绘制 `门`,默认 `种类`="gate",选择 matrix 可观察复数矩阵热图。
可选 `路径`=None 只返回 SVG,不写文件。图形用于观察算符,
不会把门作用到任何电路,也不会改变算符的数值条目。
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 绘图结果 |
> 能力.加载
*> quantum_gate_draw gate=`门` path=`路径` kind=`种类`*
这里**[调用 加载](能力.加载())**。
完成后返回*[绘制 门,默认 种类="gate",选择 matrix 可观察复数矩阵热图。 可选 路径=None 只返回 SVG,不写文件。图形用于观察算符, 不会把门作用到任何电路,也不会改变算符的数值条目。](quantum_gate_draw(gate=`门`, path=`路径`, kind=`种类`))*。
## 画态
| 参数 | 类型 | 说明 |
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 电路 | any | 必填 | 源电路,作理想演化 |
| 种类 | text | "qsphere" | qsphere 或 multibloch |
| 路径 | any | None | SVG 输出路径或 None |
| 返回 | 类型 | 说明 |
|------|------|------|
| 电路 | any | 源电路,作理想演化 |
| 种类 | text | qsphere 或 multibloch |
| 路径 | any | SVG 输出路径或 None |
| result | any | quantum_svg,含 kind 和 svg |
这里使用`电路`、`种类`="qsphere"、`路径`=None。
从 `电路` 观察整体纯态的振幅/相位球,或每条线的约化布洛赫球。
默认 `种类`="qsphere",可改为 multibloch;默认 `路径`=None,不显式落盘。
qsphere 展示基矢振幅与相位,multibloch 展示各线约化态,不能由单线球图独自证明纠缠。
这两类高级态图当前使用固定配色,主题换肤仍属 Q8c 规划,不暴露无效主题参数。
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | quantum_svg,含 kind 和 svg |
> 能力.加载
*> quantum_draw_circuit circuit=`电路` path=`路径` kind=`种类` qubit=0 theme="dark"*
这里**[调用 加载](能力.加载())**。
完成后返回*[从 电路 观察整体纯态的振幅/相位球,或每条线的约化布洛赫球。 默认 种类="qsphere",可改为 multibloch;默认 路径=None,不显式落盘。 qsphere 展示基矢振幅与相位,multibloch 展示各线约化态,不能由单线球图独自证明纠缠。 这两类高级态图当前使用固定配色,主题换肤仍属 Q8c 规划,不暴露无效主题参数。](quantum_draw_circuit(circuit=`电路`, path=`路径`, kind=`种类`, qubit=0, theme="dark"))*。
+95 -77
View File
@@ -37,132 +37,150 @@ marqdo call ext/quantum/量子/密度/索引.mq.md 本征 '密度=$rho' --effect
## 从态
| 参数 | 类型 | 说明 |
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 态 | any | 必填 | 纯态或电路 |
| 返回 | 类型 | 说明 |
|------|------|------|
| 态 | any | 纯态或电路 |
| result | any | 密度句柄 |
这里使用`态`。
由纯态或电路句柄 `态` 的理想态构造 rho。
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 密度句柄 |
> 能力.加载
*> quantum_density_from_state state=`态`*
这里**[调用 加载](能力.加载())**。
完成后返回*[由纯态或电路句柄 态 的理想态构造 rho。](quantum_density_from_state(state=`态`))*。
## 从矩阵
| 参数 | 类型 | 说明 |
|------|------|------|
| 矩阵 | any | 厄米矩阵 |
由显式厄米 `矩阵` 构造 rho。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 矩阵 | any | 必填 | 厄米矩阵 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 密度句柄 |
> 能力.加载
*> quantum_density_from_matrix matrix=`矩阵`*
这里使用`矩阵`。
由显式厄米 `矩阵` 构造 rho。
这里**[调用 加载](能力.加载())**。
完成后返回*[由显式厄米 矩阵 构造 rho。](quantum_density_from_matrix(matrix=`矩阵`))*。
## 纯度
| 参数 | 类型 | 说明 |
|------|------|------|
| 密度 | any | 密度算符 |
计算 `密度` 的 Tr(rho^2)。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 密度 | any | 必填 | 密度算符 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | number | 纯度 |
> 能力.加载
*> quantum_density_purity density=`密度`*
这里使用`密度`。
计算 `密度` 的 Tr(rho^2)。
这里**[调用 加载](能力.加载())**。
完成后返回*[计算 密度 的 Tr(rho^2)。](quantum_density_purity(density=`密度`))*。
## 部分迹
| 参数 | 类型 | 说明 |
|------|------|------|
| 密度 | any | 联合密度 |
| 保留 | any | 保留的比特下标列表 |
对联合密度 `密度` 保留 `保留` 所列比特,对其余求迹。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 密度 | any | 必填 | 联合密度 |
| 保留 | any | 必填 | 保留的比特下标列表 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 约化密度 |
> 能力.加载
*> quantum_density_partial_trace density=`密度` keep=`保留`*
这里使用`密度`、`保留`。
对联合密度 `密度` 保留 `保留` 所列比特,对其余求迹。
这里**[调用 加载](能力.加载())**。
完成后返回*[对联合密度 密度 保留 保留 所列比特,对其余求迹。](quantum_density_partial_trace(density=`密度`, keep=`保留`))*。
## 期望
| 参数 | 类型 | 说明 |
|------|------|------|
| 密度 | any | 密度算符 |
| 可观测量 | any | 泡利串或矩阵 |
`密度` 上可观测量 `可观测量` 的期望值。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 密度 | any | 必填 | 密度算符 |
| 可观测量 | any | 必填 | 泡利串或矩阵 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | number | 期望值 |
> 能力.加载
*> quantum_density_expect density=`密度` obs=`可观测量`*
这里使用`密度`、`可观测量`。
将当前输入交给 quantum_density_expect,保留同源能力的返回值和失败语义。
`密度` 上可观测量 `可观测量` 的期望值。
这里**[调用 加载](能力.加载())**。
完成后返回*[将当前输入交给 quantum_density_expect,保留同源能力的返回值和失败语义。](quantum_density_expect(density=`密度`, obs=`可观测量`))*。
## 本征
| 参数 | 类型 | 说明 |
|------|------|------|
| 密度 | any | 密度算符 |
`密度` 的厄米谱。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 密度 | any | 必填 | 密度算符 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 本征值与本征矢 |
> 能力.加载
*> quantum_density_eig density=`密度`*
这里使用`密度`。
将当前输入交给 quantum_density_eig,保留同源能力的返回值和失败语义。
`密度` 的厄米谱。
这里**[调用 加载](能力.加载())**。
完成后返回*[将当前输入交给 quantum_density_eig,保留同源能力的返回值和失败语义。](quantum_density_eig(density=`密度`))*。
## 矩阵
| 参数 | 类型 | 说明 |
|------|------|------|
| 密度 | any | Density handle / 密度句柄 |
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 密度 | any | 必填 | Density handle / 密度句柄 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 复数矩阵条目,每项含 re 与 im |
这里使用`密度`。
导出 `密度` 的显式复数嵌套矩阵。观察条目不会改变密度算符,
可用于独立计算迹或交给线性代数模块核对;物理性校验仍由调用者负责。
> 能力.加载
*> quantum_density_matrix density=`密度`*
这里**[调用 加载](能力.加载())**。
完成后返回*[导出 密度 的显式复数嵌套矩阵。观察条目不会改变密度算符, 可用于独立计算迹或交给线性代数模块核对;物理性校验仍由调用者负责。](quantum_density_matrix(density=`密度`))*。
# 密度
| 参数 | 类型 | 说明 |
|------|------|------|
| 态 | any | 默认 None |
| 矩阵 | any | 默认 None |
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 态 | any | None | 默认 None |
| 矩阵 | any | None | 默认 None |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 返回结果 |
输入:`态`=None, `矩阵`=None。
这里使用`态`=None、`矩阵`=None。
由态/电路(态=)或显式厄米矩阵=构造密度算符,宽度上限六比特。纯态与混合态共用本对象面,随后可做纯度、部分迹、本征与期望。智能体也可用同文件 ## 从态 / 从矩阵 工具逐步构造,再 toget 复用句柄。构造成功后返回密度句柄,供作者链式或 call 会话继续使用。若同时给出矩阵与态,以矩阵分支为准。
> 能力.加载
这里**[调用 加载](能力.加载())**。
1. `矩阵`
*> quantum_density_from_matrix matrix=`矩阵`*
完成后返回*[由态/电路(态=)或显式厄米矩阵=构造密度算符,宽度上限六比特。纯态与混合态共用本对象面,随后可做纯度、部分迹、本征与期望。智能体也可用同文件 ## 从态 / 从矩阵 工具逐步构造,再 toget 复用句柄。构造成功后返回密度句柄,供作者链式或 call 会话继续使用。若同时给出矩阵与态,以矩阵分支为准。](quantum_density_from_matrix(matrix=`矩阵`))*。
2. *
*> quantum_density_from_state state=`态`*
完成后返回*[由态/电路(态=)或显式厄米矩阵=构造密度算符,宽度上限六比特。纯态与混合态共用本对象面,随后可做纯度、部分迹、本征与期望。智能体也可用同文件 ## 从态 / 从矩阵 工具逐步构造,再 toget 复用句柄。构造成功后返回密度句柄,供作者链式或 call 会话继续使用。若同时给出矩阵与态,以矩阵分支为准。](quantum_density_from_state(state=`态`))*。
## 矩阵
@@ -172,7 +190,7 @@ marqdo call ext/quantum/量子/密度/索引.mq.md 本征 '密度=$rho' --effect
返回本密度算符的显式矩阵,便于检查元素,或交给包外线性代数步骤继续处理。
*> quantum_density_matrix density=`self`*
完成后返回*[返回本密度算符的显式矩阵,便于检查元素,或交给包外线性代数步骤继续处理。](quantum_density_matrix(density=`self`))*。
## 纯度
@@ -182,23 +200,23 @@ marqdo call ext/quantum/量子/密度/索引.mq.md 本征 '密度=$rho' --effect
计算 Tr(ρ²)。接近 1 表示纯态;混合态严格小于 1。部分迹后可用来快速检查纠缠或退相干。
*> quantum_density_purity density=`self`*
完成后返回*[计算 Tr(ρ²)。接近 1 表示纯态;混合态严格小于 1。部分迹后可用来快速检查纠缠或退相干。](quantum_density_purity(density=`self`))*。
## 部分迹
| 参数 | 类型 | 说明 |
|------|------|------|
| 保留 | any | 必填 |
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 保留 | any | 必填 | 必填 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 密度算符句柄 |
输入:`保留`。
这里使用`保留`。
保留所列比特(LSB=0),对其余求迹,得到约化密度。用于纠缠讲义与纯度检查。
*> quantum_density_partial_trace density=`self` keep=`保留`*
完成后返回*[保留所列比特(LSB=0),对其余求迹,得到约化密度。用于纠缠讲义与纯度检查。](quantum_density_partial_trace(density=`self`, keep=`保留`))*。
## 本征
@@ -208,37 +226,37 @@ marqdo call ext/quantum/量子/密度/索引.mq.md 本征 '密度=$rho' --effect
计算本密度的厄米谱(本征值与本征矢)。便于讲义作图,并核对构造的 rho 是否物理。
*> quantum_density_eig density=`self`*
完成后返回*[计算本密度的厄米谱(本征值与本征矢)。便于讲义作图,并核对构造的 rho 是否物理。](quantum_density_eig(density=`self`))*。
## 期望
| 参数 | 类型 | 说明 |
|------|------|------|
| 可观测量 | any | 必填 |
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 可观测量 | any | 必填 | 必填 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | number | 标量观察值 |
输入:`可观测量`。
这里使用`可观测量`。
可观测量在本密度上的期望值。可观测量可以是泡利串(左端=高比特),或与密度维数匹配的显式矩阵。
*> quantum_density_expect density=`self` obs=`可观测量`*
完成后返回*[可观测量在本密度上的期望值。可观测量可以是泡利串(左端=高比特),或与密度维数匹配的显式矩阵。](quantum_density_expect(density=`self`, obs=`可观测量`))*。
## 绘图
| 参数 | 类型 | 说明 |
|------|------|------|
| 路径 | any | 默认 None |
| 种类 | any | 默认 hinton |
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | any | None | 默认 None |
| 种类 | any | "hinton" | 默认 hinton |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | quantum_svg,含 kind 与 svg |
输入:`路径`=None, `种类`="hinton"。
这里使用`路径`=None、`种类`="hinton"。
绘制 Hinton、城市、密度格或泡利向量图。可选路径落盘;种类选择讲义采用的视觉隐喻。
*> quantum_density_draw density=`self` path=`路径` kind=`种类`*
完成后返回*[绘制 Hinton、城市、密度格或泡利向量图。可选路径落盘;种类选择讲义采用的视觉隐喻。](quantum_density_draw(density=`self`, path=`路径`, kind=`种类`))*。
+31 -25
View File
@@ -40,49 +40,55 @@ entropy 单位为自然对数 nats,贝尔态为 ln(2),两个系数各约 1/
## 张量积
| 参数 | 类型 | 说明 |
|------|------|------|
| a | any | 左因子 |
| b | any | 右因子 |
将 `a` 与 `b` 做张量积,得到更大空间上的态或算符。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| a | any | 必填 | 左因子 |
| b | any | 必填 | 右因子 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 张量积结果 |
> 能力.加载
*> quantum_kron a=`a` b=`b`*
这里使用`a`、`b`。
将 `a` 与 `b` 做张量积,得到更大空间上的态或算符。
这里**[调用 加载](能力.加载())**。
完成后返回*[将 a 与 b 做张量积,得到更大空间上的态或算符。](quantum_kron(a=`a`, b=`b`))*。
## 保真度
| 参数 | 类型 | 说明 |
|------|------|------|
| a | any | 第一态或电路 |
| b | any | 第二态或电路 |
纯态 `a` 与 `b` 的保真度为重叠绝对值的平方。可传入电路句柄(取理想模拟态)。
教学噪声忽略。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| a | any | 必填 | 第一态或电路 |
| b | any | 必填 | 第二态或电路 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | number | 保真度 |
> 能力.加载
*> quantum_fidelity a=`a` b=`b`*
这里使用`a`、`b`。
纯态 `a` 与 `b` 的保真度为重叠绝对值的平方。可传入电路句柄(取理想模拟态)。
教学噪声忽略。
这里**[调用 加载](能力.加载())**。
完成后返回*[纯态 a 与 b 的保真度为重叠绝对值的平方。可传入电路句柄(取理想模拟态)。 教学噪声忽略。](quantum_fidelity(a=`a`, b=`b`))*。
## 施密特分解
| 参数 | 类型 | 说明 |
|------|------|------|
| 态 | any | 纯态或电路 |
| 分割 | number | 子系统 A 比特数 |
对纯态或电路 `态` 做施密特分解。`分割`=1 表示子系统 A 的比特数(低位)。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 态 | any | 必填 | 纯态或电路 |
| 分割 | number | 1 | 子系统 A 比特数 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 施密特数据 |
> 能力.加载
*> quantum_schmidt state=`态` cut=`分割`*
这里使用`态`、`分割`=1。
对纯态或电路 `态` 做施密特分解。`分割`=1 表示子系统 A 的比特数(低位)。
这里**[调用 加载](能力.加载())**。
完成后返回*[对纯态或电路 态 做施密特分解。分割=1 表示子系统 A 的比特数(低位)。](quantum_schmidt(state=`态`, cut=`分割`))*。
+51 -39
View File
@@ -46,79 +46,91 @@ plugins/quantum/src/sim.rs,导出位于同目录 src/lib.rs。保持中英理
## 模拟
| 参数 | 类型 | 说明 |
|------|------|------|
| 电路 | any | 待演化电路 |
返回 `电路` 的理想态矢量振幅。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 电路 | any | 必填 | 待演化电路 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 振幅列表 |
> 能力.加载
*> quantum_simulate circuit=`电路`*
这里使用`电路`。
返回 `电路` 的理想态矢量振幅。
这里**[调用 加载](能力.加载())**。
完成后返回*[返回 电路 的理想态矢量振幅。](quantum_simulate(circuit=`电路`))*。
## 态
| 参数 | 类型 | 说明 |
|------|------|------|
| 电路 | any | 待演化电路 |
与模拟相同:取 `电路` 的理想振幅,打包为态对象,便于后续保真度或密度构造。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 电路 | any | 必填 | 待演化电路 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 理想态 |
> 能力.加载
*> quantum_state circuit=`电路`*
这里使用`电路`。
与模拟相同:取 `电路` 的理想振幅,打包为态对象,便于后续保真度或密度构造。
这里**[调用 加载](能力.加载())**。
完成后返回*[与模拟相同:取 电路 的理想振幅,打包为态对象,便于后续保真度或密度构造。](quantum_state(circuit=`电路`))*。
## 概率
| 参数 | 类型 | 说明 |
|------|------|------|
| 电路 | any | 待读取电路 |
`电路` 理想态的基矢标签到概率映射。比特 0 为最右侧。忽略噪声。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 电路 | any | 必填 | 待读取电路 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 概率映射 |
> 能力.加载
*> quantum_probabilities circuit=`电路`*
这里使用`电路`。
将当前输入交给 quantum_probabilities,保留同源能力的返回值和失败语义。
`电路` 理想态的基矢标签到概率映射。比特 0 为最右侧。忽略噪声。
这里**[调用 加载](能力.加载())**。
完成后返回*[将当前输入交给 quantum_probabilities,保留同源能力的返回值和失败语义。](quantum_probabilities(circuit=`电路`))*。
## 运行
| 参数 | 类型 | 说明 |
|------|------|------|
| 电路 | any | 待采样电路 |
| 次数 | number | 采样次数 |
| 种子 | number | 随机种子 |
对 `电路` 采样。默认 `次数`=1024、`种子`=1。若有教学噪声则轨迹含噪声。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 电路 | any | 必填 | 待采样电路 |
| 次数 | number | 1024 | 采样次数 |
| 种子 | number | 1 | 随机种子 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 计数或采样结果 |
> 能力.加载
*> quantum_run circuit=`电路` shots=`次数` seed=`种子`*
这里使用`电路`、`次数`=1024、`种子`=1。
对 `电路` 采样。默认 `次数`=1024、`种子`=1。若有教学噪声则轨迹含噪声。
这里**[调用 加载](能力.加载())**。
完成后返回*[对 电路 采样。默认 次数=1024、种子=1。若有教学噪声则轨迹含噪声。](quantum_run(circuit=`电路`, shots=`次数`, seed=`种子`))*。
## 噪声
| 参数 | 类型 | 说明 |
|------|------|------|
| 电路 | any | 电路 |
| 种类 | text | 噪声族名 |
| 强度 | number | 单位区间强度 |
在 `电路` 上附着种类 `种类`、强度 `强度` 的教学噪声。理想概率工具忽略它。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 电路 | any | 必填 | 调用方提供的电路 |
| 种类 | text | 必填 | 噪声族名 |
| 强度 | number | 必填 | 单位区间强度 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 带噪声元数据的电路 |
> 能力.加载
*> quantum_noise circuit=`电路` kind=`种类` p=`强度`*
这里使用`电路`、`种类`、`强度`。
在 `电路` 上附着种类 `种类`、强度 `强度` 的教学噪声。理想概率工具忽略它。
这里**[调用 加载](能力.加载())**。
完成后返回*[在 电路 上附着种类 种类、强度 强度 的教学噪声。理想概率工具忽略它。](quantum_noise(circuit=`电路`, kind=`种类`, p=`强度`))*。
File diff suppressed because it is too large. Load diff
+17 -14
View File
@@ -179,12 +179,12 @@ Bytecode。例子不能照抄运行就是公共接口缺陷,叙述比例再高
工具返回线路而非概率,便于继续施门、设置噪声或独立验证纠缠。
每一步接住新电路值,原值不被隐式修改。
**qc = 电路.新建 比特数=2 步骤=None**
得到**`qc` = [调用 新建](电路.新建(比特数=2, 步骤=None))**。
先让最低位具有两条等权路径,再把路径信息传播给第二条线。
**qc = 电路.哈达玛 电路=`qc` 比特=0**
*> 电路.控非 电路=`qc` 控制=0 目标=1*
得到**`qc` = [调用 哈达玛](电路.哈达玛(电路=`qc`, 比特=0))**。
完成后返回*[调用 控非](电路.控非(电路=`qc`, 控制=0, 目标=1))*。
## 贝尔态
@@ -196,8 +196,8 @@ Bytecode。例子不能照抄运行就是公共接口缺陷,叙述比例再高
00 和 11 各约一半,其余基矢为零;这是计算基关联,单靠概率还不能证明纠缠,
因此需要纠缠证据时继续调用本页纠缠分析,对照约化纯度与 ZZ 期望。
**qc = > 贝尔电路**
*> 模拟.概率 电路=`qc`*
得到**`qc` = [调用 贝尔电路](贝尔电路())**。
完成后返回*[调用 概率](模拟.概率(电路=`qc`))*。
## 纠缠分析
@@ -211,29 +211,32 @@ Bytecode。例子不能照抄运行就是公共接口缺陷,叙述比例再高
整体纯度应为 1,约化纯度应为 0.5,ZZ 应为 1,施密特熵为 ln(2)。
所有数值按 1e-9 容差核对;纯态概率与密度构造均使用理想演化。
**qc = > 贝尔电路**
**probs = 模拟.概率 电路=`qc`**
这里分析的是同一次制备的状态,避免分别重建电路导致比较对象不同。
得到**`qc` = [调用 贝尔电路](贝尔电路())**。
得到**`probs` = [调用 概率](模拟.概率(电路=`qc`))**。
先构造整体密度并计算纯度。整体纯不意味着每个局部也纯,
接着只保留最低位,检查丢弃另一个比特后出现的混合性。
**rho = 密度.从态 态=`qc`**
**whole = 密度.纯度 密度=`rho`**
得到**`rho` = [调用 从态](密度.从态(态=`qc`))**。
得到**`whole` = [调用 纯度](密度.纯度(密度=`rho`))**。
`kept` =
| 比特 |
|------|
| 0 |
**reduced = 密度.部分迹 密度=`rho` 保留=`kept`**
**local = 密度.纯度 密度=`reduced`**
得到**`reduced` = [调用 部分迹](密度.部分迹(密度=`rho`, 保留=`kept`))**。
得到**`local` = [调用 纯度](密度.纯度(密度=`reduced`))**。
ZZ 测量关联,不是单独的纠缠判据。施密特分解独立给出纯态两侧的
系数与熵;联合这些观察才能解释为何这是贝尔纯态而非经典概率混合。
返回表将各观察保留原值,便于调用者自行检查,而不是输出一个隐藏阈值的通过标签。
**correlation = 密度.期望 密度=`rho` 可观测量="ZZ"**
**split = 态.施密特分解 态=`qc` 分割=1**
得到**`correlation` = [调用 期望](密度.期望(密度=`rho`, 可观测量="ZZ"))**。
得到**`split` = [调用 施密特分解](态.施密特分解(态=`qc`, 分割=1))**。
`report` =
@@ -241,4 +244,4 @@ ZZ 测量关联,不是单独的纠缠判据。施密特分解独立给出纯
|---------------|--------|----------------|----|---------|
| `probs` | `whole` | `local` | `correlation` | `split` |
*report*
完成后返回*report*。
+9 -9
View File
@@ -26,20 +26,20 @@ marqdo call ext/quantum/量子/能力/索引.mq.md 加载 --effects plugin --jso
## 加载
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 加载成功后为空 |
通过 plugin.native_path 找到 ABI v2 quantum 共享库,再 plugin.load。若缺失则打印
安装提示并以非零退出。成功后本进程内可用 quantum_* 符号。本包中只有这里应直接
接触 lib/plugin。领域模块在需要模拟器的工具开头调用加载。
本工具无参数。
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 加载成功后为空 |
**p = > plugin.native_path name="quantum"**
得到**`p` = [定位已安装的原生插件](plugin.native_path(name="quantum"))**。
1. `p`
> plugin.load path=`p`
这里**[加载本操作依赖的原生插件](plugin.load(path=`p`))**。
2. *
> print text=ext/quantum/量子: 未找到原生 quantum 插件(请 build marqdo_plugin_quantum 或 marqdo ext add quantum)
> sys.exit code=1
****
这里**[输出本步已准备的消息](print(text="ext/quantum/量子: 未找到原生 quantum 插件(请 build marqdo_plugin_quantum 或 marqdo ext add quantum)"))**。
这里**[按指定退出码结束本次运行](sys.exit(code=1))**。
完成后返回*None*。
+81 -73
View File
@@ -38,140 +38,148 @@ marqdo call ext/quantum/量子/模拟/索引.mq.md 概率 '电路=$qc' --effects
## 哈达玛
哈达玛门把计算基变成等权叠加。本工具返回名为 H 的门句柄。
本工具无参数。
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 哈达玛门句柄 |
> 能力.加载
*> quantum_gate_new name="H" theta=None matrix=None*
## 泡利X
泡利 X 是比特翻转门。
哈达玛门把计算基变成等权叠加。本工具返回名为 H 的门句柄。
本工具无参数。
这里**[调用 加载](能力.加载())**。
完成后返回*[哈达玛门把计算基变成等权叠加。本工具返回名为 H 的门句柄。 本工具无参数。](quantum_gate_new(name="H", theta=None, matrix=None))*。
## 泡利X
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 泡利 X 句柄 |
> 能力.加载
*> quantum_gate_new name="X" theta=None matrix=None*
## 泡利Z
泡利 Z 给 ket-one 乘上负号相位。
泡利 X 是比特翻转门。
本工具无参数。
这里**[调用 加载](能力.加载())**。
完成后返回*[泡利 X 是比特翻转门。 本工具无参数。](quantum_gate_new(name="X", theta=None, matrix=None))*。
## 泡利Z
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 泡利 Z 句柄 |
> 能力.加载
*> quantum_gate_new name="Z" theta=None matrix=None*
## 控非门
两比特受控非门句柄。施到线路上时请用电路模块并写明控制位与目标位。
泡利 Z 给 ket-one 乘上负号相位。
本工具无参数。
这里**[调用 加载](能力.加载())**。
完成后返回*[泡利 Z 给 ket-one 乘上负号相位。 本工具无参数。](quantum_gate_new(name="Z", theta=None, matrix=None))*。
## 控非门
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | CNOT 门句柄 |
> 能力.加载
*> quantum_gate_new name="CX" theta=None matrix=None*
两比特受控非门句柄。施到线路上时请用电路模块并写明控制位与目标位。
本工具无参数。
这里**[调用 加载](能力.加载())**。
完成后返回*[两比特受控非门句柄。施到线路上时请用电路模块并写明控制位与目标位。 本工具无参数。](quantum_gate_new(name="CX", theta=None, matrix=None))*。
## 自定义
| 参数 | 类型 | 说明 |
|------|------|------|
| 矩阵 | any | 酉矩阵公式或列表 |
| 名 | text | 可选标签,默认 U |
用显式酉矩阵 `矩阵` 构造门。可选标签 `名`="U"。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 矩阵 | any | 必填 | 酉矩阵公式或列表 |
| 名 | text | "U" | 可选标签,默认 U |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 自定义门句柄 |
> 能力.加载
*> quantum_gate_new name=`名` theta=None matrix=`矩阵`*
这里使用`矩阵`、`名`="U"。
用显式酉矩阵 `矩阵` 构造门。可选标签 `名`="U"。
这里**[调用 加载](能力.加载())**。
完成后返回*[用显式酉矩阵 矩阵 构造门。可选标签 名="U"。](quantum_gate_new(name=`名`, theta=None, matrix=`矩阵`))*。
## 匹配
| 参数 | 类型 | 说明 |
|------|------|------|
| 门 | any | 门句柄 |
| 矩阵 | any | 期望酉矩阵 |
| 容差 | number | 绝对容差 |
检查 `门` 是否在容差 `容差`=0.000000001 内匹配 `矩阵`。
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 门 | any | 必填 | 门句柄 |
| 容差 | number | 0.000000001 | 绝对容差 |
| 矩阵 | any | 必填 | 期望酉矩阵 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | bool | 匹配则为 True |
> 能力.加载
*> quantum_gate_matches_matrix gate=`门` matrix=`矩阵` tol=`容差`*
这里使用`门`、`容差`=0.000000001、`矩阵`。
检查 `门` 是否在容差 `容差`=0.000000001 内匹配 `矩阵`。
这里**[调用 加载](能力.加载())**。
完成后返回*[检查 门 是否在容差 容差=0.000000001 内匹配 矩阵。](quantum_gate_matches_matrix(gate=`门`, matrix=`矩阵`, tol=`容差`))*。
## 具名
| 参数 | 类型 | 说明 |
|------|------|------|
| 名 | text | 内置门名 |
| 参数 | any | 旋转角或 None |
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 名 | text | "H" | 内置门名 |
| 参数 | any | None | 旋转角或 None |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 可交给施加工具的门句柄 |
这里使用`名`="H"、`参数`=None。
构造内置门 `名`="H";可选 `参数`=None,Rx、Ry、Rz 必须给出弧度角。
返回可交给电路施加的门句柄,创建过程不改变任何线路。支持名称见本页开篇表述。
> 能力.加载
*> quantum_gate_new name=`名` theta=`参数` matrix=None*
这里**[调用 加载](能力.加载())**。
完成后返回*[构造内置门 名="H";可选 参数=None,Rx、Ry、Rz 必须给出弧度角。 返回可交给电路施加的门句柄,创建过程不改变任何线路。支持名称见本页开篇表述。](quantum_gate_new(name=`名`, theta=`参数`, matrix=None))*。
## 矩阵
| 参数 | 类型 | 说明 |
|------|------|------|
| 门 | any | 门句柄 |
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 门 | any | 必填 | 门句柄 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 复数矩阵条目,每项含 re 与 im |
这里使用`门`。
导出 `门` 的显式酉矩阵。每个元素含 re、im,可用于公式复核或独立矩阵比较;
本工具仅观察算符,不改变句柄,也不把门应用到任何电路。
> 能力.加载
*> quantum_gate_matrix gate=`门`*
这里**[调用 加载](能力.加载())**。
完成后返回*[导出 门 的显式酉矩阵。每个元素含 re、im,可用于公式复核或独立矩阵比较; 本工具仅观察算符,不改变句柄,也不把门应用到任何电路。](quantum_gate_matrix(gate=`门`))*。
# 门
| 参数 | 类型 | 说明 |
|------|------|------|
| 名 | any | 默认 None |
| 参数 | number | 默认 None |
| 矩阵 | any | 默认 None |
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 名 | any | None | 默认 None |
| 参数 | number | None | 默认 None |
| 矩阵 | any | None | 默认 None |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 可交给施加工具的门句柄 |
输入:`名`=None, `参数`=None, `矩阵`=None。
这里使用`名`=None、`参数`=None、`矩阵`=None。
具名内置门(名=H)或由矩阵=(嵌套 list 或公式矩阵围栏)定义的自定义酉门。自定义门可选名=(默认 U)。作者链式与智能体 ## 工具共用本对象面。
> 能力.加载
*> quantum_gate_new name=`名` theta=`参数` matrix=`矩阵`*
这里**[调用 加载](能力.加载())**。
完成后返回*[具名内置门(名=H)或由矩阵=(嵌套 list 或公式矩阵围栏)定义的自定义酉门。自定义门可选名=(默认 U)。作者链式与智能体 ## 工具共用本对象面。](quantum_gate_new(name=`名`, theta=`参数`, matrix=`矩阵`))*。
## 矩阵
@@ -181,38 +189,38 @@ marqdo call ext/quantum/量子/模拟/索引.mq.md 概率 '电路=$qc' --effects
返回本门句柄的显式酉矩阵,便于检查元素,或在公式构造自定义门后交给匹配矩阵验收。
*> quantum_gate_matrix gate=`self`*
完成后返回*[返回本门句柄的显式酉矩阵,便于检查元素,或在公式构造自定义门后交给匹配矩阵验收。](quantum_gate_matrix(gate=`self`))*。
## 匹配矩阵
| 参数 | 类型 | 说明 |
|------|------|------|
| 矩阵 | any | 必填 |
| 容差 | any | 默认 0.000000001 |
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 矩阵 | any | 必填 | 必填 |
| 容差 | any | 0.000000001 | 默认 0.000000001 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | bool | 容差内匹配 |
输入:`矩阵`, `容差`=0.000000001。
这里使用`矩阵`、`容差`=0.000000001。
检查本门是否在绝对容差内容差内匹配给定矩阵。讲义里用公式围栏造门后,常用本方法做数值验收。
*> quantum_gate_matches_matrix gate=`self` matrix=`矩阵` tol=`容差`*
完成后返回*[检查本门是否在绝对容差内容差内匹配给定矩阵。讲义里用公式围栏造门后,常用本方法做数值验收。](quantum_gate_matches_matrix(gate=`self`, matrix=`矩阵`, tol=`容差`))*。
## 绘图
| 参数 | 类型 | 说明 |
|------|------|------|
| 路径 | any | 默认 None |
| 种类 | any | 默认 gate |
| 参数 | 类型 | 默认 | 说明 |
|---|---|---|---|
| 路径 | any | None | 默认 None |
| 种类 | any | "gate" | 默认 gate |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | quantum_svg,含 kind 与 svg |
输入:`路径`=None, `种类`="gate"。
这里使用`路径`=None、`种类`="gate"。
绘制门符号或复矩阵热力图(种类=gate 或 matrix)。可选路径落盘;亦经 record_plot 进入本会话的 view/CLI 图面。
*> quantum_gate_draw gate=`self` path=`路径` kind=`种类`*
完成后返回*[绘制门符号或复矩阵热力图(种类=gate 或 matrix)。可选路径落盘;亦经 record_plot 进入本会话的 view/CLI 图面。](quantum_gate_draw(gate=`self`, path=`路径`, kind=`种类`))*。