automatic code generation for quantum chemistry applications · xc functional zoo i true functional...
TRANSCRIPT
Automatic code generation for
quantum chemistry applications
Grzegorz Mazur1,2, Marcin Makowski1,2, Roman Lazarski3,Rados law W lodarczyk4, Ewa Czajkowska1
1Faculty of Chemistry, Jagiellonian University2Academic Computer Centre CYFRONET AGH
3Otto-Schott-Institut fur Materialforschung, Friedrich-Schiller-Universitat Jena4Institute of Chemistry, Humboldt-Universitat zu Berlin
Exchange-Correlation Functional
I Theory: E xc [ρα, ρβ] – spin density functional
I Practice:I Local Density Approximation (LDA)
E xc =
∫R3
exc (ρα(r), ρβ(r)) dr3
I Generalized Gradient Approximation (GGA)
E xc =
∫R3
exc (ρα(r), ρβ(r), σαα(r), σαβ(r), σββ(r)) dr3
I meta-GGA – additional dependency on kinetic energydensity
Exchange-Correlation Functional
I Theory: E xc [ρα, ρβ] – spin density functional
I Practice:I Local Density Approximation (LDA)
E xc =
∫R3
exc (ρα(r), ρβ(r)) dr3
I Generalized Gradient Approximation (GGA)
E xc =
∫R3
exc (ρα(r), ρβ(r), σαα(r), σαβ(r), σββ(r)) dr3
I meta-GGA – additional dependency on kinetic energydensity
XC Functional zoo
I True functional not known
I Plethora of approximationsI SlaterI SVWNI SLYPI BLYPI PBE/revPBE/mPBEI PW91/PW92I OPTXI B3LYPI PBE0I . . .
I and new ones showing up every so often. . .
XC Functional zoo
I True functional not known
I Plethora of approximationsI SlaterI SVWNI SLYPI BLYPI PBE/revPBE/mPBEI PW91/PW92I OPTXI B3LYPI PBE0I . . .
I and new ones showing up every so often. . .
XC Functional zoo
I True functional not known
I Plethora of approximationsI SlaterI SVWNI SLYPI BLYPI PBE/revPBE/mPBEI PW91/PW92I OPTXI B3LYPI PBE0I . . .
I and new ones showing up every so often. . .
XC Functional derivativesI Energy straight from xc functional
I Ground state determination requires xc functionalderivatives
I Excited state energies require xc functional secondderivatives
state number of derivativesLDA GGA
ground 1(∂Exc
∂ρσ
)3(∂Exc
∂ρσ, ∂Exc
∂γστ
)excited 2
(∂2Exc
∂ρσ∂ρτ
)9(
∂2Exc
∂ρσ∂ρτ, ∂2Exc
∂ρσ∂γστ, . . .
). . . . . . . . .
I Geometry optimization goes one order further
I Hessian requires another order of differentiation
XC Functional derivativesI Energy straight from xc functional
I Ground state determination requires xc functionalderivatives
I Excited state energies require xc functional secondderivatives
state number of derivativesLDA GGA
ground 1(∂Exc
∂ρσ
)3(∂Exc
∂ρσ, ∂Exc
∂γστ
)excited 2
(∂2Exc
∂ρσ∂ρτ
)9(
∂2Exc
∂ρσ∂ρτ, ∂2Exc
∂ρσ∂γστ, . . .
). . . . . . . . .
I Geometry optimization goes one order further
I Hessian requires another order of differentiation
XC Functional derivativesI Energy straight from xc functional
I Ground state determination requires xc functionalderivatives
I Excited state energies require xc functional secondderivatives
state number of derivativesLDA GGA
ground 1(∂Exc
∂ρσ
)3(∂Exc
∂ρσ, ∂Exc
∂γστ
)excited 2
(∂2Exc
∂ρσ∂ρτ
)9(
∂2Exc
∂ρσ∂ρτ, ∂2Exc
∂ρσ∂γστ, . . .
). . . . . . . . .
I Geometry optimization goes one order further
I Hessian requires another order of differentiation
XC Functional – example
EVWN (ρα, ρβ) := ρEc(x , ζ)
where
ρ := ρα + ρβ x :=
(3
4πρ
)1/6
ζ :=ρα − ρβ
ρ
Ec(x , ζ) := EPc (x) + EA
c (x)g(ζ)(1 + B2(x)ζ4)
g(ζ) :=9
8
((1 + ζ)4/3 + (1− ζ)4/3 − 2
)B2(x) :=
4
9(21/3 − 1)
EFc (x)− EP
c (x)
EAc (x)
− 1
EAc (x) := E
(− 1
6π2,−0.00475840, 1.13107, 13.0045, x
)EFc (x) := E (0.01554535000,−0.32500, 7.06042, 18.0578, x)
EPc (x) := E (0.03109070000,−0.10498, 3.72744, 12.9352, x)
XC Functional – example
E (A,X0,B ,C , x) :=
A
(ln
x2
X (x ,B ,C )+ 2B
arctan Q(B,C)2x+B
Q (B ,C )+
−BX0
ln (x−X0)2
X (x ,B,C)+ 2 (B + 2X0)
arctan Q(B,C)2x+B
Q(B,C)
X (X0,B ,C )
Q (b, c) :=
√4c − b2
X (x , b, c) := x2 + bx + c
We’ve got a problem
I calculating derivatives tedious and error prone
I transforming them to C or FORTRAN even more so
Computer Algebra System
I high-level, math oriented language
I built-in arithmetics, elementary functions, differentiation,integration, etc.
I automatic formula simplification
I usually ability to generate code in C and/or FORTRAN
yacas
I Yet Another Computer Algebra System
I term-rewriting based
I built-in basic math
I built-in C code generation
I easy to extend
I highly portable
I easily accessible (LGPL)
XC Functional – example
XC’ D e f i n e ( X S l a t e r ( rhoa , rhob ) ,[−3./4∗(6/ Pi ) ˆ ( 1 . / 3 . ) ∗
( rhoa ˆ ( 4 . / 3 . ) + rhob ˆ ( 4 . / 3 . ) ) ;] ) ;
XC Functional – exampleXC’ D e f i n e (CVWN( rhoa , rhob ) ,[
L o c a l ( rho , z , x , EcP , EcF , EcA , B2 , dEe , Ec , X , Q, E ) ;
X( x , b , c ) := x ˆ2 + b∗x + c ;Q( b , c ) := S q r t (4 ∗ c − b ˆ 2 ) ;
E(A , X0 , B , C , x ) := A∗( Ln ( x ˆ2 / X( x , B , C ) ) +2 ∗ B ∗ ArcTan (Q(B , C) / (2 ∗ x + B) ) / Q(B , C) −B ∗ X0 ∗ ( Ln ( ( x − X0)ˆ2/X( x , B , C ) )
+ 2∗(B + 2 ∗ X0 ) ∗ArcTan (Q(B , C) / ( 2 ∗ x + B) ) / Q(B , C ) ) / X(X0 , B , C ) ) ;
rho := rhoa + rhob ;z := ( rhoa − rhob ) / rho ;x := (3/(4∗ Pi ∗ rho ) ) ˆ ( 1 . / 6 . ) ;EcP := E ( 0 . 0 3 1 0 9 0 7 0 0 0 0 , −0 . 1 0 4 9 8 , 3 . 7 2 7 4 4 , 1 2 . 9 3 5 2 , x ) ;EcF := E ( 0 . 0 1 5 5 4 5 3 5 0 0 0 , −0 . 3 2 5 0 0 , 7 . 0 6 0 4 2 , 1 8 . 0 5 7 8 , x ) ;EcA := E (−1 ./(6 . ∗ Pi ˆ 2 ) , −0.00475840 ,1 .13107 ,13 .0045 , x ) ;B2 := 4 . / ( 9 .∗ ( 2 . ˆ ( 1 / 3 ) −1 ) ) ∗ ( EcF − EcP ) / EcA − 1 ;g := 9 . / 8 .∗ ( ( 1 . + z ) ˆ ( 4 . / 3 . ) + (1.− z ) ˆ ( 4 . / 3 . ) ) ;Ec := EcP + EcA∗g∗(1.+B2∗z ˆ 4 ) ;rho ∗ Ec ;
] ) ;
Code generation
I define functionals
I differentiate
I Common Subexpression Elimination
I generate code
I compile
Code generation
I define functionals
I differentiate
I Common Subexpression Elimination
I generate code
I compile
Does it really work?
I functionality already present in:I niedoida, up to second derivatives (excited states
energies at the hybrid-GGA level)I DFT-B parameter-suite generation package
I new version of automateuszI supports derivatives up to third-orderI code generation in C, C++, FORTRAN95, CUDA C,
OpenCLI used in adorycja, GPGPU quantum chemistry program
(part of the niedoida package)
Electron Repulsion Integrals
gµνκλ =
∫R3
∫R3
χµ(r1)χν(r1)χκ(r2)χλ(r2)
r12d3r1d
3r2
I 6 dimensions
I N4 integrals
I analytically integrable for Gaussian Type Orbitals (GTO)
Electron Repulsion Integrals
gµνκλ =
∫R3
∫R3
χµ(r1)χν(r1)χκ(r2)χλ(r2)
r12d3r1d
3r2
I 6 dimensions
I N4 integrals
I analytically integrable for Gaussian Type Orbitals (GTO)
Electron Repulsion Integrals
gµνκλ =
∫R3
∫R3
χµ(r1)χν(r1)χκ(r2)χλ(r2)
r12d3r1d
3r2
I 6 dimensions
I N4 integrals
I analytically integrable for Gaussian Type Orbitals (GTO)
Obara-Saika scheme
I auxilliary integral
ΘN000000000000 = (ss|ss)N =
2π52
pq√p + q
K xyzab K xyz
cd FN(αR2PQ),
where for primitive Cartesian Gaussian functions centeredon A,B ,C ,D with exponents equal to a, b, c , d
p = a + b q = c + d α =pq
p + q
Px =aAx + bBx
a + bXPQ = Px−Qx K xyz
ab = exp
(− ab
a + bR2AB
)I Obara-Saika recurrences
ΘN000000000000 → Θ0
ix iy iz jx jy jzkxkykz lx ly lz = (aix iy izbjx jy jz |ckxkykzdlx ly lz )
Obara-Saika recurrencesI horizontal
ΘNijkl = ΘN
ij ,k+1,l−1 + XCDΘNijk,l−1
ΘNijkl = ΘN
i+1,j−1,kl + XABΘNi ,j−1,kl
I electron transfer
ΘNi0k0 = XQCΘN
i0,k−1,0 +α
qXPQΘN+1
i0,k−1,0+
+k − 1
2q
(ΘN
i0,k−2,0 −α
qΘN+1
i0,k−2,0
)+
+i
2(p + q)ΘN+1
i−1,0,k−1,0
I vertical
ΘNi000 = XPAΘN
i−1,000 −α
pXPQΘN+1
i−1,000+
+i − 1
2p
(ΘN
i−2,000 −α
pΘN+1
i−2,000
)
Implementation glimpse
// h o r i z o n t a l r e c u r s i o n i n t h e r i g h t p a i r
500 # ERI ’ OS1P ’ h r r 1 (ERI ’ OS1P ’ g ( ma , mb , p , b , xab , xp , kab ,
mc , md , q , d , xcd , xq , kcd ,N , b s ) ) (md [ 1 ] > 0) <−−
[ERI ’ OS1P ’ g (ma , mb, p , b , xab , xp , kab ,
mc + {1 , 0 , 0} , md − {1 , 0 , 0} ,q , d , xcd , xq , kcd , N, bs ) +
xcd [ 1 ] ∗ ERI ’ OS1P ’ g (ma , mb, p , b , xab , xp , kab ,mc , md − {1 , 0 , 0} ,q , d , xcd , xq , kcd , N, bs ) ;
] ;
Code generation
I define recurrences
I write down requested integral
I recurrences are applied automatically
I Common Subexpression Elimination
I apply platform-specific optimizations
I generate code
I compile
Code generation
I define recurrences
I write down requested integral
I recurrences are applied automatically
I Common Subexpression Elimination
I apply platform-specific optimizations
I generate code
I compile
Does it really work?
I functionality present in adorycja, GPGPU quantumchemistry program (part of the niedoida package)
I part of niedoida HF energy gradient routine for CPU
ERI gradients and beyond
I gradientsI formulas derived by manual differentiation of
Obara-Saika recurrencesI implementation analogous to ERII used to implement HF energy gradientI DFT gradient being worked on
I HessianI Hermite Gaussians more involved but easier to
differentiate than Cartesian GaussiansI HF energy Hessian is being worked on
Summary
I Computational quantum chemistry involves intricatekernels
I Computer Algebra System significantly reduces thesemantic gap
I On-the-fly common subexpression elimination makes theapproach viable
I As a result, developing the kernels less tedious anderror-prone
Software
I http://www.yacas.org
I http://www.chemia.uj.edu.pl/~niedoida