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 nine packages cryptology, fundamental_algorithm, hamiltonian_simulation, linear_algebra, quantum_chemistry, quantum_machine_learning, state_preparation, search, and quantum_transport inherit from unitarylab_algorithms.algo_base.BaseAlgorithm. schrodingerization uses its own base class and return shape; see Schrödingerization.
| 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) |
The shared base class does not create algo_dir. A class that inherits from it directly must supply and create a writable directory before calling save_circuit() or save_txt(); each current algorithm subclass fills in its own default result directory and calls os.makedirs(..., exist_ok=True) in __init__(). In addition, the filepath passed to _build_return_dict() must be a string or an iterable of filenames, not None.
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 |
Quantum Search
All four classes can be imported from unitarylab_algorithms.search or the root package and inherit from the shared BaseAlgorithm. See Quantum Search Algorithms for complete parameters, examples, and return fields.
| Class | Implementation module (prefix unitarylab_algorithms.search.) | Key Parameters |
|---|---|---|
GluedTreesAlgorithm | glued_trees.algorithm | qubits, times, repetitions, order |
HiddenShiftAlgorithm | hidden_shift.algorithm | qubits, shift, measurement_mode |
QuantumWalkSearchAlgorithm | quantum_walk_search.algorithm | num_vertices, marked, graph_json, gamma, evolution_time |
QuantumBacktrackingAlgorithm | quantum_backtracking.algorithm | problem_json, phase_bits, threshold |
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 |
IsingAlgorithm | unitarylab_algorithms.quantum_machine_learning.ising.algorithm | rows, cols, coupling_J, field_h, time_step, trotter_steps, trotter_order, max_bond, cutoff, routing, seed, sample_shots, local_configuration_mode |
IsingAlgorithm is exported by its category package and included in the root __all__, so it can be imported directly by name. See Quantum Machine Learning.
Quantum Chemistry
| Class | Import Path | Key Parameters |
|---|---|---|
MolecularDMRGAlgorithm | unitarylab_algorithms.quantum_chemistry.molecular_dmrg.algorithm | xyz_file, basis, charge, multiplicity, active-space, DMRG/CVD, shots, seed, backend, device, dtype |
MolecularDMRGAlgorithm is included in the root __all__ and may be imported with from unitarylab_algorithms import MolecularDMRGAlgorithm. It requires the separate Chemistry package and supports Linux/macOS only. See Quantum Chemistry Algorithms.
Quantum Transport
| Class | Import Path | Key Parameters |
|---|---|---|
NEGFAlgorithm | unitarylab_algorithms.quantum_transport.negf.algorithm | L=4, W=4, a=1.0, t=1.0, inverse_tolerance=2e-3 |
NEGFAlgorithm is included in the root __all__ and can also be imported from unitarylab_algorithms.quantum_transport. run() does not accept backend, device, or dtype; it uses NumPy on CPU with np.complex128 internally. Execution requires Kwant. See Quantum Transport for parameters, return values, and QASM export limits.
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)
from unitarylab_algorithms.quantum_machine_learning.ising.algorithm import test
test(rows=2, cols=2, trotter_steps=2, local_configuration_mode="none")
from unitarylab_algorithms.quantum_chemistry.molecular_dmrg.algorithm import test
test(xyz_file="H2") # runs the complete, heavyweight Chemistry workflowCommon 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)