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

General spliner class #212

Merged
merged 4 commits into from
Sep 21, 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
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: setup Python
uses: actions/setup-python@v4
with:
python-version: 3.8
python-version: "3.11"

- name: setup rust
uses: dtolnay/rust-toolchain@master
Expand Down
2 changes: 0 additions & 2 deletions docs/src/references/api/python/misc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,3 @@ Miscelaneous
.. autoclass:: rascaline.Profiler
:members:
:undoc-members:

.. autofunction:: rascaline.generate_splines
1 change: 1 addition & 0 deletions docs/src/references/api/python/utils/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ Utility functions and classes that extend the core usage of rascaline.
:maxdepth: 1

power-spectrum
splines
1 change: 1 addition & 0 deletions docs/src/references/api/python/utils/splines.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. automodule:: rascaline.utils.splines
33 changes: 23 additions & 10 deletions python/rascaline-torch/rascaline/torch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,29 @@

from . import utils # noqa
from .calculator_base import CalculatorModule, register_autograd # noqa
from .system import System, systems_to_torch # noqa


# don't forget to also update `rascaline/__init__.py` and
# `rascaline/torch/calculators.py` when modifying this file
from .calculators import AtomicComposition # noqa isort: skip
from .calculators import SortedDistances # noqa isort: skip
from .calculators import NeighborList # noqa isort: skip
from .calculators import LodeSphericalExpansion # noqa isort: skip
from .calculators import SphericalExpansion # noqa isort: skip
from .calculators import SphericalExpansionByPair # noqa isort: skip
from .calculators import SoapRadialSpectrum # noqa isort: skip
from .calculators import SoapPowerSpectrum # noqa isort: skip
from .calculators import ( # noqa
AtomicComposition,
LodeSphericalExpansion,
NeighborList,
SoapPowerSpectrum,
SoapRadialSpectrum,
SortedDistances,
SphericalExpansion,
SphericalExpansionByPair,
)
from .system import System, systems_to_torch # noqa


