-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gaurav S Deshmukh
committed
Sep 25, 2023
1 parent
b6b8292
commit 037ca9d
Showing
7 changed files
with
164 additions
and
44 deletions.
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -5,3 +5,6 @@ data/* | |
| !data/dband_centers.csv | ||
| __pycache__ | ||
| *.cif | ||
| trained_models | ||
| *.pt | ||
| *__init__.py | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,87 @@ | ||
| """Basic workflow to train, validate, and test a model.""" | ||
|
|
||
| import torch | ||
|
|
||
| from ..src.constants import REPO_PATH | ||
| from ..src.data import AtomsDataset | ||
| from ..src.samplers import RandomSampler | ||
| from ..src.utils import create_dataloaders | ||
| from ..src.train import Model | ||
|
|
||
| # Set seeds | ||
| seed = 0 | ||
| torch.manual_seed(seed) | ||
|
|
||
| # Create dataset | ||
| dataset_path = REPO_PATH / "data" / "S_calcs" | ||
| prop_csv_path = dataset_path / "name_prop.csv" | ||
| dataset = AtomsDataset(root=dataset_path, prop_csv=prop_csv_path) | ||
|
|
||
| # Process dataset | ||
| # dataset.process_data(layer_cutoffs=[3, 6], | ||
| # node_features=[ | ||
| # ["atomic_number", "dband_center", "coordination"], | ||
| # ["atomic_number", "reactivity", "coordination"], | ||
| # ["atomic_number", "reactivity", "coordination"], | ||
| # ], | ||
| # edge_features=[ | ||
| # ["bulk_bond_distance"], | ||
| # ["surface_bond_distance"], | ||
| # ["adsorbate_bond_distance"], | ||
| # ]) | ||
|
|
||
| # Create sampler | ||
| sample_config = {"train": 0.6, "val": 0.2, "test": 0.2} | ||
| sampler = RandomSampler(seed, dataset.len()) | ||
| sample_idx = sampler.create_samplers(sample_config) | ||
|
|
||
| # Create dataloaders | ||
| dataloader_dict = create_dataloaders(dataset, sample_idx, batch_size=32) | ||
|
|
||
| # Create model | ||
| global_config = { | ||
| "gpu": False, | ||
| "loss_function": "mse", | ||
| "metric_function": "mae", | ||
| "learning_rate": 0.1, | ||
| "optimizer": "adam", | ||
| "lr_milestones": [3, 10] | ||
| } | ||
| partition_configs = [ | ||
| { | ||
| "n_conv": 3, | ||
| "n_hidden": 3, | ||
| "hidden_size": 30, | ||
| "conv_size": 40, | ||
| "dropout": 0.1, | ||
| "num_node_features": dataset[0][0].num_node_features, | ||
| "num_edge_features": dataset[0][0].num_edge_features, | ||
| "conv_type": "CGConv", | ||
| }, | ||
| { | ||
| "n_conv": 3, | ||
| "n_hidden": 3, | ||
| "hidden_size": 30, | ||
| "conv_size": 40, | ||
| "dropout": 0.1, | ||
| "num_node_features": dataset[0][1].num_node_features, | ||
| "num_edge_features": dataset[0][1].num_edge_features, | ||
| "conv_type": "CGConv", | ||
| }, | ||
| { | ||
| "n_conv": 3, | ||
| "n_hidden": 3, | ||
| "hidden_size": 30, | ||
| "conv_size": 40, | ||
| "dropout": 0.1, | ||
| "num_node_features": dataset[0][2].num_node_features, | ||
| "num_edge_features": dataset[0][2].num_edge_features, | ||
| "conv_type": "CGConv", | ||
| }, | ||
| ] | ||
|
|
||
| model_path = REPO_PATH / "trained_models" / "S_binary_calcs" | ||
| model = Model(global_config, partition_configs, model_path) | ||
| model.init_standardizer([dataset[i][0].y for i in sample_idx["train"]]) | ||
| results_dict = model.train(100, dataloader_dict, verbose=True) | ||
| print(results_dict) |