quantum-planning
Quantum algorithms for planning and search, on simulators: Grover search, quantum backtracking, amplitude estimation, quantum walks on game trees and QAOA.
Who this is for
- Researchers, students and teachers of quantum speedups for search: exact Grover search with a known number of solutions and BBHT exponential search with an unknown number, on a state-vector simulator. The oracle is an ordinary validity check on a candidate, such as "is this plan valid", so the same predicate serves a classical and a quantum search.
- Honest query-count comparisons: every phase-oracle application and every classical
check of a measured candidate counts as one query. Put these counts next to a classical
scan over the same oracle, and the
√NagainstNgap shows on real instances, not only in the formula. no_stddemos: the crate needs onlyalloc, so it runs in WebAssembly, for example in a browser page that shows the amplitudes change from one Grover iteration to the next.
It is a simulator: its memory doubles with each qubit and stops at 24 qubits, so it finds no solution faster than a classical search does. To solve plans, use heuristic-search for state-space search, constraint-search for constraint problems and game-tree-search for two-player games. Quantum backtracking, amplitude estimation, NAND-tree walks and QAOA on planning-qubo models are planned, not built yet.
Scope
- A state-vector simulator with
H,X,Z, phase and multi-controlledZgates, measurement probabilities and seeded sampling (little-endian: qubitqis bitqof the basis index) - Grover search over candidate plans, with phase oracles built from validity checks, for a known and an unknown (BBHT exponential search) number of solutions
- Quantum backtracking (Montanaro) as a quantum walk on search trees (planned)
- Amplitude estimation for Monte Carlo value estimates, as used in MCTS rollouts (planned)
- Quantum-walk evaluation of game trees (NAND trees) (planned)
- QAOA circuits for QUBO-encoded planning problems (planned)
- Query-count comparisons against the classical algorithms
The algorithms run on simulators and are measured in oracle and query counts against their classical counterparts, which limits instances to a few dozen qubits. QUBO models come from planning-qubo, oracles from constraint-search and game trees from game-tree-search.
Usage
An oracle marks the candidates that solve a problem; Grover search finds a marked one in
about π/4·√(N/M) oracle queries, where N candidates hold M marked ones. Here, a plan
picks two of four actions, and actions 0 and 1 must not run together.
use ;
use ;
/// Accepts plans, given as 4-bit masks over the actions, that run exactly two actions and
/// not both action 0 and action 1.
;
assert!;
assert!;
// Six plans run two actions; only one of them runs both action 0 and action 1.
let marked = .filter.count;
assert_eq!;
// Basis index `i` of a 4-qubit register is the plan with action mask `i`.
let plan = ;
let mut state = new.expect;
let mut rng = new;
// With 5 of 16 plans marked, one Grover iteration and one check find a valid plan with
// probability sin²(3θ) ≈ 0.96, where sin²θ = 5/16. `None` means: run it again.
let mut oracle = new;
if let Some = search_known
assert_eq!;
// Without the count, BBHT exponential search stops at the first verified plan or the budget.
let mut oracle = new;
let index = search_unknown.expect;
assert!;
The query counts count oracle calls, not simulator work: one phase-oracle application or one
classical check is one query. A classical scan needs about N/(M+1) queries; Grover search
needs about π/4·√(N/M).
The crate is no_std with alloc. It depends on libm and on rand_core: sampling and the
searches take any R: rand_core::Rng, and SplitMix64 is a small seeded one.
Minimum supported Rust version
Rust 1.85 (edition 2024). The MSRV applies to the library; tests may need a newer toolchain. It may be raised in a minor release when a dependency or a language feature calls for it.
Contributing
See CONTRIBUTING.md.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.