Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/build-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
name: ${{ matrix.name }} (torch v${{ matrix.torch-version }})
strategy:
matrix:
torch-version: ['2.3', '2.4', '2.5', '2.6', '2.7', '2.8', '2.9', '2.10', '2.11', '2.12']
torch-version: ['2.3', '2.4', '2.5', '2.6', '2.7', '2.8', '2.9', '2.10', '2.11', '2.12', '2.13']
arch: ['arm64', 'x86_64']
os: ['ubuntu-24.04', 'ubuntu-24.04-arm', 'macos-15', 'windows-2022']
exclude:
Expand Down Expand Up @@ -121,6 +121,7 @@ jobs:
- {torch-version: '2.10', python-version: '3.14', cibw-python: 'cp314-*'}
- {torch-version: '2.11', python-version: '3.14', cibw-python: 'cp314-*'}
- {torch-version: '2.12', python-version: '3.14', cibw-python: 'cp314-*'}
- {torch-version: '2.13', python-version: '3.14', cibw-python: 'cp314-*'}
steps:
- uses: actions/checkout@v6
with:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ changelog](https://keepachangelog.com/en/1.1.0/) format. This project follows
### Removed
-->

### Added

- Added support for PyTorch v2.13 in the `vesin-torch` wheels on PyPI

### Changed

- Importing from `vesin.torch` is deprecated, users should now import from
Expand Down
9 changes: 5 additions & 4 deletions fortran/src/cdef.f90
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ module vesin_c
!> Which algorithm to use for the calculation
integer(c_int) :: algorithm = VesinAutoAlgorithm

!> Skin size for Verlet caching. A positive value enables caching the
!! neighbor list until any atom moves farther than `skin/2` from its
!! reference coordinates.
real(c_double) :: skin = 0.0_c_double

!> Number of CPU threads to use. Must be zero or positive. If zero,
!! Vesin uses `OMP_NUM_THREADS` when set to a positive integer, and
!! otherwise defaults to the number of available CPU cores.
Expand All @@ -76,10 +81,6 @@ module vesin_c

!> Should the returned `VesinNeighborList` contain `vector`?
logical(c_bool) :: return_vectors = .false.

!> Skin size for Verlet caching.
real(c_double) :: skin = 0.0_c_double

end type VesinOptions

!> Used as return type from `vesin_neighbors()`.
Expand Down
2 changes: 1 addition & 1 deletion python/vesin/vesin/_c_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ class VesinOptions(ctypes.Structure):
("full", ctypes.c_bool),
("sorted", ctypes.c_bool),
("algorithm", VesinAlgorithm),
("skin", ctypes.c_double),
("n_threads", ctypes.c_int32),
("return_shifts", ctypes.c_bool),
("return_distances", ctypes.c_bool),
("return_vectors", ctypes.c_bool),
("skin", ctypes.c_double),
]


Expand Down
1 change: 1 addition & 0 deletions python/vesin/vesin/_neighbors.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class NeighborList:

