All checks were successful
wai-quantum WebGPU member / member · DX12 and Vulkan (cbio-windows) (pull_request) Successful in 12m23s
joule-moq-room room service / joule-moq-room · does this change touch it (pull_request) Successful in 5s
joule-moq-web browser client / joule-moq-web · does this change touch it (pull_request) Successful in 6s
wai-quantum on every processor / emulated · aarch64-unknown-linux-gnu (pull_request) Successful in 1m47s
wai-quantum on every processor / emulated · armv7-unknown-linux-gnueabihf (pull_request) Successful in 2m49s
standards workspaces build + test / which workspaces this change touches (pull_request) Successful in 6s
WAI conformance / does this change touch it (pull_request) Successful in 7s
WAI energy receipts / does this change touch it (pull_request) Successful in 10s
WAI JPEG-AI whole decode (pinned inputs, required) / does this change touch it (pull_request) Successful in 7s
WAI neural sink gates / does this change touch it (pull_request) Successful in 11s
repository checks / lockfiles, tests in CI, workflow hygiene, spec and section references, public text (pull_request) Successful in 1m12s
wai-ops-gpu integer operators on GPUs / does this change touch it (pull_request) Successful in 10s
wai-pack / wai-pack · does this change touch it (pull_request) Successful in 8s
wai-quantum command line / does this change touch it (pull_request) Successful in 8s
wai-quantum dataflow member / does this change touch it (pull_request) Successful in 6s
wai-quantum CUDA member / does this change touch it (pull_request) Successful in 7s
wai-quantum signal processor / does this change touch it (pull_request) Successful in 5s
wai-quantum FPGA member / does this change touch it (pull_request) Successful in 7s
wai-quantum HIP member / does this change touch it (pull_request) Successful in 6s
wai-quantum Metal member / does this change touch it (pull_request) Successful in 5s
wai-quantum neural-processor member / does this change touch it (pull_request) Successful in 6s
wai-quantum npu-cores member / does this change touch it (pull_request) Successful in 7s
wai-quantum on every processor / emulated · loongarch64-unknown-linux-gnu (pull_request) Successful in 3m38s
wai-quantum OpenCL member / does this change touch it (pull_request) Successful in 6s
wai-quantum CUDA member / member · CUDA (jetson-hub) (pull_request) Successful in 27s
wai-quantum-qpu / does this change touch it (pull_request) Successful in 7s
wai-quantum HIP member / member · HIP (framework-128gb) (pull_request) Successful in 20s
wai-quantum service / does this change touch it (pull_request) Successful in 6s
wai-quantum matrix-extension member / does this change touch it (pull_request) Successful in 7s
wai-quantum studio and desktop / does this change touch it (pull_request) Successful in 6s
wai-quantum tensor-engine member / does this change touch it (pull_request) Successful in 7s
wai-quantum CPU vector units / does this change touch it (pull_request) Successful in 5s
wai-quantum portable tensor program / does this change touch it (pull_request) Successful in 6s
wai-quantum OpenCL member / member · OpenCL GPU and CPU (jetson-hub) (pull_request) Successful in 24s
wai-quantum WebGPU member / does this change touch it (pull_request) Successful in 5s
WAI mbt2018_mean integer decode (regenerated vectors) / does this change touch it (pull_request) Successful in 5s
wai-web wasm32 / does this change touch it (pull_request) Successful in 5s
wai-quantum portable tensor program / tensor program · GPUs (jetson-hub) (pull_request) Successful in 15s
wai-quantum npu-cores member / member · npu-cores, neural processor (framework-128gb silicon) (pull_request) Successful in 1m13s
wai-quantum OpenCL member / member · OpenCL GPU (framework-128gb) (pull_request) Successful in 13s
wai-quantum CPU vector units / member · vector units, avx2 and avx512 (framework-128gb silicon) (pull_request) Successful in 10s
wai-quantum portable tensor program / tensor program · integrated GPU (framework-128gb) (pull_request) Successful in 8s
joule-moq-room room service / joule-moq-room, every target (pull_request) Successful in 1m3s
wai-quantum on every processor / emulated · powerpc64-unknown-linux-gnu (pull_request) Successful in 5m25s
wai-quantum on every processor / emulated · powerpc64le-unknown-linux-gnu (pull_request) Successful in 6m1s
wai-quantum on every processor / emulated · riscv64gc-unknown-linux-gnu (pull_request) Successful in 4m2s
wai-quantum WebGPU member / member · integrated GPU, Vulkan (framework-128gb) (pull_request) Successful in 7m37s
wai-quantum on every processor / emulated · s390x-unknown-linux-gnu (pull_request) Successful in 4m8s
wai-quantum on every processor / emulated · sparc64-unknown-linux-gnu (pull_request) Successful in 6m16s
wai-web reach builds / wai-web reach · does this change touch it (pull_request) Successful in 7s
wai-quantum on every processor / emulated · i686-unknown-linux-gnu (pull_request) Successful in 4m10s
wai-quantum WebGPU member / member · discrete GPU, Vulkan (jetson-hub) (pull_request) Successful in 20m25s
WAI conformance / quantum core and corpus under wasm32-wasip2 (wasmtime) (pull_request) Successful in 2m2s
WAI conformance / cross-arch byte-equality · linux (pull_request) Successful in 27s
WAI energy receipts / energy receipts · linux (pull_request) Successful in 10m17s
WAI conformance / cargo-class corpora · linux (pull_request) Successful in 18m12s
WAI neural sink gates / model-free refusals of the neural sink (pull_request) Successful in 1m24s
wai-ops-gpu integer operators on GPUs / builds · no adapter is not a pass (linux) (pull_request) Successful in 1m45s
wai-pack / wai-pack · linux (pull_request) Successful in 1m20s
wai-quantum command line / command line · linux (pull_request) Successful in 1m7s
WAI JPEG-AI whole decode (pinned inputs, required) / fetch pinned JPEG-AI inputs → whole decode + pixel hash, required (pull_request) Successful in 6m57s
wai-quantum CUDA member / member · CUDA absent (linux) (pull_request) Successful in 24s
wai-quantum dataflow member / member · dataflow device, simulated (pci 1e52:b140) (pull_request) Successful in 3m25s
wai-quantum dataflow member / member · dataflow device, simulated (pci 1e52:401e) (pull_request) Successful in 4m35s
wai-quantum FPGA member / member · FPGA simulation absent (linux) (pull_request) Successful in 21s
wai-quantum Metal member / member · Metal absent (linux) (pull_request) Successful in 26s
wai-quantum neural-processor member / member · neural processor absent (linux) (pull_request) Successful in 26s
wai-quantum OpenCL member / member · OpenCL absent (linux) (pull_request) Successful in 21s
wai-quantum-qpu / clients against their contracts (linux) (pull_request) Successful in 20s
wai-quantum service / service · linux (pull_request) Successful in 39s
wai-quantum matrix-extension member / member · matrix extension, emulated (aarch64 Linux) (pull_request) Successful in 19s
wai-quantum studio and desktop / studio · browser (pull_request) Successful in 3m23s
wai-quantum signal processor / processor and member · signal processor, emulated (pull_request) Successful in 14m8s
wai-quantum CPU vector units / member · vector unit, rvv 1024-bit (riscv64, emulated) (pull_request) Successful in 19s
wai-quantum CPU vector units / member · vector unit, sve 128-bit (aarch64, emulated) (pull_request) Successful in 28s
wai-quantum CPU vector units / member · vector unit, rvv 128-bit (riscv64, emulated) (pull_request) Successful in 14s
wai-quantum CPU vector units / member · vector unit, sve 2048-bit (aarch64, emulated) (pull_request) Successful in 10s
wai-quantum tensor-engine member / member · tensor engine, the kernel toolchain's simulator (linux) (pull_request) Successful in 8m5s
wai-quantum CPU vector units / member · vector unit, avx2 (x86_64 silicon) (pull_request) Successful in 15s
wai-quantum CPU vector units / member · vector unit, sve 512-bit (aarch64, emulated) (pull_request) Successful in 12s
wai-quantum portable tensor program / tensor program · CPU, mutants, GPU builds (pull_request) Successful in 29s
standards workspaces build + test / joule-code-rs (joule-code/joule-code-rs, joule-code-rs, linux-arm64, true) (pull_request) Successful in 3m12s
wai-quantum WebGPU member / member · software Vulkan (linux) (pull_request) Successful in 2m9s
wai-quantum WebGPU member / shader checks · browser build · wasip2 inertness · MSRV (pull_request) Successful in 3m13s
wai-web wasm32 / wai-web wasm32 build · corpus, menu and writers (pull_request) Successful in 4m18s
WAI mbt2018_mean integer decode (regenerated vectors) / regenerate mbt2018_mean integer vectors → Rust decode, required (pull_request) Successful in 5m22s
WAI conformance / v2 vocabulary · manifests validate as stated (pull_request) Successful in 15s
wai-web reach builds / wai-web reach builds · the package of record, every output as recorded (pull_request) Successful in 2m23s
WAI conformance / cargo-class corpora · linux-arm64 (pull_request) Successful in 15m0s
WAI conformance / delivery telemetry · CMCD and CMSD against an independent library (pull_request) Successful in 12s
WAI conformance / cross-arch byte-equality · linux-arm64 (pull_request) Successful in 26s
WAI conformance / C2PA manifest emission · signed, read back, validated (pull_request) Successful in 1m36s
wai-web reach builds / wai-web reach builds · this tree's wai-web, every rung on its engine line (pull_request) Successful in 4m35s
WAI energy receipts / energy receipts · linux-arm64 (pull_request) Successful in 6m54s
wai-pack / wai-pack · linux-arm64 (pull_request) Successful in 1m14s
wai-pack / wai-pack · the floor through a media prober (pull_request) Successful in 24s
wai-pack / wai-pack · dependency licences (pull_request) Successful in 1m18s
wai-quantum HIP member / member · HIP absent (linux-arm64) (pull_request) Successful in 25s
joule-moq-web browser client / joule-moq-web · browser end-to-end (macos) (pull_request) Successful in 6m16s
wai-quantum npu-cores member / member · npu-cores absent (linux-arm64) (pull_request) Successful in 23s
wai-quantum tensor-engine member / member · tensor engine absent (linux-arm64) (pull_request) Successful in 19s
wai-pack / wai-pack · independent verifier (Python) (pull_request) Successful in 4m8s
WAI conformance / independent verifiers · claims, JWP, key discovery and integer payloads (Python) (pull_request) Successful in 35m22s
standards workspaces build + test / macOS energy backends (pull_request) Successful in 8m33s
WAI conformance / cargo-class corpora · macos (pull_request) Successful in 14m16s
WAI conformance / cross-arch byte-equality · macos (pull_request) Successful in 23s
WAI conformance / codec wrappers · fuzz smoke, text decode limits, C entry points, provenance, the semantic path (pull_request) Successful in 54s
WAI energy receipts / energy receipts · macos (pull_request) Successful in 6m14s
wai-ops-gpu integer operators on GPUs / Metal GPU and browser WebGPU (macos) (pull_request) Successful in 3m12s
wai-pack / wai-pack · macos (pull_request) Successful in 1m3s
wai-quantum command line / command line · macos (pull_request) Successful in 28s
wai-quantum dataflow member / member · dataflow device absent (macos) (pull_request) Successful in 14s
wai-quantum FPGA member / member · FPGA datapath, simulated (macos) (pull_request) Successful in 1m13s
wai-quantum Metal member / member · Metal (macos) (pull_request) Successful in 29s
wai-quantum neural-processor member / member · neural processor (macos) (pull_request) Successful in 5m49s
wai-quantum OpenCL member / member · OpenCL GPU (macos) (pull_request) Successful in 29s
wai-quantum service / service · macos (pull_request) Successful in 44s
wai-quantum matrix-extension member / member · matrix extension absent (macos) (pull_request) Successful in 9s
wai-quantum studio and desktop / desktop app · macos (pull_request) Successful in 2m12s
wai-quantum CPU vector units / member · vector unit absent (macos) (pull_request) Successful in 13s
wai-quantum portable tensor program / tensor program · Metal and the arm64 CPU (macos) (pull_request) Successful in 15s
wai-quantum WebGPU member / member · Metal (macos) (pull_request) Successful in 4m26s
wai-quantum WebGPU member / member · browser WebGPU (macos) (pull_request) Successful in 1m43s
This carries 0.6.13, which was not published on its own, and 0.6.14. ## 0.6.13 The engine is the microscope and the judge, a local model is a muse that waits to be asked, and the reader is the author. Every figure is the engine's. Nothing changes the reader's program until they apply a change. engine::critique gives a program's measures before it runs: - gates by kind; one-, two- and three-qubit gates; T gates; gates off the Clifford angles; - depth and two-qubit depth, and whether it is a Clifford circuit; - a fidelity at reference error rates, named as a model. It also gives the program's smells, each with its lines and operations: gates that cancel, rotations that merge or do nothing, idle qubits, and qubits never measured. critique::variants rewrites the program's own text with the smells fixed, all of them to a fixed point and each one alone. Each candidate carries its measures and the equivalence verdict; one the check finds different is never offered. engine::equiv compares two programs up to a global phase: - by tableau for Clifford circuits, at any size; - otherwise on every basis state, to 8 qubits; - otherwise on random product states, to 22 qubits, which is evidence, not proof; - otherwise unchecked, with the reason. qasm::parse_lines gives each operation's line, and draw::layout each gate's operation index. engine::shortcuts lists every exact classical route the engine knows, priced on the program, and names the cheapest for each question: - the stabilizer tableau; - the cut-rank sum; - an exact matrix product state, at a bond bounded by the operator Schmidt ranks of the gates crossing each cut. The bound is held by a test against the true Schmidt ranks of random circuits; - the light cone; - a tensor-network contraction, when asked to be thorough; - the state vector. A cheap route proves a design classically easy; none being cheap proves nothing. On the 70-qubit random graph-state circuit the quick check finds the cut-rank sum (widest cut 30) in under 2 s. The thorough one finds widest cut 29 in about 4 minutes. Quantum Studio gains: - the critique, always on under the diagram, with the smells flagged on it, Show and Fix; - the classical cost, on request; - Alternatives: Improve (the engine's rewrites and the model's, each checked) and Explore (the model's different circuits, each measured and compared), with an atlas and Apply; - Predict first, which sets the reader's expected outcome against the run; - an assistant that asks questions first and speaks only when asked, offering (never sending) a hint when allowed. Its new tools are critique_qasm, check_equivalent and classical_shortcuts. wai-web exports the four engine calls. The desktop app answers them natively. wai-quantum-cli 0.1.1 adds critique, equivalent (exit 0/1/2), improve and shortcuts, with four MCP tools. examples/cutrank_qasm gains probs: the exact 2^n·p of given bit strings, with their linear cross-entropy. ## 0.6.14 A deep circuit on a line, contracted qubit by qubit along time, keeps a boundary of only the bonds between two neighbouring qubits: about half the depth for a controlled-Z brickwork. The contraction search rarely found that tree on its own. - Network::amplitude_split_placed builds the same network as amplitude_split, index for index, with each index's place in the circuit: a qubit and a time. - tensor_places, sweep_orders and sweep_path turn the places into the trees that sweep qubit by qubit, or time by time. - find_path_seeded and find_path_restarts_seeded score such trees beside the trials and polish the best of them all alike. A seed that is not a tree of the network is ignored. - The engine's tensor_network method and the thorough shortcut lens take both sweeps as seeds. On the 70-qubit random graph-state circuit, one amplitude's largest intermediate falls from 2^48 to 2^36, and its multiply-adds from 2^56.1 to 2^48.7, in the thorough lens. With 16 trials and no seeds the search finds 2^59. The pinned plans in tests/bit_identity.rs call find_path itself and are unchanged. The job service answers four design checks: POST /v1/critique, /v1/equivalent, /v1/improve and /v1/shortcuts, with the matching MCP tools. They run in its own process within bounds: - each counts against the client's submissions; - at most two run at once, and one that waits ten seconds is refused with a 503; - equivalence work past 4e9 gate amplitudes, and a thorough search, are refused with a 422 naming the local command. The smoke script checks each one. It now follows a job that outlasts /v1/run's wait, as a client does, instead of failing on a loaded host. wai-quantum-cli 0.1.2 carries the faster contraction. Co-Authored-By: Claude Opus 5.5 <[email protected]>
203 lines
11 KiB
Rust
203 lines
11 KiB
Rust
//! A Clifford circuit with one closing layer of single-qubit gates, read
|
||
//! from OpenQASM 2, summed exactly by `quantum_cutrank`.
|
||
//!
|
||
//! ```text
|
||
//! cargo run --release --example cutrank_qasm --features quantum_cutrank -- FILE cuts
|
||
//! cargo run --release --example cutrank_qasm --features quantum_cutrank -- FILE amplitudes N [SEED]
|
||
//! cargo run --release --example cutrank_qasm --features quantum_cutrank -- FILE sample N [SEED]
|
||
//! cargo run --release --example cutrank_qasm --features quantum_cutrank -- FILE probs STRINGS [qiskit|q0]
|
||
//! ```
|
||
//!
|
||
//! `probs` reads one bit string per line from STRINGS (as a device's samples)
|
||
//! and prints each one's `2^n · p`, then their mean and the linear cross-entropy
|
||
//! `2^n · mean(p) − 1` with its standard error. `qiskit` (the default) reads a
|
||
//! string with qubit n−1 first, as Qiskit writes it; `q0` with qubit 0 first.
|
||
//!
|
||
//! The bulk takes `h s sdg sx x y z cx cz swap`; a qubit's closing layer
|
||
//! starts at its first non-Clifford gate (`t tdg rz rx ry p u u3`) and may hold
|
||
//! any single-qubit gates. `2^n · p` is printed per bit string: for exact
|
||
//! samples of a state whose probabilities follow Porter–Thomas its mean is
|
||
//! about 2 (a linear cross-entropy of about 1).
|
||
|
||
use std::time::Instant;
|
||
use wai_quantum::gates::{C, complex};
|
||
use wai_quantum::quantum_cutrank::{Precision, ProductMeasured, Unitary};
|
||
use wai_quantum::quantum_tableau::{Clifford, Tableau};
|
||
|
||
fn mul(a: &Unitary, b: &Unitary) -> Unitary {
|
||
let m = |x: C, y: C| complex(x.re * y.re - x.im * y.im, x.re * y.im + x.im * y.re);
|
||
let add = |x: C, y: C| complex(x.re + y.re, x.im + y.im);
|
||
[add(m(a[0], b[0]), m(a[1], b[2])), add(m(a[0], b[1]), m(a[1], b[3])), add(m(a[2], b[0]), m(a[3], b[2])), add(m(a[2], b[1]), m(a[3], b[3]))]
|
||
}
|
||
|
||
fn one_qubit(name: &str, p: &[f64]) -> Option<Unitary> {
|
||
let c = complex;
|
||
let r = std::f64::consts::FRAC_1_SQRT_2;
|
||
let e = |x: f64| c(x.cos(), x.sin());
|
||
let (o, one) = (c(0.0, 0.0), c(1.0, 0.0));
|
||
Some(match name {
|
||
"h" => [c(r, 0.0), c(r, 0.0), c(r, 0.0), c(-r, 0.0)],
|
||
"x" => [o, one, one, o],
|
||
"y" => [o, c(0.0, -1.0), c(0.0, 1.0), o],
|
||
"z" => [one, o, o, c(-1.0, 0.0)],
|
||
"s" => [one, o, o, c(0.0, 1.0)],
|
||
"sdg" => [one, o, o, c(0.0, -1.0)],
|
||
"t" => [one, o, o, e(std::f64::consts::FRAC_PI_4)],
|
||
"tdg" => [one, o, o, e(-std::f64::consts::FRAC_PI_4)],
|
||
"sx" => [c(0.5, 0.5), c(0.5, -0.5), c(0.5, -0.5), c(0.5, 0.5)],
|
||
"rz" | "p" | "u1" => {
|
||
let t = p[0];
|
||
if name == "rz" { [e(-t / 2.0), o, o, e(t / 2.0)] } else { [one, o, o, e(t)] }
|
||
}
|
||
"rx" => {
|
||
let (cs, sn) = ((p[0] / 2.0).cos(), (p[0] / 2.0).sin());
|
||
[c(cs, 0.0), c(0.0, -sn), c(0.0, -sn), c(cs, 0.0)]
|
||
}
|
||
"ry" => {
|
||
let (cs, sn) = ((p[0] / 2.0).cos(), (p[0] / 2.0).sin());
|
||
[c(cs, 0.0), c(-sn, 0.0), c(sn, 0.0), c(cs, 0.0)]
|
||
}
|
||
_ => return None,
|
||
})
|
||
}
|
||
|
||
fn main() {
|
||
let args: Vec<String> = std::env::args().collect();
|
||
let (path, mode) = (&args[1], args[2].as_str());
|
||
let count: usize = args.get(3).and_then(|s| s.parse().ok()).unwrap_or(4);
|
||
let seed: u64 = args.get(4).and_then(|s| s.parse().ok()).unwrap_or(1);
|
||
let src = std::fs::read_to_string(path).expect("the file reads");
|
||
let mut n = 0u32;
|
||
let mut bulk = Vec::new();
|
||
let mut last: Vec<Unitary> = Vec::new();
|
||
let mut closing: Vec<bool> = Vec::new();
|
||
let id = [complex(1.0, 0.0), complex(0.0, 0.0), complex(0.0, 0.0), complex(1.0, 0.0)];
|
||
for line in src.lines().map(str::trim).filter(|l| !l.is_empty()) {
|
||
let line = line.trim_end_matches(';');
|
||
if let Some(rest) = line.strip_prefix("qreg q[") {
|
||
n = rest.trim_end_matches(']').parse().unwrap();
|
||
last = vec![id; n as usize];
|
||
closing = vec![false; n as usize];
|
||
continue;
|
||
}
|
||
if line.starts_with("OPENQASM") || line.starts_with("include") || line.starts_with("creg") || line.starts_with("barrier") || line.starts_with("measure") {
|
||
continue;
|
||
}
|
||
let (head, args) = line.split_once(' ').expect("a gate and its qubits");
|
||
let (name, params): (&str, Vec<f64>) = match head.split_once('(') {
|
||
Some((n, p)) => (n, p.trim_end_matches(')').split(',').map(|x| x.trim().parse().expect("a numeric angle")).collect()),
|
||
None => (head, Vec::new()),
|
||
};
|
||
let qs: Vec<u32> = args.split(',').map(|a| a.trim().trim_start_matches("q[").trim_end_matches(']').parse().unwrap()).collect();
|
||
let a = qs[0];
|
||
let non_clifford = matches!(name, "t" | "tdg" | "rz" | "rx" | "ry" | "p" | "u1");
|
||
if qs.len() == 1 && (closing[a as usize] || non_clifford) {
|
||
closing[a as usize] = true;
|
||
let u = one_qubit(name, ¶ms).unwrap_or_else(|| panic!("gate {name}"));
|
||
last[a as usize] = mul(&u, &last[a as usize]);
|
||
continue;
|
||
}
|
||
assert!(qs.iter().all(|&q| !closing[q as usize]), "a gate on {qs:?} after its closing layer began: {line}");
|
||
bulk.push(match (name, qs.as_slice()) {
|
||
("h", _) => Clifford::H(a),
|
||
("s", _) => Clifford::S(a),
|
||
("sdg", _) => Clifford::Sdg(a),
|
||
("sx", _) => Clifford::SX(a),
|
||
("x", _) => Clifford::X(a),
|
||
("y", _) => Clifford::Y(a),
|
||
("z", _) => Clifford::Z(a),
|
||
("cx", [_, b]) => Clifford::CX(a, *b),
|
||
("cz", [_, b]) => Clifford::CZ(a, *b),
|
||
("swap", [_, b]) => Clifford::Swap(a, *b),
|
||
_ => panic!("not a bulk gate: {line}"),
|
||
});
|
||
}
|
||
let t0 = Instant::now();
|
||
let mut pm = ProductMeasured::new(&Tableau::run(n, &bulk).unwrap(), &last).unwrap();
|
||
// CUTRANK_ORDER=FILE: an order (as `order` prints it) to sum in.
|
||
if let Ok(path) = std::env::var("CUTRANK_ORDER") {
|
||
let text = std::fs::read_to_string(&path).expect("the order file reads");
|
||
let line = text.lines().find(|l| l.starts_with("order: ")).expect("an `order: [...]` line");
|
||
let order: Vec<usize> = line["order: ".len()..].trim_matches(|c| c == '[' || c == ']').split(',').map(|x| x.trim().parse().unwrap()).collect();
|
||
pm = pm.with_order(&order).expect("a permutation of the qubits");
|
||
}
|
||
println!("{n} qubits, {} bulk gates; graph form and cuts in {:?}", bulk.len(), t0.elapsed());
|
||
println!("cut-ranks: {:?}", pm.cut_ranks());
|
||
println!("max cut {} bits: a table of {} entries ({} GiB at f64)", pm.max_cut(), 1u64 << pm.max_cut(), (16u64 << pm.max_cut()) >> 30);
|
||
let limit = std::env::var("CUTRANK_MAX").ok().and_then(|s| s.parse().ok()).unwrap_or(32);
|
||
let precision = if std::env::var("CUTRANK_PRECISION").as_deref() == Ok("single") { Precision::Single } else { Precision::Double };
|
||
println!("tables at {precision:?}: the largest {} GiB", pm.table_bytes(precision) >> 30);
|
||
for (kind, passes, entries) in pm.passes() {
|
||
println!(" {kind:8} {passes:3} passes, {:.2}e9 entries", entries as f64 / 1e9);
|
||
}
|
||
let scale = (n as f64).exp2();
|
||
// `order N`: anneal the order for the least work, Σ 2^cut.
|
||
let cost = |c: &[usize]| c.iter().map(|&k| (k as f64).exp2()).sum::<f64>();
|
||
match mode {
|
||
"cuts" => {}
|
||
"order" => {
|
||
let t0 = Instant::now();
|
||
let best_order = pm.anneal_order(count, seed);
|
||
let best = cost(pm.clone().with_order(&best_order).unwrap().cut_ranks());
|
||
let b = pm.clone().with_order(&best_order).unwrap();
|
||
println!("annealed {count} moves in {:?}: work Σ2^cut {best:.3e} (natural {:.3e}), max cut {}", t0.elapsed(), cost(pm.cut_ranks()), b.max_cut());
|
||
println!("cuts: {:?}", b.cut_ranks());
|
||
println!("order: {best_order:?}");
|
||
}
|
||
"amplitudes" => {
|
||
let mut s = seed;
|
||
for i in 0..count {
|
||
let x: Vec<bool> = (0..n).map(|_| {
|
||
s = s.wrapping_add(0x9e37_79b9_7f4a_7c15);
|
||
let mut z = s;
|
||
z = (z ^ (z >> 30)).wrapping_mul(0xbf58_476d_1ce4_e5b9);
|
||
(z ^ (z >> 27)) & 1 == 1
|
||
}).collect();
|
||
let t = Instant::now();
|
||
let a = pm.amplitude_in(&x, limit, precision).unwrap();
|
||
println!("amplitude {i}: {a:?}, 2^n·p = {:.6}, in {:?}", scale * (a.re * a.re + a.im * a.im), t.elapsed());
|
||
}
|
||
}
|
||
"sample" => {
|
||
let t = Instant::now();
|
||
let samples = pm.sample_in(count, seed, limit, precision).unwrap();
|
||
let el = t.elapsed();
|
||
let mean = samples.iter().map(|(_, p)| scale * p).sum::<f64>() / samples.len() as f64;
|
||
// CUTRANK_OUT=FILE: every sample, `bits 2^n·p` a line (qubit 0 first).
|
||
if let Ok(out) = std::env::var("CUTRANK_OUT") {
|
||
let text: String = samples.iter().map(|(x, p)| format!("{} {:.9}\n", x.iter().map(|&b| if b { '1' } else { '0' }).collect::<String>(), scale * p)).collect();
|
||
std::fs::write(&out, text).expect("the samples write");
|
||
}
|
||
for (x, p) in samples.iter().take(8) {
|
||
let bits: String = x.iter().map(|&b| if b { '1' } else { '0' }).collect();
|
||
println!("{bits} 2^n·p = {:.6}", scale * p);
|
||
}
|
||
println!("{count} samples in {el:?} ({:?} each); mean 2^n·p = {mean:.4}, linear XEB = {:.4}", el / count as u32, mean - 1.0);
|
||
}
|
||
// `probs FILE [qiskit|q0]`: the exact 2^n·p of each bit string in FILE (one
|
||
// a line; `qiskit`, the default: the first character is qubit n−1, as
|
||
// Qiskit prints counts; `q0`: the first is qubit 0), and their linear
|
||
// XEB, 2^n·mean(p) − 1, with its standard error. `count` is unused.
|
||
"probs" => {
|
||
let file = args.get(3).expect("a file of bit strings");
|
||
let qiskit = args.get(4).map(|s| s.as_str()) != Some("q0");
|
||
let text = std::fs::read_to_string(file).expect("the bit strings read");
|
||
let t = Instant::now();
|
||
let mut v = Vec::new();
|
||
for (i, line) in text.lines().map(str::trim).filter(|l| !l.is_empty()).enumerate() {
|
||
assert_eq!(line.len(), n as usize, "line {i}: {} characters, not {n}", line.len());
|
||
let c: Vec<bool> = line.bytes().map(|b| b == b'1').collect();
|
||
let x: Vec<bool> = (0..n as usize).map(|q| if qiskit { c[n as usize - 1 - q] } else { c[q] }).collect();
|
||
let a = pm.amplitude_in(&x, limit, precision).unwrap();
|
||
let w = scale * (a.re * a.re + a.im * a.im);
|
||
println!("{line} {w:.9}");
|
||
v.push(w);
|
||
}
|
||
let m = v.len() as f64;
|
||
let mean = v.iter().sum::<f64>() / m;
|
||
let var = v.iter().map(|w| (w - mean) * (w - mean)).sum::<f64>() / (m - 1.0).max(1.0);
|
||
println!("{} strings ({}) in {:?}: mean 2^n·p = {mean:.4}, linear XEB = {:.4} ± {:.4}", v.len(), if qiskit { "qubit n-1 first" } else { "qubit 0 first" }, t.elapsed(), mean - 1.0, (var / m).sqrt());
|
||
}
|
||
other => panic!("mode {other}"),
|
||
}
|
||
}
|