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

Remove own system in favor of metatensor.torch.atomistic.System #12

Merged
merged 2 commits into from
Mar 4, 2024

Conversation

PicoCentauri
Copy link
Contributor

@PicoCentauri PicoCentauri commented Mar 4, 2024

Our System class was always a temporary solution and is now removed and replaced by the much better metatensor.torch.atomistic.System.

To have an independent torch API the synopsis of the the pure torch MeshPotential class now is

    def compute(
        self,
        types: Union[List[torch.Tensor], torch.Tensor],
        positions: Union[List[torch.Tensor], torch.Tensor],
        cell: Union[List[torch.Tensor], torch.Tensor],
    ) -> Union[torch.Tensor, List[torch.Tensor]]:

which I think this synopsis also clear for people who only live in the torch world.

I also tried to work on the comment from @kvhuguenin and replaced species by the new lab conventions types.


📚 Documentation preview 📚: https://meshlode--12.org.readthedocs.build/en/12/

@PicoCentauri PicoCentauri requested a review from kvhuguenin March 4, 2024 10:27
@PicoCentauri PicoCentauri force-pushed the remove-own-system branch 4 times, most recently from fc6b712 to b0e74b8 Compare March 4, 2024 12:19
@PicoCentauri PicoCentauri requested review from sirmarcel and removed request for kvhuguenin March 4, 2024 12:24
@sirmarcel
Copy link
Contributor

My impression was that we were keeping metatensor as an optional dependency, as far as I can tell this change makes it an integral dependency?

@Luthaf
Copy link
Contributor

Luthaf commented Mar 4, 2024

To have an independent torch API the synopsis of the the pure torch MeshPotential class now is

Just as a suggestions, you could also do

SystemDict = {
   "types": torch.Tensor,
   "positions": torch.Tensor,
   "cell": torch.Tensor,
}

def compute(
        self,
        systems: Union[List[SystemDict], SystemDict],
    ) -> Union[torch.Tensor, List[torch.Tensor]]:

########################################################################
# alternatively
@torch.jit.script
class System:
    def __init__(self, types, positions, cell):
        self.types = types
        self.positions = positions
        self.cell = cell
        
        # add some shape checks & friends

def compute(
        self,
        systems: Union[List[System], System],
    ) -> Union[torch.Tensor, List[torch.Tensor]]:

@PicoCentauri
Copy link
Contributor Author

My impression was that we were keeping metatensor as an optional dependency, as far as I can tell this change makes it an integral dependency?

It still is. metatensor is only required for the metatensor branch of the code. The torch API is independent and even more torch like with removing the System and replacing it by the three parameters positions, types and cell as independent parameters.

@PicoCentauri
Copy link
Contributor Author

Just as a suggestions, you could also do

I am not a huge fan of dictionary. They are usually very hard to document and people abuse them a lot

A custom class was what we had before but I don't want to maintain this 😆

@sirmarcel
Copy link
Contributor

Thanks @PicoCentauri , that's good then! I'll have a look at the changes.

I agree with @PicoCentauri -- not a fan of dict either, as it's mutable and awkward to access. One could use a namedtuple instead of passing the arrays around, but I think this just makes batching awkward. I'm happy with raw arrays here.

@PicoCentauri PicoCentauri force-pushed the remove-own-system branch 2 times, most recently from f115137 to 10c4b62 Compare March 4, 2024 16:05
) -> Union[torch.Tensor, List[torch.Tensor]]:
"""Compute the potential at the position of each atom for all provided systems.
"""compute potential for all provided "systems" stacked inside list.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this start with an upper-case C?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes!

cell = torch.eye(3)

match = (
"each `type` must be a 1 dimensional tensor, got at least one tensor with "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where using type really becomes silly, in my opinion: you couldn't even write this as python code since type is reserved!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is hard but basically the user will never see type since we also work with a list which we name types. However internally this will be interesting...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also changed the error message from type -> types

@sirmarcel
Copy link
Contributor

Looks fine by me. I'm pretty opposed to the naming of types as it conflicts heavily with established computer science terminology and type is a restricted keyword in Python -- but I guess that ship has sailed. Feel free to merge.

@PicoCentauri PicoCentauri merged commit 52a8540 into main Mar 4, 2024
6 checks passed
@PicoCentauri PicoCentauri deleted the remove-own-system branch March 4, 2024 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants