Git Product home page Git Product logo

atomec-project / atomec Goto Github PK

View Code? Open in Web Editor NEW
17.0 4.0 11.0 7.84 MB

Python-based average-atom code for simulations of high energy density phenomena such as in warm dense matter.

Home Page: https://atomec-project.github.io/atoMEC/

License: BSD 3-Clause "New" or "Revised" License

Python 99.94% Shell 0.06%
electronic-structure warm-dense-matter density-functional-theory atomic-physics plasma-physics

atomec's Introduction

image

atoMEC: Average-Atom Code for Matter under Extreme Conditions

docs Python 3.12 image codecov CodeFactor

atoMEC is a python-based average-atom code for simulations of high energy density phenomena such as in warm dense matter. It is designed as an open-source and modular python package.

atoMEC uses Kohn-Sham density functional theory, in combination with an average-atom approximation, to solve the electronic structure problem for single-element materials at finite temperature.

More information on the average-atom methodology and Kohn-Sham density functional theory can be found (for example) in this paper and references therein.

This repository is structured as follows:

├── atoMEC : source code
├── docs : sphinx documentation
├── examples : simple examples to get you started with the package
└── tests : CI tests

Installation

The latest stable release of atoMEC can be installed via pip. It is first necessary to install the libxc package from a tarball source, because it currently has no official wheels distribution on PyPI. This step takes some time.

$ pip install https://gitlab.com/libxc/libxc/-/archive/6.2.2/libxc-6.2.2.tar.gz
$ pip install atoMEC

Note that atoMEC does not (yet) support Windows installation (please see the section below on supported operating systems).

Read on for instructions on how to install atoMEC from source, using the recommended pipenv installation route.

Installation via pipenv

First, clone the atoMEC repository and cd into the main directory.

  • It is recommended to install atoMEC inside a virtual environment. Below, we detail how to achive this with pipenv.

    This route is recommended because pipenv automatically creates a virtual environment and manages dependencies. Note that pyblibxc is automatically installed in this case, so there is no need to install it separately.

    1. First, install pipenv if it is not already installed, for example via pip install pipenv (or see pipenv for installation instructions)
    2. Next, install atoMEC's dependencies with pipenv install (use --dev option to install the test dependencies in the same environment)
    3. Use pipenv shell to activate the virtual environment
    4. Install atoMEC with pip install atoMEC (for developers: pip install -e .)
    5. Now run scripts from inside the atoMEC virtual environment, e.g. python examples/simple.py
  • Run the tests (see Testing section below) and report any failures (for example by raising an issue).

Supported operating systems

  • Linux and macOS: atoMEC has been installed on various linux distributions and macOS, and is expected to work for most distributions and versions
  • Windows: atoMEC does not support Windows installation. This is due to the dependency on pylibxc which currently lacks Windows support. We are looking into ways to make the dependency on pylibxc optional, in order to allow installation on Windows. However, this is not currently a priority.

Supported Python versions

  • atoMEC has been tested and is expected to work for all Python versions >= 3.8 and <= 3.12
  • atoMEC does not work for Python <= 3.7
  • Until 09.10.2023 (release 1.4.0), all development and CI testing was done with Python 3.8. As of this date, development and CI testing is done with Python 3.12.
  • Python 3.12 is therefore the recommended version for atoMEC >= 1.4.0, since this is used for the current testing and development environment

Running

You can familiarize yourself with the usage of this package by running the example scripts in examples/.

Contributing to atoMEC

We welcome your contributions, please adhere to the following guidelines when contributing to the code:

  • In general, contributors should develop on branches based off of develop and merge requests should be to develop
  • Please choose a descriptive branch name
  • Merges from develop to master will be done after prior consultation of the core development team
  • Merges from develop to master are only done for code releases. This way we always have a clean master that reflects the current release
  • Code should be formatted using black style

Testing

  • First, install the test requirements (if not already installed in the virtual env with pipenv install --dev):
# activate environment first (optional)
$ pipenv shell

# install atoMEC as editable project in current directory (for developers)
$ pip install -e .[tests]

# alternatively install package from PyPI with test dependencies
$ pip install atoMEC[tests]
  • To run the tests:
$ pytest --cov=atoMEC --random-order tests/

Build documentation locally (for developers)

Install the prerequisites:

$ pip install -r docs/requirements.txt
  1. Change into docs/ folder.
  2. Run make apidocs.
  3. Run make html. This creates a _build folder inside docs. You may also want to use make html SPHINXOPTS="-W" sometimes. This treats warnings as errors and stops the output at first occurrence of an error (useful for debugging rST syntax).
  4. Open docs/_build/html/index.html.
  5. make clean if required (e.g. after fixing errors) and building again.

