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

clebsch gordan submodule - implementation of TorchScript interface #269

Merged
merged 24 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3f8369f
initalize clebsch_gordan submodule in rascaline.torch
agoscinski Dec 29, 2023
e67d917
checkpoint all-deps and all-deps-torch tests passing
agoscinski Feb 13, 2024
5caaec8
all-deps all-deps-torch pass
agoscinski Feb 14, 2024
155f36c
change ClebschGordanReal to TensorMap
agoscinski Feb 14, 2024
3c3961b
adding for torch backend
agoscinski Feb 15, 2024
358d170
fixing TorchScript
agoscinski Feb 15, 2024
f94b8c4
fix dispatch and refactor tests
agoscinski Feb 15, 2024
2d621b6
remove _dispatch.max_axis not needed
agoscinski Feb 15, 2024
25f7ad3
add tests for properties of DensityCorrelations
agoscinski Feb 15, 2024
39aee61
simplify _parse_selected_keys, now it does not need to be scritable
agoscinski Feb 15, 2024
f6d88ef
Make CG cache contiguous, fix some
jwa7 Feb 15, 2024
3513558
Remove comment block
jwa7 Feb 15, 2024
1504c19
Update python/rascaline/rascaline/utils/clebsch_gordan/_clebsch_gorda…
agoscinski Feb 16, 2024
d024c7f
Update python/rascaline/rascaline/utils/clebsch_gordan/correlate_dens…
agoscinski Feb 16, 2024
5a69107
Test save/load for checking contiguous. Clean up. Docstring arg.
jwa7 Feb 16, 2024
3fb4ef7
Merge branch 'master' into cg-torchscript
jwa7 Feb 16, 2024
a45b73c
Partial resolution of review comments
jwa7 Feb 17, 2024
7c14c22
Get rid of __all__
jwa7 Feb 19, 2024
be331f1
Fix Python import
Luthaf Feb 19, 2024
993f005
Add CG to API docs
Luthaf Feb 19, 2024
f4337f4
linter noqa
jwa7 Feb 19, 2024
96cee2a
Make the CG cache a function not a class. Fix the mops CG cache and i…
jwa7 Feb 19, 2024
7c77adc
Review round 2
jwa7 Feb 21, 2024
44ded8c
Final review comment
jwa7 Feb 21, 2024
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
14 changes: 11 additions & 3 deletions python/rascaline-torch/tests/utils/correlate_density.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
DATA_ROOT = os.path.join(os.path.dirname(__file__), "data")


@torch.jit.script
def is_tensor_map(obj: Any):
return isinstance(obj, TensorMap)

Expand All @@ -38,7 +39,16 @@ def is_tensor_map(obj: Any):


def h2o_isolated():
return ase.io.read(os.path.join(DATA_ROOT, "h2o_isolated.xyz"), ":")
return [
ase.Atoms(
symbols=["O", "H", "H"],
positions=[
[2.56633400, 2.50000000, 2.50370100],
[1.97361700, 1.73067300, 2.47063400],
[1.97361700, 3.26932700, 2.47063400],
],
)
]


def spherical_expansion(frames: List[ase.Atoms]):
Expand Down Expand Up @@ -93,7 +103,6 @@ def test_jit_save_load():
torch.jit.save(scripted_correlate_density, buffer)
buffer.seek(0)
torch.jit.load(buffer)
buffer.close()


def test_save_load():
Expand All @@ -110,4 +119,3 @@ def test_save_load():
torch.save(corr_calculator, buffer)
buffer.seek(0)
torch.load(buffer)
buffer.close()
5 changes: 0 additions & 5 deletions python/rascaline-torch/tests/utils/data/h2o_isolated.xyz
jwa7 marked this conversation as resolved.
Outdated
Show resolved Hide resolved

This file was deleted.

89 changes: 0 additions & 89 deletions python/rascaline/rascaline/utils/_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@ def _check_all_torch_tensor(arrays: List[TorchTensor]):
)


# def _check_all_torch_tensor(arrays: List[TorchTensor]):
# for array in arrays:
# if not isinstance(array, TorchTensor):
# raise TypeError(
# f"expected argument to be a torch.Tensor, but got
# {type(array)}"
# )


