Ship quantum skill=tools tree with call session and ZH package.

Split ext/quantum into index + modules, add marqdo call --effects/--session/--toget,
narrative-ratio checks, and a same-package 量子/ tree so agents can follow a
decision path for Bell demos without inventing a second API.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-11-08 21:50:01 +08:00
1 parent 492790e985
commit 0e389f34ec
65 files changed
+3714 -1036

No files matched your search

+49
View File
@@ -0,0 +1,49 @@
---
markup: occlusion
title: ext/quantum/_capability
description: >-
Quantum ABI load skill. Prefer domain modules; call load when diagnosing plugins.
import:
plugin: lib/plugin.mq.md
sys: lib/sys.mq.md
---
Capability
This file is still a skill and a tool surface. It exists so the quantum package
can load the native ABI plugin once. Everyday author programs and agents should
call domain modules which invoke load for you. Reach for this page when checking
whether the plugin is installed, not when building a Bell state.
## For AI agents
If you were given only this file, use it only to check the plugin. Day-to-day work
should call circuit or simulate modules instead.
Call example (plain text):
marqdo call ext/quantum/_capability/index.mq.md load --effects plugin --json
*None*
## 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
star names are available in this process. This is the only sanctioned place in
the package that talks to lib/plugin for quantum. Domain skills call load at the
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"**
1. `p`
> 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
****
+320
View File
@@ -0,0 +1,320 @@
---
markup: occlusion
title: ext/quantum/circuit
description: >-
Quantum circuit skill — wires, step tables, and applying gates.
import:
cap: ext/quantum/_capability/index.mq.md
density: ext/quantum/density/index.mq.md
---
Circuit
A circuit is an ordered list of gates on n wires, starting from the all-zero
ket. You can build it with method-style steps with author method chains on this file, or
call the tools here. A steps table is a readable program. Measurement rows mark
which bits simulate.run should report; they do not collapse the ideal state
vector used by probabilities.
## For AI agents
If you were given only this file, you still know how to run it. Every ## heading
below is a tool. Execute with the shell. Always include --effects plugin.
Create a two-qubit circuit and save it as qc:
Call example (plain text):
marqdo call ext/quantum/circuit/index.mq.md new qubits=2 --effects plugin --session s --toget qc --json
Apply Hadamard on qubit 0:
Call example (plain text):
marqdo call ext/quantum/circuit/index.mq.md hadamard circuit=$qc qubit=0 --effects plugin --session s --toget qc --json
Apply CNOT from 0 to 1:
Call example (plain text):
marqdo call ext/quantum/circuit/index.mq.md cnot circuit=$qc control=0 target=1 --effects plugin --session s --toget qc --json
Then open ext/quantum/simulate/index.mq.md for probabilities. Author programs may
import this file and construct the circuit object named circuit (method chain h,
cx, …). Agents should prefer marqdo call on the ## tools above.
## new
Create a state-vector circuit of width `qubits`=1 by default. Optional
`steps`=None means no preloaded gates; when a table is provided it is parsed
like the author API.
| 参数 | 类型 | 说明 |
|------|------|------|
| qubits | number | wire count |
| steps | any | optional gate table or None |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | new circuit handle |
> cap.load
*> quantum_circuit_new qubits=`qubits` steps=`steps`*
## hadamard
Apply Hadamard on wire `qubit`=0 of an existing `circuit` by default. Prefer
this when an agent already holds a circuit from new or toget.
| 参数 | 类型 | 说明 |
|------|------|------|
| circuit | any | existing circuit |
| qubit | number | target wire |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | updated circuit |
> cap.load
*> quantum_h circuit=`circuit` qubit=`qubit`*
## cnot
Controlled-NOT on `circuit` from `control`=0 to `target`=1 by default. Together
with hadamard this prepares a Bell pair on two wires.
| 参数 | 类型 | 说明 |
|------|------|------|
| circuit | any | existing circuit |
| control | number | control wire |
| target | number | target wire |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | updated circuit |
> cap.load
*> quantum_cx circuit=`circuit` control=`control` target=`target`*
## barrier
Insert a visual barrier on `circuit`. The state does not change; drawings show a
separator so lectures can mark logical layers.
| 参数 | 类型 | 说明 |
|------|------|------|
| circuit | any | existing circuit |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | circuit with barrier recorded |
> cap.load
*> quantum_barrier circuit=`circuit`*
## measure_mark
Mark computational-basis readout on `circuit` for later simulate.run. This does
not collapse the ideal state used by probabilities. Pass `qubits`=None to mark
every wire.
| 参数 | 类型 | 说明 |
|------|------|------|
| circuit | any | existing circuit |
| qubits | any | wire list or None for all |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | circuit with measure markers |
> cap.load
*> quantum_measure circuit=`circuit` qubits=`qubits`*
# circuit
+ `qubits`=1
+ `steps`=None
State-vector circuit on n wires (default all-zero ket). Optional steps= preloads a gate table. Methods append gates and return a fresh handle for chaining. Agents should prefer the ## call tools above; authors use this object for readable method chains in programs.
> cap.load
*> quantum_circuit_new qubits=`qubits` steps=`steps`*
## h
+ `qubit`=0
Apply the Hadamard gate on the chosen wire. This creates equal superposition from computational basis states and is the first step of Bell and GHZ recipes. Returns an updated circuit handle so authors can chain without in-place mutation.
*> quantum_h circuit=`self` qubit=`qubit`*
## x
+ `qubit`=0
Apply Pauli X (bit flip) on the chosen wire. Useful for preparing |1⟩ from |0⟩ or sandwiching phase gates. Returns the updated circuit handle for further chaining.
*> quantum_x circuit=`self` qubit=`qubit`*
## y
+ `qubit`=0
Apply Pauli Y on the chosen wire. Combines bit and phase flip; returns the updated circuit handle for further chaining in author programs.
*> quantum_y circuit=`self` qubit=`qubit`*
## z
+ `qubit`=0
Apply Pauli Z (phase flip) on the chosen wire. Often used in H–Z–H sandwiches that realize an effective X. Returns the updated circuit handle.
*> quantum_z circuit=`self` qubit=`qubit`*
## s
+ `qubit`=0
Apply the phase gate S (√Z) on the chosen wire. Returns the updated circuit handle for further chaining in lecture circuits.
*> quantum_s circuit=`self` qubit=`qubit`*
## t
+ `qubit`=0
Apply the phase gate T (π/8) on the chosen wire. Returns the updated circuit handle for further chaining in lecture circuits.
*> quantum_t circuit=`self` qubit=`qubit`*
## i
+ `qubit`=0
Apply the identity on the chosen wire. Acts as a no-op spacer in step tables or noise experiments while keeping the wire explicit. Returns the updated handle.
*> quantum_i circuit=`self` qubit=`qubit`*
## rx
+ `qubit`=0
+ `theta`
Rotate the chosen wire about the X axis by angle theta in radians. Continuous single-qubit control for variational and teaching demos. Returns the updated circuit handle.
*> quantum_rx circuit=`self` qubit=`qubit` theta=`theta`*
## ry
+ `qubit`=0
+ `theta`
Rotate the chosen wire about the Y axis by angle theta in radians. Continuous single-qubit control for variational and teaching demos. Returns the updated circuit handle.
*> quantum_ry circuit=`self` qubit=`qubit` theta=`theta`*
## rz
+ `qubit`=0
+ `theta`
Rotate the chosen wire about the Z axis by angle theta in radians. Continuous single-qubit control for variational and teaching demos. Returns the updated circuit handle.
*> quantum_rz circuit=`self` qubit=`qubit` theta=`theta`*
## cx
+ `control`=0
+ `target`=1
Apply CNOT from control to target. This is the standard entangling step in Bell and GHZ preparations. Returns the updated circuit handle for chaining.
*> quantum_cx circuit=`self` control=`control` target=`target`*
## cz
+ `control`=0
+ `target`=1
Apply controlled-Z between control and target. Creates phase entanglement without flipping bits. Returns the updated circuit handle for chaining.
*> quantum_cz circuit=`self` control=`control` target=`target`*
## swap
+ `a`=0
+ `b`=1
Exchange the two wires named by a and b. Useful when routing logical qubits in a teaching layout. Returns the updated circuit handle.
*> quantum_swap circuit=`self` a=`a` b=`b`*
## barrier
Record a visual barrier only. The ideal state vector is unchanged; use barriers to separate lecture stages when drawing circuit rails.
*> quantum_barrier circuit=`self`*
## measure
+ `qubits`=None
Mark computational-basis readout wires for later run sampling. This does not collapse the ideal state used by probabilities. Pass qubits=None to mark every wire.
*> quantum_measure circuit=`self` qubits=`qubits`*
## append
+ `op`
Append another circuit’s operation list, or a gate/qubits record table, onto this circuit. Returns the combined circuit handle so programs can compose fragments.
*> quantum_append circuit=`self` op=`op`*
## apply
+ `gate`
+ `qubits`=0
Apply a gate handle (built-in name or custom unitary matrix) onto qubits given as an int or a list. Returns the updated circuit handle for further chaining.
*> quantum_apply circuit=`self` gate=`gate` qubits=`qubits`*
## noise
+ `kind`
+ `p`
Attach teaching noise of the given kind and strength for run trajectories. Ideal simulate and probabilities paths ignore this channel by design.
*> quantum_noise circuit=`self` kind=`kind` p=`p`*
## simulate
Return ideal state-vector amplitudes as re/im pairs for the current circuit. Teaching noise attached to the circuit is ignored on this ideal path.
*> quantum_simulate circuit=`self`*
## state
Return the ideal state object with the same amplitudes as simulate. Prefer this when later fidelity or density tools expect a state handle rather than raw amplitudes.
*> quantum_state circuit=`self`*
## probabilities
Map basis labels to ideal probabilities. Labels treat qubit 0 as the rightmost bit. Teaching noise is ignored so results match the pure statevector story.
*> quantum_probabilities circuit=`self`*
## run
+ `shots`=1024
+ `seed`=1
Sample computational-basis shots from this circuit. Defaults are shots=1024 and seed=1 for reproducible replays. Applies teaching noise when a noise channel was attached.
*> quantum_run circuit=`self` shots=`shots` seed=`seed`*
## draw
+ `path`=None
+ `kind`=circuit
+ `qubit`=0
+ `theme`=dark
Render an SVG figure for circuit rails, probability bars, Bloch spheres, or advanced density kinds. Theme tokens are dark, light, and bw. Optional path writes the file for CLI or view embedding.
*> quantum_draw_circuit circuit=`self` path=`path` kind=`kind` qubit=`qubit` theme=`theme`*
## density
Build the pure-state density matrix ρ=|ψ⟩⟨ψ| after ideal simulation of this circuit. Use density-module tools for mixed states and partial traces.
*> quantum_density_from_state state=`self`*
## expect
+ `obs`
Compute the expectation value of a Pauli string (left end = high bit) or an explicit matrix on this circuit’s ideal density. Teaching noise is ignored.
*> quantum_density_expect density=`self` obs=`obs`*
## schmidt
+ `cut`=1
Perform a bipartite Schmidt decomposition of the ideal state. The cut argument is the number of qubits in subsystem A counted from the low bits.
*> quantum_schmidt state=`self` cut=`cut`*
+172
View File
@@ -0,0 +1,172 @@
---
markup: occlusion
title: ext/quantum/density
description: >-
Density-operator skill — mixed states, partial trace, expectations.
import:
cap: ext/quantum/_capability/index.mq.md
---
Density
A density operator describes pure and mixed states together. Pure states have
purity one; mixing lowers purity. Build rho from a circuit or state, or from an
explicit Hermitian matrix. Partial trace discards subsystems. Expectation values
take Pauli strings or matrices.
## For AI agents
If you were given only this file, build or inspect density operators with marqdo
call and --effects plugin.
Call example (plain text):
marqdo call ext/quantum/density/index.mq.md from_state state=$qc --effects plugin --toget rho --json
marqdo call ext/quantum/density/index.mq.md purity density=$rho --effects plugin --json
Author programs may use the density object on this file.
## from_state
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.
| 参数 | 类型 | 说明 |
|------|------|------|
| state | any | pure state or circuit |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | density handle |
> cap.load
*> quantum_density_from_state state=`state`*
## from_matrix
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.
| 参数 | 类型 | 说明 |
|------|------|------|
| matrix | any | Hermitian matrix |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | density handle |
> cap.load
*> quantum_density_from_matrix matrix=`matrix`*
## purity
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 | density operator |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | number | purity |
> cap.load
*> quantum_density_purity density=`density`*
## partial_trace
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.
| 参数 | 类型 | 说明 |
|------|------|------|
| density | any | joint density |
| keep | any | qubit index list to keep |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | reduced density |
> cap.load
*> quantum_density_partial_trace density=`density` keep=`keep`*
## expect
Expectation of observable `obs` on `density`. Pauli strings use left equals
high bit. Pass a matrix when the observable is not a Pauli product.
| 参数 | 类型 | 说明 |
|------|------|------|
| density | any | density operator |
| obs | any | Pauli string or matrix |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | number | expectation value |
> cap.load
*> quantum_density_expect density=`density` obs=`obs`*
## eig
Hermitian spectrum of `density` as eigenvalues and eigenvectors. Useful when a
lecture needs the eigenbasis of rho.
| 参数 | 类型 | 说明 |
|------|------|------|
| density | any | Hermitian density |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | eigenvalues and eigenvectors |
> cap.load
*> quantum_density_eig density=`density`*
# density
+ `state`=None
+ `matrix`=None
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
1. `matrix`
*> quantum_density_from_matrix matrix=`matrix`*
2. *
*> quantum_density_from_state state=`state`*
## matrix
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
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`*
## partial_trace
+ `keep`
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
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`*
## expect
+ `obs`
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`*
## draw
+ `path`=None
+ `kind`=hinton
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`*
+150
View File
@@ -0,0 +1,150 @@
---
markup: occlusion
title: ext/quantum/gate
description: >-
Quantum gate skill — unitaries as formulas, named gates, matrix checks.
import:
cap: ext/quantum/_capability/index.mq.md
---
Gate
A gate is a unitary on one or more qubits. This skill writes the matrix in
lecture form, then builds a gate handle. Circuits apply gates; this page defines
what they are. Custom unitaries use the same path with a matrix argument from a
formula block or nested list.
## For AI agents
If you were given only this file, run tools with marqdo call and --effects plugin.
FUNCTION is the ## name. Example Hadamard gate handle:
Call example (plain text):
marqdo call ext/quantum/gate/index.mq.md hadamard --effects plugin --json
Custom unitary: pass matrix= as JSON or a prior toget. matches checks a gate
against a matrix. Author programs may also use the gate object constructor on
this file.
## hadamard
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.
So H on ket-zero yields an equal plus combination, and H on ket-one yields an
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*
## pauli_x
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*
## pauli_z
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*
## cnot
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
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*
## custom
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 | unitary matrix formula or list |
| name | text | optional label defaulting to U |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | custom gate handle |
> cap.load
*> quantum_gate_new name=`name` theta=None matrix=`matrix`*
## matches
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 | gate handle to test |
| matrix | any | expected unitary |
| tol | number | absolute tolerance |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | bool | True when matrices match |
> cap.load
*> quantum_gate_matches_matrix gate=`gate` matrix=`matrix` tol=`tol`*
# gate
+ `name`=None
+ `theta`=None
+ `matrix`=None
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`*
## matrix
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`
+ `tol`=0.000000001
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`*
## draw
+ `path`=None
+ `kind`=gate
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`*
+193
View File
@@ -0,0 +1,193 @@
---
markup: occlusion
title: ext/quantum
description: >-
Quantum package root skill. Read this file first. Every tool runs with marqdo call.
import:
state: ext/quantum/state/index.mq.md
gate: ext/quantum/gate/index.mq.md
circuit: ext/quantum/circuit/index.mq.md
simulate: ext/quantum/simulate/index.mq.md
density: ext/quantum/density/index.mq.md
viz: ext/quantum/viz/index.mq.md
---
This file is the root skill for the Marqdo quantum package. If you are an AI
agent (or any program) with no other Marqdo context, follow Choose a path, then
How to execute any tool. Do not invent MCP tools, Python wrappers, or a second
API. The Markdown ## headings in these files are the tools.
## Choose a path
Pick one row. Do not mix English and Chinese tool names or file trees. (Do not
write Marqdo branch lines here; this table is narration only.)
| If you need | Do this |
|-------------|---------|
| Only a Bell result | Run `bell_phi_plus` on this file (command in the next section). Stop. |
| Circuit handles to continue (draw, noise, more gates) | Copy the stepwise circuit then simulate calls under circuit module below. Keep one `--session` and `--toget qc`. |
| Chinese tool names | Open `ext/quantum/量子/索引.mq.md` instead and stay in that tree. |
English paths stay under `ext/quantum/` (this tree). Agents should use `##`
tools via `marqdo call`. The `# circuit` / `# gate` objects on module files are
for author programs that import the module, not the default agent path.
*None*
## How to execute any tool
Marqdo runs one function from a Markdown file with this shell command shape.
Copy it literally. Replace FILE, FUNCTION, and arguments.
Call example (plain text):
marqdo call FILE FUNCTION name=value name=value --effects plugin --json
FILE is always a path under ext/quantum/, usually ending in index.mq.md.
FUNCTION is the exact ## heading name in that file (for example new, hadamard,
probabilities). Nested ### headings use a dotted path like parent.child.
Always pass --effects plugin because the simulator is a native plugin; without
this flag marqdo call refuses the tool. Pass --json when you need the envelope
with ok and result fields. To keep a return value for the next command, add
--session some-id and --toget name (or put toget name at the end). Later
arguments may use circuit=$name. Plugin handles are rebuilt from the session
journal. Argument values may be numbers, quoted text, True, False, None, JSON
starting with [ or {, or $name session refs. Do not call ensure_plugin or any
host-star API; domain files load the plugin themselves.
Minimal first command to verify the package (no tool arguments):
Call example (plain text):
marqdo call ext/quantum/index.mq.md bell_phi_plus --effects plugin --json
*None*
## Package layout
Open only the module you need. Each module file is also a complete skill and
repeats how to marqdo call its tools.
The path ext/quantum/index.mq.md is this root map and the Bell demo tool.
The path ext/quantum/circuit/index.mq.md builds wires, applies H and CNOT, and
defines the author object circuit.
The path ext/quantum/gate/index.mq.md holds gate matrices as formulas and named
or custom gates.
The path ext/quantum/simulate/index.mq.md returns amplitudes, probabilities, and
noisy shots.
The path ext/quantum/state/index.mq.md covers kron, fidelity, and Schmidt.
The path ext/quantum/density/index.mq.md covers density operators and partial
trace.
The path ext/quantum/viz/index.mq.md draws SVG figures.
The path ext/quantum/_capability/index.mq.md only loads the plugin for diagnostics.
Author programs import the same paths in frontmatter, then call module.member.
Example: import circuit from ext/quantum/circuit/index.mq.md, then use
circuit.circuit for the object constructor, or circuit.new for the call-style
tool that agents use with marqdo call.
*None*
## circuit module
File path: ext/quantum/circuit/index.mq.md
Use this when you need a quantum circuit handle. Typical agent sequence for a
two-qubit Bell preparation (copy each line as its own shell command):
Call example (plain text):
marqdo call ext/quantum/circuit/index.mq.md new qubits=2 --effects plugin --session s1 --toget qc --json
marqdo call ext/quantum/circuit/index.mq.md hadamard circuit=$qc qubit=0 --effects plugin --session s1 --toget qc --json
marqdo call ext/quantum/circuit/index.mq.md cnot circuit=$qc control=0 target=1 --effects plugin --session s1 --toget qc --json
Main ## tools on that file: new, hadamard, cnot, barrier, measure_mark. The same
file also defines the author object circuit with methods such as h and cx.
*None*
## gate module
File path: ext/quantum/gate/index.mq.md
Use this when you need a gate handle or a formula matrix check.
Call example (plain text):
marqdo call ext/quantum/gate/index.mq.md hadamard --effects plugin --json
marqdo call ext/quantum/gate/index.mq.md cnot --effects plugin --json
Main ## tools: hadamard, pauli_x, pauli_z, cnot, custom, matches.
*None*
## simulate module
File path: ext/quantum/simulate/index.mq.md
Use this when you already have a circuit handle and want amplitudes,
probabilities, or sampled shots.
Call example (plain text):
marqdo call ext/quantum/simulate/index.mq.md probabilities circuit=$qc --effects plugin --session s1 --json
Main ## tools: simulate, state, probabilities, run, noise. Ideal probabilities
ignore teaching noise; run applies noise when set.
*None*
## state module
File path: ext/quantum/state/index.mq.md
Use this for Kronecker product, fidelity, and Schmidt decomposition.
Call example (plain text):
marqdo call ext/quantum/state/index.mq.md fidelity a=$psi b=$phi --effects plugin --json
Main ## tools: kron, fidelity, schmidt.
*None*
## density module
File path: ext/quantum/density/index.mq.md
Use this for mixed states.
Call example (plain text):
marqdo call ext/quantum/density/index.mq.md from_state state=$qc --effects plugin --toget rho --json
marqdo call ext/quantum/density/index.mq.md purity density=$rho --effects plugin --json
*None*
## viz module
File path: ext/quantum/viz/index.mq.md
Use this to draw SVG. Pass a circuit or density handle and optional path.
Call example (plain text):
marqdo call ext/quantum/viz/index.mq.md draw_circuit circuit=$qc path="bell.svg" --effects plugin --session s1 --json
Main ## tools: draw_circuit, draw_probs, draw_bloch, draw_density, draw_gate.
*None*
## bell_phi_plus
One-shot orchestration tool on this index file. It takes no parameters. It builds
the Bell Phi-plus state with Hadamard on qubit 0 and CNOT from 0 to 1, then
returns ideal basis probabilities. Use this when you only need the demo result.
Use the stepwise circuit and simulate calls above when you need intermediate
handles.
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | map of basis label to probability |
Exact command to run this tool:
Call example (plain text):
marqdo call ext/quantum/index.mq.md bell_phi_plus --effects plugin --json
**qc = > circuit.new qubits=2 steps=None**
**qc = > circuit.hadamard circuit=`qc` qubit=0**
**qc = > circuit.cnot circuit=`qc` control=0 target=1**
*> simulate.probabilities circuit=`qc`*
-332
View File
@@ -1,332 +0,0 @@
---
markup: occlusion
title: ext/quantum/quantum
description: Official quantum circuit simulator (English). Gates + circuits; ABI plugin.
import:
plugin: lib/plugin.mq.md
sys: lib/sys.mq.md
json: lib/json.mq.md
---
Official quantum circuit simulator (English). Gates + circuits; ABI plugin.
## ensure_plugin
Load the ABI v2 `quantum` plugin once.
**p = > plugin.native_path name="quantum"**
1. `p`
> 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
****
## kron
+ `a`
+ `b`
Tensor product of two states or square matrices.
> ensure_plugin
*> quantum_kron a=`a` b=`b`*
## schmidt
+ `state`
+ `cut`=1
Schmidt decomposition of a pure state / circuit across `cut` (subsystem A = low qubits).
> ensure_plugin
*> quantum_schmidt state=`state` cut=`cut`*
## fidelity
+ `a`
+ `b`
Pure-state fidelity |⟨a|b⟩|².
> ensure_plugin
*> quantum_fidelity a=`a` b=`b`*
# circuit
+ `qubits`=1
+ `steps`=None
State-vector circuit (default |0…0⟩). Optional `steps=` gate table (column or row records). Methods append gates and return an updated handle.
> ensure_plugin
*> quantum_circuit_new qubits=`qubits` steps=`steps`*
## h
+ `qubit`=0
Hadamard on qubit (default 0).
*> quantum_h circuit=`self` qubit=`qubit`*
## x
+ `qubit`=0
Pauli X on qubit.
*> quantum_x circuit=`self` qubit=`qubit`*
## y
+ `qubit`=0
Pauli Y on qubit.
*> quantum_y circuit=`self` qubit=`qubit`*
## z
+ `qubit`=0
Pauli Z on qubit.
*> quantum_z circuit=`self` qubit=`qubit`*
## s
+ `qubit`=0
Phase S on qubit.
*> quantum_s circuit=`self` qubit=`qubit`*
## t
+ `qubit`=0
Phase T on qubit.
*> quantum_t circuit=`self` qubit=`qubit`*
## i
+ `qubit`=0
Identity on qubit.
*> quantum_i circuit=`self` qubit=`qubit`*
## rx
+ `qubit`=0
+ `theta`
Rotate about X by theta.
*> quantum_rx circuit=`self` qubit=`qubit` theta=`theta`*
## ry
+ `qubit`=0
+ `theta`
Rotate about Y by theta.
*> quantum_ry circuit=`self` qubit=`qubit` theta=`theta`*
## rz
+ `qubit`=0
+ `theta`
Rotate about Z by theta.
*> quantum_rz circuit=`self` qubit=`qubit` theta=`theta`*
## cx
+ `control`=0
+ `target`=1
CNOT: control → target.
*> quantum_cx circuit=`self` control=`control` target=`target`*
## cz
+ `control`=0
+ `target`=1
Controlled-Z.
*> quantum_cz circuit=`self` control=`control` target=`target`*
## swap
+ `a`=0
+ `b`=1
Swap two qubits.
*> quantum_swap circuit=`self` a=`a` b=`b`*
## barrier
Visual separator only (no state change).
*> quantum_barrier circuit=`self`*
## measure
+ `qubits`=None
Mark computational-basis readout (`None` / empty = all qubits). Affects which bits `run` reports.
*> quantum_measure circuit=`self` qubits=`qubits`*
## append
+ `op`
Append another circuit's ops or a `{gate,qubits}` op map.
*> quantum_append circuit=`self` op=`op`*
## apply
+ `gate`
+ `qubits`=0
Apply a gate handle (named or custom `matrix=`) on `qubits` (int or list).
*> quantum_apply circuit=`self` gate=`gate` qubits=`qubits`*
## noise
+ `kind`
+ `p`
Teaching noise for `run` trajectories (`bitflip` / `depolarizing` / `amplitude_damping`). Ignored by `simulate` / `probabilities`.
*> quantum_noise circuit=`self` kind=`kind` p=`p`*
## simulate
Return state vector amplitudes `{re,im}` (ideal; no noise).
*> quantum_simulate circuit=`self`*
## state
Ideal state vector (same amplitudes as `simulate`).
*> quantum_state circuit=`self`*
## probabilities
Return map of basis label → probability (qubit 0 = rightmost bit). Ideal; ignores noise.
*> quantum_probabilities circuit=`self`*
## run
+ `shots`=1024
+ `seed`=1
Sample computational-basis shots (deterministic with `seed=`). Applies circuit `noise` if set.
*> quantum_run circuit=`self` shots=`shots` seed=`seed`*
## draw
+ `path`=None
+ `kind`=circuit
+ `qubit`=0
+ `theme`=dark
Circuit rail / probability bars / Bloch / advanced state plots (`kind=circuit|probs|bloch|hinton|city|density|paulivec|qsphere|multibloch`). Theme `dark` (default tech lab) / `light` / `bw`. Records into view/CLI plots via host `record_plot`.
*> quantum_draw_circuit circuit=`self` path=`path` kind=`kind` qubit=`qubit` theme=`theme`*
## density
Pure-state density matrix ρ=|ψ⟩⟨ψ| after ideal simulate.
*> density state=`self`*
## expect
+ `obs`
Pauli string (left = high bit) or matrix expectation on the ideal state.
*> quantum_density_expect density=`self` obs=`obs`*
## schmidt
+ `cut`=1
Schmidt / singular values across a bipartition (`cut` = qubits in subsystem A, low bits).
*> quantum_schmidt state=`self` cut=`cut`*
# gate
+ `name`=None
+ `theta`=None
+ `matrix`=None
Named built-in gate (`name=H`) or custom unitary from `matrix=` (nested list or formula matrix fence). Optional `name=` label for custom gates (default `U`).
> ensure_plugin
*> quantum_gate_new name=`name` theta=`theta` matrix=`matrix`*
## matrix
Explicit matrix of this object.
*> quantum_gate_matrix gate=`self`*
## matches_matrix
+ `matrix`
+ `tol`=0.000000001
Whether this gate matches matrix (tol).
*> quantum_gate_matches_matrix gate=`self` matrix=`matrix` tol=`tol`*
## draw
+ `path`=None
+ `kind`=gate
Gate glyph or complex-matrix heatmap (`kind=gate|matrix`). Records via host `record_plot`.
*> quantum_gate_draw gate=`self` path=`path` kind=`kind`*
# density
+ `state`=None
+ `matrix`=None
Density matrix from a state/circuit (`state=`) or an explicit Hermitian `matrix=` (≤6 qubits).
> ensure_plugin
1. `matrix`
*> quantum_density_from_matrix matrix=`matrix`*
2. *
*> quantum_density_from_state state=`state`*
## matrix
Explicit matrix of this object.
*> quantum_density_matrix density=`self`*
## purity
Tr(ρ²).
*> quantum_density_purity density=`self`*
## partial_trace
+ `keep`
Keep listed qubits (LSB=0); trace out the rest.
*> quantum_density_partial_trace density=`self` keep=`keep`*
## eig
Hermitian spectrum → `{eigenvalues, eigenvectors}`.
*> quantum_density_eig density=`self`*
## expect
+ `obs`
Expectation value of obs.
*> quantum_density_expect density=`self` obs=`obs`*
## draw
+ `path`=None
+ `kind`=hinton
Hinton / city / density-cells / Pauli vector SVG (`kind=hinton` or city or density or paulivec).
*> quantum_density_draw density=`self` path=`path` kind=`kind`*
+110
View File
@@ -0,0 +1,110 @@
---
markup: occlusion
title: ext/quantum/simulate
description: >-
Quantum simulation skill — amplitudes, probabilities, noisy shots.
import:
cap: ext/quantum/_capability/index.mq.md
---
Simulate
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.
## For AI agents
If you were given only this file, you need a circuit handle from
ext/quantum/circuit/index.mq.md (usually via --toget). Then:
Call example (plain text):
marqdo call ext/quantum/simulate/index.mq.md probabilities circuit=$qc --effects plugin --session s --json
Other tools: simulate, state, run, noise. Always --effects plugin.
## 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 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | amplitude list |
> cap.load
*> quantum_simulate circuit=`circuit`*
## 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 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | ideal state |
> cap.load
*> quantum_state circuit=`circuit`*
## 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 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | probability map |
> cap.load
*> quantum_probabilities circuit=`circuit`*
## 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 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | counts or shot result |
> cap.load
*> quantum_run circuit=`circuit` shots=`shots` seed=`seed`*
## 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 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | circuit with noise metadata |
> cap.load
*> quantum_noise circuit=`circuit` kind=`kind` p=`p`*
+86
View File
@@ -0,0 +1,86 @@
---
markup: occlusion
title: ext/quantum/state
description: >-
Quantum state skill — amplitudes, Kronecker products, fidelity, Schmidt.
import:
cap: ext/quantum/_capability/index.mq.md
---
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.
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.
## For AI agents
If you were given only this file, run state tools with marqdo call and --effects
plugin. Example fidelity:
Call example (plain text):
marqdo call ext/quantum/state/index.mq.md fidelity a=$psi b=$phi --effects plugin --json
Tools: kron, fidelity, schmidt.
## 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.
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | tensor product |
> cap.load
*> quantum_kron a=`a` b=`b`*
## 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 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | number | fidelity in the unit interval |
> cap.load
*> quantum_fidelity a=`a` b=`b`*
## 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 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | singular values and factors |
> cap.load
*> quantum_schmidt state=`state` cut=`cut`*
+114
View File
@@ -0,0 +1,114 @@
---
markup: occlusion
title: ext/quantum/viz
description: >-
Quantum visualization skill — circuit rails, probabilities, Bloch, density plots.
import:
cap: ext/quantum/_capability/index.mq.md
---
Visualization
Drawings turn a circuit or density into SVG for view mode or a path on disk.
Pick a kind for the figure and a theme for colors. Themes dark (default), light,
and bw share geometry so lectures can switch style without rewriting the
circuit. Start with circuit and probs kinds when unsure.
## For AI agents
If you were given only this file, draw with marqdo call and --effects plugin.
You need a circuit or density handle from another module (toget).
Call example (plain text):
marqdo call ext/quantum/viz/index.mq.md draw_probs circuit=$qc path="out.svg" --effects plugin --session s --json
## draw_circuit
Rail diagram of gates and barriers for `circuit`. Theme `theme`="dark" by
default. Optional `path` writes SVG for CLI or view embedding.
| 参数 | 类型 | 说明 |
|------|------|------|
| circuit | any | circuit to render |
| path | any | optional output path or None |
| theme | text | dark light or bw |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | drawing result |
> cap.load
*> quantum_draw_circuit circuit=`circuit` path=`path` kind="circuit" qubit=0 theme=`theme`*
## draw_probs
Probability bars for the ideal state of `circuit`. Same theme tokens as the
rail diagram. Uses `theme`="dark" when omitted. Optional `path` for file output.
| 参数 | 类型 | 说明 |
|------|------|------|
| circuit | any | circuit to render |
| path | any | optional output path or None |
| theme | text | dark light or bw |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | drawing result |
> cap.load
*> quantum_draw_circuit circuit=`circuit` path=`path` kind="probs" qubit=0 theme=`theme`*
## draw_bloch
Bloch sphere for one wire of `circuit`. Default `qubit`=0. Optional `path` and
`theme`="dark". Multi-qubit circuits still render one qubit reduced picture.
| 参数 | 类型 | 说明 |
|------|------|------|
| circuit | any | circuit source |
| path | any | optional output path or None |
| qubit | number | which wire |
| theme | text | dark light or bw |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | drawing result |
> cap.load
*> quantum_draw_circuit circuit=`circuit` path=`path` kind="bloch" qubit=`qubit` theme=`theme`*
## draw_density
Plot density operator `density`. Default `kind`="hinton". Optional `path`.
Choose city, density, or paulivec when the lecture uses those metaphors.
| 参数 | 类型 | 说明 |
|------|------|------|
| density | any | density operator |
| path | any | optional output path or None |
| kind | text | hinton city density or paulivec |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | drawing result |
> cap.load
*> quantum_density_draw density=`density` path=`path` kind=`kind`*
## draw_gate
Glyph or matrix heatmap for `gate`. Use `kind`="gate" by default, or matrix
when checking a custom unitary. Optional `path`.
| 参数 | 类型 | 说明 |
|------|------|------|
| gate | any | gate handle |
| path | any | optional output path or None |
| kind | text | gate or matrix |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | drawing result |
> cap.load
*> quantum_gate_draw gate=`gate` path=`path` kind=`kind`*
-332
View File
@@ -1,332 +0,0 @@
---
markup: occlusion
title: ext/quantum/量子
description: 官方量子电路模拟(中文)。门 + 电路;ABI 插件。
import:
plugin: lib/plugin.mq.md
sys: lib/sys.mq.md
json: lib/json.mq.md
---
官方量子电路模拟(中文)。门 + 电路;ABI 插件。
## 确保插件
加载 ABI v2 `quantum` 插件。
**p = > plugin.native_path name="quantum"**
1. `p`
> plugin.load path=`p`
2. *
> print text=ext/quantum: 未找到原生 quantum 插件(请 build marqdo_plugin_quantum 或 marqdo ext add quantum)
> sys.exit code=1
****
## 张量积
+ `左`
+ `右`
两态或方阵的张量积。
> 确保插件
*> quantum_kron a=`左` b=`右`*
## 施密特分解
+ `态`
+ `分割`=1
纯态 / 电路的施密特分解。
> 确保插件
*> quantum_schmidt state=`态` cut=`分割`*
## 保真度
+ `左`
+ `右`
纯态保真度 |⟨a|b⟩|²。
> 确保插件
*> quantum_fidelity a=`左` b=`右`*
# 电路
+ `比特数`=1
+ `步骤`=None
状态向量电路(默认 |0…0⟩)。可选 `步骤=` 门序列表。方法追加门并返回更新后的句柄。
> 确保插件
*> quantum_circuit_new qubits=`比特数` steps=`步骤`*
## 哈达玛
+ `比特`=0
对比特施加哈达玛(默认 0)。
*> quantum_h circuit=`self` qubit=`比特`*
## 泡利X
+ `比特`=0
对比特施加泡利 X。
*> quantum_x circuit=`self` qubit=`比特`*
## 泡利Y
+ `比特`=0
对比特施加泡利 Y。
*> quantum_y circuit=`self` qubit=`比特`*
## 泡利Z
+ `比特`=0
对比特施加泡利 Z。
*> quantum_z circuit=`self` qubit=`比特`*
## 相位S
+ `比特`=0
对比特施加相位 S。
*> quantum_s circuit=`self` qubit=`比特`*
## 相位T
+ `比特`=0
对比特施加相位 T。
*> quantum_t circuit=`self` qubit=`比特`*
## 单位
+ `比特`=0
对比特施加单位门 / 单位矩阵。
*> quantum_i circuit=`self` qubit=`比特`*
## 绕X
+ `比特`=0
+ `参数`
绕 X 旋转参数角。
*> quantum_rx circuit=`self` qubit=`比特` theta=`参数`*
## 绕Y
+ `比特`=0
+ `参数`
绕 Y 旋转参数角。
*> quantum_ry circuit=`self` qubit=`比特` theta=`参数`*
## 绕Z
+ `比特`=0
+ `参数`
绕 Z 旋转参数角。
*> quantum_rz circuit=`self` qubit=`比特` theta=`参数`*
## 控非
+ `控制`=0
+ `目标`=1
控非门:控制 → 目标。
*> quantum_cx circuit=`self` control=`控制` target=`目标`*
## 控相
+ `控制`=0
+ `目标`=1
控制相位 Z。
*> quantum_cz circuit=`self` control=`控制` target=`目标`*
## 交换
+ `比特甲`=0
+ `比特乙`=1
交换两比特。
*> quantum_swap circuit=`self` a=`比特甲` b=`比特乙`*
## 屏障
仅可视化分隔(不改态)。
*> quantum_barrier circuit=`self`*
## 测量
+ `比特`=None
标记计算基读出(空 = 全部比特)。影响 `运行` 报告哪些位。
*> quantum_measure circuit=`self` qubits=`比特`*
## 追加
+ `操作`
追加另一电路的 ops,或 `{gate,qubits}` 操作表。
*> quantum_append circuit=`self` op=`操作`*
## 施加
+ `门`
+ `比特`=0
将门句柄(具名或 `矩阵=` 自定义)施加到 `比特`(整数或列表)。
*> quantum_apply circuit=`self` gate=`门` qubits=`比特`*
## 噪声
+ `种类`
+ `概率`
教学噪声,供 `运行` 轨迹使用(`bitflip` / `depolarizing` / `amplitude_damping`,或中文:比特翻转 / 退极化 / 振幅阻尼)。`模拟` / `概率` 忽略。
*> quantum_noise circuit=`self` kind=`种类` p=`概率`*
## 模拟
返回态矢量振幅 `{re,im}`(理想;无噪声)。
*> quantum_simulate circuit=`self`*
## 态
理想态矢量(与 `模拟` 相同振幅)。
*> quantum_state circuit=`self`*
## 概率
基矢标签 → 概率(qubit 0 为最右侧比特)。理想;忽略噪声。
*> quantum_probabilities circuit=`self`*
## 运行
+ `次数`=1024
+ `种子`=1
计算基采样(`种子=` 可复现)。若设置了电路噪声则启用。
*> quantum_run circuit=`self` shots=`次数` seed=`种子`*
## 绘图
+ `路径`=None
+ `种类`=circuit
+ `比特`=0
+ `主题`=dark
电路轨线 / 概率条 / 布洛赫 / 高级态图(种类 circuit、probs、bloch、hinton、city、density、paulivec、qsphere、multibloch)。主题 dark(默认科技感)/ light / bw。经 record_plot 进入 view/CLI plots。
*> quantum_draw_circuit circuit=`self` path=`路径` kind=`种类` qubit=`比特` theme=`主题`*
## 密度
理想模拟后的纯态密度矩阵 ρ=|ψ⟩⟨ψ|。
*> 密度 态=`self`*
## 期望
+ `可观测量`
Pauli 串(左端=高比特)或矩阵期望值。
*> quantum_density_expect density=`self` obs=`可观测量`*
## 施密特
+ `分割`=1
二分施密特分解(`分割`=子系统 A 的比特数,低位)。
*> quantum_schmidt state=`self` cut=`分割`*
# 门
+ `名`=None
+ `参数`=None
+ `矩阵`=None
具名内置门(`名=H`)或由 `矩阵=`(嵌套 list 或公式矩阵围栏)定义的自定义酉门。自定义门可选 `名=`(默认 `U`)。
> 确保插件
*> quantum_gate_new name=`名` theta=`参数` matrix=`矩阵`*
## 矩阵
本对象的显式矩阵。
*> quantum_gate_matrix gate=`self`*
## 匹配矩阵
+ `矩阵`
+ `容差`=0.000000001
门是否匹配给定矩阵(容差)。
*> quantum_gate_matches_matrix gate=`self` matrix=`矩阵` tol=`容差`*
## 绘图
+ `路径`=None
+ `种类`=gate
门符号或复矩阵热力图(`种类=gate|matrix`)。经 `record_plot` 记录。
*> quantum_gate_draw gate=`self` path=`路径` kind=`种类`*
# 密度
+ `态`=None
+ `矩阵`=None
由态/电路(`态=`)或显式厄米 `矩阵=` 构造密度矩阵(≤6 比特)。
> 确保插件
1. `矩阵`
*> quantum_density_from_matrix matrix=`矩阵`*
2. *
*> quantum_density_from_state state=`态`*
## 矩阵
本对象的显式矩阵。
*> quantum_density_matrix density=`self`*
## 纯度
Tr(ρ²)。
*> quantum_density_purity density=`self`*
## 部分迹
+ `保留`
保留所列比特(LSB=0),对其余求迹。
*> quantum_density_partial_trace density=`self` keep=`保留`*
## 本征
厄米谱 → `{eigenvalues, eigenvectors}`。
*> quantum_density_eig density=`self`*
## 期望
+ `可观测量`
可观测量的期望值。
*> quantum_density_expect density=`self` obs=`可观测量`*
## 绘图
+ `路径`=None
+ `种类`=hinton
Hinton / 城市 / 密度格 / 泡利向量 SVG(`种类=hinton` 或 city / density / paulivec)。
*> quantum_density_draw density=`self` path=`路径` kind=`种类`*
+104
View File
@@ -0,0 +1,104 @@
---
markup: occlusion
title: ext/quantum/量子/可视化
description: 量子可视化 skill — 电路轨、概率条、布洛赫、密度图。
import:
能力: ext/quantum/量子/能力/索引.mq.md
---
把电路或密度画成 SVG。选择 kind 与主题。主题 dark(默认)、light、bw 几何一致。
## 给智能体
若你只拿到本文件,需要其它模块给出的电路或密度句柄(toget)。
调用示例(纯文本):
marqdo call ext/quantum/量子/可视化/索引.mq.md 画概率 电路=$qc 路径="out.svg" --effects plugin --session s --json
*None*
## 画电路
`电路` 的轨线图。默认 `主题`="dark"。可选 `路径` 落盘。
| 参数 | 类型 | 说明 |
|------|------|------|
| 电路 | any | 电路 |
| 路径 | any | 可选输出路径或 None |
| 主题 | text | dark light 或 bw |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 绘图结果 |
> 能力.加载
*> quantum_draw_circuit circuit=`电路` path=`路径` kind="circuit" qubit=0 theme=`主题`*
## 画概率
`电路` 理想态概率条。默认 `主题`="dark"。可选 `路径` 落盘。
| 参数 | 类型 | 说明 |
|------|------|------|
| 电路 | any | 电路 |
| 路径 | any | 可选路径或 None |
| 主题 | text | dark light 或 bw |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 绘图结果 |
> 能力.加载
*> quantum_draw_circuit circuit=`电路` path=`路径` kind="probs" qubit=0 theme=`主题`*
## 画布洛赫
`电路` 上单线布洛赫球。默认 `比特`=0、`主题`="dark"。可选 `路径` 落盘。
| 参数 | 类型 | 说明 |
|------|------|------|
| 电路 | any | 电路 |
| 路径 | any | 可选路径或 None |
| 比特 | number | 哪一根线 |
| 主题 | text | dark light 或 bw |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 绘图结果 |
> 能力.加载
*> quantum_draw_circuit circuit=`电路` path=`路径` kind="bloch" qubit=`比特` theme=`主题`*
## 画密度
绘制密度算符 `密度`。默认 `种类`="hinton"。可选 `路径` 落盘。
| 参数 | 类型 | 说明 |
|------|------|------|
| 密度 | any | 密度算符 |
| 路径 | any | 可选路径或 None |
| 种类 | text | hinton city density 或 paulivec |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 绘图结果 |
> 能力.加载
*> quantum_density_draw density=`密度` path=`路径` kind=`种类`*
## 画门
绘制单个 `门`。默认 `种类`="gate"。可选 `路径` 落盘。
| 参数 | 类型 | 说明 |
|------|------|------|
| 门 | any | 门句柄 |
| 路径 | any | 可选路径或 None |
| 种类 | text | gate 或 matrix |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 绘图结果 |
> 能力.加载
*> quantum_gate_draw gate=`门` path=`路径` kind=`种类`*
+170
View File
@@ -0,0 +1,170 @@
---
markup: occlusion
title: ext/quantum/量子/密度
description: 密度算符 skill — 混合态、部分迹、期望值。
import:
能力: ext/quantum/量子/能力/索引.mq.md
---
密度算符同时描述纯态与混合态。可从态/电路或显式厄米矩阵构造,再做纯度、
部分迹与期望。
## 给智能体
若你只拿到本文件:
调用示例(纯文本):
marqdo call ext/quantum/量子/密度/索引.mq.md 从态 态=$qc --effects plugin --toget rho --json
marqdo call ext/quantum/量子/密度/索引.mq.md 纯度 密度=$rho --effects plugin --json
*None*
## 从态
由纯态或电路句柄 `态` 的理想态构造 rho。
| 参数 | 类型 | 说明 |
|------|------|------|
| 态 | any | 纯态或电路 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 密度句柄 |
> 能力.加载
*> quantum_density_from_state state=`态`*
## 从矩阵
由显式厄米 `矩阵` 构造 rho。
| 参数 | 类型 | 说明 |
|------|------|------|
| 矩阵 | any | 厄米矩阵 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 密度句柄 |
> 能力.加载
*> quantum_density_from_matrix matrix=`矩阵`*
## 纯度
计算 `密度` 的 Tr(rho^2)。
| 参数 | 类型 | 说明 |
|------|------|------|
| 密度 | any | 密度算符 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | number | 纯度 |
> 能力.加载
*> quantum_density_purity density=`密度`*
## 部分迹
对联合密度 `密度` 保留 `保留` 所列比特,对其余求迹。
| 参数 | 类型 | 说明 |
|------|------|------|
| 密度 | any | 联合密度 |
| 保留 | any | 保留的比特下标列表 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 约化密度 |
> 能力.加载
*> quantum_density_partial_trace density=`密度` keep=`保留`*
## 期望
`密度` 上可观测量 `可观测量` 的期望值。
| 参数 | 类型 | 说明 |
|------|------|------|
| 密度 | any | 密度算符 |
| 可观测量 | any | 泡利串或矩阵 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | number | 期望值 |
> 能力.加载
*> quantum_density_expect density=`密度` obs=`可观测量`*
## 本征
`密度` 的厄米谱。
| 参数 | 类型 | 说明 |
|------|------|------|
| 密度 | any | 密度算符 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 本征值与本征矢 |
> 能力.加载
*> quantum_density_eig density=`密度`*
# 密度
+ `态`=None
+ `矩阵`=None
由态/电路(态=)或显式厄米矩阵=构造密度算符,宽度上限六比特。纯态与混合态共用本对象面,随后可做纯度、部分迹、本征与期望。智能体也可用同文件 ## 从态 / 从矩阵 工具逐步构造,再 toget 复用句柄。构造成功后返回密度句柄,供作者链式或 call 会话继续使用。若同时给出矩阵与态,以矩阵分支为准。
> 能力.加载
1. `矩阵`
*> quantum_density_from_matrix matrix=`矩阵`*
2. *
*> quantum_density_from_state state=`态`*
## 矩阵
返回本密度算符的显式矩阵,便于检查元素,或交给包外线性代数步骤继续处理。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_density_matrix density=`self`*
## 纯度
计算 Tr(ρ²)。接近 1 表示纯态;混合态严格小于 1。部分迹后可用来快速检查纠缠或退相干。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_density_purity density=`self`*
## 部分迹
+ `保留`
保留所列比特(LSB=0),对其余求迹,得到约化密度。用于纠缠讲义与纯度检查。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_density_partial_trace density=`self` keep=`保留`*
## 本征
计算本密度的厄米谱(本征值与本征矢)。便于讲义作图,并核对构造的 rho 是否物理。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_density_eig density=`self`*
## 期望
+ `可观测量`
可观测量在本密度上的期望值。可观测量可以是泡利串(左端=高比特),或与密度维数匹配的显式矩阵。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_density_expect density=`self` obs=`可观测量`*
## 绘图
+ `路径`=None
+ `种类`=hinton
绘制 Hinton、城市、密度格或泡利向量图。可选路径落盘;种类选择讲义采用的视觉隐喻。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_density_draw density=`self` path=`路径` kind=`种类`*
+70
View File
@@ -0,0 +1,70 @@
---
markup: occlusion
title: ext/quantum/量子/态
description: 量子态 skill — 张量积、保真度、施密特分解。
import:
能力: ext/quantum/量子/能力/索引.mq.md
---
纯态是复空间中的单位向量。本包振幅用含 re、im 的映射表示。基矢标签里比特 0 在
最右侧。理想模拟忽略教学噪声;采样轨迹见模拟模块。
## 给智能体
若你只拿到本文件,用 marqdo call 调用下面的 ## 工具,并务必加 --effects plugin。
调用示例(纯文本):
marqdo call ext/quantum/量子/态/索引.mq.md 保真度 a=$psi b=$phi --effects plugin --json
工具名:张量积、保真度、施密特分解。
*None*
## 张量积
将 `a` 与 `b` 做张量积,得到更大空间上的态或算符。
| 参数 | 类型 | 说明 |
|------|------|------|
| a | any | 左因子 |
| b | any | 右因子 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 张量积结果 |
> 能力.加载
*> quantum_kron a=`a` b=`b`*
## 保真度
纯态 `a` 与 `b` 的保真度为重叠绝对值的平方。可传入电路句柄(取理想模拟态)。
教学噪声忽略。
| 参数 | 类型 | 说明 |
|------|------|------|
| a | any | 第一态或电路 |
| b | any | 第二态或电路 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | number | 保真度 |
> 能力.加载
*> quantum_fidelity a=`a` b=`b`*
## 施密特分解
对纯态或电路 `态` 做施密特分解。`分割`=1 表示子系统 A 的比特数(低位)。
| 参数 | 类型 | 说明 |
|------|------|------|
| 态 | any | 纯态或电路 |
| 分割 | number | 子系统 A 比特数 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 施密特数据 |
> 能力.加载
*> quantum_schmidt state=`态` cut=`分割`*
+100
View File
@@ -0,0 +1,100 @@
---
markup: occlusion
title: ext/quantum/量子/模拟
description: 量子模拟 skill — 振幅、概率、含噪采样。
import:
能力: ext/quantum/量子/能力/索引.mq.md
---
模拟回答「这条电路会怎样」。理想路径(模拟、态、概率)忽略教学噪声。运行工具
做计算基采样,并在已附着噪声时应用噪声。超宽电路会被插件拒绝,不会静默截断。
## 给智能体
若你只拿到本文件,需要先有电路句柄(通常来自电路模块的 toget)。然后:
调用示例(纯文本):
marqdo call ext/quantum/量子/模拟/索引.mq.md 概率 电路=$qc --effects plugin --session s --json
其它工具:模拟、态、运行、噪声。一律 --effects plugin。
*None*
## 模拟
返回 `电路` 的理想态矢量振幅。
| 参数 | 类型 | 说明 |
|------|------|------|
| 电路 | any | 待演化电路 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 振幅列表 |
> 能力.加载
*> quantum_simulate circuit=`电路`*
## 态
与模拟相同:取 `电路` 的理想振幅,打包为态对象,便于后续保真度或密度构造。
| 参数 | 类型 | 说明 |
|------|------|------|
| 电路 | any | 待演化电路 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 理想态 |
> 能力.加载
*> quantum_state circuit=`电路`*
## 概率
`电路` 理想态的基矢标签到概率映射。比特 0 为最右侧。忽略噪声。
| 参数 | 类型 | 说明 |
|------|------|------|
| 电路 | any | 待读取电路 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 概率映射 |
> 能力.加载
*> quantum_probabilities circuit=`电路`*
## 运行
对 `电路` 采样。默认 `次数`=1024、`种子`=1。若有教学噪声则轨迹含噪声。
| 参数 | 类型 | 说明 |
|------|------|------|
| 电路 | any | 待采样电路 |
| 次数 | number | 采样次数 |
| 种子 | number | 随机种子 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 计数或采样结果 |
> 能力.加载
*> quantum_run circuit=`电路` shots=`次数` seed=`种子`*
## 噪声
在 `电路` 上附着种类 `种类`、强度 `强度` 的教学噪声。理想概率工具忽略它。
| 参数 | 类型 | 说明 |
|------|------|------|
| 电路 | any | 电路 |
| 种类 | text | 噪声族名 |
| 强度 | number | 单位区间强度 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 带噪声元数据的电路 |
> 能力.加载
*> quantum_noise circuit=`电路` kind=`种类` p=`强度`*
+362
View File
@@ -0,0 +1,362 @@
---
markup: occlusion
title: ext/quantum/量子/电路
description: 量子电路 skill — 造线、施加门;含作者对象「电路」。
import:
能力: ext/quantum/量子/能力/索引.mq.md
密度: ext/quantum/量子/密度/索引.mq.md
---
电路是 n 条线上的有序门列,初态为全零。可用本页 ## 工具逐步构造,或用对象
「电路」的方法链。测量标记只影响采样,不坍缩理想概率所用的态矢量。
## 给智能体
若你只拿到本文件,每个 ## 都是工具。一律加 --effects plugin。
创建两比特电路并保存为 qc:
调用示例(纯文本):
marqdo call ext/quantum/量子/电路/索引.mq.md 新建 比特数=2 --effects plugin --session s --toget qc --json
在比特 0 上施加哈达玛:
调用示例(纯文本):
marqdo call ext/quantum/量子/电路/索引.mq.md 哈达玛 电路=$qc 比特=0 --effects plugin --session s --toget qc --json
控非 0→1:
调用示例(纯文本):
marqdo call ext/quantum/量子/电路/索引.mq.md 控非 电路=$qc 控制=0 目标=1 --effects plugin --session s --toget qc --json
随后打开 ext/quantum/量子/模拟/索引.mq.md 取概率。作者程序可导入本文件并使用对象电路
(方法如哈达玛、控非)。智能体优先用上面的 marqdo call。
*None*
## 新建
创建宽度为 `比特数`=1 的态矢量电路。可选 `步骤`=None 表示不预载门表。
| 参数 | 类型 | 说明 |
|------|------|------|
| 比特数 | number | 线宽 |
| 步骤 | any | 可选门表或 None |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 新电路句柄 |
> 能力.加载
*> quantum_circuit_new qubits=`比特数` steps=`步骤`*
## 哈达玛
对已有 `电路` 的 `比特`=0 施加哈达玛。
| 参数 | 类型 | 说明 |
|------|------|------|
| 电路 | any | 电路句柄 |
| 比特 | number | 目标线 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 更新后的电路 |
> 能力.加载
*> quantum_h circuit=`电路` qubit=`比特`*
## 控非
对 `电路` 从 `控制`=0 到 `目标`=1 施加控非。
| 参数 | 类型 | 说明 |
|------|------|------|
| 电路 | any | 电路句柄 |
| 控制 | number | 控制位 |
| 目标 | number | 目标位 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 更新后的电路 |
> 能力.加载
*> quantum_cx circuit=`电路` control=`控制` target=`目标`*
## 屏障
在 `电路` 上记录可视化屏障(不改态)。
| 参数 | 类型 | 说明 |
|------|------|------|
| 电路 | any | 电路句柄 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 带屏障的电路 |
> 能力.加载
*> quantum_barrier circuit=`电路`*
## 测量标记
为后续运行在 `电路` 上标记计算基读出。`比特`=None 表示全部线。不坍缩理想态。
| 参数 | 类型 | 说明 |
|------|------|------|
| 电路 | any | 电路句柄 |
| 比特 | any | 线列表或 None |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 带测量标记的电路 |
> 能力.加载
*> quantum_measure circuit=`电路` qubits=`比特`*
# 电路
+ `比特数`=1
+ `步骤`=None
状态向量电路,初态为全零。可选步骤表预载门列。方法追加门并返回新句柄,供作者链式写法;智能体更宜用上方 ## 工具配合 marqdo call。测量标记只影响采样,不坍缩概率所用的理想态。
本构造返回可供链式调用的句柄,与同文件 ## 工具共用能力.加载 路径。作者程序写对象方法链;智能体优先 marqdo call 上方工具。
> 能力.加载
*> quantum_circuit_new qubits=`比特数` steps=`步骤`*
## 哈达玛
+ `比特`=0
对选定线施加哈达玛,把计算基变成等权叠加,是贝尔态与 GHZ 制备的第一步。返回更新后的电路句柄,便于继续链式写法而不原地突变。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_h circuit=`self` qubit=`比特`*
## 泡利X
+ `比特`=0
对选定线施加泡利 X(比特翻转)。常用于从 |0⟩ 制备 |1⟩,或与相位门组成三明治。返回更新后的电路句柄以便继续链式调用。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_x circuit=`self` qubit=`比特`*
## 泡利Y
+ `比特`=0
对选定线施加泡利 Y,同时含比特翻转与相位。返回更新后的电路句柄,供作者程序继续链式组合。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_y circuit=`self` qubit=`比特`*
## 泡利Z
+ `比特`=0
对选定线施加泡利 Z(相位翻转)。常见于 H–Z–H 三明治以等效实现 X。返回更新后的电路句柄。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_z circuit=`self` qubit=`比特`*
## 相位S
+ `比特`=0
对选定线施加相位门 S(√Z)。返回更新后的电路句柄,便于讲义电路继续链式写法。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_s circuit=`self` qubit=`比特`*
## 相位T
+ `比特`=0
对选定线施加相位门 T(π/8)。返回更新后的电路句柄,便于讲义电路继续链式写法。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_t circuit=`self` qubit=`比特`*
## 单位
+ `比特`=0
对选定线施加单位门。在步骤表中作占位,或在噪声实验里作对照。返回更新后的电路句柄。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_i circuit=`self` qubit=`比特`*
## 绕X
+ `比特`=0
+ `参数`
绕 X 轴按角参数(弧度)旋转选定线。用于变分线路与连续单比特教学。返回更新后的电路句柄。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_rx circuit=`self` qubit=`比特` theta=`参数`*
## 绕Y
+ `比特`=0
+ `参数`
绕 Y 轴按角参数(弧度)旋转选定线。用于变分线路与连续单比特教学。返回更新后的电路句柄。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_ry circuit=`self` qubit=`比特` theta=`参数`*
## 绕Z
+ `比特`=0
+ `参数`
绕 Z 轴按角参数(弧度)旋转选定线。用于变分线路与连续单比特教学。返回更新后的电路句柄。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_rz circuit=`self` qubit=`比特` theta=`参数`*
## 控非
+ `控制`=0
+ `目标`=1
从控制位到目标位施加控非。贝尔态与 GHZ 制备中的标准纠缠步骤。返回更新后的电路句柄以便继续链式调用。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_cx circuit=`self` control=`控制` target=`目标`*
## 控相
+ `控制`=0
+ `目标`=1
在控制位与目标位之间施加控制 Z。产生相位纠缠且不翻转比特。返回更新后的电路句柄。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_cz circuit=`self` control=`控制` target=`目标`*
## 交换
+ `比特甲`=0
+ `比特乙`=1
交换比特甲与比特乙两根线。用于教学布局里重排逻辑比特。返回更新后的电路句柄。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_swap circuit=`self` a=`比特甲` b=`比特乙`*
## 屏障
仅记录可视化分隔,不改变理想态矢量。画电路轨线时用来分开讲义阶段。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_barrier circuit=`self`*
## 测量
+ `比特`=None
为后续运行标记计算基读出线。不坍缩概率所用的理想态。比特=None 表示标记全部线。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_measure circuit=`self` qubits=`比特`*
## 追加
+ `操作`
把另一电路的操作列,或门/比特记录表,追加到本电路。返回合并后的句柄,便于组合电路片段。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_append circuit=`self` op=`操作`*
## 施加
+ `门`
+ `比特`=0
把门句柄(具名或自定义酉矩阵)施加到比特(整数或列表)。返回更新后的电路句柄以便继续链式调用。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_apply circuit=`self` gate=`门` qubits=`比特`*
## 噪声
+ `种类`
+ `概率`
附着给定种类与强度的教学噪声,供运行轨迹使用。理想模拟与概率路径按设计会忽略该通道。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_noise circuit=`self` kind=`种类` p=`概率`*
## 模拟
返回当前电路的理想态矢量振幅(re/im)。此路径忽略已附着的教学噪声。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_simulate circuit=`self`*
## 态
返回与模拟相同振幅的理想态对象。后续保真度或密度工具若需要态句柄,优先用本方法。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_state circuit=`self`*
## 概率
基矢标签到理想概率的映射;比特 0 在最右侧。忽略教学噪声,结果与纯态矢量叙述一致。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_probabilities circuit=`self`*
## 运行
+ `次数`=1024
+ `种子`=1
对本电路做计算基采样。默认次数=1024、种子=1,便于复现。若已附着教学噪声则在轨迹中启用。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_run circuit=`self` shots=`次数` seed=`种子`*
## 绘图
+ `路径`=None
+ `种类`=circuit
+ `比特`=0
+ `主题`=dark
绘制电路轨线、概率条、布洛赫或高级密度图种的 SVG。主题为 dark、light、bw。可选路径落盘供 CLI 或 view 嵌入。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_draw_circuit circuit=`self` path=`路径` kind=`种类` qubit=`比特` theme=`主题`*
## 密度
对本电路理想模拟后构造纯态密度矩阵 ρ=|ψ⟩⟨ψ|。混合态与部分迹请改用密度模块工具。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_density_from_state state=`self`*
## 期望
+ `可观测量`
在本电路理想密度上计算泡利串(左端=高比特)或矩阵的期望值。忽略教学噪声。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_density_expect density=`self` obs=`可观测量`*
## 施密特
+ `分割`=1
对理想态做二分施密特分解。分割为子系统 A 的比特数,从低位起算。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_schmidt state=`self` cut=`分割`*
+159
View File
@@ -0,0 +1,159 @@
---
markup: occlusion
title: ext/quantum/量子
description: 量子扩展根 skill。请先读本文件。每个工具用 marqdo call 执行。
import:
态: ext/quantum/量子/态/索引.mq.md
门: ext/quantum/量子/门/索引.mq.md
电路: ext/quantum/量子/电路/索引.mq.md
模拟: ext/quantum/量子/模拟/索引.mq.md
密度: ext/quantum/量子/密度/索引.mq.md
可视化: ext/quantum/量子/可视化/索引.mq.md
---
本文件是 Marqdo 量子扩展的中文根 skill。若你是没有其它 Marqdo 上下文的智能体,
请先读「选哪条路」,再按「如何执行任意工具」操作。不要发明 MCP、Python 封装或
第二套 API。这些文件里的 ## 标题就是工具。
## 选哪条路
只选一行。不要混用中英工具名或目录树。(下表是叙述,不要写成 Marqdo 分支行。)
| 若你需要 | 这样做 |
|----------|--------|
| 只要贝尔态结果 | 对本文件调用 `贝尔态`(下节命令)。到此结束。 |
| 电路句柄以便继续(画图、噪声、再施门) | 照抄下方「电路模块」里的分步电路再模拟调用。全程同一 `--session`,并用 `--toget qc`。 |
| 英文工具名 | 改开 `ext/quantum/index.mq.md`,并留在英文树。 |
中文路径留在 `ext/quantum/量子/`(本树)。智能体请用 `##` 工具配
`marqdo call`。各模块文件里的 `# 电路` / `# 门` 对象面向作者程序导入,不是
默认的智能体路径。
*None*
## 如何执行任意工具
Marqdo 用下面的 shell 命令形状,从 Markdown 文件里运行一个函数。请原样复制,
再替换 FILE、FUNCTION 与参数。
调用示例(纯文本):
marqdo call FILE FUNCTION 名=值 名=值 --effects plugin --json
FILE 总是 ext/quantum/量子/ 下的路径,通常以 索引.mq.md 结尾。FUNCTION 是该文件中 ##
标题的精确名字(例如 新建、哈达玛、概率)。嵌套的 ### 用 parent.child 路径。
本包必须加 --effects plugin,因为模拟器是原生插件;不加会被拒绝。需要机器可读
结果时加 --json。若要在下一步复用返回值,加 --session 某id 与 --toget 名字
(或在命令末尾写 toget 名字)。之后参数可用 电路=$名字。插件句柄靠会话日志
跨进程重建。参数值可以是数字、引号文本、True/False/None、以 [ 或 { 开头的 JSON、
或 $名字。不要调用 确保插件 或任何 host 星号 API;领域文件会自行加载插件。
验证本包可用的最小命令(无工具参数):
调用示例(纯文本):
marqdo call ext/quantum/量子/索引.mq.md 贝尔态 --effects plugin --json
*None*
## 包布局
只打开你需要的模块。每个模块文件本身也是完整 skill,并重复说明如何 marqdo call。
路径 ext/quantum/量子/索引.mq.md 是本根地图与贝尔演示工具。
路径 ext/quantum/量子/电路/索引.mq.md 造线、施加哈达玛与控非,并定义作者对象「电路」。
路径 ext/quantum/量子/门/索引.mq.md 用公式写酉门,并构造具名或自定义门。
路径 ext/quantum/量子/模拟/索引.mq.md 给出振幅、概率与含噪采样。
路径 ext/quantum/量子/态/索引.mq.md 做张量积、保真度、施密特分解。
路径 ext/quantum/量子/密度/索引.mq.md 做密度算符与部分迹。
路径 ext/quantum/量子/可视化/索引.mq.md 画 SVG。
路径 ext/quantum/量子/能力/索引.mq.md 仅加载插件,供排查用。
作者程序在 frontmatter 用「导入」引入相同路径,再写 模块.成员。例如导入电路:
ext/quantum/量子/电路/索引.mq.md,然后用 电路.电路 构造对象,或用 电路.新建 供智能体
marqdo call。
*None*
## 电路模块
文件路径:ext/quantum/量子/电路/索引.mq.md
需要电路句柄时用本模块。两比特贝尔态典型智能体序列(每行一条 shell 命令):
调用示例(纯文本):
marqdo call ext/quantum/量子/电路/索引.mq.md 新建 比特数=2 --effects plugin --session s1 --toget qc --json
marqdo call ext/quantum/量子/电路/索引.mq.md 哈达玛 电路=$qc 比特=0 --effects plugin --session s1 --toget qc --json
marqdo call ext/quantum/量子/电路/索引.mq.md 控非 电路=$qc 控制=0 目标=1 --effects plugin --session s1 --toget qc --json
该文件主要 ## 工具:新建、哈达玛、控非、屏障、测量标记。同文件还有作者对象电路。
*None*
## 门模块
文件路径:ext/quantum/量子/门/索引.mq.md
调用示例(纯文本):
marqdo call ext/quantum/量子/门/索引.mq.md 哈达玛 --effects plugin --json
主要 ## 工具:哈达玛、泡利X、泡利Z、控非门、自定义、匹配。
*None*
## 模拟模块
文件路径:ext/quantum/量子/模拟/索引.mq.md
调用示例(纯文本):
marqdo call ext/quantum/量子/模拟/索引.mq.md 概率 电路=$qc --effects plugin --session s1 --json
主要 ## 工具:模拟、态、概率、运行、噪声。
*None*
## 态模块
文件路径:ext/quantum/量子/态/索引.mq.md
调用示例(纯文本):
marqdo call ext/quantum/量子/态/索引.mq.md 保真度 a=$psi b=$phi --effects plugin --json
主要 ## 工具:张量积、保真度、施密特分解。
*None*
## 密度模块
文件路径:ext/quantum/量子/密度/索引.mq.md
调用示例(纯文本):
marqdo call ext/quantum/量子/密度/索引.mq.md 从态 态=$qc --effects plugin --toget rho --json
*None*
## 可视化模块
文件路径:ext/quantum/量子/可视化/索引.mq.md
调用示例(纯文本):
marqdo call ext/quantum/量子/可视化/索引.mq.md 画电路 电路=$qc 路径="bell.svg" --effects plugin --session s1 --json
*None*
## 贝尔态
本索引上的一键编排工具,无参数。在比特 0 上哈达玛再控非 0→1,返回理想基矢概率。
只要演示结果时用本工具;需要中间句柄时用上面的分步 call。
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 基矢标签到概率的映射 |
精确命令:
调用示例(纯文本):
marqdo call ext/quantum/量子/索引.mq.md 贝尔态 --effects plugin --json
**qc = > 电路.新建 比特数=2 步骤=None**
**qc = > 电路.哈达玛 电路=`qc` 比特=0**
**qc = > 电路.控非 电路=`qc` 控制=0 目标=1**
*> 模拟.概率 电路=`qc`*
+40
View File
@@ -0,0 +1,40 @@
---
markup: occlusion
title: ext/quantum/量子/能力
description: 量子 ABI 加载 skill。日常请用电路/门/模拟等模块。
import:
plugin: lib/plugin.mq.md
sys: lib/sys.mq.md
---
本文件仍是 skill 与工具面。它只负责加载原生 quantum 插件。日常作者程序与智能体
应调用电路、门、模拟等模块(它们会替你加载)。仅在排查插件是否安装时打开本页。
## 给智能体
若你只拿到本文件,请用下面命令检查插件。日常工作请改调电路或模拟模块。
调用示例(纯文本):
marqdo call ext/quantum/量子/能力/索引.mq.md 加载 --effects plugin --json
*None*
## 加载
通过 plugin.native_path 找到 ABI v2 quantum 共享库,再 plugin.load。若缺失则打印
安装提示并以非零退出。成功后本进程内可用 quantum_* 符号。本包中只有这里应直接
接触 lib/plugin。领域模块在需要模拟器的工具开头调用加载。
本工具无参数。
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 加载成功后为空 |
**p = > plugin.native_path name="quantum"**
1. `p`
> plugin.load path=`p`
2. *
> print text=ext/quantum/量子: 未找到原生 quantum 插件(请 build marqdo_plugin_quantum 或 marqdo ext add quantum)
> sys.exit code=1
****
+140
View File
@@ -0,0 +1,140 @@
---
markup: occlusion
title: ext/quantum/量子/门
description: 量子门 skill — 公式酉矩阵、具名门、矩阵核对。
import:
能力: ext/quantum/量子/能力/索引.mq.md
---
门是作用在一个或多个比特上的酉变换。本 skill 先写矩阵含义,再构造门句柄。
电路施加门;本页定义门是什么。
## 给智能体
若你只拿到本文件,用 marqdo call 调用 ## 工具,必须加 --effects plugin。
调用示例(纯文本):
marqdo call ext/quantum/量子/门/索引.mq.md 哈达玛 --effects plugin --json
作者程序也可使用本文件中的对象「门」。
*None*
## 哈达玛
哈达玛门把计算基变成等权叠加。本工具返回名为 H 的门句柄。
本工具无参数。
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 哈达玛门句柄 |
> 能力.加载
*> quantum_gate_new name="H" theta=None matrix=None*
## 泡利X
泡利 X 是比特翻转门。
本工具无参数。
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 泡利 X 句柄 |
> 能力.加载
*> quantum_gate_new name="X" theta=None matrix=None*
## 泡利Z
泡利 Z 给 ket-one 乘上负号相位。
本工具无参数。
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 泡利 Z 句柄 |
> 能力.加载
*> quantum_gate_new name="Z" theta=None matrix=None*
## 控非门
两比特受控非门句柄。施到线路上时请用电路模块并写明控制位与目标位。
本工具无参数。
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | CNOT 门句柄 |
> 能力.加载
*> quantum_gate_new name="CX" theta=None matrix=None*
## 自定义
用显式酉矩阵 `矩阵` 构造门。可选标签 `名`="U"。
| 参数 | 类型 | 说明 |
|------|------|------|
| 矩阵 | any | 酉矩阵公式或列表 |
| 名 | text | 可选标签,默认 U |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | any | 自定义门句柄 |
> 能力.加载
*> quantum_gate_new name=`名` theta=None matrix=`矩阵`*
## 匹配
检查 `门` 是否在容差 `容差`=0.000000001 内匹配 `矩阵`。
| 参数 | 类型 | 说明 |
|------|------|------|
| 门 | any | 门句柄 |
| 矩阵 | any | 期望酉矩阵 |
| 容差 | number | 绝对容差 |
| 返回 | 类型 | 说明 |
|------|------|------|
| result | bool | 匹配则为 True |
> 能力.加载
*> quantum_gate_matches_matrix gate=`门` matrix=`矩阵` tol=`容差`*
# 门
+ `名`=None
+ `参数`=None
+ `矩阵`=None
具名内置门(名=H)或由矩阵=(嵌套 list 或公式矩阵围栏)定义的自定义酉门。自定义门可选名=(默认 U)。作者链式与智能体 ## 工具共用本对象面。
本构造返回可供链式调用的句柄,与同文件 ## 工具共用能力.加载 路径。作者程序写对象方法链;智能体优先 marqdo call 上方工具。
> 能力.加载
*> quantum_gate_new name=`名` theta=`参数` matrix=`矩阵`*
## 矩阵
返回本门句柄的显式酉矩阵,便于检查元素,或在公式构造自定义门后交给匹配矩阵验收。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_gate_matrix gate=`self`*
## 匹配矩阵
+ `矩阵`
+ `容差`=0.000000001
检查本门是否在绝对容差内容差内匹配给定矩阵。讲义里用公式围栏造门后,常用本方法做数值验收。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_gate_matches_matrix gate=`self` matrix=`矩阵` tol=`容差`*
## 绘图
+ `路径`=None
+ `种类`=gate
绘制门符号或复矩阵热力图(种类=gate 或 matrix)。可选路径落盘;亦经 record_plot 进入本会话的 view/CLI 图面。
本方法把领域意图写进句柄并返回结果,便于作者程序继续组合;智能体若只需单步操作也可改调同文件上方对应的 ## 工具与 marqdo call。参数默认值写在 + 形参行;调用时只覆盖需要改的项即可。
*> quantum_gate_draw gate=`self` path=`路径` kind=`种类`*