__all__ = [
"AtomicComposition",
"LodeSphericalExpansion",
"NeighborList",
"SoapPowerSpectrum",
"SoapRadialSpectrum",
"SortedDistances",
"SphericalExpansion",
"SphericalExpansionByPair",
]
8 changes: 4 additions & 4 deletions python/rascaline-torch/rascaline/torch/calculator_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ def compute(

:param systems: single system or list of systems on which to run the
calculation. If any of the systems' ``positions`` or ``cell`` has
``requires_grad`` set to ``True``, then the corresponding gradients are
computed and registered as a custom node in the computational graph, to
``requires_grad`` set to :py:obj:`True`, then the corresponding gradients
are computed and registered as a custom node in the computational graph, to
allow backward propagation of the gradients later.

:param gradients: List of forward gradients to keep in the output. If this is
``None`` or an empty list ``[]``, no gradients are kept in the output. Some
gradients might still be computed at runtime to allow for backward
:py:obj:`None` or an empty list ``[]``, no gradients are kept in the output.
Some gradients might still be computed at runtime to allow for backward
propagation.

:param use_native_system: This can only be :py:obj:`True`, and is here for
Expand Down
9 changes: 5 additions & 4 deletions python/rascaline-torch/rascaline/torch/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,14 @@ def systems_to_torch(
this function converts them all and returns a list of converted systems.

:param positions_requires_grad: The value of ``requires_grad`` on the output
``positions``. If ``None`` and the positions of the input is already a
``positions``. If :py:obj:`None`` and the positions of the input is already a
:py:class:`torch.Tensor`, ``requires_grad`` is kept the same. Otherwise it is
initialized to ``False``.
initialized to :py:obj:`False`.

:param cell_requires_grad: The value of ``requires_grad`` on the output ``cell``. If
``None`` and the positions of the input is already a :py:class:`torch.Tensor`,
``requires_grad`` is kept the same. Otherwise it is initialized to ``False``.
:py:obj:`None` and the positions of the input is already a
:py:class:`torch.Tensor`, ``requires_grad`` is kept the same. Otherwise it is
initialized to :py:obj:`False`.
"""

try:
Expand Down
27 changes: 13 additions & 14 deletions python/rascaline/examples/splined-radial-integral.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""
.. _example-splines:

Splined radial integrals
========================

Expand All @@ -20,7 +22,8 @@
from scipy.special import jv
from scipy.special import spherical_jn as j_l

from rascaline import SphericalExpansion, generate_splines
from rascaline import SphericalExpansion
from rascaline.utils import RadialIntegralFromFunction


# %%
Expand Down Expand Up @@ -114,16 +117,16 @@ def laplacian_eigenstate_basis_derivative(n, el, r):
# %%
#
# The radial basis functions and their derivatives can be input into a spline
# generator. This will output the positions of the spline points, the
# generator class. This will output the positions of the spline points, the
# values of the basis functions evaluated at the spline points, and the
# corresponding derivatives.
spline_points = generate_splines(
laplacian_eigenstate_basis,
laplacian_eigenstate_basis_derivative,
max_radial,
max_angular,
cutoff,
requested_accuracy=1e-5,
spliner = RadialIntegralFromFunction(
radial_integral=laplacian_eigenstate_basis,
radial_integral_derivative=laplacian_eigenstate_basis_derivative,
spline_cutoff=cutoff,
max_radial=max_radial,
max_angular=max_angular,
accuracy=1e-5,
)

# %%
Expand All @@ -136,11 +139,7 @@ def laplacian_eigenstate_basis_derivative(n, el, r):
"max_radial": max_radial,
"max_angular": max_angular,
"center_atom_weight": 0.0,
"radial_basis": {
"TabulatedRadialIntegral": {
"points": spline_points,
}
},
"radial_basis": spliner.compute(),
"atomic_gaussian_width": 1.0, # ignored
"cutoff_function": {"Step": {}},
}
Expand Down
34 changes: 23 additions & 11 deletions python/rascaline/rascaline/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
from . import utils # noqa
from .calculator_base import CalculatorBase # noqa

# don't forget to also update `rascaline/torch/__init__.py` and
# `rascaline/torch/calculators.py` when modifying this file
from .calculators import (
AtomicComposition,
LodeSphericalExpansion,
NeighborList,
SoapPowerSpectrum,
SoapRadialSpectrum,
SortedDistances,
SphericalExpansion,
SphericalExpansionByPair,
)
from .log import set_logging_callback # noqa
from .profiling import Profiler # noqa
from .splines import generate_splines # noqa
from .status import RascalError # noqa
from .systems import IntoSystem, SystemBase # noqa
from .version import __version__ # noqa


# don't forget to also update `rascaline/torch/__init__.py` and
# `rascaline/torch/calculators.py` when modifying this file
from .calculators import AtomicComposition # noqa isort: skip
from .calculators import SortedDistances # noqa isort: skip
from .calculators import NeighborList # noqa isort: skip
from .calculators import LodeSphericalExpansion # noqa isort: skip
from .calculators import SphericalExpansion # noqa isort: skip
from .calculators import SphericalExpansionByPair # noqa isort: skip
from .calculators import SoapRadialSpectrum # noqa isort: skip
from .calculators import SoapPowerSpectrum # noqa isort: skip
__all__ = [
"AtomicComposition",
"LodeSphericalExpansion",
"NeighborList",
"SoapPowerSpectrum",
"SoapRadialSpectrum",
"SortedDistances",
"SphericalExpansion",
"SphericalExpansionByPair",
]
8 changes: 4 additions & 4 deletions python/rascaline/rascaline/calculator_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def compute(
faster than having to cross the FFI boundary often when accessing
the neighbor list. Otherwise the Python neighbor list is used.

:param gradients: List of gradients to compute. If this is ``None`` or
:param gradients: List of gradients to compute. If this is :py:obj:`None` or
an empty list ``[]``, no gradients are computed. Gradients are
stored inside the different blocks, and can be accessed with
``descriptor.block(...).gradient(<parameter>)``, where
Expand Down Expand Up @@ -251,7 +251,7 @@ def compute(
{\partial \mathbf{h}} \cdot \mathbf{h}

:param selected_samples: Set of samples on which to run the calculation.
Use ``None`` to run the calculation on all samples in the
Use :py:obj:`None` to run the calculation on all samples in the
``systems`` (this is the default).

If ``selected_samples`` is an :py:class:`metatensor.TensorMap`, then
Expand All @@ -269,7 +269,7 @@ def compute(
these variables as one of the entries in ``selected_samples`` will
be used.

:param selected_properties: Set of properties to compute. Use ``None``
:param selected_properties: Set of properties to compute. Use :py:obj:`None`
to run the calculation on all properties (this is the default).

If ``selected_properties`` is an :py:class:`metatensor.TensorMap`,
Expand All @@ -288,7 +288,7 @@ def compute(
``selected_properties`` will be used.

:param selected_keys: Selection for the keys to include in the output.
If this is ``None``, the default set of keys (as determined by the
If this is :py:obj:`None`, the default set of keys (as determined by the
calculator) will be used. Note that this default set of keys can
depend on which systems we are running the calculation on.
"""
Expand Down
Loading