Skip to content

Commit

Permalink
initalize clebsch_gordan submodule in rascaline.torch
Browse files Browse the repository at this point in the history
  • Loading branch information
agoscinski committed Dec 29, 2023
1 parent c0fc125 commit 667c1ef
Show file tree
Hide file tree
Showing 5 changed files with 541 additions and 3 deletions.
3 changes: 2 additions & 1 deletion python/rascaline-torch/rascaline/torch/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os

from .power_spectrum import PowerSpectrum
from . import clebsch_gordan


_HERE = os.path.dirname(__file__)
Expand All @@ -10,4 +11,4 @@
Path containing the CMake configuration files for the underlying C library
"""

__all__ = ["PowerSpectrum"]
__all__ = ["PowerSpectrum", "clebsch_gordan"]
39 changes: 39 additions & 0 deletions python/rascaline-torch/rascaline/torch/utils/clebsch_gordan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import importlib
import sys
from typing import List, Optional, Union

import torch
from metatensor.torch import Labels, TensorBlock, TensorMap

import rascaline.utils.clebsch_gordan


# For details what is happening here take a look an `rascaline.torch.calculators`.

# Step 1: create te `_classes` module as an empty module
spec = importlib.util.spec_from_loader(
"rascaline.torch.utils.clebsch_gordan._classes",
loader=None,
)
module = importlib.util.module_from_spec(spec)
# This module only exposes a handful of things, defined here. Any changes here MUST also
# be made to the `metatensor/operations/_classes.py` file, which is used in non
# TorchScript mode.
module.__dict__["Labels"] = Labels
module.__dict__["TensorBlock"] = TensorBlock
module.__dict__["TensorMap"] = TensorMap

# register the module in sys.modules, so future import find it directly
sys.modules[spec.name] = module


# Step 2: create a module named `rascaline.torch.utils.clebsch_gordan` using code from
# `rascaline.utils.clebsch_gordan`
spec = importlib.util.spec_from_file_location(
"rascaline.torch.utils.clebsch_gordan",
rascaline.utils.clebsch_gordan.__file__,
)

module = importlib.util.module_from_spec(spec)
sys.modules[spec.name] = module
spec.loader.exec_module(module)
Loading

0 comments on commit 667c1ef

Please sign in to comment.