From 94eefa063ce29c955b8779bdf60762cfee98f63a Mon Sep 17 00:00:00 2001 From: Philip Loche Date: Mon, 25 Mar 2024 11:38:16 +0100 Subject: [PATCH] Create one CI job for each example --- .github/workflows/docs.yml | 62 ++++++++++++++++--- .github/workflows/lint.yml | 12 ++-- .../{environement.yml => environment.yml} | 1 + .../{environement.yml => environment.yml} | 5 +- .../{dataset => }/charge-charge.xyz | 0 .../{environement.yml => environment.yml} | 3 +- examples/lode_linear/lode_tutorial.py | 2 +- .../{environement.yml => environment.yml} | 3 +- .../{environement.yml => environment.yml} | 1 + .../{dataset => }/input-fps.xyz | 0 examples/sample_selection/sample_selection.py | 2 +- tox.ini | 30 +++++---- 12 files changed, 88 insertions(+), 33 deletions(-) rename examples/cp2k_run_batch/{environement.yml => environment.yml} (82%) rename examples/gaas_map/{environement.yml => environment.yml} (93%) rename examples/lode_linear/{dataset => }/charge-charge.xyz (100%) rename examples/lode_linear/{environement.yml => environment.yml} (94%) rename examples/roy_gch/{environement.yml => environment.yml} (92%) rename examples/sample_selection/{environement.yml => environment.yml} (93%) rename examples/sample_selection/{dataset => }/input-fps.xyz (100%) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index c545e4f8..1d78be7e 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -10,27 +10,71 @@ on: - cron: '0 8 * * 1' # run every Monday at 8am UTC jobs: + generate-example: + runs-on: ubuntu-latest + strategy: + matrix: + example-name: [lode_linear, roy_gch, sample_selection, gaas_map, cp2k_run_batch] + + steps: + - uses: actions/checkout@v4 + - name: setup rust + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + + - name: setup Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: install tox + run: python -m pip install tox + + - name: install cp2k + if: matrix.example-name == 'cp2k_run_batch' + run: sudo apt-get install -y cp2k + + - name: build example + run: tox -e ${{ matrix.example-name }} + + - name: store example as a github artifact + uses: actions/upload-artifact@v4 + with: + name: example-${{ matrix.example-name }} + path: docs/src/examples/* # folders for each example will be merged later + overwrite: true # only keep the latest version of the example + build-and-publish: + needs: generate-example runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: setup rust uses: actions-rs/toolchain@v1 with: profile: minimal toolchain: stable - name: setup Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: - python-version: "3.10" - - name: install dependencies - run: | - sudo apt-get install -y cp2k - python -m pip install tox + python-version: "3.12" + + - name: install tox + run: python -m pip install tox + + - name: load github artifact for each example + uses: actions/download-artifact@v4 + with: + path: docs/src/examples + pattern: example-* + merge-multiple: true + - name: build documentation - run: tox -e docs + run: tox -e build_docs - - name: store documentation as github artifacts + - name: store documentation as github artifact to be downloaded by users uses: actions/upload-artifact@v4 with: name: documentation diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index ed2fa867..ad3a1fd0 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -14,12 +14,14 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: - python-version: "3.10" - - run: pip install tox + python-version: "3.12" - - name: Test Lint + - name: install dependencies + run: pip install tox + + - name: test lint run: tox -e lint diff --git a/examples/cp2k_run_batch/environement.yml b/examples/cp2k_run_batch/environment.yml similarity index 82% rename from examples/cp2k_run_batch/environement.yml rename to examples/cp2k_run_batch/environment.yml index b52c25ff..95b2c423 100644 --- a/examples/cp2k_run_batch/environement.yml +++ b/examples/cp2k_run_batch/environment.yml @@ -4,3 +4,4 @@ dependencies: - pip - pip: - ase + - matplotlib diff --git a/examples/gaas_map/environement.yml b/examples/gaas_map/environment.yml similarity index 93% rename from examples/gaas_map/environement.yml rename to examples/gaas_map/environment.yml index cb4f85d2..53253abc 100644 --- a/examples/gaas_map/environement.yml +++ b/examples/gaas_map/environment.yml @@ -5,7 +5,8 @@ dependencies: - pip: - ase - chemiscope - - skmatter - - scikit-learn + - matplotlib - metatensor + - skmatter - rascaline @ git+https://github.com/Luthaf/rascaline@ca957642f512e141c7570e987aadc05c7ac71983 + - scikit-learn diff --git a/examples/lode_linear/dataset/charge-charge.xyz b/examples/lode_linear/charge-charge.xyz similarity index 100% rename from examples/lode_linear/dataset/charge-charge.xyz rename to examples/lode_linear/charge-charge.xyz diff --git a/examples/lode_linear/environement.yml b/examples/lode_linear/environment.yml similarity index 94% rename from examples/lode_linear/environement.yml rename to examples/lode_linear/environment.yml index 9b1a26e8..b26bbe2a 100644 --- a/examples/lode_linear/environement.yml +++ b/examples/lode_linear/environment.yml @@ -4,6 +4,7 @@ dependencies: - pip - pip: - ase - - metatensor - equisolve @ git+https://github.com/lab-cosmo/equisolve.git@c858bedef4b2799eb445e4c92535ee387224089a + - matplotlib + - metatensor - rascaline @ git+https://github.com/Luthaf/rascaline@ca957642f512e141c7570e987aadc05c7ac71983 diff --git a/examples/lode_linear/lode_tutorial.py b/examples/lode_linear/lode_tutorial.py index 1c654d6e..09b43983 100644 --- a/examples/lode_linear/lode_tutorial.py +++ b/examples/lode_linear/lode_tutorial.py @@ -38,7 +38,7 @@ # For speeding up the calculations we already selected the first 130 # structures of the charge-charge structures. -frames = ase.io.read("dataset/charge-charge.xyz", ":") +frames = ase.io.read("charge-charge.xyz", ":") # %% diff --git a/examples/roy_gch/environement.yml b/examples/roy_gch/environment.yml similarity index 92% rename from examples/roy_gch/environement.yml rename to examples/roy_gch/environment.yml index fbce5f67..2cd02320 100644 --- a/examples/roy_gch/environement.yml +++ b/examples/roy_gch/environment.yml @@ -5,6 +5,7 @@ dependencies: - pip: - ase - chemiscope - - skmatter + - matplotlib - metatensor - rascaline @ git+https://github.com/Luthaf/rascaline@ca957642f512e141c7570e987aadc05c7ac71983 + - skmatter diff --git a/examples/sample_selection/environement.yml b/examples/sample_selection/environment.yml similarity index 93% rename from examples/sample_selection/environement.yml rename to examples/sample_selection/environment.yml index 0b5dffb0..8657a38d 100644 --- a/examples/sample_selection/environement.yml +++ b/examples/sample_selection/environment.yml @@ -5,6 +5,7 @@ dependencies: - pip: - ase - chemiscope + - matplotlib - skmatter - metatensor - rascaline @ git+https://github.com/Luthaf/rascaline@ca957642f512e141c7570e987aadc05c7ac71983 diff --git a/examples/sample_selection/dataset/input-fps.xyz b/examples/sample_selection/input-fps.xyz similarity index 100% rename from examples/sample_selection/dataset/input-fps.xyz rename to examples/sample_selection/input-fps.xyz diff --git a/examples/sample_selection/sample_selection.py b/examples/sample_selection/sample_selection.py index 3efac3d4..77ac49bc 100644 --- a/examples/sample_selection/sample_selection.py +++ b/examples/sample_selection/sample_selection.py @@ -33,7 +33,7 @@ # Load a subset of structures of the example dataset n_frames = 500 -frames = ase.io.read("./dataset/input-fps.xyz", f":{n_frames}", format="extxyz") +frames = ase.io.read("input-fps.xyz", f":{n_frames}", format="extxyz") # %% # Compute SOAP descriptors using rascaline diff --git a/tox.ini b/tox.ini index 7adf4aaa..1d904f24 100644 --- a/tox.ini +++ b/tox.ini @@ -13,9 +13,9 @@ lint_folders = "{toxinidir}/examples" install_conda_env = - conda env update --file examples/{envname}/environement.yml --prefix {envdir}/conda --verbose + conda env update --file examples/{envname}/environment.yml --prefix {envdir}/conda --verbose # install sphinx-gallery and its dependencies - {envdir}/conda/bin/python -m pip install sphinx-gallery sphinx pillow matplotlib + {envdir}/conda/bin/python -m pip install sphinx-gallery sphinx pillow generate_gallery = {envdir}/conda/bin/python generate-gallery.py examples/{envname} @@ -26,15 +26,8 @@ allowlist_externals = conda {envdir}/conda/bin/python -commands = - # error if the user gives a wrong testenv name in `tox -e` - python -c "import sys; print('environement {env_name} does not exist'); sys.exit(1)" - - [testenv:docs] -deps = - -r docs/requirements.txt - +description = Run all examples and build the documentation allowlist_externals = tox commands = # transform all examples to rst @@ -44,35 +37,47 @@ commands = tox -e gaas_map tox -e cp2k_run_batch - sphinx-build {posargs:-E} -W -b html docs/src docs/build/html + # Build the documentation + tox -e build_docs + +[testenv:build_docs] +description = Build the documentation (example should be generated before) +deps = -r docs/requirements.txt +commands = sphinx-build {posargs:-E} -W -b html docs/src docs/build/html [testenv:lode_linear] +description = Build the `lode_linear` examples commands = {[testenv]install_conda_env} {[testenv]generate_gallery} [testenv:roy_gch] +description = Build the `roy_gch` examples commands = {[testenv]install_conda_env} {[testenv]generate_gallery} [testenv:gaas_map] +description = Build the `gaas_map` examples commands = {[testenv]install_conda_env} {[testenv]generate_gallery} [testenv:sample_selection] +description = Build the `sample_selection` examples commands = {[testenv]install_conda_env} {[testenv]generate_gallery} [testenv:cp2k_run_batch] +description = Build the `cp2k_run_batch` examples commands = {[testenv]install_conda_env} {[testenv]generate_gallery} [testenv:lint] +description = Run linters and type checks deps = black blackdoc @@ -92,8 +97,7 @@ commands = [testenv:format] -# Abuse tox to do actual formatting. Users can call `tox -e format` to run -# formatting on all files +description = Abuse tox to do actual formatting on all files. deps = black blackdoc