-
Notifications
You must be signed in to change notification settings - Fork 8
Enable NanoPET for atomic-basis spherical targets #527
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just checked the model part for now, I will check the data augmentation and infrastructure parts later
docs/src/advanced-concepts/fitting-atomic-basis-spherical-targets.rst
Outdated
Show resolved
Hide resolved
docs/src/advanced-concepts/fitting-atomic-basis-spherical-targets.rst
Outdated
Show resolved
Hide resolved
Co-authored-by: Filippo Bigi <[email protected]> Co-authored-by: Paolo Pegolo <paolo.pegolo.epfl.ch>
Co-authored-by: Paolo Pegolo <[email protected]>
@Luthaf @frostedoyster @ppegolo here's an update - ready for review when you're ready! On my side, still to do (but shouldn't affect review in the meantime):
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how much I understand the changes to PET, so I'll let someone else check this part.
One question is how much work would it be to port this to NativePET?
if self.atomic_basis_target_info[output_name][ | ||
"type" | ||
] == "atomic_basis_spherical" and self.atomic_basis_target_info[ | ||
output_name | ||
]["sample_kind"].startswith("per_pair"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not great to read. Maybe you could extract two variable and change this to something like if atomic_basis_is_spherical and sample_is_per_pair
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure
# symmetrize the PET edge features and pass through its head | ||
if ( | ||
self.atomic_basis_target_info[output_name]["sample_kind"] | ||
== "per_pair_sym" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this a different kind of sample?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because in this case the PET features are still one whole block (i.e. we haven't sliced by s2_pi/first_atom_type/second_atom_type yet), and because it is symmetrized the normal samples aren't complete in info: we have "duplicated" samples that carry the index s2_pi=+/-1
from metatensor.torch.atomistic import System | ||
|
||
|
||
def get_samples( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
documentation please!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was following suit on what is in concatenate_structures
in structure.py in the same directory! :D But sure I can add
If ``include_atom_type=True``, the atom types are prepended dimensions, either | ||
corresponding to "center_type" if ``n_center=1`` or ["first_atom_type", | ||
"second_atom_type"] if ``n_center=2``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no longer an n_center
parameter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch
torch.zeros(len(first_atom_type), dtype=torch.int32).reshape( | ||
-1, 1 | ||
), # s2_pi = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
torch.zeros(len(first_atom_type), dtype=torch.int32).reshape( | |
-1, 1 | |
), # s2_pi = 0 | |
# s2_pi = 0 | |
torch.zeros((len(first_atom_type), 1), dtype=torch.int32), |
# ===== Slicing PET node/edge features for an atomic basis ===== | ||
|
||
|
||
def samples_for_atomic_basis_per_atom( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs please
# target keys. | ||
for target_name in targets.keys(): | ||
if predictions[target_name].keys != targets[target_name].keys: | ||
# TODO: use `metatensor.filter_blocks` once PR #XXX is available |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this metatensor/metatensor#885? I can make a release =)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! Thanks :)
# First, build the indices that split the block samples by system | ||
split_indices: List[int] = [] | ||
|
||
if target_type == "spherical": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the difference between target_type == "spherical"
and target_type == "atomic_basis_spherical"
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
atomic basis spherical doesn't have all the atomic samples in a given block - only those with the corresponding to the atom types. The splitting along the samples axis needs more care than for pure spherical targets
s2_pi: int, | ||
) -> List[int]: | ||
""" | ||
Finds the indices that splits a TensorBlock along the samples axis by system index. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this an implementation of metatensor/metatensor#627?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes :)
@@ -30,6 +30,8 @@ def __init__( | |||
self.is_scalar = False | |||
self.is_cartesian = False | |||
self.is_spherical = False | |||
self.is_atomic_basis_spherical_per_atom = False | |||
self.is_atomic_basis_spherical_per_pair = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to have a definition of what each of them mean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure can do
Extends NanoPET to enable predictions of spherical targets expressed on an atomic basis. Examples are the electron density decomposed on an auxiliary basis, and the Hamiltonian on the coupled atomic orbital basis.
Overview
NanoPET architecture details
Other metatrain infrastructure details
join_kwargs={"different_keys": "union"}
as this is required for targets on an atomic basis where different systems have different atom types (and therefore keys)Contributor (creator of pull-request) checklist
Reviewer checklist
📚 Documentation preview 📚: https://metatrain--527.org.readthedocs.build/en/527/