From 89ee6708e0560ddc877dbae0148c48d327f340a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Gonz=C3=A1lez=20Duque?= Date: Tue, 31 Oct 2023 11:05:02 +0100 Subject: [PATCH 1/9] Adds RaSP to testing --- CONTRIBUTING.md | 9 ++- src/poli/objective_repository/__init__.py | 4 - .../registry/test_problem_registration.py | 81 ++++++++++++++++++- tox.ini | 3 + 4 files changed, 90 insertions(+), 7 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b4605ae5..0e4d0c98 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -26,9 +26,16 @@ Since we are testing multiple conda environments, we settled for using a combina ```bash pip install tox -tox # from root of project + +# To test linting (from the root of the project) +tox -e lint + +# To test in the base environment for poli +tox -e poli-base-py39 ``` +If you want to run tests in all environments, remove `-e poli-base-py39` and just run `tox`. + ## Create a pull request to dev Once all tests pass and you are ready to share your changes, create a pull request to the `dev` branch. \ No newline at end of file diff --git a/src/poli/objective_repository/__init__.py b/src/poli/objective_repository/__init__.py index 22d284ae..17cd6988 100644 --- a/src/poli/objective_repository/__init__.py +++ b/src/poli/objective_repository/__init__.py @@ -4,10 +4,6 @@ from .white_noise.register import WhiteNoiseProblemFactory from .aloha.register import AlohaProblemFactory -# These have more complex dependencies -# from .super_mario_bros.register import SuperMarioBrosBlackBox -# from .rdkit_qed.register import QEDBlackBox - THIS_DIR = Path(__file__).parent.resolve() diff --git a/src/poli/tests/registry/test_problem_registration.py b/src/poli/tests/registry/test_problem_registration.py index 872a7c62..eec85e6e 100644 --- a/src/poli/tests/registry/test_problem_registration.py +++ b/src/poli/tests/registry/test_problem_registration.py @@ -346,7 +346,84 @@ def test_penalized_logp_lambo(): f.terminate() -def test_rasp_on_3ned_against_notebooks_results(): +def test_rasp_on_3ned_against_notebooks_results_on_rasp_env(): + try: + from poli.objective_repository.rasp.register import RaspProblemFactory + except ImportError: + pytest.skip("Could not import RaspProblemFactory. ") + + import torch + + # For us to match what the notebook says, we have + # to run at double precision. + torch.set_default_dtype(torch.float64) + + # If the previous import was successful, we can + # create a RaSP problem: + _, f, x0, _, _ = objective_factory.create( + name="rasp", + wildtype_pdb_path=THIS_DIR / "3ned.pdb", + ) + + wildtype_sequence = "".join(x0[0]) + three_mutations = [ + "A" + wildtype_sequence[1:], + "R" + wildtype_sequence[1:], + "N" + wildtype_sequence[1:], + ] + + x = np.array([list(mutation) for mutation in three_mutations]) + y = f(x) + + # Asserting that the results are the same as in the + # notebook: + # E1A: 0.03654138690753095 + # E1R: -0.07091977827871465 + # E1N: -0.2835593180137258 + + assert np.isclose(y[0], 0.03654138690753095) + assert np.isclose(y[1], -0.07091977827871465) + assert np.isclose(y[2], -0.2835593180137258) + + +def test_rasp_on_3ned_against_notebooks_results_isolated(): + """ + We test forceful registration of the RaSP problem. + """ + # If the previous import was successful, we can + # create a RaSP problem: + _, f, x0, _, _ = objective_factory.create( + name="rasp", + wildtype_pdb_path=THIS_DIR / "3ned.pdb", + ) + + wildtype_sequence = "".join(x0[0]) + three_mutations = [ + "A" + wildtype_sequence[1:], + "R" + wildtype_sequence[1:], + "N" + wildtype_sequence[1:], + ] + + x = np.array([list(mutation) for mutation in three_mutations]) + y = f(x) + + # Asserting that the results are the same as in the + # notebook: + # E1A: 0.03654138690753095 + # E1R: -0.07091977827871465 + # E1N: -0.2835593180137258 + + # Notice how we are clipping the actual values, + # this is because we would need double precision + # to test against the exact values described above. + # TODO: Should we do double precision by default + # inside the RaSP problem? + assert np.isclose(y[0], 0.0365, atol=1e-4) + assert np.isclose(y[1], -0.07091, atol=1e-4) + assert np.isclose(y[2], -0.283559, atol=1e-4) + + +def test_rasp_on_3ned_against_notebooks_results_on_rasp_env(): try: from poli.objective_repository.rasp.register import RaspProblemFactory except ImportError: @@ -387,4 +464,4 @@ def test_rasp_on_3ned_against_notebooks_results(): if __name__ == "__main__": - test_rasp_on_3ned_against_notebooks_results() + test_rasp_on_3ned_against_notebooks_results_isolated() diff --git a/tox.ini b/tox.ini index 48293726..3fbaf2a4 100644 --- a/tox.ini +++ b/tox.ini @@ -23,6 +23,9 @@ commands = sh -c 'if conda info --envs | grep -q poli__protein; then echo "poli__protein already exists"; else conda env create -f ./src/poli/objective_repository/foldx_stability/environment.yml; fi' sh -c "conda run -n poli__protein python -m pip uninstall -y poli" sh -c "conda run -n poli__protein python -m pip install -e ." + sh -c 'if conda info --envs | grep -q poli__rasp; then echo "poli__rasp already exists"; else conda env create -f ./src/poli/objective_repository/rasp/environment.yml; fi' + sh -c "conda run -n poli__rasp python -m pip uninstall -y poli" + sh -c "conda run -n poli__rasp python -m pip install -e ." pytest {tty:--color=yes} -v {posargs} sh -c "rm -rf ~/.poli_objectives/*.sh" sh -c "rm -rf ~/.poli_objectives/config.rc" From a905d2e752363bcac533b2e4cadcd13baf47938c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Gonz=C3=A1lez=20Duque?= Date: Tue, 31 Oct 2023 11:15:46 +0100 Subject: [PATCH 2/9] Adds forceful registration to the RaSP test --- src/poli/tests/registry/test_problem_registration.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/poli/tests/registry/test_problem_registration.py b/src/poli/tests/registry/test_problem_registration.py index eec85e6e..3cbf6fee 100644 --- a/src/poli/tests/registry/test_problem_registration.py +++ b/src/poli/tests/registry/test_problem_registration.py @@ -395,6 +395,7 @@ def test_rasp_on_3ned_against_notebooks_results_isolated(): _, f, x0, _, _ = objective_factory.create( name="rasp", wildtype_pdb_path=THIS_DIR / "3ned.pdb", + force_register=True, ) wildtype_sequence = "".join(x0[0]) From 81f396e97cdda7bdb96d223d60660a984da1d8c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Gonz=C3=A1lez=20Duque?= Date: Wed, 1 Nov 2023 10:03:54 +0100 Subject: [PATCH 3/9] Adds missing dependencies to poli__protein and poli__rasp envs --- CONTRIBUTING.md | 6 ++++ Dockerfile.test | 34 +++++++++++++++++++ requirements-dev.txt | 1 + requirements.txt | 1 - .../core/util/proteins/rasp/rasp_interface.py | 4 +++ .../foldx_sasa/environment.yml | 2 ++ .../foldx_stability/environment.yml | 2 ++ .../foldx_stability_and_sasa/environment.yml | 2 ++ .../objective_repository/rasp/environment.yml | 2 ++ 9 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 Dockerfile.test diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0e4d0c98..220fccf3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -36,6 +36,12 @@ tox -e poli-base-py39 If you want to run tests in all environments, remove `-e poli-base-py39` and just run `tox`. +## More thorough testing + +In many cases, testing with the instructions above should be enough. However, since we are dealing with creating conda environments, the definite test comes by building the Docker container specified in `Dockerfile.test`, and running it as an image. + +When contributing to the `@master` branch (i.e. to release), we will run these tests. + ## Create a pull request to dev Once all tests pass and you are ready to share your changes, create a pull request to the `dev` branch. \ No newline at end of file diff --git a/Dockerfile.test b/Dockerfile.test new file mode 100644 index 00000000..da94556b --- /dev/null +++ b/Dockerfile.test @@ -0,0 +1,34 @@ +# This dockerfile allows us to run the tests in a container +FROM --platform=linux/amd64 continuumio/anaconda3:latest + +# Set working directory +WORKDIR /app + +# Copying the files from the host to the container +COPY ./src /app/src +COPY ./pyproject.toml /app/ +COPY ./setup.cfg /app/ +COPY ./requirements.txt /app/ +COPY ./requirements-dev.txt /app/ +COPY ./tox.ini /app/ + +# Installing distutils +RUN apt-get update && \ + apt-get install build-essential -y && \ + apt-get install -y python3.9-distutils + +# Installing python dependencies +RUN conda --version +RUN pip install -r requirements.txt +RUN pip install -r requirements-dev.txt + +# Creating the relevant conda environments +# For chem +RUN conda env create --file src/poli/objective_repository/rdkit_qed/environment.yml + +# For proteins +RUN conda env create --file src/poli/objective_repository/foldx_stability/environment.yml +RUN conda env create --file src/poli/objective_repository/rasp/environment.yml + +# Running the tests +CMD ["tox"] diff --git a/requirements-dev.txt b/requirements-dev.txt index a047d7e5..fd775422 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,2 +1,3 @@ black tox +setuptools \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 6723567d..24ce15ab 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1 @@ -python numpy diff --git a/src/poli/core/util/proteins/rasp/rasp_interface.py b/src/poli/core/util/proteins/rasp/rasp_interface.py index b4d8d3e1..46fd28fc 100644 --- a/src/poli/core/util/proteins/rasp/rasp_interface.py +++ b/src/poli/core/util/proteins/rasp/rasp_interface.py @@ -32,6 +32,7 @@ import os, stat import subprocess import logging +import traceback import pandas as pd import numpy as np @@ -138,6 +139,8 @@ def get_and_compile_reduce(self): check=True, ) except subprocess.CalledProcessError: + # Printing the traceback + traceback.print_exc() raise RuntimeError( "Could not clone the reduce repository. " "Please check your internet connection." @@ -153,6 +156,7 @@ def get_and_compile_reduce(self): ) except subprocess.CalledProcessError: # TODO: should we be purging it ourselves? + traceback.print_exc() raise RuntimeError( "Something went wrong while compiling reduce. " "Purge the folder ~/.poli_objectives/rasp/reduce " diff --git a/src/poli/objective_repository/foldx_sasa/environment.yml b/src/poli/objective_repository/foldx_sasa/environment.yml index 01b71b9c..472e4bd3 100644 --- a/src/poli/objective_repository/foldx_sasa/environment.yml +++ b/src/poli/objective_repository/foldx_sasa/environment.yml @@ -1,8 +1,10 @@ name: poli__protein channels: - defaults + - conda-forge dependencies: - python=3.9 + - gcc - pip - pip: - biopython diff --git a/src/poli/objective_repository/foldx_stability/environment.yml b/src/poli/objective_repository/foldx_stability/environment.yml index 01b71b9c..472e4bd3 100644 --- a/src/poli/objective_repository/foldx_stability/environment.yml +++ b/src/poli/objective_repository/foldx_stability/environment.yml @@ -1,8 +1,10 @@ name: poli__protein channels: - defaults + - conda-forge dependencies: - python=3.9 + - gcc - pip - pip: - biopython diff --git a/src/poli/objective_repository/foldx_stability_and_sasa/environment.yml b/src/poli/objective_repository/foldx_stability_and_sasa/environment.yml index 01b71b9c..472e4bd3 100644 --- a/src/poli/objective_repository/foldx_stability_and_sasa/environment.yml +++ b/src/poli/objective_repository/foldx_stability_and_sasa/environment.yml @@ -1,8 +1,10 @@ name: poli__protein channels: - defaults + - conda-forge dependencies: - python=3.9 + - gcc - pip - pip: - biopython diff --git a/src/poli/objective_repository/rasp/environment.yml b/src/poli/objective_repository/rasp/environment.yml index 017a006e..71fe85a8 100644 --- a/src/poli/objective_repository/rasp/environment.yml +++ b/src/poli/objective_repository/rasp/environment.yml @@ -12,6 +12,8 @@ dependencies: - mpl-scatter-density - clang - cmake + - make + - gcc - pip - pip: - "git+https://github.com/MachineLearningLifeScience/poli.git@dev" From dff54415d01252902a41f1b0b1143e41153cd46b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Gonz=C3=A1lez=20Duque?= Date: Wed, 1 Nov 2023 10:51:01 +0100 Subject: [PATCH 4/9] Refactors tests, and removes RaSP from testing on dev --- ...-tox-testing-including-conda-on-master.yml | 39 ++ .../python-tox-testing-including-conda.yml | 10 +- .../registry/basic_objectives/__init__.py | 0 .../basic_objectives/test_basic_objectives.py | 21 + src/poli/tests/registry/chemistry/__init__.py | 0 .../{ => chemistry}/alphabet_qed.json | 0 .../chemistry/test_chemistry_objectives.py | 148 ++++++ .../registry/{ => proteins}/101m_Repair.pdb | 0 .../tests/registry/{ => proteins}/3ned.pdb | 0 src/poli/tests/registry/proteins/__init__.py | 0 .../tests/registry/proteins/test_foldx.py | 86 ++++ src/poli/tests/registry/proteins/test_rasp.py | 86 ++++ .../registry/test_problem_registration.py | 468 ------------------ tox.ini | 2 +- 14 files changed, 383 insertions(+), 477 deletions(-) create mode 100644 .github/workflows/python-tox-testing-including-conda-on-master.yml create mode 100644 src/poli/tests/registry/basic_objectives/__init__.py create mode 100644 src/poli/tests/registry/basic_objectives/test_basic_objectives.py create mode 100644 src/poli/tests/registry/chemistry/__init__.py rename src/poli/tests/registry/{ => chemistry}/alphabet_qed.json (100%) create mode 100644 src/poli/tests/registry/chemistry/test_chemistry_objectives.py rename src/poli/tests/registry/{ => proteins}/101m_Repair.pdb (100%) rename src/poli/tests/registry/{ => proteins}/3ned.pdb (100%) create mode 100644 src/poli/tests/registry/proteins/__init__.py create mode 100644 src/poli/tests/registry/proteins/test_foldx.py create mode 100644 src/poli/tests/registry/proteins/test_rasp.py delete mode 100644 src/poli/tests/registry/test_problem_registration.py diff --git a/.github/workflows/python-tox-testing-including-conda-on-master.yml b/.github/workflows/python-tox-testing-including-conda-on-master.yml new file mode 100644 index 00000000..07a5684c --- /dev/null +++ b/.github/workflows/python-tox-testing-including-conda-on-master.yml @@ -0,0 +1,39 @@ +name: Test (conda, python 3.9) + +on: + push: + pull-request: + branches: + - master + +jobs: + build-linux: + runs-on: ubuntu-latest + strategy: + max-parallel: 5 + + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.9 + uses: actions/setup-python@v3 + with: + python-version: '3.9' + - name: Add conda to system path + run: | + # $CONDA is an environment variable pointing to the root of the miniconda directory + echo $CONDA/bin >> $GITHUB_PATH + - name: Install dependencies + run: | + python -m pip install tox + - name: Test linting with tox + run: | + tox -e lint + - name: Test poli-base with tox + run: | + tox -e poli-base-py39 + - name: Test poli-chem with tox + run: | + tox -e poli-chem-py39 + - name: Test poli-protein with tox + run: | + tox -e poli-protein-py39 diff --git a/.github/workflows/python-tox-testing-including-conda.yml b/.github/workflows/python-tox-testing-including-conda.yml index 875a9a40..6fa5b190 100644 --- a/.github/workflows/python-tox-testing-including-conda.yml +++ b/.github/workflows/python-tox-testing-including-conda.yml @@ -24,12 +24,6 @@ jobs: - name: Test linting with tox run: | tox -e lint - - name: Test poli-base with tox + - name: Test poli-base with tox (ignoring RaSP) run: | - tox -e poli-base-py39 - - name: Test poli-chem with tox - run: | - tox -e poli-chem-py39 - - name: Test poli-protein with tox - run: | - tox -e poli-protein-py39 + tox -e poli-base-py39 --ignore=src/poli/tests/registry/proteins/test_rasp.py diff --git a/src/poli/tests/registry/basic_objectives/__init__.py b/src/poli/tests/registry/basic_objectives/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/poli/tests/registry/basic_objectives/test_basic_objectives.py b/src/poli/tests/registry/basic_objectives/test_basic_objectives.py new file mode 100644 index 00000000..52d78977 --- /dev/null +++ b/src/poli/tests/registry/basic_objectives/test_basic_objectives.py @@ -0,0 +1,21 @@ +from pathlib import Path + +import numpy as np + +from poli import objective_factory + +THIS_DIR = Path(__file__).parent.resolve() + + +def test_registering_white_noise(): + _, f, _, _, _ = objective_factory.create(name="white_noise") + x = np.array([["A", "B", "C", "D"]]) + f(x) + f.terminate() + + +def test_registering_aloha(): + _, f, _, y0, _ = objective_factory.create(name="aloha") + x = np.array([list("ALOOF")]) + assert f(x) == 3 + f.terminate() diff --git a/src/poli/tests/registry/chemistry/__init__.py b/src/poli/tests/registry/chemistry/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/poli/tests/registry/alphabet_qed.json b/src/poli/tests/registry/chemistry/alphabet_qed.json similarity index 100% rename from src/poli/tests/registry/alphabet_qed.json rename to src/poli/tests/registry/chemistry/alphabet_qed.json diff --git a/src/poli/tests/registry/chemistry/test_chemistry_objectives.py b/src/poli/tests/registry/chemistry/test_chemistry_objectives.py new file mode 100644 index 00000000..01443904 --- /dev/null +++ b/src/poli/tests/registry/chemistry/test_chemistry_objectives.py @@ -0,0 +1,148 @@ +import pytest +from pathlib import Path + +import numpy as np + +from poli import objective_factory + +THIS_DIR = Path(__file__).parent.resolve() + + +def test_qed_is_available(): + """ + We test whether the qed problem is available + when rdkit and selfies are installed. + """ + _ = pytest.importorskip("rdkit") + _ = pytest.importorskip("selfies") + from poli.objective_repository import AVAILABLE_PROBLEM_FACTORIES + + assert "rdkit_qed" in AVAILABLE_PROBLEM_FACTORIES + + +def test_logp_is_available(): + """ + We test whether the logp problem is available + when rdkit and selfies are installed. + """ + _ = pytest.importorskip("rdkit") + _ = pytest.importorskip("selfies") + from poli.objective_repository import AVAILABLE_PROBLEM_FACTORIES + + assert "rdkit_logp" in AVAILABLE_PROBLEM_FACTORIES + + +def test_force_registering_qed(): + """ + We test whether we can force-register the qed problem + if rdkit and selfies are not installed. + """ + alphabet = ["", "C", "..."] + _, f, _, y0, _ = objective_factory.create( + name="rdkit_qed", + alphabet=alphabet, + force_register=True, + ) + + # Asserting that the QED of a single carbon + # is close to 0.35978494 (according to RDKit). + assert np.isclose(y0, 0.35978494).all() + f.terminate() + + +def test_force_registering_qed_with_context_manager(): + """ + Tests the objective_factory.start method on QED. + """ + with objective_factory.start( + name="rdkit_qed", + force_register=True, + force_isolation=True, + path_to_alphabet=THIS_DIR / "alphabet_qed.json", + ) as f: + x = np.array([["C"]]) + y = f(x) + assert np.isclose(y, 0.35978494).all() + + +def test_force_registering_logp(): + """ + We test whether we can force-register the logp problem + if rdkit and selfies are not installed. + """ + alphabet = ["", "C", ""] + _, f, _, y0, _ = objective_factory.create( + name="rdkit_logp", + alphabet=alphabet, + # path_to_alphabet=THIS_DIR / "alphabet_qed.json", + force_register=True, + ) + + # Asserting that a single carbon atom has logp close + # to 0.6361. (according to RDKit) + assert np.isclose(y0, 0.6361).all() + f.terminate() + + +def test_registering_qed(): + """ + Testing whether we can register the qed problem + if rdkit and selfies are installed. + """ + _ = pytest.importorskip("rdkit") + _ = pytest.importorskip("selfies") + np = pytest.importorskip("numpy") + + _, f, _, y0, _ = objective_factory.create( + name="rdkit_qed", + path_to_alphabet=THIS_DIR / "alphabet_qed.json", + ) + x = np.array([["C"]]) + y = f(x) + + # Asserting that the QED of a single carbon + # is close to 0.35978494 (according to RDKit). + assert np.isclose(y, 0.35978494).all() + + f.terminate() + + +def test_registering_logp(): + """ + Testing whether we can register the logp problem + if rdkit and selfies are installed. + """ + rdkit = pytest.importorskip("rdkit") + selfies = pytest.importorskip("selfies") + np = pytest.importorskip("numpy") + + _, f, _, y0, _ = objective_factory.create( + name="rdkit_logp", + path_to_alphabet=THIS_DIR / "alphabet_qed.json", + ) + x = np.array([[1]]) + f(x) + + # Asserting that a single carbon atom has logp close + # to 0.6361. (according to RDKit) + assert np.isclose(y0, 0.6361).all() + + f.terminate() + + +def test_penalized_logp_lambo(): + """ + Testing whether we can register the logp problem + from lambo. + """ + from poli import objective_factory + + _ = pytest.importorskip("lambo") + + # Using create + _, f, x0, y0, _ = objective_factory.create( + name="penalized_logp_lambo", force_register=True + ) + print(x0) + print(y0) + f.terminate() diff --git a/src/poli/tests/registry/101m_Repair.pdb b/src/poli/tests/registry/proteins/101m_Repair.pdb similarity index 100% rename from src/poli/tests/registry/101m_Repair.pdb rename to src/poli/tests/registry/proteins/101m_Repair.pdb diff --git a/src/poli/tests/registry/3ned.pdb b/src/poli/tests/registry/proteins/3ned.pdb similarity index 100% rename from src/poli/tests/registry/3ned.pdb rename to src/poli/tests/registry/proteins/3ned.pdb diff --git a/src/poli/tests/registry/proteins/__init__.py b/src/poli/tests/registry/proteins/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/poli/tests/registry/proteins/test_foldx.py b/src/poli/tests/registry/proteins/test_foldx.py new file mode 100644 index 00000000..7664f02d --- /dev/null +++ b/src/poli/tests/registry/proteins/test_foldx.py @@ -0,0 +1,86 @@ +import pytest +from pathlib import Path + +import numpy as np + +from poli import objective_factory + +THIS_DIR = Path(__file__).parent.resolve() + + +def test_foldx_stability_is_available(): + """ + We test whether foldx_stability is available when + 1. foldx is installed. + 2. foldx files are in the right position + 2. biopython and python-levenshtein are installed + """ + HOME_DIR = Path().home().resolve() + PATH_TO_FOLDX_FILES = HOME_DIR / "foldx" + if not PATH_TO_FOLDX_FILES.exists(): + pytest.skip("FoldX is not installed. ") + + if not (PATH_TO_FOLDX_FILES / "foldx").exists(): + pytest.skip("FoldX is not compiled. ") + + if not (PATH_TO_FOLDX_FILES / "rotabase.txt").exists(): + pytest.skip("rotabase.txt is not in the foldx directory. ") + + _ = pytest.importorskip("Bio") + _ = pytest.importorskip("Levenshtein") + + from poli.objective_repository import AVAILABLE_PROBLEM_FACTORIES + + assert "foldx_stability" in AVAILABLE_PROBLEM_FACTORIES + + +def test_force_registering_foldx_stability(): + """ + We test whether we can force-register the foldx_stability + problem if foldx is installed. + """ + HOME_DIR = Path().home().resolve() + PATH_TO_FOLDX_FILES = HOME_DIR / "foldx" + if not PATH_TO_FOLDX_FILES.exists(): + pytest.skip("FoldX is not installed. ") + + if not (PATH_TO_FOLDX_FILES / "foldx").exists(): + pytest.skip("FoldX is not compiled. ") + + if not (PATH_TO_FOLDX_FILES / "rotabase.txt").exists(): + pytest.skip("rotabase.txt is not in the foldx directory. ") + + _, f, _, y0, _ = objective_factory.create( + name="foldx_stability", + wildtype_pdb_path=THIS_DIR / "101m_Repair.pdb", + force_register=True, + ) + + assert np.isclose(y0, 32.4896).all() + f.terminate() + + +def test_force_registering_foldx_sasa(): + """ + We test whether we can force-register the foldx_sasa + problem if foldx is installed. + """ + HOME_DIR = Path().home().resolve() + PATH_TO_FOLDX_FILES = HOME_DIR / "foldx" + if not PATH_TO_FOLDX_FILES.exists(): + pytest.skip("FoldX is not installed. ") + + if not (PATH_TO_FOLDX_FILES / "foldx").exists(): + pytest.skip("FoldX is not compiled. ") + + if not (PATH_TO_FOLDX_FILES / "rotabase.txt").exists(): + pytest.skip("rotabase.txt is not in the foldx directory. ") + + _, f, _, y0, _ = objective_factory.create( + name="foldx_sasa", + wildtype_pdb_path=THIS_DIR / "101m_Repair.pdb", + force_register=True, + ) + + assert np.isclose(y0, 8411.45578009).all() + f.terminate() diff --git a/src/poli/tests/registry/proteins/test_rasp.py b/src/poli/tests/registry/proteins/test_rasp.py new file mode 100644 index 00000000..a301a731 --- /dev/null +++ b/src/poli/tests/registry/proteins/test_rasp.py @@ -0,0 +1,86 @@ +import pytest +from pathlib import Path + +import numpy as np + +from poli import objective_factory + +THIS_DIR = Path(__file__).parent.resolve() + + +def test_rasp_on_3ned_against_notebooks_results_on_rasp_env(): + try: + from poli.objective_repository.rasp.register import RaspProblemFactory + except ImportError: + pytest.skip("Could not import RaspProblemFactory. ") + + import torch + + # For us to match what the notebook says, we have + # to run at double precision. + torch.set_default_dtype(torch.float64) + + # If the previous import was successful, we can + # create a RaSP problem: + _, f, x0, _, _ = objective_factory.create( + name="rasp", + wildtype_pdb_path=THIS_DIR / "3ned.pdb", + ) + + wildtype_sequence = "".join(x0[0]) + three_mutations = [ + "A" + wildtype_sequence[1:], + "R" + wildtype_sequence[1:], + "N" + wildtype_sequence[1:], + ] + + x = np.array([list(mutation) for mutation in three_mutations]) + y = f(x) + + # Asserting that the results are the same as in the + # notebook: + # E1A: 0.03654138690753095 + # E1R: -0.07091977827871465 + # E1N: -0.2835593180137258 + + assert np.isclose(y[0], 0.03654138690753095) + assert np.isclose(y[1], -0.07091977827871465) + assert np.isclose(y[2], -0.2835593180137258) + + +def test_rasp_on_3ned_against_notebooks_results_isolated(): + """ + We test forceful registration of the RaSP problem. + """ + # If the previous import was successful, we can + # create a RaSP problem: + _, f, x0, _, _ = objective_factory.create( + name="rasp", + wildtype_pdb_path=THIS_DIR / "3ned.pdb", + force_register=True, + ) + + wildtype_sequence = "".join(x0[0]) + three_mutations = [ + "A" + wildtype_sequence[1:], + "R" + wildtype_sequence[1:], + "N" + wildtype_sequence[1:], + ] + + x = np.array([list(mutation) for mutation in three_mutations]) + y = f(x) + + # Asserting that the results are the same as in the + # notebook: + # E1A: 0.03654138690753095 + # E1R: -0.07091977827871465 + # E1N: -0.2835593180137258 + + # Notice how we are clipping the actual values, + # this is because we would need double precision + # to test against the exact values described above. + # TODO: Should we do double precision by default + # inside the RaSP problem? + assert np.isclose(y[0], 0.0365, atol=1e-4) + assert np.isclose(y[1], -0.07091, atol=1e-4) + assert np.isclose(y[2], -0.283559, atol=1e-4) diff --git a/src/poli/tests/registry/test_problem_registration.py b/src/poli/tests/registry/test_problem_registration.py deleted file mode 100644 index 3cbf6fee..00000000 --- a/src/poli/tests/registry/test_problem_registration.py +++ /dev/null @@ -1,468 +0,0 @@ -import pytest -from pathlib import Path - -import numpy as np - -from poli import objective_factory - -THIS_DIR = Path(__file__).parent.resolve() - - -def test_registering_white_noise(): - print("testing white noise") - np = pytest.importorskip("numpy") - _, f, _, _, _ = objective_factory.create(name="white_noise") - x = np.array([["A", "B", "C", "D"]]) - f(x) - f.terminate() - - -def test_registering_aloha(): - np = pytest.importorskip("numpy") - _, f, _, y0, _ = objective_factory.create(name="aloha") - x = np.array([list("ALOOF")]) - assert f(x) == 3 - f.terminate() - - -def test_qed_is_available(): - """ - We test whether the qed problem is available - when rdkit and selfies are installed. - """ - _ = pytest.importorskip("rdkit") - _ = pytest.importorskip("selfies") - from poli.objective_repository import AVAILABLE_PROBLEM_FACTORIES - - assert "rdkit_qed" in AVAILABLE_PROBLEM_FACTORIES - - -def test_logp_is_available(): - """ - We test whether the logp problem is available - when rdkit and selfies are installed. - """ - _ = pytest.importorskip("rdkit") - _ = pytest.importorskip("selfies") - from poli.objective_repository import AVAILABLE_PROBLEM_FACTORIES - - assert "rdkit_logp" in AVAILABLE_PROBLEM_FACTORIES - - -def test_foldx_stability_is_available(): - """ - We test whether foldx_stability is available when - 1. foldx is installed. - 2. foldx files are in the right position - 2. biopython and python-levenshtein are installed - """ - HOME_DIR = Path().home().resolve() - PATH_TO_FOLDX_FILES = HOME_DIR / "foldx" - if not PATH_TO_FOLDX_FILES.exists(): - pytest.skip("FoldX is not installed. ") - - if not (PATH_TO_FOLDX_FILES / "foldx").exists(): - pytest.skip("FoldX is not compiled. ") - - if not (PATH_TO_FOLDX_FILES / "rotabase.txt").exists(): - pytest.skip("rotabase.txt is not in the foldx directory. ") - - _ = pytest.importorskip("Bio") - _ = pytest.importorskip("Levenshtein") - - from poli.objective_repository import AVAILABLE_PROBLEM_FACTORIES - - assert "foldx_stability" in AVAILABLE_PROBLEM_FACTORIES - - -def test_force_registering_qed(): - """ - We test whether we can force-register the qed problem - if rdkit and selfies are not installed. - """ - alphabet = ["", "C", "..."] - _, f, _, y0, _ = objective_factory.create( - name="rdkit_qed", - alphabet=alphabet, - force_register=True, - ) - - # Asserting that the QED of a single carbon - # is close to 0.35978494 (according to RDKit). - assert np.isclose(y0, 0.35978494).all() - f.terminate() - - -def test_force_registering_qed_with_context_manager(): - """ - Tests the objective_factory.start method on QED. - """ - with objective_factory.start( - name="rdkit_qed", - force_register=True, - force_isolation=True, - path_to_alphabet=THIS_DIR / "alphabet_qed.json", - ) as f: - x = np.array([["C"]]) - y = f(x) - assert np.isclose(y, 0.35978494).all() - - -def test_force_registering_logp(): - """ - We test whether we can force-register the logp problem - if rdkit and selfies are not installed. - """ - alphabet = ["", "C", ""] - _, f, _, y0, _ = objective_factory.create( - name="rdkit_logp", - alphabet=alphabet, - # path_to_alphabet=THIS_DIR / "alphabet_qed.json", - force_register=True, - ) - - # Asserting that a single carbon atom has logp close - # to 0.6361. (according to RDKit) - assert np.isclose(y0, 0.6361).all() - f.terminate() - - -def test_force_registering_foldx_stability(): - """ - We test whether we can force-register the foldx_stability - problem if foldx is installed. - """ - HOME_DIR = Path().home().resolve() - PATH_TO_FOLDX_FILES = HOME_DIR / "foldx" - if not PATH_TO_FOLDX_FILES.exists(): - pytest.skip("FoldX is not installed. ") - - if not (PATH_TO_FOLDX_FILES / "foldx").exists(): - pytest.skip("FoldX is not compiled. ") - - if not (PATH_TO_FOLDX_FILES / "rotabase.txt").exists(): - pytest.skip("rotabase.txt is not in the foldx directory. ") - - _, f, _, y0, _ = objective_factory.create( - name="foldx_stability", - wildtype_pdb_path=THIS_DIR / "101m_Repair.pdb", - force_register=True, - ) - - assert np.isclose(y0, 32.4896).all() - f.terminate() - - -def test_force_registering_foldx_sasa(): - """ - We test whether we can force-register the foldx_sasa - problem if foldx is installed. - """ - HOME_DIR = Path().home().resolve() - PATH_TO_FOLDX_FILES = HOME_DIR / "foldx" - if not PATH_TO_FOLDX_FILES.exists(): - pytest.skip("FoldX is not installed. ") - - if not (PATH_TO_FOLDX_FILES / "foldx").exists(): - pytest.skip("FoldX is not compiled. ") - - if not (PATH_TO_FOLDX_FILES / "rotabase.txt").exists(): - pytest.skip("rotabase.txt is not in the foldx directory. ") - - _, f, _, y0, _ = objective_factory.create( - name="foldx_sasa", - wildtype_pdb_path=THIS_DIR / "101m_Repair.pdb", - force_register=True, - ) - - assert np.isclose(y0, 8411.45578009).all() - f.terminate() - - -# TODO: Automated testing via GitHub actions -# struggles with this test, even after adding -# xvbf coactions. We need to add/raise errors -# in the objective function itself to see -# why that is... - -# For now, we'll remove it. - -# def test_force_registering_smb(): -# # assert False -# print("Testing SMB") -# _, f, _, y0, _ = objective_factory.create( -# name="super_mario_bros", -# force_register=True, -# ) -# f.terminate() - - -def test_registering_qed(): - """ - Testing whether we can register the qed problem - if rdkit and selfies are installed. - """ - _ = pytest.importorskip("rdkit") - _ = pytest.importorskip("selfies") - np = pytest.importorskip("numpy") - - _, f, _, y0, _ = objective_factory.create( - name="rdkit_qed", - path_to_alphabet=THIS_DIR / "alphabet_qed.json", - ) - x = np.array([["C"]]) - y = f(x) - - # Asserting that the QED of a single carbon - # is close to 0.35978494 (according to RDKit). - assert np.isclose(y, 0.35978494).all() - - f.terminate() - - -def test_registering_logp(): - """ - Testing whether we can register the logp problem - if rdkit and selfies are installed. - """ - rdkit = pytest.importorskip("rdkit") - selfies = pytest.importorskip("selfies") - np = pytest.importorskip("numpy") - - _, f, _, y0, _ = objective_factory.create( - name="rdkit_logp", - path_to_alphabet=THIS_DIR / "alphabet_qed.json", - ) - x = np.array([[1]]) - f(x) - - # Asserting that a single carbon atom has logp close - # to 0.6361. (according to RDKit) - assert np.isclose(y0, 0.6361).all() - - f.terminate() - - -def test_registering_foldx_stability(): - """ - Testing whether we can register the logp problem - if biopython and python-levenshtein are installed. - """ - HOME_DIR = Path().home().resolve() - PATH_TO_FOLDX_FILES = HOME_DIR / "foldx" - if not PATH_TO_FOLDX_FILES.exists(): - pytest.skip("FoldX is not installed. ") - - if not (PATH_TO_FOLDX_FILES / "foldx").exists(): - pytest.skip("FoldX is not compiled. ") - - if not (PATH_TO_FOLDX_FILES / "rotabase.txt").exists(): - pytest.skip("rotabase.txt is not in the foldx directory. ") - - if not (THIS_DIR / "101m_Repair.pdb").exists(): - pytest.skip("Could not find wildtype 101m_Repair.pdb in test folder.") - - _ = pytest.importorskip("Bio") - _ = pytest.importorskip("Levenshtein") - - _, f, _, y0, _ = objective_factory.create( - name="foldx_stability", - wildtype_pdb_path=THIS_DIR / "101m_Repair.pdb", - ) - - assert np.isclose(y0, 32.4896).all() - - -def test_registering_foldx_sasa(): - """ - Testing whether we can register the logp problem - if biopython and python-levenshtein are installed. - """ - HOME_DIR = Path().home().resolve() - PATH_TO_FOLDX_FILES = HOME_DIR / "foldx" - if not PATH_TO_FOLDX_FILES.exists(): - pytest.skip("FoldX is not installed. ") - - if not (PATH_TO_FOLDX_FILES / "foldx").exists(): - pytest.skip("FoldX is not compiled. ") - - if not (PATH_TO_FOLDX_FILES / "rotabase.txt").exists(): - pytest.skip("rotabase.txt is not in the foldx directory. ") - - _ = pytest.importorskip("Bio") - _ = pytest.importorskip("Levenshtein") - - _, f, _, y0, _ = objective_factory.create( - name="foldx_sasa", - wildtype_pdb_path=THIS_DIR / "101m_Repair.pdb", - ) - - assert np.isclose(y0, 8411.45578009).all() - - -def test_registering_foldx_stability_and_sasa(): - """ - Testing whether we can register the logp problem - if biopython and python-levenshtein are installed. - """ - HOME_DIR = Path().home().resolve() - PATH_TO_FOLDX_FILES = HOME_DIR / "foldx" - if not PATH_TO_FOLDX_FILES.exists(): - pytest.skip("FoldX is not installed. ") - - if not (PATH_TO_FOLDX_FILES / "foldx").exists(): - pytest.skip("FoldX is not compiled. ") - - if not (PATH_TO_FOLDX_FILES / "rotabase.txt").exists(): - pytest.skip("rotabase.txt is not in the foldx directory. ") - - _ = pytest.importorskip("Bio") - _ = pytest.importorskip("Levenshtein") - - _, f, _, y0, _ = objective_factory.create( - name="foldx_stability_and_sasa", - wildtype_pdb_path=THIS_DIR / "101m_Repair.pdb", - ) - - assert np.isclose(y0[:, 0], 32.4896).all() - assert np.isclose(y0[:, 1], 8411.45578009).all() - - -def test_penalized_logp_lambo(): - """ - Testing whether we can register the logp problem - from lambo. - """ - from poli import objective_factory - - _ = pytest.importorskip("lambo") - - # Using create - _, f, x0, y0, _ = objective_factory.create( - name="penalized_logp_lambo", force_register=True - ) - print(x0) - print(y0) - f.terminate() - - -def test_rasp_on_3ned_against_notebooks_results_on_rasp_env(): - try: - from poli.objective_repository.rasp.register import RaspProblemFactory - except ImportError: - pytest.skip("Could not import RaspProblemFactory. ") - - import torch - - # For us to match what the notebook says, we have - # to run at double precision. - torch.set_default_dtype(torch.float64) - - # If the previous import was successful, we can - # create a RaSP problem: - _, f, x0, _, _ = objective_factory.create( - name="rasp", - wildtype_pdb_path=THIS_DIR / "3ned.pdb", - ) - - wildtype_sequence = "".join(x0[0]) - three_mutations = [ - "A" + wildtype_sequence[1:], - "R" + wildtype_sequence[1:], - "N" + wildtype_sequence[1:], - ] - - x = np.array([list(mutation) for mutation in three_mutations]) - y = f(x) - - # Asserting that the results are the same as in the - # notebook: - # E1A: 0.03654138690753095 - # E1R: -0.07091977827871465 - # E1N: -0.2835593180137258 - - assert np.isclose(y[0], 0.03654138690753095) - assert np.isclose(y[1], -0.07091977827871465) - assert np.isclose(y[2], -0.2835593180137258) - - -def test_rasp_on_3ned_against_notebooks_results_isolated(): - """ - We test forceful registration of the RaSP problem. - """ - # If the previous import was successful, we can - # create a RaSP problem: - _, f, x0, _, _ = objective_factory.create( - name="rasp", - wildtype_pdb_path=THIS_DIR / "3ned.pdb", - force_register=True, - ) - - wildtype_sequence = "".join(x0[0]) - three_mutations = [ - "A" + wildtype_sequence[1:], - "R" + wildtype_sequence[1:], - "N" + wildtype_sequence[1:], - ] - - x = np.array([list(mutation) for mutation in three_mutations]) - y = f(x) - - # Asserting that the results are the same as in the - # notebook: - # E1A: 0.03654138690753095 - # E1R: -0.07091977827871465 - # E1N: -0.2835593180137258 - - # Notice how we are clipping the actual values, - # this is because we would need double precision - # to test against the exact values described above. - # TODO: Should we do double precision by default - # inside the RaSP problem? - assert np.isclose(y[0], 0.0365, atol=1e-4) - assert np.isclose(y[1], -0.07091, atol=1e-4) - assert np.isclose(y[2], -0.283559, atol=1e-4) - - -def test_rasp_on_3ned_against_notebooks_results_on_rasp_env(): - try: - from poli.objective_repository.rasp.register import RaspProblemFactory - except ImportError: - pytest.skip("Could not import RaspProblemFactory. ") - - import torch - - # For us to match what the notebook says, we have - # to run at double precision. - torch.set_default_dtype(torch.float64) - - # If the previous import was successful, we can - # create a RaSP problem: - _, f, x0, _, _ = objective_factory.create( - name="rasp", - wildtype_pdb_path=THIS_DIR / "3ned.pdb", - ) - - wildtype_sequence = "".join(x0[0]) - three_mutations = [ - "A" + wildtype_sequence[1:], - "R" + wildtype_sequence[1:], - "N" + wildtype_sequence[1:], - ] - - x = np.array([list(mutation) for mutation in three_mutations]) - y = f(x) - - # Asserting that the results are the same as in the - # notebook: - # E1A: 0.03654138690753095 - # E1R: -0.07091977827871465 - # E1N: -0.2835593180137258 - - assert np.isclose(y[0], 0.03654138690753095) - assert np.isclose(y[1], -0.07091977827871465) - assert np.isclose(y[2], -0.2835593180137258) - - -if __name__ == "__main__": - test_rasp_on_3ned_against_notebooks_results_isolated() diff --git a/tox.ini b/tox.ini index 3fbaf2a4..48fe6ce8 100644 --- a/tox.ini +++ b/tox.ini @@ -35,7 +35,7 @@ description = check the code style with black deps = black commands = - black --check --diff {posargs:.} + black --check --diff . [testenv:poli-base-py39] description = run the tests with pytest on the base environment for poli From cd0cab050c464a637812e58bdc1d2a97ae6916ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Gonz=C3=A1lez=20Duque?= Date: Wed, 1 Nov 2023 10:52:28 +0100 Subject: [PATCH 5/9] Specifies the ignore paths as posargs in tox --- .github/workflows/python-tox-testing-including-conda.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/python-tox-testing-including-conda.yml b/.github/workflows/python-tox-testing-including-conda.yml index 6fa5b190..00b4eeac 100644 --- a/.github/workflows/python-tox-testing-including-conda.yml +++ b/.github/workflows/python-tox-testing-including-conda.yml @@ -26,4 +26,4 @@ jobs: tox -e lint - name: Test poli-base with tox (ignoring RaSP) run: | - tox -e poli-base-py39 --ignore=src/poli/tests/registry/proteins/test_rasp.py + tox -e poli-base-py39 -- --ignore=src/poli/tests/registry/proteins/test_rasp.py From c1985e6b7716874fbbb05a68da5b11c0dad2115c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Gonz=C3=A1lez=20Duque?= Date: Wed, 1 Nov 2023 11:04:38 +0100 Subject: [PATCH 6/9] Specifies a different configuration file for dev and master testing --- ...-tox-testing-including-conda-on-master.yml | 11 +++-- .../python-tox-testing-including-conda.yml | 2 +- tox.dev.ini | 45 +++++++++++++++++++ tox.ini => tox.master.ini | 0 4 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 tox.dev.ini rename tox.ini => tox.master.ini (100%) diff --git a/.github/workflows/python-tox-testing-including-conda-on-master.yml b/.github/workflows/python-tox-testing-including-conda-on-master.yml index 07a5684c..9e5be94d 100644 --- a/.github/workflows/python-tox-testing-including-conda-on-master.yml +++ b/.github/workflows/python-tox-testing-including-conda-on-master.yml @@ -1,8 +1,7 @@ name: Test (conda, python 3.9) on: - push: - pull-request: + pull_request: branches: - master @@ -27,13 +26,13 @@ jobs: python -m pip install tox - name: Test linting with tox run: | - tox -e lint + tox -c tox.master.ini -e lint - name: Test poli-base with tox run: | - tox -e poli-base-py39 + tox -c tox.master.ini -e poli-base-py39 - name: Test poli-chem with tox run: | - tox -e poli-chem-py39 + tox -c tox.master.ini -e poli-chem-py39 - name: Test poli-protein with tox run: | - tox -e poli-protein-py39 + tox -c tox.master.ini -e poli-protein-py39 diff --git a/.github/workflows/python-tox-testing-including-conda.yml b/.github/workflows/python-tox-testing-including-conda.yml index 00b4eeac..0127ede8 100644 --- a/.github/workflows/python-tox-testing-including-conda.yml +++ b/.github/workflows/python-tox-testing-including-conda.yml @@ -26,4 +26,4 @@ jobs: tox -e lint - name: Test poli-base with tox (ignoring RaSP) run: | - tox -e poli-base-py39 -- --ignore=src/poli/tests/registry/proteins/test_rasp.py + tox -c tox.dev.ini -e poli-base-py39 -- --ignore=src/poli/tests/registry/proteins/test_rasp.py diff --git a/tox.dev.ini b/tox.dev.ini new file mode 100644 index 00000000..763835e2 --- /dev/null +++ b/tox.dev.ini @@ -0,0 +1,45 @@ +[tox] +env_list = + lint + poli-base-py39 +minversion = 4.10.0 + +[testenv] +description = run the tests with pytest +package = wheel +wheel_build_env = .pkg +allowlist_externals = + sh +deps = + pytest>=6 +commands = + sh -c "rm -rf ~/.poli_objectives/*.sh" + sh -c "rm -rf ~/.poli_objectives/config.rc" + sh -c 'if conda info --envs | grep -q poli__chem; then echo "poli__chem already exists"; else conda env create -f ./src/poli/objective_repository/rdkit_qed/environment.yml; fi' + sh -c "conda run -n poli__chem python -m pip uninstall -y poli" + sh -c "conda run -n poli__chem python -m pip install -e ." + sh -c 'if conda info --envs | grep -q poli__protein; then echo "poli__protein already exists"; else conda env create -f ./src/poli/objective_repository/foldx_stability/environment.yml; fi' + sh -c "conda run -n poli__protein python -m pip uninstall -y poli" + sh -c "conda run -n poli__protein python -m pip install -e ." + sh -c 'if conda info --envs | grep -q poli__rasp; then echo "poli__rasp already exists"; else conda env create -f ./src/poli/objective_repository/rasp/environment.yml; fi' + pytest {tty:--color=yes} -v {posargs} + sh -c "rm -rf ~/.poli_objectives/*.sh" + sh -c "rm -rf ~/.poli_objectives/config.rc" + +[testenv:lint] +description = check the code style with black +deps = + black +commands = + black --check --diff . + +[testenv:poli-base-py39] +description = run the tests with pytest on the base environment for poli +basepython = python3.9 +wheel_build_env = .pkg +deps= + {[testenv]deps} + numpy + -e. +commands= + {[testenv]commands} diff --git a/tox.ini b/tox.master.ini similarity index 100% rename from tox.ini rename to tox.master.ini From c982a38dafbc55416879d847a727054e88e9e44a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Gonz=C3=A1lez=20Duque?= Date: Wed, 1 Nov 2023 11:06:20 +0100 Subject: [PATCH 7/9] Specifies config file for linting in the github action --- .../python-tox-testing-including-conda-on-master.yml | 2 +- .github/workflows/python-tox-testing-including-conda.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/python-tox-testing-including-conda-on-master.yml b/.github/workflows/python-tox-testing-including-conda-on-master.yml index 9e5be94d..70cd153c 100644 --- a/.github/workflows/python-tox-testing-including-conda-on-master.yml +++ b/.github/workflows/python-tox-testing-including-conda-on-master.yml @@ -1,4 +1,4 @@ -name: Test (conda, python 3.9) +name: Test (master, conda, python 3.9) on: pull_request: diff --git a/.github/workflows/python-tox-testing-including-conda.yml b/.github/workflows/python-tox-testing-including-conda.yml index 0127ede8..e5bb748f 100644 --- a/.github/workflows/python-tox-testing-including-conda.yml +++ b/.github/workflows/python-tox-testing-including-conda.yml @@ -1,4 +1,4 @@ -name: Test (conda, python 3.9) +name: Test (dev, conda, python 3.9) on: [push] @@ -23,7 +23,7 @@ jobs: python -m pip install tox - name: Test linting with tox run: | - tox -e lint + tox -c tox.dev.ini -e lint - name: Test poli-base with tox (ignoring RaSP) run: | tox -c tox.dev.ini -e poli-base-py39 -- --ignore=src/poli/tests/registry/proteins/test_rasp.py From 675646e7eaa55f076aa47e8fff6e6b253ccf9056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Gonz=C3=A1lez=20Duque?= Date: Wed, 1 Nov 2023 11:27:46 +0100 Subject: [PATCH 8/9] Removes the installation of the poli__rasp environment from tox dev --- CONTRIBUTING.md | 4 ++-- tox.dev.ini | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 220fccf3..66996c5e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -28,10 +28,10 @@ Since we are testing multiple conda environments, we settled for using a combina pip install tox # To test linting (from the root of the project) -tox -e lint +tox -c tox.dev.ini -e lint # To test in the base environment for poli -tox -e poli-base-py39 +tox -c tox.dev.ini -e poli-base-py39 ``` If you want to run tests in all environments, remove `-e poli-base-py39` and just run `tox`. diff --git a/tox.dev.ini b/tox.dev.ini index 763835e2..37a38b4c 100644 --- a/tox.dev.ini +++ b/tox.dev.ini @@ -21,7 +21,6 @@ commands = sh -c 'if conda info --envs | grep -q poli__protein; then echo "poli__protein already exists"; else conda env create -f ./src/poli/objective_repository/foldx_stability/environment.yml; fi' sh -c "conda run -n poli__protein python -m pip uninstall -y poli" sh -c "conda run -n poli__protein python -m pip install -e ." - sh -c 'if conda info --envs | grep -q poli__rasp; then echo "poli__rasp already exists"; else conda env create -f ./src/poli/objective_repository/rasp/environment.yml; fi' pytest {tty:--color=yes} -v {posargs} sh -c "rm -rf ~/.poli_objectives/*.sh" sh -c "rm -rf ~/.poli_objectives/config.rc" From f7851169211dedd7f2377930026cc56ac20e56b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20Gonz=C3=A1lez=20Duque?= Date: Wed, 1 Nov 2023 11:48:26 +0100 Subject: [PATCH 9/9] Incorporates these changes to testing in the documentation of how to contribute --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 66996c5e..9e99c4af 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -20,7 +20,7 @@ pip install black black ./path/to/files ``` -## Testing your changes +## Testing your changes for `dev`` Since we are testing multiple conda environments, we settled for using a combination of `tox` and `pytest`. @@ -38,7 +38,7 @@ If you want to run tests in all environments, remove `-e poli-base-py39` and jus ## More thorough testing -In many cases, testing with the instructions above should be enough. However, since we are dealing with creating conda environments, the definite test comes by building the Docker container specified in `Dockerfile.test`, and running it as an image. +In many cases, testing with the instructions above should be enough. However, since we are dealing with creating conda environments, the definite test comes by building the Docker image specified in `Dockerfile.test`, and running it. When contributing to the `@master` branch (i.e. to release), we will run these tests.