Algorithm Guide¶
The SparQ algorithm stack has two layers that mirror each other:
C++ layer (
SparQ_Algorithm/): production implementations composed from the core operators, rendered per header in the C++ API Reference.Python layer (
pysparq.algorithms): pure-Python counterparts used for rapid prototyping and cross-validation, auto-documented in the API tree below.
Each algorithm below lists its Python entry points, the C++ header it replicates, and where to see it running. The line-level correspondence between the two layers is documented in the algorithm porting guide.
Grover Search¶
QRAM-oracle-driven Grover search with amplitude amplification and quantum counting.
Python:
GroverOperator,GroverOracle,grover_search(),grover_count()C++:
grover.hin the algorithm libraryBuilding blocks: the diffusion step is the reflection primitive from phase and reflection operators; the oracle marks states conditionally (conditional operations)
Try it: the custom-oracle example in Dynamic Operator Extension
Shor’s Factoring¶
Shor factoring (standard and semiclassical variants) built on modular multiplication.
C++:
shor.hin the algorithm libraryBuilding blocks: arithmetic operators (modular add/mul) and QFT
Quantum Linear Systems (QDA)¶
Discrete-adiabatic quantum linear-system solvers built on block encoding and state preparation.
Python:
qda_solve(),qda_solve_tridiagonal(),qda_solve_via_qram(), plus the orchestration classesWalkS,LCU,BlockEncoding, andStatePreparationBuilding blocks: block encoding (below); the step-size/condition-number hyperparameters are introduced in Operators
Production: the Poiseuille benchmark
Experiment_PoiseuilleQDABench_cuda(Experiments/QDA/QDA_Poiseuille/) validates the tridiagonal path up to 2^20 dimensions on a single A800, including the dimension-adaptive--czEpsClearZero threshold — verification recorddocs/verification/v1d-qda-linsolver-a800.md
Hamiltonian Simulation (CKS)¶
Hamiltonian simulation via quantum walk / LCU / sparse-matrix oracle, with the CKS experiment as the reference implementation.
Python:
TOperator,QuantumWalkNStepsinpysparq.algorithms.cks_solverC++:
hamiltonian_simulation.hin the algorithm library (theTstate-preparation operator andSparseMatrixOracle1live here); for constant-diagonal tridiagonal matrices the QRAM-free direct-oracle path lives inhamiltonian_simulation_tridiagonal.h(same page), validated at 2^20 dimensions on a single A800 (docs/verification/v1e-cks-direct-oracle-linsolver.md)Related: the quantum-walk dynamic operator example in Dynamic Operator Extension
Block Encoding¶
Encodes a classical matrix into a larger unitary — the core subroutine of the linear-system and Hamiltonian-simulation algorithms above.
Python:
BlockEncodingTridiagonal,BlockEncodingViaQRAMinpysparq.algorithms.block_encodingC++: Block Encoding
Try it: Example 4 in the Examples guide (tridiagonal walkthrough with runnable code) and the Block Encoding section of the operator usage notebook
State Preparation¶
QRAM-based preparation of arbitrary target states from |0⟩.
Python:
StatePrepViaQRAM,StatePreparationC++:
state_preparation.hin the algorithm libraryBuilding blocks: rotation and state preparation operators and QRAM operators