API Usage Overview
Overview
This page is a navigation guide for the unitarylab_algorithms/ library, summarizing the class names, import paths, key parameters, and .test() signatures of all available algorithms.
This page is not a complete auto-generated API reference. Its purpose is to help you quickly locate the algorithm you need and understand how to call it.
BaseAlgorithm — Shared Base Class
The algorithm classes in the six packages cryptology, fundamental_algorithm, hamiltonian_simulation, linear_algebra, quantum_machine_learning, and state_preparation all inherit from unitarylab_algorithms.algo_base.BaseAlgorithm (the schrodingerization package uses its own separate schrodingerization.base.BaseAlgorithm, and its returned dictionary shape is also different — see the Schrödingerization Methods section for details). Every algorithm instance has the following methods:
| Method | Description |
|---|---|
.run(*args, **kwargs) | Executes the algorithm and returns Dict[str, Any] (the base class itself raises NotImplementedError; implemented by subclasses) |
.log(message) | Prints the message and appends it to the internal log; when passed a dict, prints each entry in - key = value format (not appended to self.info) |
.update_input(input_dict) | Merges into self.input, and prints "Starting {name}" along with the parameter list |
.update_output(output_dict) | Merges into self.output, and prints the output information list |
.save_circuit(circuit, name=None) | Saves the circuit SVG and returns the full file path (when name is not specified, the filename is generated from the algorithm name) |
.save_txt() | Writes the content of format_result_ascii() to a text file and returns only the filename (without the directory, unlike save_circuit) |
.format_result_ascii() | Formats the status/input/log/output/summary as text according to text_mode ('plain' or 'legacy') |
._build_return_dict(success, circuit_path, filepath, circuit=None) | Internal use: constructs {"status": "ok"/"failed", "circuit_path": ..., "plot": [...], "circuit": ...}, and merges in self.output; the "format" field of each item in plot is the last 3 characters of the filename (not an explicitly declared extension) |
Algorithm Index by Category
Cryptology
| Class | Import Path | Key Parameters |
|---|---|---|
DiscreteLogAlgorithm | unitarylab_algorithms.cryptology.discrete_log.algorithm | g, y, P |
ShorAlgorithm | unitarylab_algorithms.cryptology.shor.algorithm | N, method, max_retries |
SimonAlgorithm | unitarylab_algorithms.cryptology.simon.algorithm | s |
Fundamental Quantum Algorithms
| Class | Import Path | Key Parameters |
|---|---|---|
AmplitudeAmplificationAlgorithm | unitarylab_algorithms.fundamental_algorithm.amplitude_amplification.algorithm | U, good_zero_qubits, p, reps |
AmplitudeEstimationAlgorithm | unitarylab_algorithms.fundamental_algorithm.amplitude_estimation.algorithm | U, good_zero_qubits, d |
GroverAlgorithm | unitarylab_algorithms.fundamental_algorithm.grover.algorithm | n, target |
HadamardTestAlgorithm | unitarylab_algorithms.fundamental_algorithm.hadamard_test.algorithm | mode, U, prepare_psi, prepare_phi, imag, shots |
HadamardTransformAlgorithm | unitarylab_algorithms.fundamental_algorithm.hadamard_transform.algorithm | n, mode |
QPEAlgorithm | unitarylab_algorithms.fundamental_algorithm.qpe.algorithm | U, d, prepare_target |
Hamiltonian Simulation
| Class | Import Path | Key Parameters |
|---|---|---|
CartanDecompositionAlgorithm | unitarylab_algorithms.hamiltonian_simulation.cartan.algorithm | H, t, error |
QDriftAlgorithm | unitarylab_algorithms.hamiltonian_simulation.qdrift.algorithm | H, t, error, steps |
QSPHSAlgorithm | unitarylab_algorithms.hamiltonian_simulation.qsp.algorithm | H, t, error, degree, beta |
TaylorAlgorithm | unitarylab_algorithms.hamiltonian_simulation.taylor.algorithm | H, t, error, degree |
TrotterAlgorithm | unitarylab_algorithms.hamiltonian_simulation.trotter.algorithm | H, t, error, order, steps |
Linear Algebra
| Class | Import Path | Key Parameters |
|---|---|---|
AQCAlgorithm | unitarylab_algorithms.linear_algebra.aqc.algorithm | n, T, p, backend, device, dtype (does not accept user-defined A/b; internally generated using a fixed np.random.seed(42) — see Linear Algebra Algorithms for details) |
HHLAlgorithm | unitarylab_algorithms.linear_algebra.hhl.algorithm | A, b, d |
LCUAlgorithm | unitarylab_algorithms.linear_algebra.lcu.algorithm | alphas, unitaries, n_sys, initial_state |
QFTAlgorithm | unitarylab_algorithms.linear_algebra.qft.algorithm | n, state, inverse |
QSPAlgorithm | unitarylab_algorithms.linear_algebra.qsp.algorithm | t, d, x |
QSVTLinearSolverAlgorithm | unitarylab_algorithms.linear_algebra.qsvt_qlsa.algorithm | A, b, epsilon |
VQLSAlgorithm | unitarylab_algorithms.linear_algebra.vqls.algorithm | A, b, cost_function='local_ht', n_layers=4, maxiter=500, tol=1e-6, seed=42, epsilon=None, backend/device/dtype |
Quantum Machine Learning
| Class | Import Path | Key Parameters |
|---|---|---|
CVQNNAlgorithm | unitarylab_algorithms.quantum_machine_learning.cvqnn.algorithm | x_train, y_train, n_layers, cutoff, epochs, lr |
FermiHubbardVQEAlgorithm | unitarylab_algorithms.quantum_machine_learning.fermi_hubbard_vqe.algorithm | params, L, t, U, B, layers, max_iter, seed, measure_shots, backend, device, dtype |
QAOAAlgorithm | unitarylab_algorithms.quantum_machine_learning.qaoa.algorithm | edges, n, layers, max_iter |
QCBMAlgorithm | unitarylab_algorithms.quantum_machine_learning.qcbm.algorithm | n, layers, epochs, lr |
VQCAlgorithm | unitarylab_algorithms.quantum_machine_learning.vqc.algorithm | layers, epochs, lr, batch_size |
VQEAlgorithm | unitarylab_algorithms.quantum_machine_learning.vqe.algorithm | n, layers, max_iter, seed, hamiltonian, normalize |
State Preparation
| Class | Import Path | Key Parameters |
|---|---|---|
MottonenAlgorithm | unitarylab_algorithms.state_preparation.mottonen.algorithm | Psi, target_qubits, target_error |
MultiplexerAlgorithm | unitarylab_algorithms.state_preparation.multiplexer.algorithm | Psi, target_qubits, target_error |
MPSAlgorithm | unitarylab_algorithms.state_preparation.mps.algorithm | Psi, target_qubits, target_error, mps, work_wires, right_canonicalize, mps_max_bond_dim, rng_seed |
PauliAlgorithm | unitarylab_algorithms.state_preparation.pauli.algorithm | Psi, target_qubits, target_error |
SuperpositionAlgorithm | unitarylab_algorithms.state_preparation.Superposition.algorithm | Psi, target_qubits, target_error |
See State Preparation Algorithms for details, which includes 9 package-level discrepancy notes such as the backend/device/dtype parameters, and inconsistencies between the target_error default value and parameters.json (MPS, Superposition).
Schrödingerization (PDE Solvers)
| Class | Import Path | Notes |
|---|---|---|
AdvectionEquationAlgorithm | unitarylab_algorithms.schrodingerization.equation_advection.algorithm | 1D linear advection |
HeatEquationAlgorithm | unitarylab_algorithms.schrodingerization.equation_heat.algorithm | 1D heat diffusion |
Heat2dEquationAlgorithm | unitarylab_algorithms.schrodingerization.equation_heat2d.algorithm | 2D heat diffusion |
.test() Quick Reference
Most algorithm modules provide a standalone test() function that can be used to quickly run a default example or verify that the algorithm is available:
# Run using built-in defaults — no need to instantiate the class
from unitarylab_algorithms.fundamental_algorithm.grover.algorithm import test
test()
from unitarylab_algorithms.cryptology.shor.algorithm import test
test(N=15, method='matrix', max_retries=15)
from unitarylab_algorithms.linear_algebra.hhl.algorithm import test
test(A=[[0.8, 0], [0, 0.4]], b=[1, 2], d=11)
from unitarylab_algorithms.quantum_machine_learning.vqe.algorithm import test
test(n=2, layers=2, max_iter=150)
from unitarylab_algorithms.state_preparation.mottonen.algorithm import test
test(Psi=[1, 0, 0, 1], target_qubits=2, target_error=1e-6)Common Usage Patterns
Passing a Circuit Object
Algorithms such as QPE, LCU, and Amplitude Amplification accept a Circuit object from unitarylab:
from unitarylab.core import Circuit
from unitarylab_algorithms import QPEAlgorithm
# Build a unitary circuit whose phase we want to estimate
U = Circuit(1)
U.t(0) # T gate has phase π/4
algo = QPEAlgorithm()
result = algo.run(U=U, d=4)Passing a Hamiltonian Matrix
Hamiltonian simulation algorithms accept a NumPy array or a 2D Python list:
import numpy as np
from unitarylab_algorithms import TrotterAlgorithm
H = np.array([[2, 1], [1, 3]])
algo = TrotterAlgorithm()
result = algo.run(H=H, t=1.0, error=1e-8, order=1, steps=1000)