Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates for PyTorch 2.1 #243

Merged
merged 3 commits into from
Oct 6, 2023
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
6 changes: 3 additions & 3 deletions .github/workflows/torch-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ jobs:
cargo-test-flags: --release

- os: ubuntu-20.04
torch-version: 2.0.*
torch-version: 2.1.*
python-version: "3.11"
cargo-test-flags: --release
do-valgrind: true

- os: macos-11
torch-version: 2.0.*
torch-version: 2.1.*
python-version: "3.11"
cargo-test-flags: --release

- os: windows-2019
torch-version: 2.0.*
torch-version: 2.1.*
python-version: "3.11"
cargo-test-flags: --release

Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ myst-parser # markdown => rst translation, used in extensions/rascaline_json

# dependencies for the tutorials
--extra-index-url https://download.pytorch.org/whl/cpu
metatensor[torch] @ https://github.com/lab-cosmo/metatensor/archive/2248a3c.zip
metatensor[torch] @ git+https://github.com/lab-cosmo/metatensor@ae10944
torch
chemfiles
matplotlib
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ classifiers = [
]

dependencies = [
"metatensor-core @ https://github.com/lab-cosmo/metatensor/archive/2248a3c.zip#subdirectory=python/metatensor-core",
"metatensor-core @ git+https://github.com/lab-cosmo/metatensor@ae10944#subdirectory=python/metatensor-core",
]

[project.urls]
Expand Down
2 changes: 1 addition & 1 deletion python/rascaline-torch/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ requires = [
"wheel >=0.38",
"cmake",
"torch >= 1.11",
"metatensor-torch @ https://github.com/lab-cosmo/metatensor/archive/2248a3c.zip#subdirectory=python/metatensor-torch",
"metatensor-torch @git+https://github.com/lab-cosmo/metatensor@ae10944#subdirectory=python/metatensor-torch",
]

# use a custom build backend to add a dependency on the right version of rascaline
Expand Down
4 changes: 2 additions & 2 deletions rascaline-c-api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ endif()
# ============================================================================ #
# Setup metatensor

set(METATENSOR_GIT_VERSION "2248a3c")
set(METATENSOR_GIT_VERSION "ae10944")
set(METATENSOR_REQUIRED_VERSION "0.1")
if (RASCALINE_FETCH_METATENSOR)
message(STATUS "Fetching metatensor @ ${METATENSOR_GIT_VERSION} from github")
Expand All @@ -226,7 +226,7 @@ if (RASCALINE_FETCH_METATENSOR)
FetchContent_Declare(
metatensor
URL https://github.com/lab-cosmo/metatensor/archive/${METATENSOR_GIT_VERSION}.zip
URL_HASH MD5=50e70a2e74246a985e1520260a74205c
URL_HASH MD5=1de1208bd96fa9acda0b835d1c9e2c5d
SOURCE_SUBDIR metatensor-core
VERBOSE
)
Expand Down
4 changes: 2 additions & 2 deletions rascaline-c-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ chemfiles = ["rascaline/chemfiles"]

[dependencies]
rascaline = {path = "../rascaline", version = "0.1.0", default-features = false}
metatensor = {git = "https://github.com/lab-cosmo/metatensor", rev = "2248a3c"}
metatensor = {git = "https://github.com/lab-cosmo/metatensor", rev = "ae10944"}

ndarray = "0.15"
log = { version = "0.4", features = ["std"] }
Expand All @@ -29,7 +29,7 @@ libc = "0.2"
[build-dependencies]
cbindgen = { version = "0.24", default-features = false }
fs_extra = "1"
metatensor = {git = "https://github.com/lab-cosmo/metatensor", rev = "2248a3c"}
metatensor = {git = "https://github.com/lab-cosmo/metatensor", rev = "ae10944"}

