Lazy Matrices for Contraction-Based Algorithms
Total Page:16
File Type:pdf, Size:1020Kb
The storage problem Lazy matrices Lazy matrices in quantum chemistry Future work A&Q Lazy matrices for contraction-based algorithms Michael F. Herbst [email protected] https://michael-herbst.com Interdisziplinäres Zentrum für wissenschaftliches Rechnen Ruprecht-Karls-Universität Heidelberg 4th October 2017 1 / 26 The storage problem Lazy matrices Lazy matrices in quantum chemistry Future work A&Q Contents 1 The storage problem Problems with conventional approaches contraction-based algorithms 2 Lazy matrices The lazyten lazy matrix library 3 Lazy matrices in quantum chemistry molsturm program package 4 Future work Outlook 1 / 26 The storage problem Lazy matrices Lazy matrices in quantum chemistry Future work A&Q Contents 1 The storage problem Problems with conventional approaches contraction-based algorithms 2 Lazy matrices The lazyten lazy matrix library 3 Lazy matrices in quantum chemistry molsturm program package 4 Future work Outlook 2 / 26 The storage problem Lazy matrices Lazy matrices in quantum chemistry Future work A&Q Problems with conventional approaches Processor vs. memory performance improvement 100000 CPU clock speed Memory bus speed 10000 1000 Processor vs. Memory 100 performance gap 10 1 1980 1985 1990 1995 2000 2005 2010 Data from https://dave.cheney.net/2014/06/07/five-things-that-make-go-fast 3 / 26 The storage problem Lazy matrices Lazy matrices in quantum chemistry Future work A&Q Problems with conventional approaches Hartree-Fock equations Hartree-Fock equations 1 − ∆+ Vˆ + Vˆ {ψ } + Vˆ {ψ } − ε ψ (r) = 0 2 Nuc H f f∈I x f f∈I f f with 1 − ∆ Kinetic energy of electrons 2 VˆNuc Electron-nuclear interaction ˆ VH {ψf }f∈I Hartree potential ˆ Vx {ψf }f∈I Exchange potential Non-linear system of partial differential equations Non-linear eigenproblem for eigenpairs {(εf , ψf )}f∈I 4 / 26 The storage problem Lazy matrices Lazy matrices in quantum chemistry Future work A&Q Problems with conventional approaches Finite-element discretisation Finite elements: Piecewise polynomials with support only on a few neighbouring cells ⇒ Need many finite elements (> 106) Typically sparse matrix structures: 0 1000 2000 3000 4000 5000 6000 7000 0 1000 0 2000 2 − 3000 4 − 6 4000 − 8 − 5000 10 − 12 6000 − 7000 1 ˆ ˆ Typical discretisation of − 2 ∆+ VNuc + VH 5 / 26 The storage problem Lazy matrices Lazy matrices in quantum chemistry Future work A&Q Problems with conventional approaches Finite-element discretisation Caveat But . Vˆx is so-called non-local: 0 1000 2000 3000 4000 5000 6000 7000 0 1000 0 2000 2 − 3000 4 − 6 4000 − 8 − 5000 10 − 12 6000 − 7000 K: Discretisation of Vˆx Building K takes Ω(N 2) time and O(N 2) storage Typically 106 · 106 elements ≈ 8 TB storage 6 / 26 The storage problem Lazy matrices Lazy matrices in quantum chemistry Future work A&Q contraction-based algorithms Finite-element discretisation contraction-based scheme Iterative solvers only need matrix-vector products Matrix-vector product of K: Theoretically O(N) ⇒ contraction-based or matrix-free algorithm: Never build K in storage Use expression for K to directly form contraction of matrix to vectors 7 / 26 The storage problem Lazy matrices Lazy matrices in quantum chemistry Future work A&Q contraction-based algorithms contraction-based SCF Possible problems For SCF we will need F = T + VNuc + J + K + ··· Requirements differ: Optimal storage scheme Optimal contraction scheme Approximations / costs ⇒ contraction expression complicated to code ⇒ We would like to stay flexible 8 / 26 The storage problem Lazy matrices Lazy matrices in quantum chemistry Future work A&Q contraction-based algorithms Characteristics of contraction-based algorithms Advantages Scaling (storage and time) reduced — in examples to O(N) Parallelisation easier ⇒ Less data management Hardware trends are in favour Disadvantages Matrices more intuitive than contraction-functions More computations ⇒ Need efficient contraction schemes for the contraction ⇒ Algorithms more complicated 9 / 26 The storage problem Lazy matrices Lazy matrices in quantum chemistry Future work A&Q contraction-based algorithms Characteristics of contraction-based algorithms Advantages Scaling (storage and time) reduced — in examples to O(N) Parallelisation easier ⇒ Less data management Hardware trends are in favour Disadvantages Matrices more intuitive than contraction-functions More computations ⇒ Need efficient contraction schemes for the contraction ⇒ Algorithms more complicated 9 / 26 The storage problem Lazy matrices Lazy matrices in quantum chemistry Future work A&Q contraction-based algorithms Characteristics of contraction-based algorithms 100000 CPU clock speed Memory bus speed 10000 1000 Processor vs. Memory 100 performance gap 10 1 1980 1985 1990 1995 2000 2005 2010 Data from https://dave.cheney.net/2014/06/07/five-things-that-make-go-fast 9 / 26 The storage problem Lazy matrices Lazy matrices in quantum chemistry Future work A&Q contraction-based algorithms Characteristics of contraction-based algorithms Advantages Scaling (storage and time) reduced — in examples to O(N) Parallelisation easier ⇒ Less data management Hardware trends are in favour Disadvantages Matrices more intuitive than contraction-functions More computations ⇒ Need efficient contraction schemes for the contraction ⇒ Algorithms more complicated 9 / 26 The storage problem Lazy matrices Lazy matrices in quantum chemistry Future work A&Q Contents 1 The storage problem Problems with conventional approaches contraction-based algorithms 2 Lazy matrices The lazyten lazy matrix library 3 Lazy matrices in quantum chemistry molsturm program package 4 Future work Outlook 10 / 26 The storage problem Lazy matrices Lazy matrices in quantum chemistry Future work A&Q The lazyten lazy matrix library Lazy matrices Stored matrix: All elements reside in memory Lazy matrix: Generalisation of matrices State Non-linear Elements may be expressions ⇒ Obtaining elements expensive Evaluation of internal expression: Delayed until contraction For convenience: Offer matrix-like interface 11 / 26 The storage problem Lazy matrices Lazy matrices in quantum chemistry Future work A&Q The lazyten lazy matrix library Using lazy matrices Program as usual D = A + B Build expression tree internally D = A + B On application: Dx = (Ax) + (Bx) 12 / 26 The storage problem Lazy matrices Lazy matrices in quantum chemistry Future work A&Q The lazyten lazy matrix library Using lazy matrices Program as usual D = A + B Build expression tree internally + D = A + B = A B On application: Dx = (Ax) + (Bx) 12 / 26 The storage problem Lazy matrices Lazy matrices in quantum chemistry Future work A&Q The lazyten lazy matrix library Using lazy matrices Program as usual D = A + B Build expression tree internally + D = A + B = A B On application: Dx = (Ax) + (Bx) 12 / 26 The storage problem Lazy matrices Lazy matrices in quantum chemistry Future work A&Q The lazyten lazy matrix library Notes and observations lazyten: Bookkeeping for contraction-functions Programmer still sees matrices ⇒ Language for writing contraction-based algorithms Lazy matrices allow layered responsibility for computation, e.g. (A + B)x Ax and Bx decided by implementation of A and B (Ax) + (Bx) done in linear algebra backend ⇒ Proper modularisation between Higher-level algorithms Lazy matrix implementations LA backends 13 / 26 The storage problem Lazy matrices Lazy matrices in quantum chemistry Future work A&Q The lazyten lazy matrix library lazyten: Lazy matrix library Structure of the library Algorithms e.g. Integrals e.g. SCF Upper layers common user-provided interface lazy matrices lazyten built-in lazy LA backends solvers matrices Armadillo ARPACK Iterative inverse Bohrium LAPACK LA backend Eigen Anasazi Italic: planned 14 / 26 The storage problem Lazy matrices Lazy matrices in quantum chemistry Future work A&Q The lazyten lazy matrix library lazyten in practice: Example code lazyten1: Prototype C++ implementation 1 typedef SmallVector<double> vector_type; 2 typedef SmallMatrix<double> matrix_type; 3 auto v = random<vector_type>(100); 4 DiagonalMatrix<matrix_type> diag(v); 5 auto a = random<matrix_type>(100,100); 6 auto b = random<matrix_type>(100,100); 7 8 // No computation: Just build expression tree 9 auto sum = diag + a; 10 auto projector = sum * inverse(sum); 11 auto tree = b - projector * b; 12 13 // Evaluate tree on application: 14 SmallVector<double> res = tree * v; 1https://lazyten.org 15 / 26 The storage problem Lazy matrices Lazy matrices in quantum chemistry Future work A&Q Contents 1 The storage problem Problems with conventional approaches contraction-based algorithms 2 Lazy matrices The lazyten lazy matrix library 3 Lazy matrices in quantum chemistry molsturm program package 4 Future work Outlook 16 / 26 The storage problem Lazy matrices Lazy matrices in quantum chemistry Future work A&Q molsturm program package Lazy matrices for quantum chemistry codes contraction-based algorithms ⇒ Lower memory footprint, scaling improvements Readable code ⇒ Great for teaching or to play around Abstraction between integrals and SCF algorithms ⇒ Plug and play integral libraries ⇒ Swap LA backends ⇒ Basis-type independent SCF / quantum chemistry 17 / 26 The storage problem Lazy matrices Lazy matrices in quantum chemistry Future work A&Q molsturm program package molsturm structure Integral backends Post HF methods MP2 Gaussians molsturm ADC Interface layer and python driver Sturmians Full CI gint gscf Ionis. sturmians Integral interface SCF algorithms Coupled Cluster Finite elements lazyten Finite