def __init__(
self,
*,
cutoff: float,
full_list: bool,
sorted: bool = False,
Expand Down
19 changes: 17 additions & 2 deletions python/vesin_torch/tests/test_neighbors.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,23 @@ def test_all_alone_no_neighbors(quantities, dtype):


class NeighborListWrap:
def __init__(self, cutoff: float, full_list: bool, sorted: bool):
self._c = NeighborList(cutoff=cutoff, full_list=full_list, sorted=sorted)
def __init__(
self,
cutoff: float,
full_list: bool,
sorted: bool,
algorithm: str,
skin: float,
n_threads: int,
):
self._c = NeighborList(
cutoff=cutoff,
full_list=full_list,
sorted=sorted,
algorithm=algorithm,
skin=skin,
n_threads=n_threads,
)

def compute(
self,
Expand Down
5 changes: 5 additions & 0 deletions python/vesin_torch/vesin_torch/_neighbors.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def __init__(
full_list: bool,
sorted: bool = False,
algorithm: str = "auto",
skin: float = 0.0,
n_threads: int = 0,
):
"""
Expand All @@ -23,6 +24,9 @@ def __init__(
second point index (``j``) and shifts in the list of pairs is unspecified.
:param algorithm: algorithm to use when computing the neighbor list. One of
``"auto"``, ``"brute_force"``, or ``"cell_list"``.
:param skin: skin size for Verlet caching. A positive value enables
caching the neighbor list until any atom moves farther than
``skin/2`` from its reference coordinates.
:param n_threads: number of CPU threads to use. Must be 0 or a positive
integer. If set to 0, Vesin uses ``OMP_NUM_THREADS`` when set to a
positive integer, and otherwise the number of available CPU cores.
Expand All @@ -36,6 +40,7 @@ def __init__(
full_list=full_list,
sorted=sorted,
algorithm=algorithm,
skin=skin,
n_threads=n_threads,
)

Expand Down
15 changes: 9 additions & 6 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ lint-folders = python setup.py
package = external
package_env = build-vesin

build_single_wheel = --no-deps --force-reinstall --no-build-isolation --check-build-dependencies

# this warning fires when collecting tests and seemingly can not be
# supressed by the code in pyproject.toml, so we add it as a CLI flag
test_args = -W "ignore:`torch.jit.script` is not supported in Python 3.14+ and may break:DeprecationWarning"
Expand All @@ -28,14 +30,14 @@ packaging_deps =
optional_deps =
ase
metatomic-torch >=0.1,<0.2
torch
torch=={env:VESIN_TESTS_TORCH_VERSION:2.12}.*

[testenv:check-cuda-available]
description = Tests that CUDA is available in PyTorch and CuPy
package = skip
passenv = *
deps =
torch
torch=={env:VESIN_TESTS_TORCH_VERSION:2.12}.*
allowlist_externals = bash
commands =
bash ./scripts/install-cupy.sh
Expand Down Expand Up @@ -99,7 +101,7 @@ deps =

changedir = python/vesin_torch
commands =
pip install . --no-deps --no-build-isolation --check-build-dependencies
pip install {[testenv]build_single_wheel} .

# Make torch.autograd.gradcheck works with pytest
python {toxinidir}/scripts/pytest-dont-rewrite-torch.py
Expand All @@ -118,7 +120,8 @@ deps =
{[testenv]optional_deps}

commands =
pip install .[torch]
pip install {[testenv]build_single_wheel} python/vesin
pip install {[testenv]build_single_wheel} python/vesin_torch

pytest {[testenv]test_args} --suppress-no-test-exit-code --doctest-modules --pyargs vesin
pytest {[testenv]test_args} --suppress-no-test-exit-code --doctest-modules --pyargs vesin_torch
Expand Down Expand Up @@ -199,13 +202,13 @@ deps =

ford == 7.0.*

torch
torch=={env:VESIN_TESTS_TORCH_VERSION:2.12}.*
metatomic-torch >=0.1,<0.2
cmake
setuptools >= 77
wheel >= 0.41

commands =
pip install python/vesin_torch --no-deps --force-reinstall --no-build-isolation --check-build-dependencies
pip install {[testenv]build_single_wheel} python/vesin_torch
sphinx-build -d docs/build/doctrees -W -b html docs/src docs/build/html
ford fortran/docs.md --output_dir=../docs/build/html/fortran/
7 changes: 6 additions & 1 deletion vesin-torch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ target_include_directories(vesin_torch PUBLIC
$<INSTALL_INTERFACE:include>
)

target_compile_features(vesin_torch PUBLIC cxx_std_17)
if (${Torch_VERSION} VERSION_GREATER_EQUAL 2.13)
# Torch 2.13+ requires C++20
target_compile_features(vesin_torch PUBLIC cxx_std_20)
else()
target_compile_features(vesin_torch PUBLIC cxx_std_17)
endif()

target_compile_definitions(vesin_torch PRIVATE VESIN_TORCH_EXPORTS)
set_target_properties(vesin_torch PROPERTIES
Expand Down
5 changes: 5 additions & 0 deletions vesin-torch/include/vesin_torch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,17 @@ class VESIN_TORCH_API NeighborListHolder: public torch::CustomClassHolder {
// shifts in the list of pairs is unspecified.
/// @param algorithm the algorithm to use for neighbor list calculation. One
/// of `"auto"`, `"brute_force"`, or `"cell_list"`.
/// @param skin skin size for Verlet caching. A positive value enables
/// caching the neighbor list until any atom moves farther than
/// ``skin/2`` from its reference coordinates.
/// @param n_threads number of CPU threads to use. Must be zero or positive.
/// A value of 0 lets Vesin choose from `OMP_NUM_THREADS` or CPU cores.
NeighborListHolder(
double cutoff,
bool full_list,
bool sorted = false,
std::string algorithm = "auto",
double skin = 0.0,
int64_t n_threads = 0
);
~NeighborListHolder();
Expand Down Expand Up @@ -103,6 +107,7 @@ class VESIN_TORCH_API NeighborListHolder: public torch::CustomClassHolder {
bool full_list_;
bool sorted_;
std::string algorithm_;
double skin_;
int64_t n_threads_;
VesinNeighborList* data_;
};
Expand Down
6 changes: 5 additions & 1 deletion vesin-torch/src/vesin_torch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,14 @@ NeighborListHolder::NeighborListHolder(
bool full_list,
bool sorted,
std::string algorithm,
double skin,
int64_t n_threads
):
cutoff_(cutoff),
full_list_(full_list),
sorted_(sorted),
algorithm_(std::move(algorithm)),
skin_(skin),
n_threads_(n_threads),
data_(nullptr) {
if (n_threads_ < 0) {
Expand Down Expand Up @@ -180,6 +182,7 @@ std::vector<torch::Tensor> NeighborListHolder::compute(
/*full=*/this->full_list_,
/*sorted=*/this->sorted_,
/*algorithm=*/algorithm,
/*skin=*/this->skin_,
/*n_threads=*/n_threads,
/*return_shifts=*/return_shifts,
/*return_distances=*/return_distances,
Expand Down Expand Up @@ -322,11 +325,12 @@ TORCH_LIBRARY(vesin, m) {
// clang-format off
m.class_<NeighborListHolder>("_NeighborList")
.def(
torch::init<double, bool, bool, std::string, int64_t>(), DOCSTRING, {
torch::init<double, bool, bool, std::string, double, int64_t>(), DOCSTRING, {
torch::arg("cutoff"),
torch::arg("full_list"),
torch::arg("sorted") = false,
torch::arg("algorithm") = "auto",
torch::arg("skin") = 0.0,
torch::arg("n_threads") = 0,
}
)
Expand Down
9 changes: 4 additions & 5 deletions vesin/include/vesin.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ struct VesinOptions {
bool sorted;
/// Which algorithm to use for the calculation
VesinAlgorithm algorithm;
/// Skin size for Verlet caching. A positive value enables caching: vesin
/// builds the cached topology with `cutoff + skin` and reuses it until an
/// atom moves more than `skin / 2` from the cached reference positions.
double skin;
/// Number of CPU threads to use. This must be zero or positive. A value of
/// zero means using the `OMP_NUM_THREADS` environment variable when set to a
/// positive value, or otherwise defaulting to the number of available CPU
Expand All @@ -70,11 +74,6 @@ struct VesinOptions {
bool return_distances;
/// Should the returned `VesinNeighborList` contain `vector`?
bool return_vectors;

/// Skin size for Verlet caching. A positive value enables caching: vesin
/// builds the cached topology with `cutoff + skin` and reuses it until an
/// atom moves more than `skin / 2` from the cached reference positions.
double skin;
};

/// Device on which the data can be
Expand Down