-
Notifications
You must be signed in to change notification settings - Fork 2
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
Confusing "parameter flow" for the calculators #57
Comments
Just to add to this, it's a huge potential foot-gun that various parts of the infrastructure now store the |
Not directly the issue but related: While benchmarking, I found a couple of places that are slowing down the code just because we do multiplication with floats in the code. @sirmarcel already mentioned this but now I really saw it. On top: In many places we may overcome repeating calculations by adding buffers in the init of each class to compute prefactors. |
We have to be careful here if the prefactors depend on stuff, e.g. the smearing. |
Good point! this is why these points are in the correct place inside this issue. We can also update buffers if we have to, but hopefully we can avoid. |
We had some brainstorming meeting with @E-Rum and @GardevoirX and came up some refined structure for the calculator classes. Basically, we will split the calculators into classes of This means we don't have to branch a lot if a potential has a finite import torch
class CalcultorBase(torch.nn.Module):
def __init__(self): ...
def forward(self):
# validate the input and call the _compute method
return self._compute()
def _compute(self):
raise NotImplementedError("Only implemented in subclasses")
class EwaldCalculator(CalcultorBase):
def __init__(self, potential):
super().__init__()
if potential.smearing is None:
raise ValueError()
def _compute(self):
return (
self._compute_kspace()
+ self._compute_rspace()
+ self._compute_background_contribution()
+ self._compute_self_contriubution()
)
def _compute_background_contribution(self): ...
def _compute_self_contriubution(self): ...
def _compute_kspace(self): ...
def _compute_rspace(self): ...
class PMECalculator(EwaldCalculator):
def __init__(self): ...
def _compute_kspace(self):
# override `_compute_kspace` from Ewald with PME logic
...
class P3MCalculator(EwaldCalculator):
def __init__(self): ...
def _compute_kspace(self): ...
class DirectCalculator(CalcultorBase):
def __init__(self, potential):
if potential.smearing is not None:
raise ValueError()
def _compute(self):
# call potential.from_dist() and multiply the charges
... As you see this will not break API at all and should simplify the parameter flow. If there are no objection, @E-Rum volunteered to check the implementation and do it. THANKS A LOT ALREADY!!!! |
The calculators use a mix of class parameters and "compute function" parameters to define e.g. the smearing and the calculation accuracy. This is confusing and a bit clunky - it'd be better to streamline the implementation to avoid having to worry too much about (re)setting these values.
The text was updated successfully, but these errors were encountered: