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

Save input configuration #463

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 13 additions & 15 deletions janus_core/cli/descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ def descriptors(
calc_per_atom
Whether to calculate descriptors for each atom. Default is False.
arch
MLIP architecture to use for single point calculations.
Default is "mace_mp".
MLIP architecture to use for calculations. Default is "mace_mp".
device
Device to run model on. Default is "cpu".
model_path
Expand Down Expand Up @@ -111,8 +110,9 @@ def descriptors(
carbon_summary,
check_config,
end_summary,
get_config,
get_struct_info,
parse_typer_dicts,
save_struct_calc,
start_summary,
)

Expand All @@ -127,6 +127,14 @@ def descriptors(
if "filename" in write_kwargs:
raise ValueError("'filename' must be passed through the --out option")

# Set initial config
all_kwargs = {
"read_kwargs": read_kwargs.copy(),
"calc_kwargs": calc_kwargs.copy(),
"write_kwargs": write_kwargs.copy(),
}
config = get_config(params=ctx.params, all_kwargs=all_kwargs)

# Set default filname for writing structure with descriptors if not specified
if out:
write_kwargs["filename"] = out
Expand Down Expand Up @@ -162,24 +170,14 @@ def descriptors(
).absolute()
log = descript.log_kwargs["filename"]

# Store inputs for yaml summary
inputs = descriptors_kwargs.copy()

# Add structure, MLIP information, and log to inputs
save_struct_calc(
inputs=inputs,
info = get_struct_info(
struct=descript.struct,
struct_path=struct,
arch=arch,
device=device,
model_path=model_path,
read_kwargs=read_kwargs,
calc_kwargs=calc_kwargs,
log=log,
)

# Save summary information before calculation begins
start_summary(command="descriptors", summary=summary, inputs=inputs)
start_summary(command="descriptors", summary=summary, config=config, info=info)

# Calculate descriptors
descript.run()
Expand Down
28 changes: 14 additions & 14 deletions janus_core/cli/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ def eos(
carbon_summary,
check_config,
end_summary,
get_config,
get_struct_info,
parse_typer_dicts,
save_struct_calc,
set_read_kwargs_index,
start_summary,
)
Expand All @@ -160,6 +161,15 @@ def eos(
if eos_type not in get_args(EoSNames):
raise ValueError(f"Fit type must be one of: {get_args(EoSNames)}")

# Set initial config
all_kwargs = {
"read_kwargs": read_kwargs.copy(),
"calc_kwargs": calc_kwargs.copy(),
"minimize_kwargs": minimize_kwargs.copy(),
"write_kwargs": write_kwargs.copy(),
}
config = get_config(params=ctx.params, all_kwargs=all_kwargs)

# Read only first structure by default and ensure only one image is read
set_read_kwargs_index(read_kwargs)

Expand Down Expand Up @@ -205,24 +215,14 @@ def eos(
).absolute()
log = equation_of_state.log_kwargs["filename"]

# Store inputs for yaml summary
inputs = eos_kwargs.copy()

# Add structure, MLIP information, and log to inputs
save_struct_calc(
inputs=inputs,
info = get_struct_info(
struct=equation_of_state.struct,
struct_path=struct,
arch=arch,
device=device,
model_path=model_path,
read_kwargs=read_kwargs,
calc_kwargs=calc_kwargs,
log=log,
)

# Save summary information before calculations begin
start_summary(command="eos", summary=summary, inputs=inputs)
# Save summary information before calculation begins
start_summary(command="eos", summary=summary, config=config, info=info)

# Run equation of state calculations
equation_of_state.run()
Expand Down
28 changes: 14 additions & 14 deletions janus_core/cli/geomopt.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,9 @@ def geomopt(
carbon_summary,
check_config,
end_summary,
get_config,
get_struct_info,
parse_typer_dicts,
save_struct_calc,
set_read_kwargs_index,
start_summary,
)
Expand All @@ -236,6 +237,15 @@ def geomopt(
[read_kwargs, calc_kwargs, minimize_kwargs, write_kwargs]
)

# Set initial config
all_kwargs = {
"read_kwargs": read_kwargs.copy(),
"calc_kwargs": calc_kwargs.copy(),
"minimize_kwargs": minimize_kwargs.copy(),
"write_kwargs": write_kwargs.copy(),
}
config = get_config(params=ctx.params, all_kwargs=all_kwargs)

# Read only first structure by default and ensure only one image is read
set_read_kwargs_index(read_kwargs)

Expand Down Expand Up @@ -296,24 +306,14 @@ def geomopt(
).absolute()
log = optimizer.log_kwargs["filename"]

# Store inputs for yaml summary
inputs = optimize_kwargs.copy()

# Add structure, MLIP information, and log to inputs
save_struct_calc(
inputs=inputs,
info = get_struct_info(
struct=optimizer.struct,
struct_path=struct,
arch=arch,
device=device,
model_path=model_path,
read_kwargs=read_kwargs,
calc_kwargs=calc_kwargs,
log=log,
)

# Save summary information before optimization begins
start_summary(command="geomopt", summary=summary, inputs=inputs)
# Save summary information before calculation begins
start_summary(command="geomopt", summary=summary, config=config, info=info)

# Run geometry optimization and save output structure
optimizer.run()
Expand Down
29 changes: 16 additions & 13 deletions janus_core/cli/md.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,9 @@ def md(
carbon_summary,
check_config,
end_summary,
get_config,
get_struct_info,
parse_typer_dicts,
save_struct_calc,
set_read_kwargs_index,
start_summary,
)
Expand Down Expand Up @@ -385,6 +386,17 @@ def md(
if ensemble not in get_args(Ensembles):
raise ValueError(f"ensemble must be in {get_args(Ensembles)}")

# Set initial config
all_kwargs = {
"read_kwargs": read_kwargs.copy(),
"calc_kwargs": calc_kwargs.copy(),
"minimize_kwargs": minimize_kwargs.copy(),
"ensemble_kwargs": ensemble_kwargs.copy(),
"write_kwargs": write_kwargs.copy(),
"post_process_kwargs": post_process_kwargs.copy(),
}
config = get_config(params=ctx.params, all_kwargs=all_kwargs)

# Read only first structure by default and ensure only one image is read
set_read_kwargs_index(read_kwargs)

Expand Down Expand Up @@ -553,23 +565,14 @@ def md(
log = dyn.log_kwargs["filename"]

# Store inputs for yaml summary
inputs = dyn_kwargs | {"ensemble": ensemble}

# Add structure, MLIP information, and log to inputs
save_struct_calc(
inputs=inputs,
info = get_struct_info(
struct=dyn.struct,
struct_path=struct,
arch=arch,
device=device,
model_path=model_path,
read_kwargs=read_kwargs,
calc_kwargs=calc_kwargs,
log=log,
)

# Save summary information before simulation begins
start_summary(command="md", summary=summary, inputs=inputs)
# Save summary information before calculation begins
start_summary(command="md", summary=summary, config=config, info=info)

# Run molecular dynamics
dyn.run()
Expand Down
45 changes: 21 additions & 24 deletions janus_core/cli/neb.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
Summary,
WriteKwargs,
)
from janus_core.cli.utils import dict_paths_to_strs, yaml_converter_callback
from janus_core.cli.utils import yaml_converter_callback

app = Typer()

Expand Down Expand Up @@ -175,8 +175,9 @@ def neb(
carbon_summary,
check_config,
end_summary,
get_config,
get_struct_info,
parse_typer_dicts,
save_struct_calc,
start_summary,
)
from janus_core.helpers.janus_types import Interpolators
Expand Down Expand Up @@ -204,6 +205,18 @@ def neb(
]
)

# Set initial config
all_kwargs = {
"write_kwargs": write_kwargs.copy(),
"neb_kwargs": neb_kwargs.copy(),
"interpolator_kwargs": interpolator_kwargs.copy(),
"optimizer_kwargs": optimizer_kwargs.copy(),
"minimize_kwargs": minimize_kwargs.copy(),
"read_kwargs": read_kwargs.copy(),
"calc_kwargs": calc_kwargs.copy(),
}
config = get_config(params=ctx.params, all_kwargs=all_kwargs)

if band_structs:
if init_struct or final_struct:
raise ValueError(
Expand Down Expand Up @@ -256,40 +269,24 @@ def neb(
summary = neb._build_filename("neb-summary.yml", filename=summary).absolute()
log = neb.log_kwargs["filename"]

# Store inputs for yaml summary
inputs = neb_inputs.copy()

del inputs["init_struct"]
del inputs["final_struct"]
del inputs["band_structs"]

# Add structure, MLIP information, and log to inputs
save_struct_calc(
inputs=inputs,
info = get_struct_info(
struct=neb.struct,
struct_path=init_struct,
arch=arch,
device=device,
model_path=model_path,
read_kwargs=read_kwargs,
calc_kwargs=calc_kwargs,
log=log,
)

if band_structs:
inputs["band_structs"] = inputs.pop("traj")
info["band_structs"] = info.pop("traj")
else:
inputs["init_struct"] = inputs.pop("struct")
inputs["final_struct"] = {
info["init_struct"] = info.pop("struct")
info["final_struct"] = {
"n_atoms": len(neb.final_struct),
"struct_path": final_struct,
"formula": neb.final_struct.get_chemical_formula(),
}

# Convert all paths to strings in inputs nested dictionary
dict_paths_to_strs(inputs)

# Save summary information before calculations begin
start_summary(command="neb", summary=summary, inputs=inputs)
start_summary(command="neb", summary=summary, config=config, info=info)

# Run equation of state calculations
neb.run()
Expand Down
34 changes: 16 additions & 18 deletions janus_core/cli/phonons.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,10 @@ def phonons(
from janus_core.cli.utils import (
carbon_summary,
check_config,
dict_tuples_to_lists,
end_summary,
get_config,
get_struct_info,
parse_typer_dicts,
save_struct_calc,
set_read_kwargs_index,
start_summary,
)
Expand All @@ -261,6 +261,17 @@ def phonons(
]
)

# Set initial config
all_kwargs = {
"displacement_kwargs": displacement_kwargs.copy(),
"read_kwargs": read_kwargs.copy(),
"calc_kwargs": calc_kwargs.copy(),
"minimize_kwargs": minimize_kwargs.copy(),
"dos_kwargs": dos_kwargs.copy(),
"pdos_kwargs": pdos_kwargs.copy(),
}
config = get_config(params=ctx.params, all_kwargs=all_kwargs)

# Read only first structure by default and ensure only one image is read
set_read_kwargs_index(read_kwargs)

Expand Down Expand Up @@ -340,27 +351,14 @@ def phonons(
summary = phonon._build_filename("phonons-summary.yml", filename=summary).absolute()
log = phonon.log_kwargs["filename"]

# Store inputs for yaml summary
inputs = phonons_kwargs.copy()

# Add structure, MLIP information, and log to inputs
save_struct_calc(
inputs=inputs,
info = get_struct_info(
struct=phonon.struct,
struct_path=struct,
arch=arch,
device=device,
model_path=model_path,
read_kwargs=read_kwargs,
calc_kwargs=calc_kwargs,
log=log,
)

# Convert all tuples to list in inputs nested dictionary
dict_tuples_to_lists(inputs)

# Save summary information before calculations begin
start_summary(command="phonons", summary=summary, inputs=inputs)
# Save summary information before calculation begins
start_summary(command="phonons", summary=summary, config=config, info=info)

# Run phonon calculations
phonon.run()
Expand Down
9 changes: 7 additions & 2 deletions janus_core/cli/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,15 @@ def preprocess(
from janus_core.cli.utils import carbon_summary, end_summary, start_summary
from janus_core.training.preprocess import preprocess as run_preprocess

inputs = {"mlip_config": str(mlip_config)}
config = {
"mlip_config": mlip_config,
"log": log,
"tracker": tracker,
"summary": summary,
}

# Save summary information before preprocessing begins
start_summary(command="preprocess", summary=summary, inputs=inputs)
start_summary(command="preprocess", summary=summary, config=config, info={})

log_kwargs = {"filemode": "w"}
if log:
Expand Down
Loading
Loading