quantum_planning/lib.rs
1//! # Quantum planning
2//!
3//! Quantum algorithms for planning and search, on simulators: Grover search, quantum backtracking, amplitude estimation, quantum walks on game trees and QAOA.
4//!
5//! ## Scope
6//!
7//! - A state-vector simulator ([`StateVector`]) with `H`, `X`, `Z`, phase and multi-controlled
8//! `Z` gates, measurement probabilities and seeded sampling over any [`rand_core::Rng`]
9//! - Grover search over candidate plans, with phase oracles ([`PhaseOracle`]) built from
10//! validity checks, for a known ([`grover::search_known`]) and an unknown
11//! ([`grover::search_unknown`], BBHT) number of solutions
12//! - Quantum backtracking (Montanaro) as a quantum walk on search trees (planned)
13//! - Amplitude estimation for Monte Carlo value estimates, as used in MCTS rollouts (planned)
14//! - Quantum-walk evaluation of game trees (NAND trees) (planned)
15//! - QAOA circuits for QUBO-encoded planning problems (planned)
16//! - Query-count comparisons against the classical algorithms
17//!
18//! ## Query count
19//!
20//! The algorithms count oracle queries, not simulator work: one application of a
21//! [`PhaseOracle`] is one query, and one classical check of a measured candidate is one
22//! query. Compare these counts with the queries of a classical scan.
23//!
24//! The crate is `no_std` and needs `alloc` for the amplitudes.
25//!
26//! Repository: <https://github.com/sunsided/quantum-planning>
27
28#![no_std]
29#![forbid(unsafe_code)]
30
31extern crate alloc;
32
33mod complex;
34pub mod grover;
35mod phase_oracle;
36mod rng;
37mod state;
38
39pub use complex::Complex;
40pub use phase_oracle::PhaseOracle;
41pub use rng::SplitMix64;
42pub use state::{MAX_QUBITS, StateVector, TooManyQubits};
43
44/// A predicate that marks valid candidates, the oracle of a quantum search.
45///
46/// The predicate must be pure: the same candidate always gets the same answer, since the
47/// algorithms count oracle queries.
48pub trait Oracle<Candidate> {
49 /// Whether `candidate` is a solution.
50 fn accepts(&self, candidate: &Candidate) -> bool;
51}
52
53/// A reference to an oracle is an oracle, so a [`PhaseOracle`] can borrow one.
54impl<Candidate, O: Oracle<Candidate> + ?Sized> Oracle<Candidate> for &O {
55 fn accepts(&self, candidate: &Candidate) -> bool {
56 (**self).accepts(candidate)
57 }
58}
59
60/// Doctests for the code examples in README.md (not part of the API).
61#[cfg(doctest)]
62#[doc = include_str!("../README.md")]
63mod readme_doctests {}