[dev-dependencies]
which = "4"
3 changes: 1 addition & 2 deletions rascaline-c-api/src/calculator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,13 @@ pub unsafe extern fn rascal_calculator(name: *const c_char, parameters: *const c
let mut raw = std::ptr::null_mut();
let unwind_wrapper = std::panic::AssertUnwindSafe(&mut raw);
let status = catch_unwind(move || {
let unwind_wrapper = unwind_wrapper;

check_pointers!(name, parameters);
let name = CStr::from_ptr(name).to_str()?;
let parameters = CStr::from_ptr(parameters).to_str()?;
let calculator = Calculator::new(name, parameters.to_owned())?;
let boxed = Box::new(rascal_calculator_t(calculator));

let _ = &unwind_wrapper;
*unwind_wrapper.0 = Box::into_raw(boxed);
Ok(())
});
Expand Down
2 changes: 1 addition & 1 deletion rascaline-c-api/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl From<Error> for rascal_status_t {
/// the error into `rascal_status_t`.
pub fn catch_unwind<F>(function: F) -> rascal_status_t where F: FnOnce() -> Result<(), Error> + UnwindSafe {
match std::panic::catch_unwind(function) {
Ok(Ok(_)) => rascal_status_t(RASCAL_SUCCESS),
Ok(Ok(())) => rascal_status_t(RASCAL_SUCCESS),
Ok(Err(error)) => error.into(),
Err(error) => Error::from(error).into()
}
Expand Down
2 changes: 1 addition & 1 deletion rascaline-c-api/tests/catch/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
add_library(catch STATIC catch.cpp)
target_include_directories(catch PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_features(catch PUBLIC cxx_std_11)
target_compile_features(catch PUBLIC cxx_std_17)
6 changes: 3 additions & 3 deletions rascaline-torch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ find_package(Torch 1.11 REQUIRED)
# ============================================================================ #
# Setup metatensor_torch

set(METATENSOR_GIT_VERSION "2248a3c")
set(METATENSOR_GIT_VERSION "ae10944")
set(REQUIRED_METATENSOR_TORCH_VERSION "0.1")
if (RASCALINE_TORCH_FETCH_METATENSOR_TORCH)
message(STATUS "Fetching metatensor_torch @ ${METATENSOR_GIT_VERSION} from github")
Expand All @@ -67,7 +67,7 @@ if (RASCALINE_TORCH_FETCH_METATENSOR_TORCH)
FetchContent_Declare(
metatensor_torch
URL https://github.com/lab-cosmo/metatensor/archive/${METATENSOR_GIT_VERSION}.zip
URL_HASH MD5=50e70a2e74246a985e1520260a74205c
URL_HASH MD5=1de1208bd96fa9acda0b835d1c9e2c5d
SOURCE_SUBDIR metatensor-torch
VERBOSE
)
Expand Down Expand Up @@ -106,7 +106,7 @@ add_library(rascaline_torch SHARED
)

target_link_libraries(rascaline_torch PUBLIC torch metatensor_torch rascaline)
target_compile_features(rascaline_torch PUBLIC cxx_std_14)
target_compile_features(rascaline_torch PUBLIC cxx_std_17)
target_include_directories(rascaline_torch PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
Expand Down
2 changes: 1 addition & 1 deletion rascaline-torch/tests/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub fn setup_pytorch(build_dir: PathBuf) -> PathBuf {
.expect("failed to run python");
assert!(status.success(), "failed to run `python -m pip install --upgrade pip`");

let torch_version = std::env::var("RASCALINE_TORCH_TEST_VERSION").unwrap_or("2.0.*".into());
let torch_version = std::env::var("RASCALINE_TORCH_TEST_VERSION").unwrap_or("2.1.*".into());
let status = Command::new(&python)
.arg("-m")
.arg("pip")
Expand Down
2 changes: 1 addition & 1 deletion rascaline/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ name = "soap-power-spectrum"
harness = false

[dependencies]
metatensor = {git = "https://github.com/lab-cosmo/metatensor", rev = "2248a3c", features = ["rayon"]}
metatensor = {git = "https://github.com/lab-cosmo/metatensor", rev = "ae10944", features = ["rayon"]}

ndarray = {version = "0.15", features = ["approx-0_5", "rayon", "serde"]}
num-traits = "0.2"
Expand Down
2 changes: 1 addition & 1 deletion rascaline/src/calculators/neighbor_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ impl FullNeighborList {
system.compute_neighbors(self.cutoff)?;
let species = system.species()?;

for pair in system.pairs()?.iter() {
for pair in system.pairs()? {
let first_block_i = descriptor.keys().position(&[
species[pair.first].into(), species[pair.second].into()
]);
Expand Down
4 changes: 2 additions & 2 deletions rascaline/src/calculators/soap/spherical_expansion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl SphericalExpansion {
let neighbor_i = pair.second;

result.pair_to_pair_ids.entry((pair.first, pair.second))
.or_insert_with(Vec::new)
.or_default()
.push(pair_id);

let species_neighbor_i = result.species_mapping[&species[neighbor_i]];
Expand Down Expand Up @@ -253,7 +253,7 @@ impl SphericalExpansion {
let neighbor_i = pair.first;

result.pair_to_pair_ids.entry((pair.second, pair.first))
.or_insert_with(Vec::new)
.or_default()
.push(pair_id);


Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ lint-folders = "{toxinidir}/python" "{toxinidir}/setup.py"
# we need to manually install dependencies for rascaline, since tox will install
# the fresh wheel with `--no-deps` after building it.
metatensor-core-requirement =
metatensor-core @ https://github.com/lab-cosmo/metatensor/archive/2248a3c.zip\#subdirectory=python/metatensor-core
metatensor-core @ git+https://github.com/lab-cosmo/metatensor@ae10944\#subdirectory=python/metatensor-core

metatensor-torch-requirement =
metatensor-torch @ https://github.com/lab-cosmo/metatensor/archive/2248a3c.zip\#subdirectory=python/metatensor-torch
metatensor-torch @ git+https://github.com/lab-cosmo/metatensor@ae10944\#subdirectory=python/metatensor-torch

build-single-wheel = --no-deps --no-build-isolation --check-build-dependencies

Expand Down