Skip to Content

Hamiltonian Simulation

hamiltonian_simulation() approximates the time-evolution operator . The unified entry point selects among seven algorithm families and returns a common result-object structure.

Minimal example

import numpy as np from unitarylab.library import hamiltonian_simulation H = np.array([[0, 1], [1, 0]], dtype=float) result = hamiltonian_simulation( H, t=0.5, method="trotter", target_error=1e-3, steps=20, order=1, backend="torch", device="cpu", ) print(result.circuit) print(result.total_error) print(result.evolution_result)

Entry signature

hamiltonian_simulation( H, t, method="trotter", target_error=1e-6, backend="torch", device="cpu", dtype=np.complex128, **kwargs )

H must be a finite Hermitian square matrix, t must be finite, and target_error must be positive. If the dimension is not , the matrix is zero-padded to the next power of two and a notice is emitted; result matrices can still be read at the original dimension.

Methods and method-specific parameters

methodUseMethod-specific parameters and defaults
trotterDeterministic product formulaorder=1, steps=1000
qdriftRandom sampling of Pauli termssteps=5000
taylorTaylor/Chebyshev approximationdegree=5
qsp / qsvtSignal transformation with block encodingdegree=15, beta=0.7, block_encoding_method="nagy"
bessel-lcuBessel expansion and LCUNo method-specific parameters
cartan-laxCartan–Lax flow for real symmetric matricesevol_time, lr, max_steps, reps
cartan-optimizationNumerical Cartan optimization for real symmetric matricesevol_time, lr, max_steps, optimizer

Pass only keyword arguments supported by the selected method. Unknown methods or unsupported parameters raise ValueError. Cartan methods require a real symmetric input matrix.

Result object

HamiltonianSimulationResult provides these lazy properties:

PropertyDescription
.circuitConstruct and cache the simulation circuit
.evolution_resultApproximate evolution matrix represented by the circuit
.total_errorOperator error between exact and the approximation

Accessing a lazy property performs the corresponding construction or matrix calculation. .total_error is the actual approximation error; target_error is the requested accuracy. Do not assume all methods strictly guarantee the requested value in the same way.

Scale recommendations

  • Start with or matrices to check methods and parameters.
  • steps, degree, and input dimension can increase circuit length; state-vector and matrix computations grow exponentially with qubit count.
  • For reproducible experiments, set a seed through the parameters supported by methods that use randomness.
  • If only the circuit is needed, avoid accessing .evolution_result or .total_error in advance.
Last updated on