def _check_all_np_ndarray(arrays):
for array in arrays:
if not isinstance(array, np.ndarray):
Expand All @@ -49,14 +40,6 @@ def _check_all_np_ndarray(arrays):
)


# def _check_all_np_ndarray(arrays):
# for array in arrays:
# if not isinstance(array, np.ndarray):
# raise TypeError(
# f"expected argument to be a np.ndarray, but got {type(array)}"
# )


def concatenate(arrays: List[TorchTensor], axis: int):
"""
Concatenate a group of arrays along a given axis.
Expand All @@ -78,16 +61,6 @@ def concatenate(arrays: List[TorchTensor], axis: int):
raise TypeError(UNKNOWN_ARRAY_TYPE)


# def concatenate(arrays, axis: Optional[int] = 0):
# """Concatenate arrays along an axis."""
# if isinstance(arrays[0], TorchTensor):
# return torch.cat(arrays, dim=axis)
# elif isinstance(arrays[0], np.ndarray):
# return np.concatenate(arrays, axis=axis)
# else:
# raise TypeError(UNKNOWN_ARRAY_TYPE)


def empty_like(array, shape: Optional[List[int]] = None, requires_grad: bool = False):
"""
Create an uninitialized array, with the given ``shape``, and similar dtype,
Expand All @@ -114,33 +87,6 @@ def empty_like(array, shape: Optional[List[int]] = None, requires_grad: bool = F
raise TypeError(UNKNOWN_ARRAY_TYPE)


# def empty_like(array, shape: Optional[List[int]] = None, requires_grad: bool = False):
# """
# Create an empty array, with the given ``shape``, and similar dtype, device
# and other options as ``array``.

# If ``shape`` is :py:obj:`None`, the array shape is used instead.
# ``requires_grad`` is only used for torch tensors, and set the corresponding
# value on the returned array.

# This is the equivalent to ``np.empty_like(array, shape=shape)``.
# """
# if isinstance(array, TorchTensor):
# if shape is None:
# shape = array.size()

# return torch.empty(
# shape,
# dtype=array.dtype,
# layout=array.layout,
# device=array.device,
# ).requires_grad_(requires_grad)
# elif isinstance(array, np.ndarray):
# return np.empty_like(array, shape=shape, subok=False)
# else:
# raise TypeError(UNKNOWN_ARRAY_TYPE)


def list_to_array(array, data: List[List[int]]):
"""Create an object from data with the same type as ``array``."""
if isinstance(array, TorchTensor):
Expand Down Expand Up @@ -195,14 +141,6 @@ def unique(array, axis: Optional[int] = None):
raise TypeError(UNKNOWN_ARRAY_TYPE)


# def unique(array, axis: Optional[int] = None):
# """Find the unique elements of an array."""
# if isinstance(array, TorchTensor):
# return torch.unique(array, dim=axis)
# elif isinstance(array, np.ndarray):
# return np.unique(array, axis=axis)


def zeros_like(array, shape: Optional[List[int]] = None, requires_grad: bool = False):
"""
Create an array filled with zeros, with the given ``shape``, and similar
Expand Down Expand Up @@ -232,33 +170,6 @@ def zeros_like(array, shape: Optional[List[int]] = None, requires_grad: bool = F
raise TypeError(UNKNOWN_ARRAY_TYPE)


# def zeros_like(array, shape: Optional[List[int]] = None, requires_grad: bool = False):
# """
# Create an array filled with zeros, with the given ``shape``, and similar
# dtype, device and other options as ``array``.

# If ``shape`` is :py:obj:`None`, the array shape is used instead.
# ``requires_grad`` is only used for torch tensors, and set the corresponding
# value on the returned array.

# This is the equivalent to ``np.zeros_like(array, shape=shape)``.
# """
# if isinstance(array, TorchTensor):
# if shape is None:
# shape = array.size()

# return torch.zeros(
# shape,
# dtype=array.dtype,
# layout=array.layout,
# device=array.device,
# ).requires_grad_(requires_grad)
# elif isinstance(array, np.ndarray):
# return np.zeros_like(array, shape=shape, subok=False)
# else:
# raise TypeError(UNKNOWN_ARRAY_TYPE)


def where(array):
"""Return the indices where `array` is True.

Expand Down
Loading
Loading