-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #188 from apax-hub/val_bs_fix
Val bs fix and distance computation refactor
- Loading branch information
Showing
18 changed files
with
373 additions
and
406 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,5 +79,3 @@ checkpoints: | |
progress_bar: | ||
disable_epoch_pbar: false | ||
disable_nl_pbar: false | ||
|
||
maximize_l2_cache: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import dataclasses | ||
import logging | ||
import os | ||
from typing import Optional | ||
|
||
import numpy as np | ||
from ase import Atoms | ||
|
||
from apax.data.input_pipeline import AtomisticDataset, create_dict_dataset | ||
from apax.data.statistics import compute_scale_shift_parameters | ||
from apax.utils.data import load_data, split_atoms, split_idxs, split_label | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
@dataclasses.dataclass | ||
class RawDataset: | ||
atoms_list: list[Atoms] | ||
additional_labels: Optional[dict] = None | ||
|
||
|
||
def load_data_files(data_config, model_version_path): | ||
log.info("Running Input Pipeline") | ||
if data_config.data_path is not None: | ||
log.info(f"Read data file {data_config.data_path}") | ||
atoms_list, label_dict = load_data(data_config.data_path) | ||
|
||
train_idxs, val_idxs = split_idxs( | ||
atoms_list, data_config.n_train, data_config.n_valid | ||
) | ||
train_atoms_list, val_atoms_list = split_atoms(atoms_list, train_idxs, val_idxs) | ||
train_label_dict, val_label_dict = split_label(label_dict, train_idxs, val_idxs) | ||
|
||
np.savez( | ||
os.path.join(model_version_path, "train_val_idxs"), | ||
train_idxs=train_idxs, | ||
val_idxs=val_idxs, | ||
) | ||
|
||
elif data_config.train_data_path and data_config.val_data_path is not None: | ||
log.info(f"Read training data file {data_config.train_data_path}") | ||
log.info(f"Read validation data file {data_config.val_data_path}") | ||
train_atoms_list, train_label_dict = load_data(data_config.train_data_path) | ||
val_atoms_list, val_label_dict = load_data(data_config.val_data_path) | ||
else: | ||
raise ValueError("input data path/paths not defined") | ||
|
||
train_raw_ds = RawDataset( | ||
atoms_list=train_atoms_list, additional_labels=train_label_dict | ||
) | ||
val_raw_ds = RawDataset(atoms_list=val_atoms_list, additional_labels=val_label_dict) | ||
|
||
return train_raw_ds, val_raw_ds | ||
|
||
|
||
def initialize_dataset(config, raw_ds, calc_stats: bool = True): | ||
inputs, labels = create_dict_dataset( | ||
raw_ds.atoms_list, | ||
r_max=config.model.r_max, | ||
external_labels=raw_ds.additional_labels, | ||
disable_pbar=config.progress_bar.disable_nl_pbar, | ||
pos_unit=config.data.pos_unit, | ||
energy_unit=config.data.energy_unit, | ||
) | ||
|
||
if calc_stats: | ||
ds_stats = compute_scale_shift_parameters( | ||
inputs, | ||
labels, | ||
config.data.shift_method, | ||
config.data.scale_method, | ||
config.data.shift_options, | ||
config.data.scale_options, | ||
) | ||
|
||
dataset = AtomisticDataset( | ||
inputs, | ||
labels, | ||
config.n_epochs, | ||
buffer_size=config.data.shuffle_buffer_size, | ||
) | ||
|
||
if calc_stats: | ||
return dataset, ds_stats | ||
else: | ||
return dataset |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.