Abstract
The Spinsim python package simulates spin-half and spin-one quantum mechanical systems following a time dependent Shroedinger equation. It makes use of numba.cuda, which is an LLVM (Low Level Virtual Machine) compiler for Nvidia Cuda compatible systems using GPU parallelization. Along with other optimizations, this allows for speed improvements from 3 to 4 orders of magnitude while staying just as accurate, compared to industry standard packages. It is available for installation on PyPI, and the source code is available on github. The initial use-case for the Spinsim will be to simulate quantum sensing-based ultracold atom experiments for the Monash University School of Physics & Astronomy spinor Bose-Einstein condensate (spinor BEC) lab, but we anticipate it will be useful in simulating any range of spin-half or spin-one quantum systems with time dependent Hamiltonians that cannot be solved analytically. These appear in the fields of nuclear magnetic resonance (NMR), nuclear quadrupole resonance (NQR) and magnetic resonance imaging (MRI) experiments and quantum sensing, and with the spin-one systems of nitrogen vacancy centres (NVCs), ultracold atoms, and BECs.
Introduction
In quantum sensing, researchers utilize atoms to measure minute magnetic or electrical signals, necessitating precise simulations of quantum state evolution over time. This requires solving the time-dependent Schrödinger equation, a task often hindered by significant computational bottlenecks. Standard differential equation solvers, such as those in SciPy or Mathematica, are frequently too slow for the extensive "parameter sweeps" required to optimize experimental setups. Furthermore, researchers often resort to approximations like the Rotating Wave Approximation (RWA) or simplifying spin-one systems into spin-half models to save time, potentially sacrificing the accuracy needed for high-precision sensing.
Spinsim addresses these challenges by providing a high-performance tool that is fast enough for large-scale batches while maintaining physical rigor.
Methods and Implementation
Spinsim’s performance is derived from a combination of hardware acceleration and specialized numerical integrators. The package leverages numba.cuda to compile Python code into kernels for NVIDIA GPUs. While the quantum state at time $t$ depends on the state at $t-1$, the evolution operators for different time segments can be calculated independently in parallel across thousands of GPU cores.
The core numerical methods include:
- Magnus Expansion (CF4): A 4th-order commutator-free Magnus expansion is used instead of standard Runge-Kutta methods. As a "geometric integrator," it inherently preserves the unitary nature of quantum evolution, preventing probability "leakage."
- Dynamic Rotating Frames: The solver automatically shifts into a rotating frame matching the system's dominant frequency. This "slows down" fast oscillations, allowing for larger, more accurate time steps without the physical simplifications of the RWA.
- Lie-Trotter Exponentiation: Hamiltonians are converted into evolution operators using the Lie-Trotter product formula combined with iterative squaring, optimized for numerical stability.
Results and Benchmarking
Spinsim was benchmarked against industry standards including SciPy (ivp_solve), QuTiP (sesolve), and Mathematica (NDSolve) using a simulated 100 ms quantum sensing experiment.
Key results include:
- Massive Speedups: Spinsim is 3 to 4 orders of magnitude faster than Mathematica and QuTiP for equivalent error tolerances. A batch simulation that would take three weeks using standard SciPy scripts can be completed in less than one minute on a modern GPU.
- Superior Accuracy: For a fixed time-step size, Spinsim demonstrates up to 10,000x greater accuracy than standard SciPy solvers.
- Hardware Scaling: Performance scales almost linearly with the number of CUDA cores, ensuring continued relevance as GPU hardware improves.
Limitations and Future Work
Currently, Spinsim is specialized for single spin-half or spin-one systems and does not support multi-particle entanglement or many-body physics. It focuses on pure states (Schrödinger equation) rather than mixed states (Lindblad master equation). Additionally, the lack of automatic differentiation prevents direct integration into machine learning frameworks for Quantum Optimal Control. Future development may address these areas to broaden the package's applicability.
Summary updated