Developers

Scientific Supervision

Core Developers and Maintainers

Contributions (alphabetical)

Citing atoMEC

If you use code from this repository in a published work, please cite

  1. T. J. Callow, D. Kotik, E. Kraisler, and A. Cangi, "atoMEC: An open-source average-atom Python code", Proceedings of the 21st Python in Science Conference, edited by Meghann Agarwal, Chris Calloway, Dillon Niederhut, and David Shupe (2022), pp. 31 – 39
  2. The DOI corresponding to the specific version of atoMEC that you used (DOIs are listed at Zenodo.org)

atomec's People

Contributors

acangi avatar danielkotik avatar ekaterinahs avatar nathanera avatar timcallow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

atomec's Issues

Publish to PyPI skipped in CI on a new release

Check, why the step for publishing to PyPI got skipped for release v1.1.0. This step should be triggerd for a tagged commit. Even though a bumpversion minor ... creates a tagged commit locally, pushing it without the --tags flag will not trigger the pipeline and probably not even if the tag is subsequently pushed.

  • Find a better criteria, maybe creating a release out of the tag on GitHub is a good choice

Make new release 1.1.0

Steps to perform:

  1. Create a PR from develop to master #109
  2. Merge the PR
  3. Adjust date-released: ... in CITATION.cff (on master)
  4. Create a tagged (and signed) commit on master with bumpversion minor --allow-dirty (check changes with git show or git diff HEAD^)
  5. Check out develop and do a git merge master --ff
  6. Push develop and master to origin
  7. Create a new release out of the tag and add release notes: https://github.com/atomec-project/atoMEC/releases → Draft a new release
  8. Check if release got published to PyPI

Math equations not rendering correctly

It seems some math is being rendered by Sphinx but most of it not. One of the issues may be that we need to somewhere import physics and amsmath packages with something like the following command in conf.py:

imgmath_latex_preamble = r"""                                                                                                                                                                                      
\usepackage{amsmath}                                                                                                                                                                                               
\usepackage{physics}                                                                                                                                                                                               
"""

Hartree potential has small error

The Hartree potential integral is performed in two parts:

Screenshot from 2021-08-24 14-29-24

In the code this is done as:

Screenshot from 2021-08-24 14-30-59

Since we have a discrete grid we need to choose where the splitting point of the Hartree integral is (ie whether to use <= or < in the above). At the moment, it seems the split is not right when considering the integral discretization. So the inequalities need to be swapped (which makes a small difference to the numerics).

Boundary conditions at leftmost gridpoint `x0`

Currently, the boundary condition applied at the LHS grid-point forces the (transformed) orbitals to be exactly zero. This is not strictly correct, in particular when we have l=0 angular quantum number.

This doesn't yet seem to be having an adverse impact on the computation of observables, but it would be interesting to see the impact of applying the correct boundary conditions. In the current Numerov diagonalization scheme, this would involve appropriate changes to the hamiltonian matrix in the top LH corner.

See the extract from Eli's thesis for the correct constraints (of course, our grid is just a log grid, we have no dependence on atomic number Z.)

Screenshot from 2021-08-05 13-03-51

Parallelization fails for jobs running simultaneously from same folder

atoMEC uses the joblib library for a simple parallelization over spin and l quantum numbers when diagonalizing the Hamiltonian. It is recommended in joblib to dump large arrays to a file which is then deleted after.

Currently in atoMEC this writing to file does not work when multiple simulations are performed simultaneously from the same directory (i.e. quite likely on on HPC), because the data file for a given run is overwritten by the data file for another run.

Simple fix will be just to randomize the name of the data file.

Codecov showing different coverage than locally

The codecov reports are showing a lower percentage coverage than what is seen locally. This seems to have been triggered by renaming pressure_test.py to pressure_test_log.py, and introducing a new test pressure_test_sqrt.py in PR #179.

This page gives advice on finding the cause of the issue. In this case, I'm pretty sure we know the cause, as described above. I don't know how to fix it however.

Docs need checking

Over time, some docstrings / comments have been neglected and do not reflect the code accurately. At some point, all docstrings should be checked for accuracy.

This is probably an ideal task for chatGPT (particularly the API).

AttributeError with test `boundary_comp.py`

python boundary_comp.py gives

func:'CalcEnergy' took: 83.0255 sec
Traceback (most recent call last):
  File "..../atoMEC_import/tests/boundary_comp.py", line 27, in <module>
    print("Total free energy with dirichlet :" + str(energy_dirichlet.F_tot))
AttributeError: 'dict' object has no attribute 'F_tot'

Version number in `setup.py` vs `CITATION.cff`

