Skip to content

Commit

Permalink
Merge pull request #163 from naik-aakash/debug_test
Browse files Browse the repository at this point in the history
Fix tests
  • Loading branch information
JaGeo authored Oct 22, 2024
2 parents e5ea5e6 + 264a974 commit c3c5c25
Show file tree
Hide file tree
Showing 18 changed files with 45 additions and 262 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
python -m pip install --upgrade pip && \
python -m uv pip install .[strict,tests] && \
python -m uv pip install ase==3.23.0 && \
pytest --cov=autoplex --cov-report term-missing --cov-append --splits 5 --group ${{ matrix.split }} -vv --durations-path /workspace/tests/test_data/.pytest-split-durations
OMP_NUM_THREADS=1 pytest --cache-clear --cov=autoplex --cov-report term-missing --cov-append --splits 5 --group ${{ matrix.split }} -vv --durations-path /workspace/tests/test_data/.pytest-split-durations
"
- name: Upload coverage
uses: actions/upload-artifact@v3
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ strict = [
"torchdata==0.7.1",
]
dev = ["pre-commit>=2.12.1"]
tests = ["pytest", "pytest-mock", "pytest-split", "pytest-cov", "types-setuptools"]
tests = ["pytest", "pytest-mock", "pytest-split==0.9.0", "pytest-cov", "types-setuptools"]

[tool.versioningit.vcs]
method = "git"
Expand Down
5 changes: 0 additions & 5 deletions tests/auto/test_auto_flows.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
from __future__ import annotations
import os
import pytest
from monty.serialization import loadfn
from atomate2.common.schemas.phonons import PhononBSDOSDoc
from pymatgen.core.structure import Structure
from autoplex.auto.phonons.flows import CompleteDFTvsMLBenchmarkWorkflow
from jobflow.core.job import Response

os.environ["OMP_NUM_THREADS"] = "4" # export OMP_NUM_THREADS=4
os.environ["OPENBLAS_NUM_THREADS"] = "1" # export OPENBLAS_NUM_THREADS=1


@pytest.fixture(scope="class")
Expand Down
3 changes: 0 additions & 3 deletions tests/auto/test_auto_jobs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import os
from jobflow import Flow
from pymatgen.core.structure import Structure
from autoplex.auto.phonons.jobs import (
Expand All @@ -18,8 +17,6 @@
import pytest
from pytest import approx

os.environ["OMP_NUM_THREADS"] = "4" # export OMP_NUM_THREADS=4
os.environ["OPENBLAS_NUM_THREADS"] = "1" # export OPENBLAS_NUM_THREADS=1


@pytest.fixture(scope="class")
Expand Down
3 changes: 0 additions & 3 deletions tests/data/test_datagen_flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
from autoplex.data.common.flows import GenerateTrainingDataForTesting
from autoplex.data.phonons.flows import IsoAtomMaker, RandomStructuresDataGenerator, MLPhononMaker

os.environ["OMP_NUM_THREADS"] = "4" # export OMP_NUM_THREADS=4
os.environ["OPENBLAS_NUM_THREADS"] = "1" # export OPENBLAS_NUM_THREADS=1


def test_ml_phonon_maker(test_dir, clean_dir, memory_jobstore):
from jobflow import run_locally
Expand Down
3 changes: 0 additions & 3 deletions tests/data/test_datagen_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
filter_outlier_energy,
filter_outlier_forces,
)
from autoplex.data.phonons.utils import update_phonon_displacement_maker

os.environ["OMP_NUM_THREADS"] = "4" # export OMP_NUM_THREADS=4
os.environ["OPENBLAS_NUM_THREADS"] = "1" # export OPENBLAS_NUM_THREADS=1

fig, ax_list = plt.subplots(nrows=1, ncols=1)
fig.set_size_inches(15, 20)
Expand Down
96 changes: 2 additions & 94 deletions tests/fitting/test_fitting_flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,9 @@ def fit_input_dict(vasp_test_dir):


