Skip to Content

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:

MethodDescription
.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

ClassImport PathKey Parameters
DiscreteLogAlgorithmunitarylab_algorithms.cryptology.discrete_log.algorithmg, y, P
ShorAlgorithmunitarylab_algorithms.cryptology.shor.algorithmN, method, max_retries
SimonAlgorithmunitarylab_algorithms.cryptology.simon.algorithms

Fundamental Quantum Algorithms

ClassImport PathKey Parameters
AmplitudeAmplificationAlgorithmunitarylab_algorithms.fundamental_algorithm.amplitude_amplification.algorithmU, good_zero_qubits, p, reps
AmplitudeEstimationAlgorithmunitarylab_algorithms.fundamental_algorithm.amplitude_estimation.algorithmU, good_zero_qubits, d
GroverAlgorithmunitarylab_algorithms.fundamental_algorithm.grover.algorithmn, target
HadamardTestAlgorithmunitarylab_algorithms.fundamental_algorithm.hadamard_test.algorithmmode, U, prepare_psi, prepare_phi, imag, shots
HadamardTransformAlgorithmunitarylab_algorithms.fundamental_algorithm.hadamard_transform.algorithmn, mode
QPEAlgorithmunitarylab_algorithms.fundamental_algorithm.qpe.algorithmU, d, prepare_target

Hamiltonian Simulation

ClassImport PathKey Parameters
CartanDecompositionAlgorithmunitarylab_algorithms.hamiltonian_simulation.cartan.algorithmH, t, error
QDriftAlgorithmunitarylab_algorithms.hamiltonian_simulation.qdrift.algorithmH, t, error, steps
QSPHSAlgorithmunitarylab_algorithms.hamiltonian_simulation.qsp.algorithmH, t, error, degree, beta
TaylorAlgorithmunitarylab_algorithms.hamiltonian_simulation.taylor.algorithmH, t, error, degree
TrotterAlgorithmunitarylab_algorithms.hamiltonian_simulation.trotter.algorithmH, t, error, order, steps

Linear Algebra

ClassImport PathKey Parameters
AQCAlgorithmunitarylab_algorithms.linear_algebra.aqc.algorithmn, 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)
HHLAlgorithmunitarylab_algorithms.linear_algebra.hhl.algorithmA, b, d
LCUAlgorithmunitarylab_algorithms.linear_algebra.lcu.algorithmalphas, unitaries, n_sys, initial_state
QFTAlgorithmunitarylab_algorithms.linear_algebra.qft.algorithmn, state, inverse
QSPAlgorithmunitarylab_algorithms.linear_algebra.qsp.algorithmt, d, x
QSVTLinearSolverAlgorithmunitarylab_algorithms.linear_algebra.qsvt_qlsa.algorithmA, b, epsilon
VQLSAlgorithmunitarylab_algorithms.linear_algebra.vqls.algorithmA, b, cost_function='local_ht', n_layers=4, maxiter=500, tol=1e-6, seed=42, epsilon=None, backend/device/dtype

Quantum Machine Learning

ClassImport PathKey Parameters
CVQNNAlgorithmunitarylab_algorithms.quantum_machine_learning.cvqnn.algorithmx_train, y_train, n_layers, cutoff, epochs, lr
FermiHubbardVQEAlgorithmunitarylab_algorithms.quantum_machine_learning.fermi_hubbard_vqe.algorithmparams, L, t, U, B, layers, max_iter, seed, measure_shots, backend, device, dtype
QAOAAlgorithmunitarylab_algorithms.quantum_machine_learning.qaoa.algorithmedges, n, layers, max_iter
QCBMAlgorithmunitarylab_algorithms.quantum_machine_learning.qcbm.algorithmn, layers, epochs, lr
VQCAlgorithmunitarylab_algorithms.quantum_machine_learning.vqc.algorithmlayers, epochs, lr, batch_size
VQEAlgorithmunitarylab_algorithms.quantum_machine_learning.vqe.algorithmn, layers, max_iter, seed, hamiltonian, normalize

State Preparation

ClassImport PathKey Parameters
MottonenAlgorithmunitarylab_algorithms.state_preparation.mottonen.algorithmPsi, target_qubits, target_error
MultiplexerAlgorithmunitarylab_algorithms.state_preparation.multiplexer.algorithmPsi, target_qubits, target_error
MPSAlgorithmunitarylab_algorithms.state_preparation.mps.algorithmPsi, target_qubits, target_error, mps, work_wires, right_canonicalize, mps_max_bond_dim, rng_seed
PauliAlgorithmunitarylab_algorithms.state_preparation.pauli.algorithmPsi, target_qubits, target_error
SuperpositionAlgorithmunitarylab_algorithms.state_preparation.Superposition.algorithmPsi, 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)

ClassImport PathNotes
AdvectionEquationAlgorithmunitarylab_algorithms.schrodingerization.equation_advection.algorithm1D linear advection
HeatEquationAlgorithmunitarylab_algorithms.schrodingerization.equation_heat.algorithm1D heat diffusion
Heat2dEquationAlgorithmunitarylab_algorithms.schrodingerization.equation_heat2d.algorithm2D 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)
Last updated on