Skip to content
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

Adapt Makers to use pydantic models instead of yamls #307

Merged
merged 85 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
acb670d
load yamls using postin > no need to copy to remote server
naik-aakash Dec 22, 2024
3b9dbde
Merge branch 'autoatml:main' into fix_custom_yaml_loading
naik-aakash Jan 4, 2025
113ab43
Merge branch 'autoatml:main' into fix_custom_yaml_loading
naik-aakash Jan 6, 2025
05416e4
Merge branch 'autoatml:main' into fix_custom_yaml_loading
naik-aakash Jan 7, 2025
354fbd6
add CONFIG as const to maker
naik-aakash Jan 7, 2025
0a90c9f
add simple tests for RSSMaker __post_init__
naik-aakash Jan 8, 2025
fa842fe
update doc
naik-aakash Jan 8, 2025
777fa8c
add strict Path checks
naik-aakash Jan 9, 2025
3ddfb14
make limitations of config file clear and update code snippets
naik-aakash Jan 9, 2025
52a8fdb
remove print
naik-aakash Jan 9, 2025
0205e7d
add initial pydantic config for RSS
naik-aakash Jan 9, 2025
5bd40bb
update test
naik-aakash Jan 9, 2025
2982dba
update test config file
naik-aakash Jan 9, 2025
4ee2e2c
restore rss_default config to initial
naik-aakash Jan 9, 2025
3e77720
remove config_file arg and use pydantic model instead
naik-aakash Jan 9, 2025
50f5854
Merge branch 'autoatml:main' into fix_custom_yaml_loading
naik-aakash Jan 9, 2025
58e6b2a
add MLIP hypers models
naik-aakash Jan 9, 2025
b918db8
add MODULE_DIR
naik-aakash Jan 9, 2025
83b54b8
Merge branch 'autoatml:main' into fix_custom_yaml_loading
naik-aakash Jan 9, 2025
b0913e1
make RssConfig and MLIPHYPERs at root level
naik-aakash Jan 10, 2025
30e7cf6
remove load_hypers function and use models instead
naik-aakash Jan 10, 2025
8cab4fb
adapt machine_learning_fit (GAP, J-ACE)
naik-aakash Jan 10, 2025
b94ba98
update utils tests for gap constructor
naik-aakash Jan 10, 2025
c8f2f8e
Merge branch 'autoatml:main' into fix_custom_yaml_loading
naik-aakash Jan 10, 2025
2d79c34
fix imports error
naik-aakash Jan 10, 2025
f87161f
use deep copy
naik-aakash Jan 10, 2025
4faeebd
temp disable ValueError raise behaviour
naik-aakash Jan 10, 2025
3b3ee47
fix rssmaker issue
naik-aakash Jan 10, 2025
6013e40
add from_file method and rename update_fields>update_parameters
naik-aakash Jan 12, 2025
1bc2be7
extend use of MLIP hypers model to M3GNET, MACE, NEQUIP
naik-aakash Jan 12, 2025
5a15564
method rename not applied > fix failing test
naik-aakash Jan 12, 2025
a713593
method rename not applied > fix failing test
naik-aakash Jan 12, 2025
6e7886d
add MACE kwargs
naik-aakash Jan 15, 2025
0b253f7
update MACE finetuning tests
naik-aakash Jan 15, 2025
355ff75
move database_dir back to make
naik-aakash Jan 15, 2025
cb2eaf3
adapt tests
naik-aakash Jan 15, 2025
7e8c65e
remove use_defaults arg
naik-aakash Jan 15, 2025
37752a3
update NEQUIP hypers
naik-aakash Jan 17, 2025
72758de
update NEQUIP hypers
naik-aakash Jan 17, 2025
618eb56
add hyperparameter arg
naik-aakash Jan 17, 2025
37e83b5
minor change in tests
naik-aakash Jan 17, 2025
834d553
extend m3gnet hypers and make finetuning m3gnet possible
naik-aakash Jan 17, 2025
13dfbe8
cleanup json/yaml load remanants
naik-aakash Jan 17, 2025
e071cef
remove unused imports
naik-aakash Jan 17, 2025
09b2f6d
update docs
naik-aakash Jan 17, 2025
07e686b
add note to AIRSS install instructions
naik-aakash Jan 17, 2025
0eabca3
add example script to root
naik-aakash Jan 17, 2025
aa3e10c
delete unused yaml and jsons from src
naik-aakash Jan 17, 2025
ab71920
disable package data section
naik-aakash Jan 17, 2025
902b982
update doc-strings
naik-aakash Jan 19, 2025
a38b461
update rss config models
naik-aakash Jan 19, 2025
6f311e2
use config yaml from tutorial
naik-aakash Jan 19, 2025
bc8a05e
add __all__
naik-aakash Jan 19, 2025
d2f2222
add pending M3GNET parameters
naik-aakash Jan 20, 2025
ffb5ee8
fix kwargs in tests of m3gnet
naik-aakash Jan 20, 2025
8545d4d
correct kwargs in m3gnet
naik-aakash Jan 20, 2025
99b13d7
remove typechecking
naik-aakash Jan 20, 2025
c38104c
add missing kwarg
naik-aakash Jan 21, 2025
75db906
add missing m3gnet finetuning tests
naik-aakash Jan 21, 2025
68798cf
small fix for kwargs updates and rename field name
naik-aakash Jan 21, 2025
55490a6
adapt test for config read
naik-aakash Jan 21, 2025
5f6e3e3
update doc of rss maker
naik-aakash Jan 21, 2025
224630e
fix none type return issue
naik-aakash Jan 21, 2025
5a069b5
Merge branch 'autoatml:main' into fix_custom_yaml_loading
naik-aakash Jan 21, 2025
0ab9fa4
update RssConfig model , add backward compatiblity
naik-aakash Jan 30, 2025
3bcd392
adapt config processing to new format
naik-aakash Jan 30, 2025
bb83042
adapt rss tutorials to new changes
naik-aakash Jan 30, 2025
09cffbf
update example config files
naik-aakash Jan 30, 2025
a64bb35
minor change in nequip phonon tests
naik-aakash Jan 30, 2025
7a60c5d
update buildcell install instructions
naik-aakash Jan 30, 2025
63450bf
fix logic of backward compatiblity with rss config yaml
naik-aakash Jan 30, 2025
a9dcd30
remove redundant variable creation
naik-aakash Jan 30, 2025
0b18cfd
add as_dict and from_dict method to pydantic models, address review c…
naik-aakash Jan 31, 2025
484d585
add as_dict and from_dict method to pydantic models, address review c…
naik-aakash Jan 31, 2025
36d5888
pre-commit auto-fixes
pre-commit-ci[bot] Jan 31, 2025
112b1e0
update example config to show all options
naik-aakash Jan 31, 2025
a368920
add set option to buildcell_options>SYSTEM
naik-aakash Jan 31, 2025
29fd84b
fix mlip_path errors
naik-aakash Jan 31, 2025
71cb7b4
fix doc-strings
naik-aakash Jan 31, 2025
5c31936
minor change to m3gnet finetuning arg name
naik-aakash Jan 31, 2025
cc538b7
adapt m3gnet finetuning test arg
naik-aakash Jan 31, 2025
45996cf
Merge branch 'autoatml:main' into fix_custom_yaml_loading
naik-aakash Feb 3, 2025
29a9abf
Merge branch 'autoatml:main' into fix_custom_yaml_loading
naik-aakash Feb 4, 2025
3813b84
add label to automated prs
naik-aakash Feb 5, 2025
30b9404
add note for workflow managers
naik-aakash Feb 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions docs/user/rss/flow/quick_start/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ Parameters can be specified either through a YAML configuration file or as direc