def test_mlip_fit_maker(test_dir, clean_dir, memory_jobstore, vasp_test_dir, fit_input_dict):
import os
import shutil
from pathlib import Path
from jobflow import run_locally

parent_dir = os.getcwd()

os.chdir(test_dir / "fitting")

# Test to check if gap fit runs with default hyperparameter sets (i.e. two_body and soap is True)
gapfit = MLIPFitMaker().make(
species_list=["Li", "Cl"],
Expand All @@ -93,28 +87,16 @@ def test_mlip_fit_maker(test_dir, clean_dir, memory_jobstore, vasp_test_dir, fit
gapfit, ensure_success=True, create_folders=True, store=memory_jobstore
)

test_files_dir = Path(test_dir / "fitting").resolve()
path_to_job_files = list(test_files_dir.glob("job*"))
# check if gap fit file is generated
assert Path(gapfit.output["mlip_path"].resolve(memory_jobstore)).exists()

for job_dir in path_to_job_files:
shutil.rmtree(job_dir)

os.chdir(parent_dir)


def test_mlip_fit_maker_with_kwargs(
test_dir, clean_dir, memory_jobstore, vasp_test_dir, fit_input_dict
):
import os
import shutil
from pathlib import Path
from jobflow import run_locally

parent_dir = os.getcwd()

os.chdir(test_dir / "fitting")

# Test to check if gap fit runs with default hyperparameter sets (i.e. include_two_body and include_soap is True)
gapfit = MLIPFitMaker().make(
Expand All @@ -135,30 +117,16 @@ def test_mlip_fit_maker_with_kwargs(
gapfit, ensure_success=True, create_folders=True, store=memory_jobstore
)

test_files_dir = Path(test_dir / "fitting").resolve()
path_to_job_files = list(test_files_dir.glob("job*"))

# check if gap fit file is generated
assert Path(gapfit.output["mlip_path"].resolve(memory_jobstore)).exists()

for job_dir in path_to_job_files:
shutil.rmtree(job_dir)

os.chdir(parent_dir)


def test_mlip_fit_maker_with_pre_database_dir(
test_dir, memory_jobstore, vasp_test_dir, fit_input_dict, clean_dir
):
import os
import shutil
from pathlib import Path
from jobflow import run_locally

parent_dir = os.getcwd()

os.chdir(test_dir / "fitting")

test_files_dir = Path(test_dir / "fitting").resolve()

# Test if gap fit runs with pre_database_dir
Expand All @@ -172,28 +140,16 @@ def test_mlip_fit_maker_with_pre_database_dir(

run_locally(gapfit, ensure_success=True, create_folders=True, store=memory_jobstore)

path_to_job_files = list(test_files_dir.glob("job*"))

# check if gap potential file is generated
assert Path(gapfit.output["mlip_path"].resolve(memory_jobstore)).exists()

for job_dir in path_to_job_files:
shutil.rmtree(job_dir)

os.chdir(parent_dir)


def test_mlip_fit_maker_jace(
test_dir, memory_jobstore, vasp_test_dir, fit_input_dict, clean_dir
):
import os
import shutil
from pathlib import Path
from jobflow import run_locally

parent_dir = os.getcwd()

os.chdir(test_dir / "fitting")

test_files_dir = Path(test_dir / "fitting").resolve()

Expand All @@ -217,29 +173,18 @@ def test_mlip_fit_maker_jace(
jacefit, ensure_success=True, create_folders=True, store=memory_jobstore
)

path_to_job_files = list(test_files_dir.glob("job*"))

# check if julia-ACE potential file is generated
assert Path(jacefit.output["mlip_path"].resolve(memory_jobstore)).exists()

for job_dir in path_to_job_files:
shutil.rmtree(job_dir)

os.chdir(parent_dir)


def test_mlip_fit_maker_nequip(
test_dir, memory_jobstore, vasp_test_dir, fit_input_dict, clean_dir
):
import os
import shutil
from pathlib import Path
from jobflow import run_locally

parent_dir = os.getcwd()

os.chdir(test_dir / "fitting")


test_files_dir = Path(test_dir / "fitting").resolve()

# Test NEQUIP fit runs with pre_database_dir
Expand All @@ -261,28 +206,18 @@ def test_mlip_fit_maker_nequip(
nequipfit, ensure_success=True, create_folders=True, store=memory_jobstore
)

path_to_job_files = list(test_files_dir.glob("job*"))

# check if NEQUIP potential file is generated
assert Path(nequipfit.output["mlip_path"].resolve(memory_jobstore)).exists()

for job_dir in path_to_job_files:
shutil.rmtree(job_dir)

os.chdir(parent_dir)


def test_mlip_fit_maker_m3gnet(
test_dir, memory_jobstore, vasp_test_dir, fit_input_dict, clean_dir
):
import os
import shutil
from pathlib import Path
from jobflow import run_locally

parent_dir = os.getcwd()

os.chdir(test_dir / "fitting")

test_files_dir = Path(test_dir / "fitting").resolve()

Expand Down Expand Up @@ -313,28 +248,16 @@ def test_mlip_fit_maker_m3gnet(
m3gnetfit, ensure_success=True, create_folders=True, store=memory_jobstore
)

path_to_job_files = list(test_files_dir.glob("job*"))

# check if M3GNET potential file is generated
assert Path(m3gnetfit.output["mlip_path"].resolve(memory_jobstore)).exists()

for job_dir in path_to_job_files:
shutil.rmtree(job_dir)

os.chdir(parent_dir)


def test_mlip_fit_maker_mace(
test_dir, memory_jobstore, vasp_test_dir, fit_input_dict, clean_dir
):
import os
import shutil
from pathlib import Path
from jobflow import run_locally

parent_dir = os.getcwd()

os.chdir(test_dir / "fitting")

test_files_dir = Path(test_dir / "fitting").resolve()

Expand Down Expand Up @@ -365,15 +288,10 @@ def test_mlip_fit_maker_mace(
macefit, ensure_success=True, create_folders=True, store=memory_jobstore
)

path_to_job_files = list(test_files_dir.glob("job*"))

# check if MACE potential file is generated
assert Path(macefit.output["mlip_path"].resolve(memory_jobstore)).exists()

for job_dir in path_to_job_files:
shutil.rmtree(job_dir)

os.chdir(parent_dir)


def test_mlip_fit_maker_glue_xml(
Expand All @@ -385,7 +303,6 @@ def test_mlip_fit_maker_glue_xml(
from jobflow import run_locally

parent_dir = os.getcwd()

os.chdir(test_dir / "fitting")

fit_input_dict = {
Expand Down Expand Up @@ -470,17 +387,13 @@ def test_mlip_fit_maker_glue_xml(
os.chdir(parent_dir)



def test_mlip_fit_maker_with_automated_separated_dataset(
test_dir, memory_jobstore, vasp_test_dir, clean_dir, fit_input_dict
):
import os
import shutil
from pathlib import Path
from jobflow import run_locally

parent_dir = os.getcwd()

os.chdir(test_dir / "fitting")

test_files_dir = Path(test_dir / "fitting").resolve()

Expand All @@ -497,14 +410,9 @@ def test_mlip_fit_maker_with_automated_separated_dataset(

run_locally(gapfit, ensure_success=True, create_folders=True, store=memory_jobstore)

path_to_job_files = list(test_files_dir.glob("job*"))

# check if gap potential file is generated
assert Path(gapfit.output["mlip_path"].resolve(memory_jobstore)).exists()
assert Path(gapfit.output["mlip_path"].resolve(memory_jobstore) + "/train_phonon.extxyz").exists()
assert Path(gapfit.output["mlip_path"].resolve(memory_jobstore) + "/train_rand_struc.extxyz").exists()

for job_dir in path_to_job_files:
shutil.rmtree(job_dir)

os.chdir(parent_dir)
Loading

0 comments on commit c3c5c25

Please sign in to comment.