Ask Hjorth Larsen asklarsen@gmail - CAMD decentral webserverdcaskhl/files/gpaw-slides.pdf · WAGP...

16

Transcript of Ask Hjorth Larsen asklarsen@gmail - CAMD decentral webserverdcaskhl/files/gpaw-slides.pdf · WAGP...

Page 1: Ask Hjorth Larsen asklarsen@gmail - CAMD decentral webserverdcaskhl/files/gpaw-slides.pdf · WAGP Wrapping up Ask Hjorth Larsen asklarsen@gmail.com Nano-bio Spectroscopy Group and

GPAW Wrapping up

Ask Hjorth [email protected]

Nano-bio Spectroscopy Groupand ETSF Scienti�c Development CentreUniversidad del País Vasco UPV/EHU

May 31, 2017

Page 2: Ask Hjorth Larsen asklarsen@gmail - CAMD decentral webserverdcaskhl/files/gpaw-slides.pdf · WAGP Wrapping up Ask Hjorth Larsen asklarsen@gmail.com Nano-bio Spectroscopy Group and

GPAW Wrapping up

GPAW

I Density functional theory code written in Python and C

I https://wiki.fysik.dtu.dk/gpaw/

I Projector augmented wave method (Blöchl Phys. Rev. B 50,17953, 1994)

I Calculations are written as Python scripts using ASE

I Three calculation modes: FD, LCAO, PW

I Parallelization with MPI; highly scalable (except PW)

I Python interfaces for important functions from MPI, BLAS,LAPACK, ScaLAPACK

Page 3: Ask Hjorth Larsen asklarsen@gmail - CAMD decentral webserverdcaskhl/files/gpaw-slides.pdf · WAGP Wrapping up Ask Hjorth Larsen asklarsen@gmail.com Nano-bio Spectroscopy Group and

GPAW Wrapping up

The case for Python in DFT codes

I Probably more than 90% of CPU time is spent in less than10% of the code

I Write 90% in a nice language and 10% in C/Fortran

I DFT codes do many non-computational things:I Glue components together (Poisson, eigensolver, mixing, etc.)I Read and write dataI String processing (parse pseudopotentials, format output, ...)I Parallel operations (time spent waiting for hardware)

I Disadvantage: Mixing languages does have some extracomplexity

Page 4: Ask Hjorth Larsen asklarsen@gmail - CAMD decentral webserverdcaskhl/files/gpaw-slides.pdf · WAGP Wrapping up Ask Hjorth Larsen asklarsen@gmail.com Nano-bio Spectroscopy Group and

GPAW Wrapping up

PAW and the quest for smooth wavefunctions

0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0Distance from atom [Bohr]

−0.5

0.0

0.5

1.0

1.5

2.0

2.5

φ(r

)[a

rb.

units

]

Fe 4s AEFe 3d AEFe 4s HGHFe 3d HGHFe 4s PAWFe 3d PAW

I Wavefunctions oscillate and are expensive to represent

I Remove core electrons, replace nuclei with pseudopotentials

I PAW: Extension to pseudopotentials. Avoidsnorm-conservation, and retains �all-electron� information

Page 5: Ask Hjorth Larsen asklarsen@gmail - CAMD decentral webserverdcaskhl/files/gpaw-slides.pdf · WAGP Wrapping up Ask Hjorth Larsen asklarsen@gmail.com Nano-bio Spectroscopy Group and

GPAW Wrapping up

The projector augmented wave method

I Valence states represented by |ψ〉 = T |ψ〉I PAW transformation: T = 1 +

∑ai

(|φai 〉 − |φai 〉) 〈pai |

I Given atomic states φai (r), choose smooth functions φai (r) andlocalized �projectors� pai (r); this de�nes T .

I PAW transformation maps nice smooth pseudowavefunctionsto ugly oscillating all-electron wavefunctions

I Calculate quantities from smooth functions plus atomiccontributions:

〈φ|O|ψ〉 = 〈φ|O|ψ〉︸ ︷︷ ︸3D grid

+∑ai

〈φ|pai 〉⟨

atomicproperties

⟩︸ ︷︷ ︸

System independent

〈pai |ψ〉

I Projector functions couple 3D calculation to atomic corrections

Page 6: Ask Hjorth Larsen asklarsen@gmail - CAMD decentral webserverdcaskhl/files/gpaw-slides.pdf · WAGP Wrapping up Ask Hjorth Larsen asklarsen@gmail.com Nano-bio Spectroscopy Group and

GPAW Wrapping up

GPAW

Uniform real-space grids

I Accurate, parallelizes very well

I Grid causes �egg-box� e�ect

Numeric atomic orbitals

I Very fast � easy to do thousands of atoms

I Not as accurate; cannot easily reach complete basis set

Planewave mode

I Fast for small systems (crystals)

I Planewaves numerically well-behaved

I Not scalable

Page 7: Ask Hjorth Larsen asklarsen@gmail - CAMD decentral webserverdcaskhl/files/gpaw-slides.pdf · WAGP Wrapping up Ask Hjorth Larsen asklarsen@gmail.com Nano-bio Spectroscopy Group and

GPAW Wrapping up

Real-space (�FD�) mode

I GPAW(mode='fd', h=0.18)

I Iterative eigensolvers (solve �a bit� every iteration)

I 3D main CPU mesh: distribute ψkn(r) over spins/k-points,domains and bands

I Wave functions on coarse grid, density/potential on �ne grid

I Multigrid: Solve 2x2x2 grid; then on 4x4x4 grid; then on8x8x8 grid; etc.

I Features: Real-time TDDFT, Linear response TDDFT

Page 8: Ask Hjorth Larsen asklarsen@gmail - CAMD decentral webserverdcaskhl/files/gpaw-slides.pdf · WAGP Wrapping up Ask Hjorth Larsen asklarsen@gmail.com Nano-bio Spectroscopy Group and

GPAW Wrapping up

Stencils

I Di�erential operators represented by �nite-di�erence stencils

I Oψ(x, y, z) =∑ijk

wijkψ(x+ i dx, y + j dy, z + k dz)

x

x

x x x x x

x

x

More nearest neighbours → higher order → better convergence

Page 9: Ask Hjorth Larsen asklarsen@gmail - CAMD decentral webserverdcaskhl/files/gpaw-slides.pdf · WAGP Wrapping up Ask Hjorth Larsen asklarsen@gmail.com Nano-bio Spectroscopy Group and

GPAW Wrapping up

PW mode

I GPAW(mode=PW(400))

I Same eigensolvers as FD mode (iterative)

I (Almost) no egg-box e�ect

I Parallelize over spins/k-points and states (�bands�)

I Only mode supporting stresses

I Features: RPA linear response, G0W0 (not selfconsistent butunder development), Bethe�Salpeter equation

Page 10: Ask Hjorth Larsen asklarsen@gmail - CAMD decentral webserverdcaskhl/files/gpaw-slides.pdf · WAGP Wrapping up Ask Hjorth Larsen asklarsen@gmail.com Nano-bio Spectroscopy Group and

GPAW Wrapping up

LCAO mode

I GPAW(mode='lcao', basis='dzp', h=0.18)

I Wavefunctions represented as |ψn〉 =∑µ

|Φµ〉 cµn

I |Φµ〉 are localized functions based on atomic orbitals

I Small basis set (∼ 5�20 functions per atom) allows directdiagonalization

I Kohn�Sham equations explicitly solved as generalized

eigenvalue problem:∑ν

HµνCνn =∑ν

SµνCνnεn

I Parallelize over spins/k-points, domains, orbitals

I Parallelize linear algebra with BLACS/ScaLAPACK

I Features: Time-propagation TDDFT (LCAO-TDDFT)

