Repository navigation
Tags
Tags
Merge develop into main (#1770) * Build the aperiodic search box orthogonal to the periodic lattice vectors (#1727) * Build the aperiodic search box orthogonal to the periodic lattice vectors Moving the atoms into the fictitious search box is only half of what makes the neighbour list independent of where the caller put the structure. The box is also built along a Cartesian axis, and any periodic lattice vector with a component on that axis can carry an atom straight back out of it. matscipy then wraps the atom and reports the wrap as a shift, which downstream is added to the caller's unwrapped positions, so a bond comes back as a vector many times the cutoff at an unchanged edge count. Two shapes reach it. A partially periodic cell whose periodic vectors reach out of the plane they span loses its edge vectors once the structure is displaced along a periodic direction, which unwrapped trajectory coordinates do. A one-dimensional cell leaves two axes for an image to escape along, and past roughly 45 degrees off the Cartesian axis it is already wrong with the structure at the origin and no displacement at all. Each non-periodic axis now gets a direction orthogonal to every periodic lattice vector, by Gram-Schmidt against them, and the atoms are anchored along that direction instead. No periodic image can move an atom along it, so the box holds whatever the coordinates are. Where the Cartesian axis is already free, which is every cell built the usual way and every molecule, it is the direction returned, so nothing about those changes. Measured against the brute-force oracle over 180 randomly generated translated systems spanning all six periodicity patterns: 0 mismatches, against 57 before this change and 128 before the displacement fix. The returned cell changes for one family, and only there: partially periodic, with a non-periodic row that is all zeros, and periodic vectors that are tilted. That row is read by the stress, which divides by det(cell), and by the electrostatics, which use it as their k-space box. It changes for the better. Along a Cartesian axis the real separation between periodic images is only the projection of that row on the surface normal, which is less vacuum than the padding asked for, and det understates the slab volume. At a tilt of 2.0 the gap goes from 11.47 to 13.35 Angstrom and the volume from 152.89 to 177.99. Nothing built by ASE is in that family, and the golden suite is unchanged. The atoms are also given a cutoff of clearance rather than being placed flush against the wall of the box. On the wall matscipy pays for the boundary bins: a 600 atom slab took 3.88 ms against 3.38 ms on the unfixed code, and 3.57 ms with the clearance. * Cover skewed cells and check translation invariance on the energy Two gaps in the previous round, both raised in review. The neighbour list tests now run over eight named skewed cells rather than one: sheared inside the periodic plane, tilted out of it by three growing amounts, an acute 20 degree angle, the vacuum on an axis other than z, and two one-dimensional cells whose single lattice vector points nowhere near an axis. Each is compared edge by edge against the brute-force oracle after five rigid translations, which is what a skewed cell is sensitive to. Alongside them a seeded sweep of 120 randomly skewed cells covers all six periodicity patterns, so the coverage is not limited to the shapes someone thought to name. On the code before this branch, 29 of those cases disagree with the oracle. The neighbour list was also only ever checked as a neighbour list. A structure that falls outside its own search box does not raise: the edge vectors come back many times the cutoff and the radial cutoff zeroes them, so the model quietly sees fewer interactions. Only an energy tells you that happened. There are now end to end checks that build a small MACE and compare energy and forces across rigid translations, for a molecule in vacuum and for skewed slabs. They agree to 7e-15 eV and 1e-14 eV/Angstrom, which is float64 round-off on the coordinates themselves, against a 0.226 eV and 0.42 eV/Angstrom disagreement for a slab displaced 91 Angstrom along a periodic direction without this fix. The molecule cases pass on develop already, since #1726 fixed that half. They are kept because nothing was guarding it: that regression reached a release. * Compute the oracle's image range and push the skew tests past 1:200 Skew has no natural ceiling. Nested sampling walks the cell shape and reaches aspect ratios of 1:20 and beyond, which is far outside anything the named cells covered. Testing that turned up a defect in the reference itself. Its image range was searched for rather than computed: grown one step at a time until two consecutive radii gave the same edge set. A sheared cell needs a very different range on each axis, so the growing cubic range can plateau on an incomplete set and stop there. A cell sheared by 20 on two axes did exactly that, and the oracle returned a wrong reference with no error, which reads as a failure of the code under test. An independent enumeration settles it the other way: matscipy returns 376 edges, every one of them shorter than the cutoff, and the oracle's answer was a subset. The range now comes from the reciprocal lattice and is exact. An edge needs the lattice translation to be at most cutoff + span long, so projecting on the reciprocal vector bounds each index by |b_d| * (cutoff + span). The search is also vectorised over images in chunks, since the exact bound reaches 1127 on one axis where the old ceiling was 12, and it refuses loudly rather than running for hours when the bound is absurd. The randomly skewed sweep went from 1.46 s to 0.08 s on the way. With a reference that survives skew, the tests can go where the reviewer asked. A cell written in a deliberately bad basis is the check with no ceiling at all: a_2 -> k * a_1 + a_2 is the same lattice, so the edge vectors must be identical however large k is, and no reference implementation is involved. That holds for k up to 200, on 3D cells and on slabs, and costs 18 ms against 1.8 ms for a well conditioned basis. Two 1:20 cells join the named table, and the heavily sheared cell is pinned against the repaired oracle. Worth stating plainly: everything in this commit except the two 1:20 named cells passes on develop too. The neighbour list was already right at extreme skew, so these tests answer the question rather than guard a fix. The oracle was the part that was wrong. * Install graph_longrange from PyPI (#1751) * Install graph_longrange from PyPI graph_longrange 0.4.4 is now published on PyPI and its wheel is file for file identical to the commit requirements/polar.txt pinned. CI installs the exact release, and a new polar extra gives users pip install mace-torch[polar]. * Record the polar extra in the feature inventory * accelerate stress calculations (#1498) * Accelerate stress calculations: single-graph fast path in get_symmetric_displacement For num_graphs == 1 index the cell directly instead of gathering cell[batch[sender]] per edge. Tests cover forward equivalence vs the multi-graph path and finite differences (CPU/CUDA), batch_size=1 stress training through the full forward/backward/optimizer loop, and a gloo/CPU DDP run with an uneven split. Adds a Raven A100 multi-GPU jobscript and dummy-data generator for the real distributed check. * Remove tests and job tooling already covered upstream test_stress_partial_pbc runs the num_graphs == 1 path against a finite-difference strain derivative, and the golden calculator snapshots pin single-graph stress values; the multi-graph branch is unchanged code. --------- Co-authored-by: Alejandro Acosta <acostadiaza@mpip-mainz.mpg.de> Co-authored-by: Theo Keane <20931519+theochemtheo@users.noreply.github.com> Co-authored-by: joehart2001 <jh2536@cam.ac.uk> Co-authored-by: vue1999 <ev333@cam.ac.uk> Co-authored-by: Rhys Goodall <rhys.goodall@outlook.com> Co-authored-by: Ilyes Batatia <48651863+ilyes319@users.noreply.github.com> Co-authored-by: Nils Goennheimer <92968559+Nilsgoe@users.noreply.github.com> Co-authored-by: Laurence Midgley <loll.midgley@gmail.com> Co-authored-by: Cheuk Hin Ho <83716598+CheukHinHoJerry@users.noreply.github.com> Co-authored-by: Alin Marin Elena <alin@elena.re> Co-authored-by: Samuel M. Blau <smblau@lbl.gov> Co-authored-by: darthjaja6 <darthjaja6@gmail.com> Co-authored-by: Steffen Wedig <74673778+steffen-wedig@users.noreply.github.com> * Drop Python 3.10, require torch 2.5 and add Python 3.14 (#1759) * Drop Python 3.10 Python 3.10 reaches end of life this month. The floor moves to 3.11 in setup.cfg, the README and the pylint, mypy and ruff targets, and 3.10 leaves every CI matrix. The extension jobs pinned to 3.10 move to 3.11, and the PR frontier for workflows and the release smoke become 3.11 and 3.13. Nothing in mace/ was written around 3.10, so no code changes. * Raise the torch floor to 2.5 and test it in CI setup.cfg declared torch>=1.12, but prepare_graph calls torch.compiler.is_compiling (2.3) and checkpoint loading calls add_safe_globals (2.4), so older releases crash on the core path. 2.4.1 is the release the README already marked as unsupported. 2.5.0 is the first release with wheels for every supported Python. Measured on Python 3.11: tests/unit and tests/golden give 1230 passed, 130 skipped on torch 2.5.0, the same as on 2.14.1. No CI job pinned torch, so the declared floor was never exercised. The unit job gains a 3.11 leg that installs torch==2.5.0 after the project. TorchScript accepts PEP 604 unions from torch 2.2, so the py39 ruff target on the scripted modules no longer guards anything. * Add Python 3.14 to CI Every dependency now ships a cp314 wheel, matscipy included, so the install needs no source build. 3.14 joins the unit, workflows and nightly matrices and the classifiers, and becomes the upper end of the PR frontier for workflows and of the release smoke. Measured on 3.14 with torch 2.14.1: tests/unit, tests/golden and the LAMMPS contract tier give 1339 passed, 133 skipped, and tests/workflows gives 200 passed, 20 skipped. torch warns that TorchScript is not supported on 3.14+ and may break. It works today, including the LAMMPS export, and this matrix is what will show the day it stops. * Start DataLoader workers with fork on Linux Python 3.14 made forkserver the default start method on Linux. A forkserver worker receives the dataset over a socket, and under torch's file_descriptor sharing strategy each tensor is sent as its own descriptor, past the 256 that forkserver accepts. Every run_train with --num_workers on Linux and Python 3.14 failed with `ValueError: too many fds` while computing avg_num_neighbors. tools.worker_start_method returns "fork" when there are workers and the platform is not macOS, which keeps the start method every earlier Python used on Linux. The four loaders in run_train pass it, and the augmented loader inherits the original's context. Checked on Linux in python:3.14 with torch 2.14.1: the new tests and test_a_run_with_workers_trains pass, and both fail with `too many fds` when worker_start_method returns None. * Add opt-in PolarMACE polarizability from dipole and energy derivatives (#1755) * Add field-derived dipole and polarizability calculations for PolarMACE * Add opt-in polarizability for PolarMACE with two derivative routes PolarMACE.forward gains `compute_polarizability: bool = False` and `polarizability_method: str = "dipole"`; MACECalculator gains `get_polarizability(atoms, method="dipole")`. Both return the physical alpha_ij = d(dipole_i)/d(field_j) per graph, shape [n_graphs, 3, 3]. The model's `external_field` enters the energy as +field.dipole, i.e. it is minus the physical field, so both routes carry a sign flip. "dipole" (default): alpha = -d(dipole)/d(external_field). One autograd pass off the model's dipole readout; the definition of alpha. "energy": alpha = -d2(energy)/d(external_field)2. Two autograd passes; the intermediate d(energy)/d(external_field) is also returned as "dipole_from_energy". For a variational model the two coincide; PolarMACE is not variational, so they differ and both are exposed. The key is only produced on request, so a plain energy call keeps its current output surface (pinned by the golden contract test). Merges the field-derivative implementation of #1737 (energy route) with the dipole-readout implementation. Compared to #1737 the switch is a forward/calculator argument rather than a model-construction option, so no CLI flags, no persisted model config, and no new state on the model. * PolarMACE polarizability: refuse periodic structures, inventory dipole_from_energy, lint get_polarizability runs the same pbc_handling check as calculate and then raises ValueError for any periodic direction: the dipole is charge times position, so its field derivative depends on the image choice under PBC. Two tests cover the forced-mode mismatch and a periodic cell that calculate accepts. Add dipole_from_energy to the golden feature inventory, harness channels (e*Ang, like PolarMACE's dipole) and model_keys; the inventory gate failed with 44 source keys against 43 rows. isort/black: split the aliased compute_polarizability import, wrap the autograd line in compute_polarizability. --------- Co-authored-by: arnon-1 <arn@mail.be> --------- Co-authored-by: Arn De Moor <86566033+arnon-1@users.noreply.github.com> Co-authored-by: Theo Keane <20931519+theochemtheo@users.noreply.github.com> Co-authored-by: joehart2001 <jh2536@cam.ac.uk> Co-authored-by: vue1999 <ev333@cam.ac.uk> Co-authored-by: Rhys Goodall <rhys.goodall@outlook.com> Co-authored-by: Ilyes Batatia <48651863+ilyes319@users.noreply.github.com> Co-authored-by: Nils Goennheimer <92968559+Nilsgoe@users.noreply.github.com> Co-authored-by: Laurence Midgley <loll.midgley@gmail.com> Co-authored-by: Cheuk Hin Ho <83716598+CheukHinHoJerry@users.noreply.github.com> Co-authored-by: Alin Marin Elena <alin@elena.re> Co-authored-by: Samuel M. Blau <smblau@lbl.gov> Co-authored-by: darthjaja6 <darthjaja6@gmail.com> Co-authored-by: Steffen Wedig <74673778+steffen-wedig@users.noreply.github.com> Co-authored-by: SunZichen-2004 <zichensun040314@gmail.com> Co-authored-by: arnon-1 <arn@mail.be>
PreviousNext