How-To & Examples
recipes · 12 examplesPractical recipes for common NWO-ASM workflows. Every example is self-contained — copy, save as a .nwo file, run nwo-asm build, and you've got something working. Local-only recipes require no credentials.
setup for a guided walkthrough, or troubleshoot for common fixes.
The three-line loop
Every NWO-ASM workflow reduces to three commands. Anything more advanced is a flag on one of these.
Twelve worked examples
Every example below is real, runnable code. Click any to expand. Tagged by skill level and what they touch.
Hello, process matrix
Smallest possible NWO-ASM program: declare a module, hold a 1-qubit identity matrix, emit. CPU-only. No credentials.
module hello { output r : pmx[1] r = pmx.identity() }
Anomaly score on a signal
Read a NumPy array, score it with the free-energy bound, print the result. Runs locally on CPU.
use metastate.anomaly module ascore { input s : f32[N] output v : f32 v = anomaly.score(s) }
Closed-form fit (eml)
Fit a symbolic expression to data — useful when you'd rather hold a small equation than a giant tensor.
use metastate.symbolic module fit { input xs : f32[N] input ys : f32[N] output e : expr e = symbolic.regress(xs, ys) }
Route to QPU (with classical fallback)
Build a 2-qubit process matrix and route it through MetaState; QPU if available, GPU if not.
use metastate.quantum module qroute { input e : expr output h : handle h = quantum.route(pmx.lift(e), { prefer: qpu, fallback: gpu, }) }
Proof of Inference
Have the substrate re-verify your inference and return a signed proof. Auditable by anyone.
use metastate.poi module verify { input h : handle output p : proof p = poi.verify(h) # signed (PQC) }
Anchor a proof on Base
Prepare the calldata that settles through the existing splitter — 35/35/30, plus 15% to your affiliate if set.
use metastate.anchor module settle { input p : proof output c : calldata c = anchor.prepare(p, usdc(base)) # no new contract }
Dry-run before spending
Simulate the full dispatch locally to see expected cost and routing without touching any backend.
nwo-asm dispatch app.qasm3 --dry-run --explain → would route to: qpu (origin_wukong, expected 42ms) → estimated cost: $0.0008 USDC → no on-chain calls executed
Contribute GPU and earn
Run the nwo-agi client and let the network rent your idle GPU. Earns USDC paid through the same splitter.
# one-liner install pip install nwo-agi nwo-agi start --wallet 0xYourBaseAddress → node registered: NODE-0xC7…2A → accepting tasks · health 100%
Open a Portal from the terminal
Use the built-in terminal to bind a Portal to a wallet and watch its live metrics.
# inside the NWO ASM Terminal nwo> portal.new qpu → opened PRT-0x5C41 on qpu · per-call USDC nwo> portal.health PRT-0x5C41 → PRT-0x5C41 · health 100% · latency 21ms · throughput 2.4 M/s
Set an affiliate address
Earn 15% of every call routed through a link you share. Configure once in nwo-asm.toml; payouts are on-chain.
[settlement] affiliate = "0xYourBaseAddress" # 15% of every settled call
Sign a build for provenance
Attach a CRYSTALS-Dilithium signature so consumers can verify the artifact you produced.
nwo-asm build app.nwo --sign → app.qasm3 → app.qasm3.sig (dilithium3, key ~/.nwo-asm/keys/identity)
Embed in Rust
Use NWO-ASM from inside a Rust app — same compiler, same dispatch, same settlement.
use nwo_asm::{Compile, Dispatch}; use metastate_client::Base; let art = Compile::build("signal.nwo")?; let res = Dispatch::new(art) .target("qpu") .settle(Base::usdc()) .send()?; println!("proof: {}", res.proof);
A few patterns worth knowing
Set a budget
The optimizer can run forever finding placements. budget_ms = 800 in config caps it; deterministic builds get a fixed budget.
Always dry-run first
Before paying for a live dispatch, use --dry-run --explain. It prints the placement, the proof, and the expected USDC cost — without spending anything.
Pin a backend
Override the optimizer when you need reproducibility: --backend qpu:origin_wukong. The build still verifies that backend can host your IR.
Use the keychain
Store secrets in your OS keychain instead of .env: nwo-asm key store IBM_QUANTUM_TOKEN. The toolchain reads it transparently.
What the recipes use
| Layer | Tech | Notes |
|---|---|---|
| Language | NWO-ASM source · process matrices · causal coherence | MIT-licensed, embeddable. |
| CLI | nwo-asm binary · subcommands: new · build · dispatch · key · doctor | Self-contained. |
| Library | Rust crate nwo-asm · client crate metastate-client | For embedded use. |
| Substrate | MetaState endpoints · A2A Agent Card | Live; opt-in. |
| Compute mesh | nwo-agi client (Python) | Optional; earn by contributing GPU. |
| Settlement | MetaStateSplitter on Base 8453 | Existing audited contract; no new deploy. |