Some checks failed
no-vanity-metrics / Scan committed Markdown for vanity metrics (push) Has been cancelled
standards workspaces build + test / aac-rs (push) Has been cancelled
standards workspaces build + test / arl-rs (push) Has been cancelled
standards workspaces build + test / eoc-rs (push) Has been cancelled
standards workspaces build + test / jcp-rs (push) Has been cancelled
standards workspaces build + test / joule-code-rs (push) Has been cancelled
standards workspaces build + test / joule-ui-rs (push) Has been cancelled
standards workspaces build + test / jouleclaw-rs (push) Has been cancelled
standards workspaces build + test / joulecontract-rs (push) Has been cancelled
standards workspaces build + test / jouledesk-rs (push) Has been cancelled
standards workspaces build + test / joulehook-rs (push) Has been cancelled
standards workspaces build + test / map-rs (push) Has been cancelled
standards workspaces build + test / mesh-rs (push) Has been cancelled
standards workspaces build + test / openpay (push) Has been cancelled
standards workspaces build + test / proof-rs (push) Has been cancelled
standards workspaces build + test / sandbox-rs (push) Has been cancelled
standards workspaces build + test / sense-rs (push) Has been cancelled
standards workspaces build + test / smart-byte-rs (push) Has been cancelled
Everything in this crate carried a pure state. That runs circuits, but it cannot do quantum information science, because the interesting objects there are not pure: throw away half of an entangled pair and what remains is not a state vector at all. It is a mixture, and its entropy is the entire point. quantum_info adds the density matrix, the partial trace that produces one, purity, exact Pauli expectations for arbitrary strings, and CHSH. It stays in the simulator's fixed point, so a reduced state carries a portable hash like everything else — two machines agree on the mixture, not on a rendering of it. The tests are the statements worth making. Half a Bell pair comes back maximally mixed with purity exactly one half and no off-diagonal coherence, which is the fact no state vector can express and the reason the module exists. A product state's half stays pure. And CHSH on the Bell state reaches 2√2: past the bound of 2 that binds any local hidden-variable account of the world, and exactly at Tsirelson's, which quantum theory itself cannot exceed. It is computed from exact Pauli expectations rather than sampled, so the violation is arithmetic and not statistics. Also adds runnable examples — bell, threshold, receipt — because a crate with 22 features whose entire learning surface was one README snippet is not accessible, whatever its API docs say. One test of mine was wrong and is now right: mixing a state with itself returns it numerically, not bit-for-bit, since halving twice rounds twice. Demanding an identical hash there was demanding that fixed-point division be lossless. 224 tests pass. Co-Authored-By: Claude Opus 5 <[email protected]>
37 lines
1.5 KiB
Rust
37 lines
1.5 KiB
Rust
//! Sealing a computation into a signed, energy-accounted receipt — and watching
|
|
//! verification reject a doctored one.
|
|
//!
|
|
//! cargo run --example receipt
|
|
|
|
use wai_quantum::ed25519_dalek::SigningKey;
|
|
use wai_quantum::quantum::Measure;
|
|
use wai_quantum::quantum_receipt::QuantumReceipt;
|
|
use wai_quantum::quantum_toolchain as qt;
|
|
|
|
fn main() {
|
|
let circuit = qt::ghz(3);
|
|
let key = SigningKey::from_bytes(&[42u8; 32]); // demo key; use a real one
|
|
|
|
let receipt = QuantumReceipt::seal(
|
|
&key,
|
|
"did:key:example",
|
|
&circuit,
|
|
Some(Measure { seed: 7, shots: 4096 }),
|
|
0, // measured microjoules; 0 means unmetered
|
|
None,
|
|
)
|
|
.expect("seal");
|
|
|
|
println!("verifies {}", receipt.verify());
|
|
println!("re-simulates to claim {}", receipt.verify_reconstruction(&circuit));
|
|
println!("work {} amplitude updates", receipt.work_amp_updates);
|
|
println!("energy {} uJ (0 = unmetered)", receipt.joules_micro);
|
|
|
|
// The work is recomputable by anyone from (n_qubits, n_ops), so a sink cannot
|
|
// inflate it. The energy is only as good as the signature, and says so.
|
|
let json = receipt.to_json();
|
|
let tampered = json.replace("\"work_amp_updates\":24", "\"work_amp_updates\":2400");
|
|
assert_ne!(json, tampered, "expected the work field in the JSON");
|
|
let forged = QuantumReceipt::from_json(&tampered).expect("still parses");
|
|
println!("\nclaiming 100x the work: verifies = {}", forged.verify());
|
|
}
|