Story of ASE

ASE Workshop
Chalmers, November 19-22, 2019

Jens Jørgen Mortensen, CAMd, Department of Physics, Technical University of Denmark

  • ASE-1.0
  • ASE-2.0
  • ASE-3.0
  • The future

Presenter Notes

ASE-1.0

It all started with Dacapo (a Fortran USPP plane-wave DFT code):

S. R. Bahn and K. W. Jacobsen, An object-oriented scripting interface to a legacy electronic structure code, Comput. Sci. Eng., Vol. 4, 56-66, 2002, https://dx.doi.org/10.1109/5992.998641
  • Use Python scripts
  • Write input to netCDF file
  • Communicate with Fortran code through a socket
  • Read output from netCDF file

Presenter Notes

Overview

ase1.gif

Presenter Notes

Example

from Simulations.Dacapo import *
mysim = Simulation()
mysim.bands = ElectronicBands(9)
mysim.config = ListOfAtoms(
    atoms=[Atom(Mg_GGA, Vector([0, 0, 0]))],
    unitcell=BravaisLattice(
        [[-1.425, 1.425, 1.425],
         [1.425, -1.425, 1.425],
         [1.425, 1.425, -1.425]])
mysim.plancut = PlaneWaveCutoff(340)
mysim.Execute()

Presenter Notes

ASE-2.0

Problems with ASE-1:

  • Other codes (from Dacapo to ASAP)
  • Millions of atoms
  • Too many objects?

After many discussions and meetings, ASE-2.0 was created from scratch.

  • Simulation -> ListOfAtoms
  • ListOfAtoms.GetCartesianPositions() -> numpy.ndarray

Presenter Notes

Lines of code

lines2.png

Presenter Notes

Calculators

calculators.png

ASE-3.19: ~40 calculators

Presenter Notes

Installation ASE in the old days

install2.png

Presenter Notes

ASE-3.0

Problems with ASE-2:

  • Weird unit system
  • Weird naming convention (files and function names)
  • ListOfAtoms -> Atoms
  • ...

Rewrite from scratch or adapt current code base?

  1. Rewrite
  2. Ask for permission later

Presenter Notes

Lines of code ...

lines.png

279 contributors so far ...

Presenter Notes

Some highlights

  • A beta version of the new ASE-3.0 will be used for the electronic structure course at CAMd. (10 Jan 2008)
  • The new Sphinx page is now up and running! (2 Apr 2008)
  • CAMd/Cinf will do a "doc-sprint" from 9 to 16. (17 Apr 2008)
  • ASE version 3.0.0 released (13 November 2008).
  • ASE has reached revision 1000 (16 July 2009).
  • The source code is now on GitLab (18 September 2015).
  • Reference paper in J. Phys. Condens. Matter: The Atomic Simulation Environment | A Python library for working with atoms (7 June 2017).

Presenter Notes

Technology

  • Web-page: Home-made thing -> MoinMoin wiki -> Sphinx + Python scripts.
  • Testing: home-made framework:
    • After every commit: GitLab-CI
    • Every night: VASP + GPAW
  • Numeric -> numarray -> numpy, scipy
  • Python 1.x -> 3.8
  • CVS -> SVN -> Git
  • spglib?, C-code?

Presenter Notes

You want to contribute to ASE

Thank you!

Let's do it right:

  • code review
  • documentation
    • low level: docstrings
    • high level: how to use it
  • tests
  • release notes
  • remove old way of doing it

Presenter Notes

Contribute to ASE?

Think of a contribution like a puppy: you might view it as this cute,
wonderful thing you're giving me while I'm looking at it as over a
decade of feeding, walking, and vet bills.

-- Brett Cannon

Not everything is a good fit for ASE

Alternatives:

  • Code snippets in a tutorial plus a few helper functions added to ASE.
  • Its own thing: PyPI + GitLab + ReadTheDocs + JOSS

Presenter Notes

The Zen of ASE

  • less is more
  • so nothing at all could be a good solution
  • if your thing has documentation and tests then it might be a good fit for ASE
  • if it doesn't, we don't want it
  • ... unless you are from Denmark

Presenter Notes

Issues and MR's

issues.png

Merge requests: 1245 merged, 195 closed and 47 open.

Presenter Notes

Presenter Notes

Maintenance

Keeping ASE going is more work that most people think!

  • Review and merge MR's
  • Fix issues
  • Mail-list support
  • Find and nudge the expert that knows something

There are many bigger projects necessary in order to keep ASE moving in the right direction. Example: Calculators!

Presenter Notes

Should we try to get funding for an ASE maintainer?

"If you have found ASE to be useful in your work, research or company, please consider making a donation to the project commensurate with your resources. Any amount helps! All donations will be used strictly to fund the development of ASE’s open source software, documentation and community."

Presenter Notes

What could we offer sponsors?

  • ASE will also be in good shape two years from now
  • Generate goodwill thanks to your appearance in the list of sponsors
  • Influence the work of sponsored developers so that ASE continues to fit your needs
  • Your favorite electronic structure code will be supported and part of the daily tests.

Presenter Notes

Type hints

A simple example from ASE's code:

import re

def strip_number(s):
    """Split string to number and the rest.

    >>> strip_number('2Au')
    2
    """
    m = re.match('[0-9]*', s)
    return int(m.group() or 1), s[m.end():]

x = strip_number('12Cu') * 2.5

See also: https://gitlab.com/ase/ase-workshop-discussion/issues/2

Presenter Notes

Type hints + MyPy

import re
from typing import Tuple

def strip_number(s: str) -> Tuple[int, str]:
    m = re.match('[0-9]*', s)
    return int(m.group() or 1), s[m.end():]

x = strip_number('12Cu') * 2.5
$ mypy hint.py
hint.py:6: error: Item "None" of "Optional[Match[str]]"
           has no attribute "group"
hint.py:6: error: Item "None" of "Optional[Match[str]]"
           has no attribute "end"
hint.py:8: error: Unsupported operand types for * ("Tuple[int, str]"
                                                   and "float")
Found 3 errors in 1 file (checked 1 source file)

Presenter Notes

Type hints + MyPy ...

import re
from typing import Tuple

def strip_number(s: str) -> Tuple[int, str]:
    m = re.match('[0-9]*', s)
    assert m is not None
    return int(m.group() or 1), s[m.end():]

x = strip_number('12Cu')[0] * 2.5
$ mypy hint.py
Success: no issues found in 1 source file

Presenter Notes

Type hint in ASE?

  • we can do it gradually

  • it's documentation that mypy can check for us

  • code is read a lot more than written

  • make it easier for new contributors

  • improved editor-completion

  • find bugs for us

  • lead to simpler code

  • wait for ASE to drop Python 3.5:

    ...
    number = []  # type: List[int]
    number: List[int] = []
    

Presenter Notes

Summary

  • ASE has been rewritten from scratch twice - I hope we will not need a 4.0 rewrite
  • Please donate to ASE - somehow
  • Type hints are great!

Presenter Notes