Skip to content

Commit

Permalink
Maintenance on test infrastructure (#659)
Browse files Browse the repository at this point in the history
* make tests a module
This is needed because we want to have a common.py file at the root of the Test folder and the only way to get relative imports working is to make everything a module

* skip tests with mpi
Skip all existing tests under mpi
* mark legacy tests
Skip them by default
* change github actions
* Add SR MPI tests

* fix mpi tests

* simplify sr tests

* fixup!

* fixup!

* document a bit more

* switch to myst_parser instead of recommonmark

recommonmark is now deprecated in favour of myst parser

* Add documentation for contributors

* update README badges

- change the anaconda badge to display last version - - uploaded rather than nothing
- remove travis badge, as we dont use it anymore
- add codecov badge ( i never find the right link)
- remove github issue badget (it's just above there)
[ci skip]
  • Loading branch information
PhilipVinc committed Apr 29, 2021
1 parent 8a0c465 commit 59a0f52
Show file tree
Hide file tree
Showing 56 changed files with 652 additions and 382 deletions.
43 changes: 29 additions & 14 deletions .github/workflows/CI.yml
@@ -1,4 +1,4 @@
name: Coverage
name: CI

on:
pull_request:
Expand All @@ -14,9 +14,19 @@ jobs:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
python-version: 3.8
mpi: ""
legacy: true

- os: ubuntu-latest
python-version: 3.8
mpi: "mpich"

- os: macos-latest
python-version: 3.8
mpi: "mpich"

- os: macos-latest
python-version: 3.8
mpi: ""
Expand All @@ -37,36 +47,41 @@ jobs:
python-version: ${{ matrix.python-version }}

- name: Install MPI
if: matrix.mpi != ''
run: |
sh ./conf/travis-install-mpi.sh mpich
sh ./conf/travis-install-mpi.sh ${{ matrix.mpi }}
- name: Get pip cache dir
id: pip-cache
run: |
python -m pip install --upgrade pip
echo "::set-output name=dir::$(pip cache dir)"
#- name: pip cache
# uses: actions/cache@v2
# with:
# path: ${{ steps.pip-cache.outputs.dir }}
# key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.py', '**/pyproject.toml') }}
# restore-keys: |
# ${{ runner.os }}-pip-

- name: Pip install python dependencies
- name: Pip install packages
run: |
pip install jaxlib
pip install -e ".[dev,mpi]"
if [ -z "${{ matrix.mpi }}" ]; then
pip install -e ".[dev]"
else
pip install -e ".[dev, mpi]"
fi
- name: MPI tests
if: matrix.mpi != ''
run: |
mpirun -host localhost:2 -np 2 coverage run -m pytest -n 0 Test/MPI
mpirun -host localhost:2 -np 2 coverage run -m pytest -n 0 Test
- name: Netket tests
if: ${{ !matrix.legacy }}
run : |
export NETKET_EXPERIMENTAL=1
pytest --cov=netket --cov-append Test
- name: Netket Legacy tests
if: ${{ matrix.legacy }}
run : |
export NETKET_EXPERIMENTAL=1
pytest --cov=netket --cov-append
pytest --cov=netket --cov-append --legacy-only Test
- name: Upload coverage
uses: codecov/codecov-action@v1
95 changes: 2 additions & 93 deletions CONTRIBUTING.md
@@ -1,96 +1,5 @@
# Contributing guidelines

Thank you for getting involved in NetKet. It is only thanks to the involvement of
a large community of developers that open-source software like NetKet can thrive.
Please take the time to read the following guidelines, to ensure that your contributions
are in line with the general goals of this project and its requirements.
Those have been moved to our website. Please visit

## Pull Request Checklist

Before sending your pull requests, make sure you followed this list.

- Read [contributing guidelines](CONTRIBUTING.md).
- Read [Code of Conduct](CODE_OF_CONDUCT.md).
- Check if your changes are consistent with the [guidelines](CONTRIBUTING.md#general-guidelines-and-philosophy-for-contribution).
- Check if your changes are consistent with the [Python](CONTRIBUTING.md#python-coding-style) code style and run the Black code formatter as needed.
- Run [Unit Tests](CONTRIBUTING.md#running-unit-tests).

## How to become a contributor and submit your own code

### Contributing code

If you have improvements to NetKet, or want to get involved in one of our [Open Issues](https://github.com/netket/netket/issues) send us your pull requests! For those just getting started, Github has a [howto](https://help.github.com/articles/using-pull-requests/).

NetKet team members will be assigned to review your pull requests. Once the pull requests are approved and pass continuous integration checks, we will merge the pull requests.

If you want to contribute but you're not sure where to start, take a look at the
[issues with the "help wanted" label](https://github.com/netket/netket/labels/help%20wanted).
These are issues that we believe are particularly well suited for outside
contributions. If you decide to start on an issue, leave a comment so that other people know that
you're working on it. If you want to help out, but not alone, use the issue comment thread to coordinate.

### Contribution guidelines and standards

Before sending your pull request for
[review](https://github.com/netket/netket/pulls),
make sure your changes are consistent with the guidelines and follow the
NetKet coding style.

#### General guidelines and philosophy for contribution

* Include unit tests when you contribute new features, as they help to
a) prove that your code works correctly, and b) guard against future breaking
changes to lower the maintenance cost.
* Bug fixes also generally require unit tests, because the presence of bugs
usually indicates insufficient test coverage.
* When you contribute a new feature to NetKet, the maintenance burden is (by
default) transferred to the NetKet team. This means that benefit of the
contribution must be compared against the cost of maintaining the feature.

#### License

Include a license at the top of new files.

#### Python coding style

Python code should follow [PEP 8](https://www.python.org/dev/peps/pep-0008/).
For consistency, we use the [Black](https://github.com/python/black) code formatter, which you can install in your Python environment using `pip install black`.
If you edit Python code, you should run Black on the affected files.
On the command line, this can be done via
```bash
# to reformat a specific file
black Path/To/The/file.py
# to reformat all files below the specified directories
black Test/ Examples/
```
before creating a pull request.
There are other options of running Black: For example, an [Atom package](https://atom.io/packages/python-black) is available and Black is integrated into the [VS Code Python extension](https://code.visualstudio.com/docs/python/editing#_formatting).


#### Including new unit tests

Contributions implementing new features **must** include associated unit tests.
Unit tests in NetKet are based on [pytest](https://docs.pytest.org/en/latest/) and are located in the directory `Test`.

#### Running unit tests
Unit tests can be run locally doing

```bash
pytest Test --verbose
```

this will highlight cases where tests are failing. These must be addressed before any pull request can be merged on stable branches.

#### Test MPI code

For code that relies on MPI operations, there are units tests in the `Test_MPI` subfolder.
If you add MPI-related code, please also add corresponding unit tests to that directory.

The MPI tests can be run with
```bash
mpirun -np 2 pytest Test_MPI --verbose
```
Note that this will print the test output twice, as `pytest` itself is not aware of being run with MPI.
Running these tests also provides a quick way to check if your MPI setup is working.
If `test_is_running_with_multiple_procs` or `test_mpi_setup` is failing, you should check your MPI configuration,
for example whether `mpi4py` is compiled against the correct MPI libraries for your machine.
https://www.netket.org/docs/contributing.html
5 changes: 2 additions & 3 deletions README.md
Expand Up @@ -5,13 +5,12 @@
# __NetKet__

[![Release](https://img.shields.io/github/release/netket/netket.svg)](https://github.com/netket/netket/releases)
[![Anaconda-Server Badge](https://anaconda.org/conda-forge/netket/badges/installer/conda.svg)](https://conda.anaconda.org/conda-forge)
[![Build Status](https://travis-ci.org/netket/netket.svg?branch=master)](https://travis-ci.org/netket/netket)
[![GitHub Issues](https://img.shields.io/github/issues/netket/netket.svg)](http://github.com/netket/netket/issues)
[![Anaconda-Server Badge](https://anaconda.org/conda-forge/netket/badges/version.svg)](https://anaconda.org/conda-forge/netket)
[![Paper](https://img.shields.io/badge/paper-SoftwareX%2010%2C%20100311%20(2019)-B31B1B)](https://doi.org/10.1016/j.softx.2019.100311)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/netket/netket/v.2.0)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![codecov](https://codecov.io/gh/netket/netket/branch/master/graph/badge.svg?token=gzcOlpO5lB)](https://codecov.io/gh/netket/netket)

NetKet is an open-source project delivering cutting-edge methods for the study
of many-body quantum systems with artificial neural networks and machine learning techniques.
Expand Down
Empty file added Test/Graph/__init__.py
Empty file.
6 changes: 5 additions & 1 deletion Test/Graph/test_graph.py
@@ -1,3 +1,5 @@
import pytest

import netket as nk
import networkx as nx
import math
Expand All @@ -6,7 +8,9 @@

from netket.graph import *

import pytest
from .. import common

pytestmark = common.skipif_mpi

nxg = nx.star_graph(10)
graphs = [
Expand Down
Empty file added Test/GroundState/__init__.py
Empty file.
4 changes: 4 additions & 0 deletions Test/GroundState/test_vmc.py
Expand Up @@ -13,6 +13,10 @@
import tempfile
import re

from .. import common

pytestmark = common.skipif_mpi

SEED = 214748364


Expand Down
Empty file added Test/Hilbert/__init__.py
Empty file.
5 changes: 4 additions & 1 deletion Test/Hilbert/test_hilbert.py
Expand Up @@ -22,6 +22,10 @@
import jax
from jax import numpy as jnp

from .. import common

pytestmark = common.skipif_mpi

hilberts = {}

# Spin 1/2
Expand Down Expand Up @@ -83,7 +87,6 @@

# hilberts["Tensor: Spin x Fock"] = Spin(s=0.5, N=4) * Fock(4, N=2)


#
# Tests
#
Expand Down
4 changes: 4 additions & 0 deletions Test/Legacy/Callbacks/test_callbacks.py
@@ -1,6 +1,10 @@
import netket.legacy as nk
import time

import pytest

pytestmark = pytest.mark.legacy

SEED = 3141592
L = 8

Expand Down
3 changes: 3 additions & 0 deletions Test/Legacy/Dynamics/test_dynamics.py
Expand Up @@ -6,6 +6,9 @@
import netket.legacy as nk
from netket.exact import PyExactTimePropagation

import pytest

pytestmark = pytest.mark.legacy

ATOL = 1e-9
RTOL = 1e-9
Expand Down
4 changes: 4 additions & 0 deletions Test/Legacy/GroundState/test_legacy_groundstate.py
Expand Up @@ -5,6 +5,10 @@
import shutil
import tempfile

import pytest

pytestmark = pytest.mark.legacy


SEED = 3141592

Expand Down
4 changes: 4 additions & 0 deletions Test/Legacy/GroundState/test_legacy_vmc.py
Expand Up @@ -9,6 +9,10 @@
import tempfile
import re

import pytest

pytestmark = pytest.mark.legacy

SEED = 214748364
nk.random.seed(SEED)

Expand Down
22 changes: 0 additions & 22 deletions Test/Legacy/MPI/test_legacy_mpi_setup.py

This file was deleted.

0 comments on commit 59a0f52

Please sign in to comment.