Skip to content

Commit

Permalink
Adding a extra condition to restart_incomplete_calcution (#179)
Browse files Browse the repository at this point in the history
Also, add tests to restart an ENERGY calculation and to test an unrecoverable problem.

Co-authored-by: Aliaksandr Yakutovich <[email protected]>
  • Loading branch information
AndresOrtegaGuerrero and yakutovicha authored Dec 6, 2022
1 parent 08de674 commit d7ba2b0
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 13 deletions.
3 changes: 2 additions & 1 deletion aiida_cp2k/workchains/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ def restart_incomplete_calculation(self, calc):

# CP2K was updating geometry - continue with that.
restart_geometry_transformation = "Max. gradient =" in content_string
end_inner_scf_loop = "Total energy: " in content_string
# The message is written in the log file when the CP2K input parameter `LOG_PRINT_KEY` is set to True.
if not (restart_geometry_transformation or "Writing RESTART" in content_string):
if not (restart_geometry_transformation or end_inner_scf_loop or "Writing RESTART" in content_string):
self.report("It seems that the restart of CP2K calculation wouldn't be able to fix the problem as the "
"previous calculation didn't produce any output to restart from. "
"Sending a signal to stop the Base work chain.")
Expand Down
144 changes: 144 additions & 0 deletions examples/workchains/example_base_energy_restart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
# pylint: disable=invalid-name
###############################################################################
# Copyright (c), The AiiDA-CP2K authors. #
# SPDX-License-Identifier: MIT #
# AiiDA-CP2K is hosted on GitHub at https://github.com/aiidateam/aiida-cp2k #
# For further information on the license, see the LICENSE.txt file. #
###############################################################################
"""An example testing the restart calculation handler for ENERGY run in CP2K."""

import os
import sys

import ase.io
import click
from aiida.common import NotExistent
from aiida.engine import run_get_node
from aiida.orm import Dict, SinglefileData, load_code
from aiida.plugins import DataFactory, WorkflowFactory

Cp2kBaseWorkChain = WorkflowFactory("cp2k.base")
StructureData = DataFactory("core.structure") # pylint: disable=invalid-name


def example_base(cp2k_code):
"""Run simple DFT calculation through a workchain."""

thisdir = os.path.dirname(os.path.realpath(__file__))

print("Testing CP2K ENERGY on H2O (DFT) through a workchain...")

# Basis set.
basis_file = SinglefileData(
file=os.path.join(thisdir, "..", "files", "BASIS_MOLOPT")
)

# Pseudopotentials.
pseudo_file = SinglefileData(
file=os.path.join(thisdir, "..", "files", "GTH_POTENTIALS")
)

# Structure.
structure = StructureData(
ase=ase.io.read(os.path.join(thisdir, "..", "files", "h2o.xyz"))
)

# Parameters.
parameters = Dict(
{
"GLOBAL": {
"RUN_TYPE": "ENERGY",
"WALLTIME": "00:00:30", # Not enough time to converge an SCF loop
},
"FORCE_EVAL": {
"METHOD": "Quickstep",
"DFT": {
"BASIS_SET_FILE_NAME": "BASIS_MOLOPT",
"POTENTIAL_FILE_NAME": "GTH_POTENTIALS",
"QS": {
"EPS_DEFAULT": 1.0e-16,
"WF_INTERPOLATION": "ps",
"EXTRAPOLATION_ORDER": 3,
},
"MGRID": {
"NGRIDS": 4,
"CUTOFF": 450,
"REL_CUTOFF": 70,
},
"XC": {
"XC_FUNCTIONAL": {
"_": "LDA",
},
},
"POISSON": {
"PERIODIC": "none",
"PSOLVER": "MT",
},
"SCF": {"PRINT": {"RESTART": {"_": "ON"}}},
},
"SUBSYS": {
"KIND": [
{
"_": "O",
"BASIS_SET": "DZVP-MOLOPT-SR-GTH",
"POTENTIAL": "GTH-LDA-q6",
},
{
"_": "H",
"BASIS_SET": "DZVP-MOLOPT-SR-GTH",
"POTENTIAL": "GTH-LDA-q1",
},
],
},
},
}
)

# Construct process builder.
builder = Cp2kBaseWorkChain.get_builder()

# Switch on resubmit_unconverged_geometry disabled by default.
builder.handler_overrides = Dict(
{"restart_incomplete_calculation": {"enabled": True}}
)

# Input structure.
builder.cp2k.structure = structure
builder.cp2k.parameters = parameters
builder.cp2k.code = cp2k_code
builder.cp2k.file = {
"basis": basis_file,
"pseudo": pseudo_file,
}
builder.cp2k.metadata.options = {
"resources": {
"num_machines": 1,
"num_mpiprocs_per_machine": 1,
},
"max_wallclock_seconds": 1 * 1 * 60,
}

print("Submitted calculation...")
_, process_node = run_get_node(builder)

if process_node.exit_status == 0:
print("Work chain is finished correctly.")
else:
print("ERROR! Work chain failed.")
sys.exit(3)


@click.command("cli")
@click.argument("codelabel")
def cli(codelabel):
"""Click interface."""
try:
code = load_code(codelabel)
except NotExistent:
print(f"The code '{codelabel}' does not exist")
sys.exit(1)
example_base(code)


if __name__ == "__main__":
cli() # pylint: disable=no-value-for-parameter
26 changes: 15 additions & 11 deletions examples/workchains/example_base_failed_restart.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# AiiDA-CP2K is hosted on GitHub at https://github.com/aiidateam/aiida-cp2k #
# For further information on the license, see the LICENSE.txt file. #
###############################################################################
"""Run simple DFT calculation through a workchain."""
"""An example that fails due to lack of restart data."""

import os
import sys
Expand Down Expand Up @@ -47,23 +47,22 @@ def example_base(cp2k_code):
parameters = Dict(
{
"GLOBAL": {
"RUN_TYPE": "GEO_OPT",
"WALLTIME": "00:00:05", # Can't even do one geo opt step.
"RUN_TYPE": "ENERGY",
},
"FORCE_EVAL": {
"METHOD": "Quickstep",
"DFT": {
"BASIS_SET_FILE_NAME": "BASIS_MOLOPT",
"POTENTIAL_FILE_NAME": "GTH_POTENTIALS",
"QS": {
"EPS_DEFAULT": 1.0e-12,
"EPS_DEFAULT": 1.0e-16,
"WF_INTERPOLATION": "ps",
"EXTRAPOLATION_ORDER": 3,
},
"MGRID": {
"NGRIDS": 4,
"CUTOFF": 280,
"REL_CUTOFF": 30,
"CUTOFF": 450,
"REL_CUTOFF": 70,
},
"XC": {
"XC_FUNCTIONAL": {
Expand Down Expand Up @@ -110,12 +109,17 @@ def example_base(cp2k_code):
"basis": basis_file,
"pseudo": pseudo_file,
}
builder.cp2k.metadata.options.resources = {
"num_machines": 1,
"num_mpiprocs_per_machine": 1,
builder.cp2k.metadata.options = {
"resources": {
"num_machines": 1,
"num_mpiprocs_per_machine": 1,
},
"max_wallclock_seconds": 1 * 1 * 60, # 30 min
"mpirun_extra_params": [
"timeout",
"1",
], # Kill the calculation after 1 second to test the restart failure.
}
builder.cp2k.metadata.options.max_wallclock_seconds = 1 * 3 * 60

print("Submitted calculation...")
_, process_node = run_get_node(builder)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# AiiDA-CP2K is hosted on GitHub at https://github.com/aiidateam/aiida-cp2k #
# For further information on the license, see the LICENSE.txt file. #
###############################################################################
"""Run simple DFT calculation through a workchain."""
"""An example testing the restart calculation handler for geo_opt run in CP2K."""

import os
import sys
Expand Down

0 comments on commit d7ba2b0

Please sign in to comment.