Eve library

phase-103.md

Tracker

Revision 1

On this page

Historical task source. The Eve task board holds current task state.

Phase 103: Kalika Computational Engine — Numerical Engine (Rust), HPC Orchestration, GPU Acceleration, Tensor Networks, Monte Carlo & FEM/Spectral Methods#

Implements the high-performance numerical computation backbone. Every kernel targets native Rust performance with WASM portability. Exceeds or matches: PETSc/SLEPc (sparse solvers), MAGMA (GPU dense LA), ITensor/TeNPy (tensor networks), FEniCS/Dedalus (FEM/spectral), Cuba (Monte Carlo integration), SUNDIALS (ODE/DAE), and DifferentialEquations.jl (adaptive solvers).


103.1 Numerical Engine — Rust Core (@kalika/numerical-engine)#

103.1.1 Dense Linear Algebra (matching LAPACK + MAGMA)#

  • 103.1.1.1 Implement dense matrix operations in Rust: matrix multiplication (BLAS Level 3 — blocking for cache, SIMD vectorization via std::simd or packed_simd, Strassen for large matrices), triangular solve (BLAS Level 2/3), symmetric matrix operations, complex matrix operations — with auto-dispatch for real/complex, single/double/quad precision
  • 103.1.1.2 Implement LU factorization: partial pivoting (LAPACK dgetrf equivalent), complete pivoting, threshold pivoting, panel-based algorithm for cache efficiency, and mixed-precision (compute in single, refine in double via iterative refinement — matching MAGMA's approach for 2x speedup)
  • 103.1.1.3 Implement QR factorization: Householder reflectors (LAPACK dgeqrf equivalent), Gram-Schmidt (classical and modified), Givens rotations, column-pivoted QR (rank-revealing), and communication-avoiding QR (CAQR for distributed systems)
  • 103.1.1.4 Implement eigenvalue solvers: symmetric/Hermitian (divide-and-conquer dsyevd, MRRR dsyevr for O(n^2) all-eigenpairs), non-symmetric (QR iteration with implicit shifts dgeev, Schur decomposition), generalized eigenvalue (QZ algorithm dggev), and partial eigenvalue computation (Lanczos for symmetric, Arnoldi for non-symmetric — matching ARPACK/SLEPc)
  • 103.1.1.5 Implement SVD: divide-and-conquer (dgesdd — fastest for all singular values), Golub-Kahan bidiagonalization + QR iteration (dgesvd — more accurate), randomized SVD (Halko-Martinsson-Tropp for truncated SVD of large matrices — O(mn log k) for rank-k approximation), and partial SVD via Lanczos on A^T A
  • 103.1.1.6 Implement Cholesky factorization: standard (dpotrf), pivoted (rank-revealing), banded, packed storage, and incomplete Cholesky (preconditioner for iterative solvers)
  • 103.1.1.7 Implement matrix functions: matrix exponential (scaling and squaring with Padé, matching Higham's expm), matrix logarithm, matrix square root, matrix sign function, general f(A) via Schur-Parlett algorithm — for quantum mechanics (unitary evolution U = exp(-iHt)) and GR (exponential map)

103.1.2 Sparse Linear Algebra (matching PETSc/SLEPc)#

  • 103.1.2.1 Implement sparse matrix formats: CSR (Compressed Sparse Row), CSC, COO (Coordinate), BSR (Block Sparse Row), diagonal, and skyline — with automatic format selection based on sparsity pattern and operation type
  • 103.1.2.2 Implement sparse direct solvers: LU factorization with fill-reducing ordering (AMD, METIS, nested dissection), symbolic factorization + numerical factorization (matching UMFPACK/SuperLU), Cholesky for SPD sparse matrices (matching CHOLMOD) — for moderate-size sparse systems (N < 10^6)
  • 103.1.2.3 Implement Krylov subspace solvers: CG (Conjugate Gradient for SPD), BiCGStab (nonsymmetric), GMRES (with restarts, flexible), MINRES (symmetric indefinite), TFQMR, CGS — all with convergence monitoring, residual computation, and configurable stopping criteria
  • 103.1.2.4 Implement preconditioners: Jacobi (diagonal), block-Jacobi, SSOR, ILU(k) (incomplete LU with fill level k), ILUT (threshold), ICC (incomplete Cholesky), algebraic multigrid (AMG — classical Ruge-Stuben and smoothed aggregation), geometric multigrid, domain decomposition (additive/multiplicative Schwarz) — matching PETSc's preconditioner zoo
  • 103.1.2.5 Implement sparse eigenvalue solvers: Lanczos (symmetric, with reorthogonalization strategies: full, selective, thick restart), Arnoldi (non-symmetric, implicitly restarted — matching ARPACK), Jacobi-Davidson, LOBPCG (locally optimal block preconditioned CG), shift-and-invert spectral transformation — for partial eigenvalue problems with N > 10^6, matching SLEPc
  • 103.1.2.6 Implement nonlinear solvers: Newton-Raphson (with line search — backtracking, cubic interpolation), Newton-Krylov (JFNK — Jacobian-free via finite differences), trust region methods, Anderson acceleration (for fixed-point iterations), and homotopy continuation — matching PETSc's SNES

103.1.3 GPU Acceleration#

  • 103.1.3.1 Implement GPU compute abstraction via wgpu (WebGPU): shader-based general-purpose compute targeting Vulkan/Metal/DX12/WebGPU backends, resource management (buffers, bind groups), compute pipeline creation, and workgroup dispatch — providing a unified GPU interface across all platforms including browser (WebGPU)
  • 103.1.3.2 Implement GPU-accelerated dense linear algebra: matrix multiplication (matching cuBLAS performance characteristics via tiled compute shaders), batched small-matrix operations (for many independent small systems — common in FEM and particle physics), and mixed-precision solve
  • 103.1.3.3 Implement GPU-accelerated sparse operations: SpMV (sparse matrix-vector multiply — CSR and ELL formats optimized for GPU), sparse triangular solve, and GPU-accelerated Krylov solvers (CG, BiCGStab with GPU SpMV kernel)
  • 103.1.3.4 Implement GPU-accelerated lattice field theory kernels: SU(3) matrix multiplication (complex 3x3), staggered/Wilson Dirac operator application (stencil operation on 4D lattice), gauge field update (molecular dynamics force computation) — matching QUDA's approach for lattice QCD GPU acceleration
  • 103.1.3.5 Implement GPU-accelerated Monte Carlo: parallel random number generation (Philox counter-based RNG), parallel Metropolis (checkerboard decomposition for lattice models), GPU-based numerical integration (VEGAS on GPU)

103.2 Differential Equation Solvers (@kalika/numerical)#

103.2.1 ODE Solvers (matching SUNDIALS + DifferentialEquations.jl)#

  • 103.2.1.1 Implement explicit Runge-Kutta methods: RK4 (classical), Dormand-Prince 4(5) (DP45 — the MATLAB ode45 default), Fehlberg 7(8), Verner 6(5) "efficient" — with embedded error estimation and adaptive step control (PI controller, predictive controller)
  • 103.2.1.2 Implement implicit methods for stiff systems: backward Euler, trapezoidal rule (Crank-Nicolson), implicit midpoint, SDIRK (singly diagonally implicit RK), Radau IIA (5th order, L-stable), BDF (backward differentiation formulas, orders 1-5, matching SUNDIALS CVODE/LSODA) — with Newton iteration for implicit solve and automatic stiffness detection
  • 103.2.1.3 Implement symplectic integrators: Stormer-Verlet / leapfrog (2nd order), Ruth (3rd order), Forest-Ruth (4th order), Yoshida (4th/6th/8th order compositions) — essential for Hamiltonian systems (N-body, molecular dynamics, geodesic integration in GR) where energy conservation matters
  • 103.2.1.4 Implement exponential integrators: exponential Euler, ETDRK4 (exponential time differencing Runge-Kutta 4th order — matching Dedalus/Kassam-Trefethen) — for stiff PDEs where the linear part can be solved exactly
  • 103.2.1.5 Implement DAE (differential-algebraic equation) solvers: index-1 DAEs via BDF (matching SUNDIALS IDA), index reduction via Pantelides algorithm, consistent initial condition computation
  • 103.2.1.6 Implement SDE (stochastic differential equation) solvers: Euler-Maruyama, Milstein, stochastic Runge-Kutta (SRK), adaptive stepping for SDEs (Lamba-Mattingly-Stuart), strong and weak convergence modes — for Langevin dynamics, stochastic quantization, and financial physics

103.2.2 PDE Solvers#

  • 103.2.2.1 Implement finite difference methods: 2nd/4th/6th/8th order central differences, upwind schemes (1st and 3rd order), compact finite differences (Lele), method of lines (MOL — reduce PDE to ODE system, solve with ODE integrator), structured grid management (uniform and stretched)
  • 103.2.2.2 Implement spectral methods (matching Dedalus): Chebyshev-tau and Chebyshev-Galerkin methods for bounded domains, Fourier spectral method for periodic domains, spherical harmonic expansion for spherical geometry, spectral element methods (combining spectral accuracy with geometric flexibility), and the Dedalus-style sparse banded operator approach for efficient implicit time-stepping
  • 103.2.2.3 Implement finite element method (FEM) framework (matching FEniCS): mesh generation interface (triangular/tetrahedral via Delaunay, quadrilateral/hexahedral structured), Lagrange elements (P1-P5), variational form assembly (bilinear and linear forms from weak formulation), Galerkin projection, boundary condition imposition (Dirichlet, Neumann, Robin), and adaptive mesh refinement (a posteriori error estimation, bisection/red-green refinement)
  • 103.2.2.4 Implement discontinuous Galerkin (DG) methods: local DG with numerical fluxes (Lax-Friedrichs, Roe, HLLC), hp-adaptivity, and shock capturing — for hyperbolic conservation laws (compressible flow, relativistic hydrodynamics)

103.3 Monte Carlo Methods#

103.3.1 Monte Carlo Integration#

  • 103.3.1.1 Implement Monte Carlo integration algorithms: plain Monte Carlo, importance sampling, stratified sampling, VEGAS adaptive (multi-dimensional, matching Cuba library), SUAVE (subregion-adaptive), DIVONNE (stratified sampling with partitioning), CUHRE (deterministic cubature rules) — supporting high-dimensional integration (d > 10) as needed for multi-loop Feynman integrals and lattice field theory
  • 103.3.1.2 Implement quasi-Monte Carlo: Halton sequences, Sobol sequences, Niederreiter sequences, lattice rules — for faster convergence (O(1/N) vs O(1/sqrt(N))) on smooth integrands, with automatic scrambling for error estimation

103.3.2 MCMC & Sampling#

  • 103.3.2.1 Implement Markov Chain Monte Carlo: Metropolis-Hastings (random walk, independent), Gibbs sampling, Hamiltonian Monte Carlo (HMC — leapfrog integration with Hamiltonian dynamics, NUTS auto-tuning of trajectory length matching Stan), slice sampling, parallel tempering (replica exchange), and affine-invariant ensemble sampler (matching emcee)
  • 103.3.2.2 Implement nested sampling: MultiNest algorithm (ellipsoidal decomposition, matching PyMultiNest), PolyChord (slice-sampling-based nested sampling for high-dimensional posteriors), dynesty (dynamic nested sampling with flexible stopping criteria) — for Bayesian evidence computation and parameter estimation in physics (cosmological parameters, gravitational wave PE)
  • 103.3.2.3 Implement cluster algorithms for lattice models: Swendsen-Wang, Wolff single-cluster — for overcoming critical slowing down near phase transitions (dramatically faster than local Metropolis for Ising/Potts models)
  • 103.3.2.4 Implement normalizing flows for MCMC: real NVP, neural spline flows, coupling layers — for learning efficient proposal distributions, applied to lattice field theory (matching Kanwar-Albergo et al.'s flow-based gauge field generation) and Bayesian inference

103.4 Tensor Network Methods (@kalika/tensor-networks)#

  • 103.4.1.1 Implement tensor network core: tensor contraction engine (optimal contraction ordering via dynamic programming for small networks, greedy heuristics for large), tensor decomposition (SVD-based truncation, QR-based), tensor network diagrams as a data structure, automatic index management (Einstein summation convention)
  • 103.4.1.2 Implement Matrix Product States (MPS) / Tensor Trains: MPS construction from wavefunction, canonical forms (left-canonical, right-canonical, mixed), MPS arithmetic (addition, inner product, application of MPO), and bond dimension truncation with controlled error — matching ITensor's MPS capabilities
  • 103.4.1.3 Implement DMRG (Density Matrix Renormalization Group): ground state search (two-site DMRG with adaptive bond dimension), excited states (targeting with orthogonality constraints), time evolution (TEBD — time-evolving block decimation, tDMRG), finite-temperature DMRG (purification), and infinite DMRG (iDMRG) — matching ITensor/TeNPy performance for 1D quantum systems
  • 103.4.1.4 Implement MERA (Multi-scale Entanglement Renormalization Ansatz): binary MERA for critical systems, optimization (variational energy minimization with isometry/disentangler updates), scale-invariant MERA, and connection to AdS/CFT (Swingle's tensor network / holography correspondence)
  • 103.4.1.5 Implement PEPS (Projected Entangled Pair States): 2D tensor network ansatz, variational optimization (simple update, full update), contraction algorithms (boundary MPS, corner transfer matrix renormalization — CTMRG, matching TeNPy for 2D), infinite PEPS (iPEPS)
  • 103.4.1.6 Implement tensor network for lattice gauge theory: gauge-invariant tensor networks, SU(2)/SU(3) symmetric tensors, Gauss's law enforcement, and real-time evolution for out-of-equilibrium dynamics (sign-problem-free alternative to Monte Carlo)

103.5 HPC Orchestrator (@kalika/hpc-orchestrator)#

  • 103.5.1.1 Implement job scheduler: submit computation jobs to local workers (thread pool), GPU devices (via wgpu), or remote HPC resources (SSH + SLURM/PBS/SGE job submission), with automatic resource matching (CPU-bound vs GPU-bound vs memory-bound), job dependency DAG, priority queuing, and checkpointing (save/resume long computations)
  • 103.5.1.2 Implement distributed computation: MPI-style message passing over WebSocket/TCP for multi-node parallelism, domain decomposition (distribute lattice/grid across nodes), collective operations (allreduce, broadcast, gather, scatter), and fault tolerance (checkpoint/restart on node failure)
  • 103.5.1.3 Implement computation caching: content-addressed cache of expensive computation results (integration results, IBP reductions, Groebner bases, eigenvalue decompositions) keyed by input hash, with LRU eviction, optional persistence to disk/S3, and cache invalidation on code changes
  • 103.5.1.4 Implement resource monitoring: real-time tracking of CPU/GPU/memory utilization, computation progress (estimated time to completion), cost estimation (cloud compute pricing), and automatic scaling (spin up additional workers for parallelizable computations)

103.6 Special Function Numerical Evaluation#

  • 103.6.1.1 Implement arbitrary-precision numerical evaluation for ALL special functions from Phase 99 (gamma, Bessel, hypergeometric, elliptic, zeta, polylogarithm, Mathieu, etc.): using ball arithmetic with rigorous error bounds, automatic algorithm selection by parameter region (series expansion near origin, asymptotic expansion for large argument, connection formulas for intermediate, uniform asymptotic for large order), and precision auto-increase when results are insufficiently accurate — matching mpmath/arb's 10,000+ digit capability
  • 103.6.1.2 Implement numerical evaluation of Meijer G-function and Fox H-function: Mellin-Barnes integral representation evaluated via numerical contour integration, with automatic contour selection and pole handling — enabling numerical evaluation of any definite integral expressible as a Meijer G convolution

103.7 Tests & Benchmarks#

  • 103.7.1.1 Create numerical linear algebra benchmark suite: compare against LAPACK/OpenBLAS for dense operations, PETSc for sparse operations, at matrix sizes 100x100 through 10000x10000 — with regression tracking
  • 103.7.1.2 Create PDE solver validation suite: compare spectral method and FEM solutions against exact solutions for Laplace equation, heat equation, wave equation, Navier-Stokes (Taylor-Green vortex), and Poisson equation — with convergence rate verification (spectral: exponential, FEM: polynomial in h)
  • 103.7.1.3 Create tensor network benchmark: compare DMRG ground state energy for XXZ Heisenberg chain against exact Bethe ansatz results, verify convergence with bond dimension — minimum 50 test cases
  • 103.7.1.4 Create Monte Carlo integration test suite: verify VEGAS integration of known integrals (unit hypercube in d dimensions, Feynman parameter integrals, lattice observables) against exact values — with statistical consistency checking (chi-squared test)