Skip to content

Commit

Permalink
Merge pull request #350 from torchmd/fix_windows
Browse files Browse the repository at this point in the history
Fix windows builds
  • Loading branch information
stefdoerr authored Jan 24, 2025
2 parents b90b49d + e118a57 commit 531e434
Show file tree
Hide file tree
Showing 12 changed files with 201 additions and 80 deletions.
57 changes: 50 additions & 7 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ on:

jobs:
test:
runs-on: "ubuntu-latest"
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: ["ubuntu-latest", "macos-latest", "macos-13", "windows-2022"]
python-version: ["3.10"]

defaults: # Needed for conda
run:
shell: bash -l {0}
Expand All @@ -21,18 +28,50 @@ jobs:
- name: Check out
uses: actions/checkout@v4

- name: Create a conda environment
uses: conda-incubator/setup-miniconda@v3
- uses: conda-incubator/setup-miniconda@v3
with:
python-version: ${{ matrix.python-version }}
channels: conda-forge
conda-remove-defaults: "true"
if: matrix.os != 'macos-13'

- uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: torchmd-net
environment-file: environment.yml
python-version: ${{ matrix.python-version }}
channels: conda-forge
mamba-version: "*"
conda-remove-defaults: "true"
if: matrix.os == 'macos-13'

- name: Install the package
run: pip -vv install .
- name: Install OS-specific conda dependencies
run: |
if [[ "${{ runner.os }}" == "Linux" ]]; then
conda install --file conda_deps_linux.txt --channel conda-forge --override-channels
elif [[ "${{ runner.os }}" == "macos-13" ]]; then
mamba install --file conda_deps_osx.txt --channel conda-forge --override-channels
elif [[ "${{ runner.os }}" == "macOS" ]]; then
conda install --file conda_deps_osx.txt --channel conda-forge --override-channels
elif [[ "${{ runner.os }}" == "Windows" ]]; then
conda install --file conda_deps_win.txt --channel conda-forge --override-channels
fi
- name: Install testing packages
run: conda install -y -c conda-forge flake8 pytest psutil

- name: List the conda environment
run: conda list

- name: Build and install the package
run: |
if [[ "${{ runner.os }}" == "Windows" ]]; then
export LIB="C:/Miniconda/envs/test/Library/lib"
pip -vv install .
else
pip -vv install .
fi
env:
CPU_ONLY: 1

- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
Expand All @@ -42,6 +81,10 @@ jobs:
- name: Run tests
run: pytest -v -s
env:
CPU_ONLY: 1
WINDOWS_TESTS: ${{ runner.os == 'Windows' && 'true' || 'false' }}
OMP_PREFIX: ${{ runner.os == 'macOS' && '/Users/runner/miniconda3/envs/test' || '' }}

- name: Test torchmd-train utility
run: torchmd-train --help
10 changes: 10 additions & 0 deletions conda_deps_linux.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
h5py
nnpops
pip
libtorch >=2.5.1
pytorch-cpu >=2.5.1
pytorch_geometric
lightning
torchmetrics
tqdm
gxx
12 changes: 12 additions & 0 deletions conda_deps_osx.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
h5py
nnpops
pip
libtorch>=2.5.1
pytorch-cpu>=2.5.1
pytorch_geometric
lightning
torchmetrics
tqdm
clangxx
llvm-openmp
pybind11
13 changes: 13 additions & 0 deletions conda_deps_win.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
h5py
pip
libtorch >=2.5.1
pytorch-cpu >=2.5.1
pytorch_geometric
lightning
torchmetrics
tqdm
vc
vc14_runtime
vs2015_runtime
vs2019_win-64
sleef
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import torch
from torch.utils.cpp_extension import BuildExtension, CUDAExtension, include_paths, CppExtension
import os
import sys

is_windows = sys.platform == 'win32'

try:
version = (
Expand Down Expand Up @@ -43,7 +46,7 @@ def set_torch_cuda_arch_list():
ExtensionType = CppExtension if not use_cuda else CUDAExtension
extensions = ExtensionType(
name='torchmdnet.extensions.torchmdnet_extensions',
sources=[os.path.join(extension_root, "extensions.cpp")] + neighbor_sources,
sources=[os.path.join(extension_root, "torchmdnet_extensions.cpp")] + neighbor_sources,
include_dirs=include_paths(),
define_macros=[('WITH_CUDA', 1)] if use_cuda else [],
)
Expand All @@ -58,5 +61,5 @@ def set_torch_cuda_arch_list():
'build_ext': BuildExtension.with_options(no_python_abi_suffix=True, use_ninja=False)},
include_package_data=True,
entry_points={"console_scripts": ["torchmd-train = torchmdnet.scripts.train:main"]},
package_data={"torchmdnet": ["extensions/torchmdnet_extensions.so"]},
package_data={"torchmdnet": ["extensions/torchmdnet_extensions.so"] if not is_windows else ["extensions/torchmdnet_extensions.dll"]},
)
7 changes: 6 additions & 1 deletion tests/test_dataset_comp6.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_dataset_s66x8():
),
atol=1e-4,
)
assert pt.allclose(sample.y, pt.tensor([[-5755.7288331]],dtype=pt.float64))
assert pt.allclose(sample.y, pt.tensor([[-5755.7288331]], dtype=pt.float64))
assert pt.allclose(
sample.neg_dy,
-pt.tensor(
Expand All @@ -65,3 +65,8 @@ def test_dataset_s66x8():
data_loader = DataLoader(dataset=data_set, batch_size=32, num_workers=2)
for batch in data_loader:
pass

# Extra cleanup for Windows tests which are sensitive to open mmap files
del sample
del data_loader
del data_set
18 changes: 17 additions & 1 deletion tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from torchmdnet.module import LNNP
from torchmdnet.data import DataModule
from torchmdnet import priors
import os

from utils import load_example_args, DummyDataset

Expand All @@ -30,6 +31,15 @@ def test_load_model():
@mark.parametrize("use_atomref", [True, False])
@mark.parametrize("precision", [32, 64])
def test_train(model_name, use_atomref, precision, tmpdir):
import torch
import platform

accelerator = "auto"
if platform.system() == "Darwin" and (os.getenv("CI", None) is not None):
# MPS backend runs out of memory on Github
torch.set_default_device("cpu")
accelerator = "cpu"

args = load_example_args(
model_name,
remove_prior=not use_atomref,
Expand All @@ -53,6 +63,12 @@ def test_train(model_name, use_atomref, precision, tmpdir):

module = LNNP(args, prior_model=prior)

trainer = pl.Trainer(max_steps=10, default_root_dir=tmpdir, precision=args["precision"],inference_mode=False)
trainer = pl.Trainer(
max_steps=10,
default_root_dir=tmpdir,
precision=args["precision"],
inference_mode=False,
accelerator=accelerator,
)
trainer.fit(module, datamodule)
trainer.test(module, datamodule)
5 changes: 5 additions & 0 deletions tests/test_neighbors.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,11 @@ def test_per_batch_box(device, strategy, n_batches, use_forward):
def test_torch_compile(device, dtype, loop, include_transpose):
import sys

# Skip if WINDOWS_TESTS is set to true
if os.environ.get("WINDOWS_TESTS", "false") == "true":
# torch.compile doesn't detect cl.exe on Windows Github Actions
pytest.skip("Skipping test on Windows")

if sys.version_info >= (3, 12):
pytest.skip("Not available in this version")
if torch.__version__ < "2.0.0":
Expand Down
Loading

0 comments on commit 531e434

Please sign in to comment.