In setup.py the version is given as 0.1.0, whereas in CITATION.cff it is 1.0.0. Should we make these consistent? @DanielKotik I defer to your judgement on which is more appropriate.

(Also, I'm the only author listed in setup.py. I guess this ok since we can't list everyone there)

"About" section

I have added a short description (taken directly from the README) and a few suggested topics. @acangi feel free to make any changes you would like.

about_atoMEC

Temperature warnings need changing

A warning is currently issued if the temperature is outside of the range [0.01, 3.5] Hartree. A message is then printed that the "normal temperature range for atoMEC is 0.01 - 100 eV". There are two problems here:

  1. The printed range does not actually match correctly to the range which triggers the warning
  2. 100 eV is a bit of a random choice. We can certainly do temperatures that high, indeed we can often reach up to 1000 eV. It depends on the density.

I think we should essentially scrap these warnings. Somewhere in the documentation we should include a section on calculation issues in which we can mention the conditions under which atoMEC struggles, and possible strategies in those cases,

Mirror to CASUS not working

I noticed that the mirror from this repository to https://github.com/casus/atoMEC iseems not to be working. On the CASUS mirror it does not have the most recent updates to the code, with the last update being on 07.03.22 . Maybe it's because the PRs made since then weren't approved before being merged? But I don't think that's the reason because #117 was approved and the mirror didn't update. So maybe it was the one of the commits made on March 7th that caused this error.

Laplacian of KS orbitals incorrect at RHS boundary

The laplace function in mathtools module gives some numerical errors on the RHS boundary, due to the numpy.gradient function which uses finite differences.

This contaminates the kinetic energy density and thus the total kinetic energy with a small (but significant when computing pressures) numerical error. See for example the attached, we see the k.e.d. seems to approaching an asymptotic limit but the final 3 points are incorrect.

Screenshot from 2021-08-24 10-01-35

Add option for "full_quantum" unbound electron treatment

Currrently, the only unbound electron treatment supported is "ideal". Since we perform a full diagonalization of the Hamiltonian and have access to a large number of eigenstates, we can use these eigenstates for the unbound electrons, like a "discretized continuum".

To make this work, the way that bound electrons are currently treated can basically be copied for unbound electrons, only now a new matrix such as "l_unbound" should be introduced which only takes into account the positive energy eigenvalues.

Test workflow warnings

Some warnings appear in new test workflow:

image

image

  • your are using a rather old version of the cache action (v1 instead of v3), an update should resolve some of the above issues
  • change runs-on: ubuntu-18.04 to a more recent version

Explore better ways for writing output

See this comment. Probably nicer ways of outputting data from calculations. Note that not only the <x>_to_csv functions have potential for improvement but a lot of the writeoutput module is a bit hacked together. We might also want to introduce options to store various objects (e.g. using pickle), maybe bundled up together, for re-use in postprocessing / restarting calculations.

`__init__` methods do not get parsed by Sphinx autodoc

Looks good.
I think the docstring in models.ISModel is not rendering correctly due to some incorrect formatting... But even if it were rendering there would the same error as we saw in PRs #18 and #16. I will fix later today.

Mhh, for me this docsting looks good. Also, there are now warning messages anymore.

Strange there are no warnings, but I don't see any of the class parameters displaying? And the propertys have no docs

Screenshot from 2021-06-28 12-02-10

Originally posted by @timcallow in #19 (comment)

Sparse eigenvalue solver from `scipy` struggles when many eigenvalues are needed

atoMEC uses a sparse linear eigenvalue solver from scipy which has a tendency to break down when a large number of eigenfunctions are required, particularly for the "neumann" boundary condition. This is often the case e.g. at very low densities: the solver can only return the lowest magnitude eigenvalues, whereas we seek the actual lowest eigenvalues (i.e. negative ones with large magnitudes). This means we often have to ask for many more eigenvalues than actually needed.

Solution: Adding a constant to the KS potential shifts the eigenvalues by the same constant. If we choose a large enough number then all eigenvalues will have positive sign and we don't need to request so many arbitrary eigenvalues. Will see if this works.

Chemical potential should not stored as a `config` variable

The chemical potential (config.mu) is really a property of the staticKS.Orbitals class and thus should be moved there. Storing it as a variable in config causes a bug when post-processing a set of orbitals under different conditions, because the occupation numbers are recalculated with the last saved value of config.mu instead of their actual chemical potential.

Numpy docstring style compliance

Job test-docstrings fails in gh-pages workflow. The checks performed are done via

pydocstyle --convention=numpy atoMEC

All the errors given, need to be fixed for the docs pipeline to run successfully.

Mirror: prevent workflows from beeing tirggered

