File size: 3,492 Bytes
e9e349d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# NequIP training config for diamond ML interatomic potential
# Trained on 50 displaced 2x2x2 FCC diamond supercells (QE PBE, ecutwfc=60 Ry)

run: [train, test]

cutoff_radius: 5.0          # Angstrom — covers ~5 neighbor shells in diamond
num_layers: 4
l_max: 2                    # l=2 for better angular accuracy (diamond has sp3 bonding)
num_features: 32            # 32 is safe for 6GB GPU with l_max=2

model_type_names: [C]
chemical_species: ${model_type_names}
monitored_metric: val0_epoch/weighted_sum

data:
  _target_: nequip.data.datamodule.ASEDataModule
  seed: 42

  split_dataset:
    file_path: ${hydra:runtime.cwd}/dataset.xyz
    train: 0.8      # 40 train
    val: 0.1        # 5 val
    test: 0.1       # 5 test

  transforms:
    - _target_: nequip.data.transforms.ChemicalSpeciesToAtomTypeMapper
      model_type_names: ${model_type_names}
    - _target_: nequip.data.transforms.NeighborListTransform
      r_max: ${cutoff_radius}

  train_dataloader:
    _target_: torch.utils.data.DataLoader
    batch_size: 2
    num_workers: 4
    shuffle: true
  val_dataloader:
    _target_: torch.utils.data.DataLoader
    batch_size: 10
    num_workers: ${data.train_dataloader.num_workers}
  test_dataloader: ${data.val_dataloader}

  stats_manager:
    _target_: nequip.data.CommonDataStatisticsManager
    dataloader_kwargs:
      batch_size: 10
    type_names: ${model_type_names}

trainer:
  _target_: lightning.Trainer
  accelerator: gpu
  enable_checkpointing: true
  max_epochs: 2000
  log_every_n_steps: 10

  logger:
    _target_: lightning.pytorch.loggers.CSVLogger
    save_dir: ${hydra:runtime.output_dir}
    name: nequip_diamond

  callbacks:
    - _target_: lightning.pytorch.callbacks.EarlyStopping
      monitor: ${monitored_metric}
      min_delta: 1e-4
      patience: 50

    - _target_: lightning.pytorch.callbacks.ModelCheckpoint
      monitor: ${monitored_metric}
      dirpath: ${hydra:runtime.output_dir}
      filename: best
      save_last: true

    - _target_: lightning.pytorch.callbacks.LearningRateMonitor
      logging_interval: epoch

training_module:
  _target_: nequip.train.EMALightningModule
  ema_decay: 0.999

  loss:
    _target_: nequip.train.EnergyForceLoss
    per_atom_energy: true
    coeffs:
      total_energy: 1.0
      forces: 1.0

  val_metrics:
    _target_: nequip.train.EnergyForceMetrics
    coeffs:
      total_energy_mae: 1.0
      forces_mae: 1.0
  train_metrics: ${training_module.val_metrics}
  test_metrics: ${training_module.val_metrics}

  optimizer:
    _target_: torch.optim.Adam
    lr: 0.005

  lr_scheduler:
    scheduler:
      _target_: torch.optim.lr_scheduler.ReduceLROnPlateau
      factor: 0.5
      patience: 20
      threshold: 0.01
      min_lr: 1e-6
    monitor: ${monitored_metric}
    interval: epoch
    frequency: 1

  model:
    _target_: nequip.model.NequIPGNNModel
    seed: 42
    model_dtype: float32
    type_names: ${model_type_names}
    r_max: ${cutoff_radius}

    num_bessels: 8
    bessel_trainable: false
    polynomial_cutoff_p: 6

    num_layers: ${num_layers}
    l_max: ${l_max}
    parity: true
    num_features: ${num_features}

    radial_mlp_depth: 2
    radial_mlp_width: 64

    avg_num_neighbors: ${training_data_stats:num_neighbors_mean}
    per_type_energy_scales: ${training_data_stats:per_type_forces_rms}
    per_type_energy_shifts: ${training_data_stats:per_atom_energy_mean}
    per_type_energy_scales_trainable: false
    per_type_energy_shifts_trainable: false