Module 08 · Computational Laboratory

How do we calculate realistic spin dynamics with limited computational resources?

Scientifically correct equations can still produce unreliable results if Hilbert-space growth, numerical propagation, or stochastic sampling is mishandled. We connect representation choices and convergence tests to observable-level accuracy.

How this follows: The biological examples demand realistic Hamiltonians and trajectories. This chapter tests whether a chosen numerical strategy can actually support the prediction.

Learning objectives 3 outcomes · expand to view
01

Estimate Hilbert-, operator- and Liouville-space scaling before choosing a numerical method.

02

Understand when sparse/Krylov or state-vector methods avoid impossible dense representations.

03

Design convergence tests for timestep, stochastic trace samples, orientations and molecular ensembles.

01

Representation

Count the Hilbert space before choosing an algorithm

Physical meaning

The numerical representation is part of the physical modelling strategy

Hilbert space

What it is: The vector space containing all pure spin states. Its dimension is the product of the dimensions of the individual spins.

What it changes: It sets the size of state vectors and the fundamental cost of exact propagation.

What you observe: Not a laboratory observable; it determines whether a proposed simulation is computationally feasible.

Density matrix / Liouville space

What it is: The density matrix stores populations and coherences for ensembles or mixed states; vectorizing it creates a Liouville-space object of dimension \(D^2\).

What it changes: It makes relaxation and ensemble dynamics natural to express but increases memory and propagation cost dramatically.

What you observe: It is the numerical object from which populations, coherences and expectation values are calculated.

For independent spins \(I_k\), the Hilbert-space dimension is

\[ D=\prod_k(2I_k+1). \]

For \(N\) spin-\(\tfrac12\) particles this becomes \(D=2^N\). A state vector contains \(D\) complex amplitudes. A dense operator or density matrix contains \(D^2\) complex numbers. A dense Liouville-space superoperator would contain \(D^4\).

02

Interactive

See when dense representations become impossible

Interactive model

Spin-space scaling explorer

spin-\(\tfrac12\) model
Try this: increase the number of spins one at a time. Then compare a state vector, a dense operator and an explicitly stored Liouvillian. The difference is not subtle.
Hilbert dimension \(D\) 16,384 State vector 256 KiB Dense \(D\times D\) operator 4.00 GiB Dense \(D^2\times D^2\) Liouvillian 1.00 EiB Sampling standard-error factor 0.289 σ

At this size a state-vector method is still modest, while a dense operator is already expensive and a dense Liouvillian is completely impractical.

Sampling noise \(\propto1/\sqrt M\)1.0× baseline
number of spins log₁₀ bytes state operator L

Memory estimates assume 16 bytes per complex double. The Monte-Carlo number is \(\sigma/\sqrt M\): the standard error relative to the single-sample standard deviation, not a guaranteed relative error in the final observable.

03

Propagation strategies

Do not build a matrix just because the equation contains one

Physical meaning

Numerical efficiency comes from applying the generator without representing every zero explicitly

Sparsity

What it is: Most spin Hamiltonians contain local or few-spin terms, so many matrix elements in a product basis are exactly zero.

What it changes: Sparse storage and matrix–vector products can reduce memory and work dramatically compared with dense linear algebra.

What you observe: Much larger spin systems become tractable without changing the underlying physical Hamiltonian.

Krylov propagation

What it is: A method that approximates \(e^{-iHt}|\psi\rangle\) inside a low-dimensional subspace generated by repeated actions of \(H\) on the current state.

What it changes: It avoids constructing the full matrix exponential and concentrates effort on the part of Hilbert space explored during that step.

What you observe: Controlled propagation error with far lower memory cost for large sparse systems.

Integrator tolerance / timestep

What it is: A numerical accuracy parameter controlling how closely the discrete propagation follows the continuous equation of motion.

What it changes: Too coarse a step can distort phase, populations or decay even when the physical model is correct.

What you observe: A result that changes when \(\Delta t\) is halved is a numerical result that is not yet converged.

Dense diagonalization / exponentiation

Simple and accurate for small systems. Becomes memory- and compute-limited quickly as \(D\) grows.

Sparse / Krylov propagation

Exploit the action of \(H\) or a sparse generator on a vector without constructing a full matrix exponential.

State-vector trajectories

Propagate \(D\)-component vectors rather than \(D^2\)-component density matrices when an appropriate stochastic or pure-state formulation exists.

Operator-space propagation

Useful when the density matrix or superoperator structure is essential, but it requires more aggressive sparsity or symmetry exploitation.

ADV

Matrix-free thinking

You often need the action of an operator, not the operator itself

Krylov and related propagation methods exploit a simple numerical fact: to approximate \(e^{-iHt}|\psi\rangle\), it can be enough to evaluate repeated products \(H|\psi\rangle\) without ever constructing or storing the full matrix exponential. If \(H\) itself is sparse or can be applied as a sum of local spin operators, the memory saving can be enormous.

Closed-system checkVerify norm conservation and, when appropriate, energy conservation or reversibility.
Density-matrix checkVerify trace preservation and monitor Hermiticity; physical generators should not create obviously negative populations.
Observable checkConverge the quantity you report, not only an internal solver tolerance.
04

Trace sampling

Stochastic trace estimation trades memory for variance

Physical meaning

Random sampling here is a numerical approximation, not necessarily physical noise

Trace sampling

What it is: A Monte-Carlo estimator that approximates a high-dimensional trace by averaging expectation values over random vectors.