> **Recommendation**: This is currently our recommended approach for setting up and managing RSS workflows.

The RSS workflow can be initiated using a custom YAML configuration file. A comprehensive list of parameters, including default settings and modifiable options, is available in `autoplex/auto/rss/rss_default_configuration.yaml`. When creating a new YAML file, any specified keys will override the corresponding default values. To start a new workflow, pass the path to your YAML file as the `config_file` argument in the `make` method. If you are using remote submission via jobflow-remote, please be aware that the configuration file has to be placed on the remote cluster and the file path has to reflect this as well (i.e., it is a path on the remote cluster).
The RSS workflow can be initiated using a custom YAML configuration file. A comprehensive list of parameters, including default settings and modifiable options, is available in `autoplex/auto/rss/rss_default_configuration.yaml`. When creating a new YAML file, any specified keys will override the corresponding default values. To start a new workflow, pass the path to your YAML file as the `config_file` argument in the `make` method.

```python
from autoplex.auto.rss.flows import RssMaker
from fireworks import LaunchPad
from jobflow import Flow
from jobflow.managers.fireworks import flow_to_workflow

rss_job = RssMaker(name="your workflow name").make(config_file='path/to/your/name.yaml')
Expand Down
49 changes: 22 additions & 27 deletions src/autoplex/auto/rss/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
from pathlib import Path

from jobflow import Flow, Maker, Response, job
from ruamel.yaml import YAML
from monty.serialization import loadfn

from autoplex.auto.rss.jobs import do_rss_iterations, initial_rss

MODULE_DIR = Path(os.path.dirname(__file__))


@dataclass
class RssMaker(Maker):
Expand All @@ -19,24 +21,32 @@ class RssMaker(Maker):
----------
name: str
Name of the flow.
path_to_default_config_parameters: Path | str | None
Path to the default RSS configuration file 'rss_default_configuration.yaml'.
If None, the default path will be used.
config_file: Path | str | None
Path to the custom configuration file that defines the setup parameters for the whole RSS workflow.
If not provided, the default file 'rss_default_configuration.yaml' will be used.
"""

name: str = "ml-driven rss"
path_to_default_config_parameters: Path | str | None = None
config_file: Path | str | None = None
CONFIG = loadfn(MODULE_DIR / "rss_default_configuration.yaml")
naik-aakash marked this conversation as resolved.
Show resolved Hide resolved

def __post_init__(self) -> None:
"""Ensure that custom configuration parameters are loaded when the maker is initialized."""
if self.config_file and os.path.exists(self.config_file):
new_config = loadfn(self.config_file)

for key, value in new_config.items():
# TODO: Need better defaults in default file or we move to pydantic models
if key in self.CONFIG and isinstance(value, type(self.CONFIG[key])):
self.CONFIG[key] = value

@job
def make(self, config_file: str | None = None, **kwargs):
def make(self, **kwargs):
"""
Make a rss workflow using the specified configuration file and additional keyword arguments.

Parameters
----------
config_file: str | None
Path to the configuration file that defines the setup parameters for the whole RSS workflow.
If not provided, the default file 'rss_default_configuration.yaml' will be used.
kwargs: dict, optional
Additional optional keyword arguments to customize the job execution.

Expand Down Expand Up @@ -235,25 +245,10 @@ def make(self, config_file: str | None = None, **kwargs):
- 'current_iter': int, The current iteration index.
- 'kb_temp': float, The temperature (in eV) for Boltzmann sampling.
"""
rss_default_config_path = (
self.path_to_default_config_parameters
or Path(__file__).absolute().parent / "rss_default_configuration.yaml"
)

yaml = YAML(typ="safe", pure=True)

with open(rss_default_config_path) as f:
config = yaml.load(f)

if config_file and os.path.exists(config_file):
with open(config_file) as f:
new_config = yaml.load(f)
config.update(new_config)

config.update(kwargs)
self._process_hookean_paras(config)
self.CONFIG.update(kwargs)
self._process_hookean_paras(self.CONFIG)

config_params = config.copy()
config_params = self.CONFIG.copy()

if "train_from_scratch" not in config_params:
raise ValueError(
Expand Down
2 changes: 1 addition & 1 deletion src/autoplex/auto/rss/rss_default_configuration.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# General Parameters
tag:
tag: ''
naik-aakash marked this conversation as resolved.
Show resolved Hide resolved
train_from_scratch: true
resume_from_previous_state:
test_error:
Expand Down
19 changes: 18 additions & 1 deletion tests/auto/rss/test_flows.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os
import pytest
from pathlib import Path
from jobflow import run_locally, Flow
from tests.conftest import mock_rss, mock_do_rss_iterations, mock_do_rss_iterations_multi_jobs
from autoplex.auto.rss.flows import RssMaker

os.environ["OMP_NUM_THREADS"] = "1"

Expand Down Expand Up @@ -307,3 +307,20 @@ def test_mock_workflow_multi_node(test_dir, mock_vasp, memory_jobstore, clean_di
selected_atoms = job2.output.resolve(memory_jobstore)

assert len(selected_atoms) == 3

def test_rssmaker_custom_config(test_dir):

# For now only test if __post_init is working and updating defaults
rss = RssMaker(config_file= test_dir / "rss" / "rss_config.yaml")

# TODO: test needs to be more robust after updating default config files
assert rss.CONFIG["tag"] == "test"
assert rss.CONFIG["generated_struct_numbers"] == [9000, 1000]
assert rss.CONFIG["num_processes_buildcell"] == 64
assert rss.CONFIG["num_processes_fit"] == 64
assert rss.CONFIG["device_for_rss"] == "gpu"
assert rss.CONFIG["isolatedatom_box"] == [10, 10, 10]
assert rss.CONFIG["dimer_box"] == [10, 10, 10]



143 changes: 143 additions & 0 deletions tests/test_data/rss/rss_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# General Parameters
tag: "test"
train_from_scratch: true
resume_from_previous_state:
test_error:
pre_database_dir:
mlip_path:
isolated_atom_energies:

# Buildcell Parameters
generated_struct_numbers:
- 9000
- 1000
buildcell_options:
fragment_file: null
fragment_numbers: null
num_processes_buildcell: 64

# Sampling Parameters
num_of_initial_selected_structs:
- 80
- 20
num_of_rss_selected_structs: 100
initial_selection_enabled: true
rss_selection_method: 'bcur2i'
bcur_params:
soap_paras:
l_max: 12
n_max: 12
atom_sigma: 0.0875
cutoff: 10.5
cutoff_transition_width: 1.0
zeta: 4.0
average: true
species: true
frac_of_bcur: 0.8
bolt_max_num: 3000
random_seed: null

# DFT Labelling Parameters
include_isolated_atom: true
isolatedatom_box:
- 10.0
- 10.0
- 10.0
e0_spin: false
include_dimer: true
dimer_box:
- 10.0
- 10.0
- 10.0
dimer_range:
- 1.0
- 5.0
dimer_num: 21
custom_incar:
ISMEAR: 0
SIGMA: 0.05
PREC: 'Accurate'
ADDGRID: '.TRUE.'
EDIFF: 1e-7
NELM: 250
LWAVE: '.FALSE.'
LCHARG: '.FALSE.'
ALGO: 'Normal'
AMIX: null
LREAL: '.FALSE.'
ISYM: 0
ENCUT: 520.0
KSPACING: 0.20
GGA: null
KPAR: 8
NCORE: 16
LSCALAPACK: '.FALSE.'
LPLANE: '.FALSE.'
custom_potcar:
vasp_ref_file: 'vasp_ref.extxyz'

# Data Preprocessing Parameters
config_types:
- 'initial'
- 'traj_early'
- 'traj'
rss_group:
- 'traj'
test_ratio: 0.1
regularization: true
scheme: 'linear-hull'
reg_minmax:
- [0.1, 1]
- [0.001, 0.1]
- [0.0316, 0.316]
- [0.0632, 0.632]
distillation: false
force_max: null
force_label: null
pre_database_dir: null

# MLIP Parameters
mlip_type: 'GAP'
ref_energy_name: 'REF_energy'
ref_force_name: 'REF_forces'
ref_virial_name: 'REF_virial'
auto_delta: true
num_processes_fit: 64
device_for_fitting: 'cpu'
##The following hyperparameters are only applicable to GAP.
##If you want to use other models, please replace the corresponding hyperparameters.
twob:
cutoff: 5.0
n_sparse: 15
theta_uniform: 1.0
threeb:
cutoff: 3.0
soap:
l_max: 10
n_max: 10
atom_sigma: 0.5
n_sparse: 2500
cutoff: 5.0
general:
three_body: false

# RSS Exploration Parameters
scalar_pressure_method: 'uniform'
scalar_exp_pressure: 1
scalar_pressure_exponential_width: 0.2
scalar_pressure_low: 0
scalar_pressure_high: 25
max_steps: 300
force_tol: 0.01
stress_tol: 0.01
stop_criterion: 0.01
max_iteration_number: 25
num_groups: 6
initial_kt: 0.3
current_iter_index: 1
hookean_repul: false
hookean_paras:
keep_symmetry: false
write_traj: true
num_processes_rss: 128
device_for_rss: 'gpu'
Loading