Page 11: Ask Hjorth Larsen asklarsen@gmail - CAMD decentral webserverdcaskhl/files/gpaw-slides.pdf · WAGP Wrapping up Ask Hjorth Larsen asklarsen@gmail.com Nano-bio Spectroscopy Group and

GPAW Wrapping up

Localized basis sets

0 1 2 3 4 5 6 7 8r [Bohr]

0.1

0.0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

φr

Basis functions: Au dzp

6s-sz confin5d-sz confin6s-dz split-5d-dz split-p-type Gauss

Page 12: Ask Hjorth Larsen asklarsen@gmail - CAMD decentral webserverdcaskhl/files/gpaw-slides.pdf · WAGP Wrapping up Ask Hjorth Larsen asklarsen@gmail.com Nano-bio Spectroscopy Group and

GPAW Wrapping up

Parallel scaling

I Parallel performance of GPAW/LCAO

I Timing per SCF step

I 2500�10000 atoms

1/16

2/32

4/64

8/128

16/25

6

Number of nodes/cores

101

102

103

104

Tim

e[s

]

1N3NSCF

2N4Ndiag

1/16

2/32

4/64

8/128

16/25

6

Number of nodes/cores

100

101

102

103

total xclibvdwxc

1/16

2/32

4/64

8/128

16/25

6

Number of nodes/cores

10−1

100

101

102

totalFFTWconvolution

Page 13: Ask Hjorth Larsen asklarsen@gmail - CAMD decentral webserverdcaskhl/files/gpaw-slides.pdf · WAGP Wrapping up Ask Hjorth Larsen asklarsen@gmail.com Nano-bio Spectroscopy Group and

GPAW Wrapping up

Parallel scripting

I GPAW compiles MPI-enabled interpreter gpaw-python

I mpirun -np 4 gpaw-python script.py

I Each core has distinct �rank� but runs the same code

import numpy as np

from gpaw.mpi import world

print('hello {}/{} '.format(world.rank , world.size))

array = np.ones (3) * world.rank

big_array = None

if world.rank == 0:

big_array = np.zeros (3 * world.size)

world.gather(array , 0, big_array)

if world.rank == 0:

print(big_array)

world.sum(array)

print(array)

Page 14: Ask Hjorth Larsen asklarsen@gmail - CAMD decentral webserverdcaskhl/files/gpaw-slides.pdf · WAGP Wrapping up Ask Hjorth Larsen asklarsen@gmail.com Nano-bio Spectroscopy Group and

GPAW Wrapping up

ASE

I Web page: https://wiki.fysik.dtu.dk/ase/

I Mailing list: [email protected]

I git: https://gitlab.com/ase/ase

I IRC: #ase on irc.freenode.net

I License: LGPLv2.1+

GPAW

I Web page: https://wiki.fysik.dtu.dk/gpaw/

I Mailing list: [email protected]

I git: https://gitlab.com/gpaw/gpaw

I IRC: #gpaw on irc.freenode.net

I License: GPLv3+

Page 15: Ask Hjorth Larsen asklarsen@gmail - CAMD decentral webserverdcaskhl/files/gpaw-slides.pdf · WAGP Wrapping up Ask Hjorth Larsen asklarsen@gmail.com Nano-bio Spectroscopy Group and

GPAW Wrapping up

Contribute to ASE!

I https://wiki.fysik.dtu.dk/ase/development/

contribute.html

I Create account on Gitlab

I Clone ASE (and learn git...)

I Hack

I Push changes to your own branch on Gitlab

I Create merge request

Things to do

I Report and �x bugs

I Add your favourite calculator

I Add your favourite �le format

I Translate ASE GUI into Catalan

Page 16: Ask Hjorth Larsen asklarsen@gmail - CAMD decentral webserverdcaskhl/files/gpaw-slides.pdf · WAGP Wrapping up Ask Hjorth Larsen asklarsen@gmail.com Nano-bio Spectroscopy Group and

GPAW Wrapping up

Ask not what free software can do for you;ask what you can do for free software!� Not quite JFK