What it changes: It replaces an exact sum over a huge basis by a controllable statistical error that decreases roughly as \(M^{-1/2}\).

What you observe: Run-to-run sampling fluctuations and convergence of the final observable as the number of samples increases.

Physical stochasticity

What it is: Random trajectories used to represent environmental noise or a stochastic Schrödinger equation describe actual model dynamics rather than merely estimating a trace.

What it changes: They change the time evolution being modelled, not just how efficiently a deterministic quantity is evaluated.

What you observe: Noise-induced relaxation, dephasing or distribution of trajectories after ensemble averaging.

If random normalized states satisfy \(\mathbb E[\lvert r\rangle\langle r\rvert]=\mathbb I_D/D\), then the trace of an operator \(\hat A\) can be estimated as

\[ \operatorname{Tr}(\hat A) \approx \frac{D}{M} \sum_{m=1}^{M} \langle r_m|\hat A|r_m\rangle. \]

For independent, identically distributed samples with finite variance, the Monte Carlo standard error decreases asymptotically as \(M^{-1/2}\); the prefactor depends on the operator and sampling ensemble. Correlated or insufficiently mixed samples reduce the effective sample size, while an incorrectly normalized sampler can introduce bias. Twelve samples therefore do not imply a fixed percentage accuracy. Check the convergence of the actual observable against an independent benchmark where possible.

ADV

A habit worth keeping

Solve a tiny version exactly before trusting the large one

This is probably the least glamorous and most useful numerical trick in the whole library: make the model small enough that you know the answer. Then compare the clever method against that reference before scaling up.

Reduce the Hilbert spaceRemove nuclei or interactions until direct diagonalization or dense propagation is easy.
Take a known limitSet \(J=0\), make two \(g\)-values identical, remove relaxation, or choose a single uncoupled spin whose motion is analytic.
Compare observablesCheck the quantity you actually care about—population, yield, spectrum, polarization—not only an internal solver residual.
Add complexity backTurn on one ingredient at a time. When the answer changes, you know which piece caused it.
05

Convergence

Converge the observable, not just the propagator

A reliable numerical result should be tested against the knobs that can change it:

Timestep / integrator tolerancehalve \(\Delta t\) or tighten the tolerance and verify that the observable no longer changes appreciably.
Trace samplesrepeat with larger \(M\) and, ideally, independent random seeds to estimate sampling uncertainty.
Orientation gridpowder and anisotropic observables need converged angular averaging.
Trajectory ensemblefor dynamic Hamiltonians, convergence can be limited by molecular sampling rather than quantum propagation.

Plotting a result as a function of \(M\), \(\Delta t\), orientation count or trajectory number is much more informative than reporting one calculation and assuming it is converged.

For stochastic sampling, convergence should also carry an uncertainty estimate whenever possible. If independent samples give values \(x_m\), a practical standard error is

\[ \mathrm{SE}(\bar x) = \frac{s_x}{\sqrt{M}}, \]

where \(s_x\) is the sample standard deviation. Reporting \(M\) without the variance can be misleading: twelve exceptionally consistent samples can be more informative than one hundred highly variable ones, while correlated samples reduce the effective sample size.

06

MolSpin

Use the software as a laboratory, not a black box

MolSpin is designed around general spin systems and multiple propagation strategies. The important skill is not memorizing an input file; it is understanding which Hamiltonian, state, relaxation model, numerical method and observable the input represents.

For released syntax and examples, use the Software page and the public MolSpin documentation rather than copying teaching pseudocode from this lecture.

07

Selected reading

Methods behind the calculations

Stochastic state vectors

Spin Dynamics of Radical Pairs Using the Stochastic Schrödinger Equation in MolSpin

State-vector propagation and stochastic methods for large radical-pair spin systems.

J. Chem. Theory Comput. (2024) →
Open-system propagation

Modeling spin relaxation in complex radical systems using MolSpin

Relaxation theory and practical density-matrix spin dynamics.

J. Comput. Chem. (2023) →
L

Key external literature

Further reading

These are deliberately selected from outside my own work: foundational papers or reviews that are especially useful for this topic.

Matrix exponentials

EXPOKIT: A Software Package for Computing Matrix Exponentials

R. B. Sidje · ACM Transactions on Mathematical Software (1998). A classic reference for matrix-free Krylov evaluation of exponential propagators.

Open DOI →
Trace estimation

A Stochastic Estimator of the Trace of the Influence Matrix for Laplacian Smoothing Splines

M. F. Hutchinson · Communications in Statistics—Simulation and Computation (1989). The historical source of the random-vector trace estimator now widely known as Hutchinson estimation.

Open DOI →
Large spin systems

Spinach – A software library for simulation of spin dynamics in large spin systems

H. J. Hogben et al. · Journal of Magnetic Resonance (2011). A useful comparison point for sparse and restricted-state-space strategies in large spin simulations.

Open DOI →

From this chapter to the next

What we can now explain. We can evaluate computational scaling and select appropriate deterministic or stochastic solvers with explicit convergence checks.

What remains unresolved. How do we encode those physical assumptions in a reproducible MolSpin model? Continue with MolSpin examples

Prerequisites and related modules
Builds on

Home of numerical tractability and convergence: representation, sparsity, Krylov propagation, stochastic sampling and observable-level validation live here.

Concept checkpoint

Test your understanding

Use the question to test the main physical idea—not your ability to memorize an equation.

How do the Hilbert-space size and dense density-matrix storage scale with N spin-1/2 particles?