Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Draft towards a general pair potential class #43

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

agoscinski
Copy link
Collaborator

@agoscinski agoscinski commented Mar 18, 2023

This is the next iteration of a class that can interface with MD codes with the feedback from PR #10

The corresponding i-pi driver is implemented here. I decided to move the code logic of the driver here, so one does not switch between repo's to understand the concept
Here is the corresponding branch in i-pi agoscinski/i-pi#2 which should work in the future.

It is still not functional. But I think it's enough to have another discussion in which direction this should go.

I did not had time to include an option to save the pickle model together with the script.py file in a zip in PR #41 like TorchScript does it

def save(module: Module, f: str):

The idea is to store the script.py which contains the model definition and the model.pickle in a zip, then run the script.py to get the models definition to then be able to load the model.pickle file.


📚 Documentation preview 📚: https://equisolve--43.org.readthedocs.build/en/43/

* rm not implemented errors

* add metaclass to estimator and transformer
Because we want to allow people to transfert their NumpyModule
to a TorchModule so they can get access to TorchScript (see issue #42)
we need to change the way how we do the inheritance. Before it was

Module (reference to torch.nn.Module or our BaseModule)
  --> CustomModule (e.g. Ridge)

But that means when loading the library there is just one class CustomModule
that even inherits from torch.nn.Module or BaseModule depending if torch
is available on the machine. With one inheritance, it is hard switch between
the classes. Changing the base class is very hacky, so this is not a
good approach. There we create both classes when torch is present
(note BaseModule wase renamed to NumpyModule)

def factory_custom_module(base):
    class _CustomModule(base):
        ...
    # change name ...
    return _CustomModule

CustomNumpyModule = factory_custom_module(NumpyModule)
CustomTorchModule = factory_custom_module(torch.nn.Module)

if HAS_TORCH:
    CustomModule = CustomTorchModule
else:
    CustomModule = CustomNumpyModule
* also added example and model file to run example
@agoscinski agoscinski force-pushed the equistore-pair-potential-draft branch from 46c2fbc to a0c9b65 Compare March 19, 2023 17:11
@agoscinski agoscinski force-pushed the equistore-pair-potential-draft branch from a0c9b65 to fe481b7 Compare March 20, 2023 09:56
@agoscinski
Copy link
Collaborator Author

Got to work with i-pi, but it is super hacky code

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant