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

Make restart tests work #222

Merged
merged 7 commits into from
Jan 27, 2025
Merged
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
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# For further information on the license, see the LICENSE.txt file. #
###############################################################################

ARG AIIDA_VERSION=2.5.0
ARG AIIDA_VERSION=2.5.2

FROM aiidateam/aiida-core-with-services:${AIIDA_VERSION}

Expand All @@ -24,6 +24,10 @@ RUN mamba create --yes -c conda-forge -n cp2k cp2k=9.1 && mamba clean --all -f -

# Install aiida-cp2k plugin.
COPY --chown="${SYSTEM_UID}:${SYSTEM_GID}" . /home/aiida/aiida-cp2k

# Test fix, cause latest aiida-core was not put on Dockerhub.
RUN pip install aiida-core==2.6.3

RUN pip install ./aiida-cp2k[dev,docs]

# Install coverals.
Expand Down
2 changes: 1 addition & 1 deletion aiida_cp2k/calculations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ def _trajectory_to_xyz_and_cell(trajectory):
if "cells" in trajectory.get_arraynames():
cell = "# Step Time [fs] Ax [Angstrom] Ay [Angstrom] Az [Angstrom] Bx [Angstrom] By [Angstrom] Bz [Angstrom] Cx [Angstrom] Cy [Angstrom] Cz [Angstrom] Volume [Angstrom^3]\n"
cell_vecs = [
f"{stepid+1} {(stepid+1)*0.5:6.3f} {cellvec[0][0]:25.16f} {cellvec[0][1]:25.16f} {cellvec[0][2]:25.16f} {cellvec[1][0]:25.16f} {cellvec[1][1]:25.16f} {cellvec[1][2]:25.16f} {cellvec[2][0]:25.16f} {cellvec[2][1]:25.16f} {cellvec[2][2]:25.16f} {np.dot(cellvec[0],np.cross(cellvec[1],cellvec[2]))}"
f"{stepid+1} {(stepid+1)*0.5:6.3f} {cellvec[0][0]:25.16f} {cellvec[0][1]:25.16f} {cellvec[0][2]:25.16f} {cellvec[1][0]:25.16f} {cellvec[1][1]:25.16f} {cellvec[1][2]:25.16f} {cellvec[2][0]:25.16f} {cellvec[2][1]:25.16f} {cellvec[2][2]:25.16f} {np.dot(cellvec[0], np.cross(cellvec[1], cellvec[2]))}"
for (stepid, cellvec) in zip(stepids, trajectory.get_array("cells"))
]
cell += "\n".join(cell_vecs)
Expand Down
16 changes: 9 additions & 7 deletions aiida_cp2k/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
add_ext_restart_section,
add_first_snapshot_in_reftraj_section,
add_wfn_restart_section,
increase_geo_opt_max_iter_by_factor,
)
from .parser import parse_cp2k_output, parse_cp2k_output_advanced, parse_cp2k_trajectory
from .workchains import (
Expand All @@ -34,18 +35,19 @@
"add_ext_restart_section",
"add_first_snapshot_in_reftraj_section",
"add_wfn_restart_section",
"parse_cp2k_output",
"parse_cp2k_output_advanced",
"parse_cp2k_trajectory",
"HARTREE2EV",
"HARTREE2KJMOL",
"check_resize_unit_cell",
"get_input_multiplicity",
"get_kinds_section",
"HARTREE2EV",
"HARTREE2KJMOL",
"increase_geo_opt_max_iter_by_factor",
"merge_dict",
"merge_Dict",
"ot_has_small_bandgap",
"resize_unit_cell",
"merge_trajectory_data_unique",
"merge_trajectory_data_non_unique",
"ot_has_small_bandgap",
"parse_cp2k_output",
"parse_cp2k_output_advanced",
"parse_cp2k_trajectory",
"resize_unit_cell",
]
10 changes: 10 additions & 0 deletions aiida_cp2k/utils/input_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,13 @@ def add_first_snapshot_in_reftraj_section(input_dict, first_snapshot):
params = input_dict.get_dict()
params["MOTION"]["MD"]["REFTRAJ"]["FIRST_SNAPSHOT"] = first_snapshot
return Dict(params)


@calcfunction
def increase_geo_opt_max_iter_by_factor(input_dict, factor):
"""Increase the MAX_ITER in GEO_OPT section by a factor."""
params = input_dict.get_dict()
params.setdefault("MOTION", {}).setdefault("GEO_OPT", {})["MAX_ITER"] = int(
factor * params.get("MOTION", {}).get("GEO_OPT", {}).get("MAX_ITER", 100)
)
return Dict(params)
6 changes: 6 additions & 0 deletions aiida_cp2k/workchains/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def overwrite_input_structure(self):
@engine.process_handler(priority=401, exit_codes=[
Cp2kCalculation.exit_codes.ERROR_OUT_OF_WALLTIME,
Cp2kCalculation.exit_codes.ERROR_OUTPUT_INCOMPLETE,
Cp2kCalculation.exit_codes.ERROR_MAXIMUM_NUMBER_OPTIMIZATION_STEPS_REACHED,
], enabled=False)
def restart_incomplete_calculation(self, calc):
"""This handler restarts incomplete calculations."""
Expand Down Expand Up @@ -111,6 +112,11 @@ def restart_incomplete_calculation(self, calc):
pass
params = utils.add_ext_restart_section(params)

if calc.exit_code == Cp2kCalculation.exit_codes.ERROR_MAXIMUM_NUMBER_OPTIMIZATION_STEPS_REACHED:
# If the maximum number of optimization steps is reached, we increase the number of steps by 40%.
print(type(params))
params = utils.increase_geo_opt_max_iter_by_factor(params, 1.4)

self.ctx.inputs.parameters = params # params (new or old ones) that include the necessary restart information.
self.report(
"The CP2K calculation wasn't completed. The restart of the calculation might be able to "
Expand Down
1 change: 0 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import sphinx_rtd_theme

html_theme = "sphinx_rtd_theme"
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

import aiida_cp2k

Expand Down
6 changes: 5 additions & 1 deletion examples/workchains/example_base_geoopt_restart.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ def example_base(cp2k_code):
{
"GLOBAL": {
"RUN_TYPE": "GEO_OPT",
"WALLTIME": "00:00:20", # too short
},
"MOTION": {
"GEO_OPT": {
"MAX_ITER": 8,
},
},
"FORCE_EVAL": {
"METHOD": "Quickstep",
Expand Down
2 changes: 1 addition & 1 deletion examples/workchains/example_base_md_restart.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def example_base(cp2k_code):
{
"GLOBAL": {
"RUN_TYPE": "MD",
"WALLTIME": "00:00:20", # too short
"WALLTIME": "00:00:14", # too short
},
"FORCE_EVAL": {
"METHOD": "Quickstep",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def example_base(cp2k_code):
"GLOBAL": {
"RUN_TYPE": "MD",
"PRINT_LEVEL": "LOW",
"WALLTIME": 4,
"WALLTIME": 3,
"PROJECT": "aiida",
},
"MOTION": {
Expand Down
Loading