Each push to the mirror repository triggers workslfows. This is not supercritical because deploying to GitHub pages and PyPI fails due to missing permissions of the mirror, but these and all other workflows do not have to run at all.

Structural problems with code

atoMEC currently relies on the config.py module to store various global variables. This worked ok for the initial purpose of the code, which was basically just set up to solve the KS-DFT equations for an average-atom model.

However, it's becoming clear to me that this a major problem when one wants to use the code in a modular way as more functionality is added, particularly post-processing tools for a given output of a KS calculation. Such issues are not limited to just the config.py module, some classes are initialized in such a way that it is not possible (without great difficulty) for a user to create their own instances, rather they only work if created via a KS-DFT calculation.

Fixing this issue will require a significant reformulation of the code... But needs to be done!

Defaults need overhaul

The defaults used by atoMEC were set in the initial development of the code. Since then, more advanced options have been added which significantly enhance the accuracy of the code. The defaults should be updated to use the "best" options (either most accurate or efficient, depending on the circumstance).

Black: line length formatting fails for docstrings!?

Black sets line lengths to 88 by default (PEP8 recommends however a line length of 79 characters). Either way, I have noticed that black does not reformat docstrings to adjust the line length. @timcallow can you confirm this? If we have to manually adjust the line length for docstrings, I would suggest to use flake8/pycodestyle to check against it (also in the pipeline).

We first have to agree on the number of characters per line (I am fine with both 79 and 88, but not more). If this differs from black's default, we should add a pyproject.toml with

[tool.black]
line-length = 79

Add GGA support via pylibxc

Currently only the lda family of xc-functionals is supported in atoMEC. We should also add GGA functionals since they just need the gradient of the density as input.

`sqlite3.ProgrammingError` sometimes occurs with parallelization

When using multiple cores with joblib, sometimes the following error is raised:

Exception during reset or similar
Traceback (most recent call last):
  File "/home/callow46/.local/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 697, in _finalize_fairy
    fairy._reset(pool)
  File "/home/callow46/.local/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 893, in _reset
    pool._dialect.do_rollback(self)
  File "/home/callow46/.local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 543, in do_rollback
    dbapi_connection.rollback()
sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 139675633149760 and this is thread id 139675095406336.
Exception closing connection <sqlite3.Connection object at 0x7f08a8e3e030>

The code continues to run after the error is raised and it does not affect the results. However it's annoying since it doesn't look good (and I'm not sure but maybe is capable of causing something critical). It seems random as to whether this error appears or not.

It seems the sqlalchemy library is called indirectly through the mendeleev library imported into atoMEC. This only performs some initialization of the Atom object and joblib is supposed to work in a self-contained way, i.e. multiple threads should only be used during the diagonalization and then the code should return to single threading. So I'm not sure why joblib is interfering with sqalchemy. Either way it would be good to prevent this error from happening, or at the very least tell atoMEC just to ignore this error (I'm not sure how to do this since I don't know when exactly the error is induced).

@DanielKotik any ideas?

`EnergyAlt` class misses the potential shift

In the EnergyAlt class, the total energy is computed using an alternative method (sum over the eigenvalues and subtracting the integral over the Hxc potential, \int dr n(r) v_Hxc(r)).

If this approach is used and config.v_shift=True, then the constant shift in the eigenvalues must be compensated for by an equal and opposite term in the potential integral. Currently, this is not done.

atoMEC not installable for Python > 3.9

Due to the dependence on the rather strange pylibxc library, atoMEC is not installable for Python > 3.9.

We need to add a warning in the README. But also test exactly which Python versions it is compatible with.

Clash between `pydocstyle` errors and `property` documentation

Running pydocstyle --convention=numpy <file.py> produces errors such as:

staticKS.py:523 in public method `E_xc`:
        D401: First line should be in imperative mood; try rephrasing (found 'dict')
staticKS.py:523 in public method `E_xc`:
        D403: First word of the first line should be properly capitalized ('Dict', not 'dict')

which clash (especially the first error) with how we document property tags (which follows the advice in https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_numpy.html).

Fix ignored `pyproject.toml` in workflow python-style-checks

In workflow python-style-checks in step Check docstrings following message appears:

Run pydocstyle --convention=numpy atoMEC
WARNING: The /home/runner/work/atoMEC/atoMEC/pyproject.toml configuration file was ignored, because the `toml` package is not installed.

GitHub Actions deploy fail

When a review is approved, the build-and-deploy-pages pipeline gets triggered but fails with

build-and-deploy-pages
Action failed with "not found deploy key or tokens"

The expected behaviour is, that this pipeline is skipped when a PR gets approved and only gets triggered, when the actual merge happens. Even better would be, if building the pages gets triggered when a PR is created and build+deploy finally on merge.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.