-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_add_noise.py
31 lines (25 loc) · 1.17 KB
/
_add_noise.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from nequip.nn import SequentialGraphNetwork
from nequip_example_extension.nn import AddNoiseModule
def AddNoiseToPairEnergies(
config, model: SequentialGraphNetwork
) -> SequentialGraphNetwork:
"""Model builder that adds an `AddNoiseModule` to an Allegro model to add noise to the pair energies.
See configs/minimal_custom_module.yaml for how to use.
"""
model.insert_from_parameters(
# see allegro/models/_allegro.py for the names of all modules in an Allegro model
# `"edge_eng"` is the final readout MLP
after="edge_eng",
# name for our new module
name="add_noise",
# hardcoded parameters from the builder
params=dict(field="edge_energy"),
# config from which to pull other parameters--- this means we can set
# `noise_sigma` in our YAML config file!
shared_params=config,
# the module to add:
builder=AddNoiseModule,
)
return model
# If your modifications are more extensive, you can also copy and update the full Allegro model builder from `allegro/model/_allegro.py`.
# This can be pariticularly helpful if you are _replacing_, rather than adding, modules.