Skip to content

Commit

Permalink
add some drafts
Browse files Browse the repository at this point in the history
  • Loading branch information
JaGeo committed Dec 21, 2024
1 parent 5c231fb commit 6a3a342
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
43 changes: 40 additions & 3 deletions src/autoplex/auto/phonons/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
MPGGAStaticMaker,
)
from atomate2.vasp.jobs.base import BaseVaspMaker
from jobflow import Flow, Maker
from jobflow import Flow, Maker, job
from pymatgen.core.structure import Structure
from pymatgen.io.vasp.sets import (
MPRelaxSet,
MPStaticSet,
)
from pyparsing import Dict

from autoplex.auto.phonons.jobs import (
complete_benchmark,
Expand All @@ -25,6 +26,7 @@
generate_supercells,
get_iso_atom,
run_supercells,
do_iterative_rattled_structures
)
from autoplex.benchmark.phonons.jobs import write_benchmark_metrics
from autoplex.data.phonons.flows import IsoAtomStaticMaker, TightDFTStaticMaker
Expand All @@ -36,13 +38,36 @@
)

__all__ = [
"IterativeCompleteDFTvsMLBenchmarkWorkflow",
"CompleteDFTvsMLBenchmarkWorkflow",
"CompleteDFTvsMLBenchmarkWorkflowMPSettings",
"DFTSupercellSettingsMaker",
]


# Volker's idea: provide several default flows with different setting/setups
@dataclass
class IterativeCompleteDFTvsMLBenchmarkWorkflow:
"""
Maker to run CompleteDFTvsMLBenchmarkWorkflow in an iterative
fashion to ensure convergence of the potentials
"""
# random seed has to be changed in each iteration
# fitting folder has to be made accessible to the new workflows
# benchmark runs must be reused
input_kwargs: dict = field(default_factory=dict)
max_iterations: int = 10
rms_max: float = 0.2

@job
def make(self,
structure_list: list[Structure],
mp_ids,
dft_references: list[PhononBSDOSDoc] | None = None,
benchmark_structures: list[Structure] | None = None,
benchmark_mp_ids: list[str] | None = None,
fit_kwargs_list: list | None = None):

return do_iterative_rattled_structures(number_iteration=0, rms=None, max_iteration=self.max_iterations, **self.input_kwargs)


@dataclass
Expand Down Expand Up @@ -264,6 +289,7 @@ def make(
"""
flows = []
fit_input = {}
fit_outputs=[]
bm_outputs = []

default_hyperparameters = load_mlip_hyperparameter_defaults(
Expand Down Expand Up @@ -391,6 +417,9 @@ def make(
**fit_kwargs,
)
flows.append(add_data_fit)

# do i need to add more info here to get the right files?
fit_outputs.append(add_data_fit.output)
if (benchmark_structures is not None) and (benchmark_mp_ids is not None):
for ibenchmark_structure, benchmark_structure in enumerate(
benchmark_structures
Expand Down Expand Up @@ -469,6 +498,10 @@ def make(
soap=soap_dict,
)
flows.append(loop_data_fit)
# do i need to add more info here to get the right file?
fit_outputs.append(loop_data_fit.output)
# save the outputs from the fit somewhere

if (benchmark_structures is not None) and (
benchmark_mp_ids is not None
):
Expand Down Expand Up @@ -507,9 +540,13 @@ def make(
metrics=bm_outputs,
filename_prefix=self.summary_filename_prefix,
)
# collect_bm must be extended in a way that we get access to all benchmark structures and the previous databases

flows.append(collect_bm)

return Flow(jobs=flows, output=collect_bm, name=self.name)
# leave the dicts similar to before but add info from all stages?
new_output={"metrics": collect_bm, "fit_input": fit_input}
return Flow(jobs=flows, output=new_output, name=self.name)

@staticmethod
def add_dft_phonons(
Expand Down
17 changes: 17 additions & 0 deletions src/autoplex/auto/phonons/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@
)
from autoplex.data.phonons.jobs import reduce_supercell_size

@job
def do_iterative_rattled_structures(number_of_iteration=1, rms=0.2, iteration_max=5, rms_max=0.2, random_seed=0,output_previous=None, **input_kwargs):

if not (number_of_iteration<=iteration_max and rms>rms_max) or rms is None:
flows = []
from autoplex.auto.phonons.flows import CompleteDFTvsMLBenchmarkWorkflow
# adapt the random seed correctly and set the random seed
flow1=CompleteDFTvsMLBenchmarkWorkflow(**input_kwargs)
flows.append(flow1)
# pass required info from Complete.. to do_iterative_phonon
flow2=do_iterative_rattled_structures()
flows.append(flow2)

return Response(flows, flow2.output)

return output_previous


@job
def complete_benchmark( # this function was put here to prevent circular import
Expand Down

0 comments on commit 6a3a342

Please sign in to comment.