JqmcRestartWorkChain#

JqmcRestartWorkChain (entry point jqmc.restart) carries one jqmc calculation to completion, across as many scheduler jobs as needed. It is an AiiDA BaseRestartWorkChain (aiida.engine.BaseRestartWorkChain) around JqmcCalculation, whose inputs it exposes in the jqmc namespace.

The target#

jqmc.parameters describes the whole calculation exactly as for one uninterrupted jqmc run. The number of steps of the job type,

job type

steps

counter

mcmc

num_mcmc_steps

mcmc_counter

vmc

num_opt_steps

opt_step_counter

lrdmc-bra, lrdmc-tau

num_mcmc_steps

gfmc_counter

is the number of steps to do in this work chain. The target counter is that number, plus the counter of the parent checkpoint when jqmc.parent_folder is given. The parent must then come from a successful JqmcCalculation, whose output_parameters hold its counter (otherwise ERROR_PARENT_COUNTER_UNKNOWN (410)).

from aiida import orm
from aiida.engine import submit
from aiida.plugins import WorkflowFactory

JqmcRestartWorkChain = WorkflowFactory("jqmc.restart")

builder = JqmcRestartWorkChain.get_builder()
builder.jqmc.code = orm.load_code("jqmc@<computer>")
builder.jqmc.hamiltonian = orm.SinglefileData("/path/to/hamiltonian_data.h5")
builder.jqmc.parameters = orm.Dict(
    {
        "control": {"job_type": "mcmc", "number_of_walkers": 4, "mcmc_seed": 1},
        "mcmc": {"num_mcmc_steps": 600000, "num_mcmc_warmup_steps": 1000, "num_mcmc_bin_blocks": 10},
    }
)
builder.jqmc.metadata.options = {
    "resources": {"num_machines": 1, "num_mpiprocs_per_machine": 4},  # adapt to the computer
    "queue_name": "<queue>",
    "account": "<account>",
    "max_wallclock_seconds": 3600,
}
builder.max_iterations = orm.Int(10)
node = submit(builder)

What happens after each job#

Each job runs with max_time set from its wall time (see JqmcCalculation). After it, the work chain decides:

The job finished successfully.

If its counter reached the target, the work chain ends and exposes the outputs of that job; for a VMC run that took several jobs, output_parameters holds the steps of every job and output_hamiltonians the Hamiltonians of every job. If not, the next job continues from its checkpoint with the remaining steps (target - counter). A job that did not advance the counter ends the work chain with ERROR_NO_PROGRESS (411).

The job was cut off before jqmc ended (ERROR_OUTPUT_STDOUT_INCOMPLETE, ERROR_SCHEDULER_OUT_OF_WALLTIME, ERROR_SCHEDULER_NODE_FAILURE). : The job is resubmitted from the last good checkpoint (or from the start if there is none yet), with max_time_margin doubled, but never more than half the wall time. Two such jobs in a row are resubmitted; a third ends the work chain with ERROR_TOO_MANY_INTERRUPTED_JOBS (412). A job that ended with neither an exception nor a scheduler verdict (ERROR_OUTPUT_STDOUT_INCOMPLETE, e.g. a segmentation fault or an MPI abort) is resubmitted only once: the same checkpoint and random state would crash again, so a second one in a row ends the work chain with ERROR_REPEATED_CRASH (413).

Anything else (invalid input, an exception in jqmc, NaN, no checkpoint, jqmc not started).

The work chain stops and reports the exit code of the job. Resubmitting would not change the result; the decision is the caller’s.

max_iterations (default 5) bounds the total number of jobs.

Continuation jobs#

Only the inputs that wire the restart change from job to job:

  • parent_folder is the remote_folder of the job whose checkpoint is continued, and hamiltonian is dropped;

  • the step count is the remaining number of steps;

  • the keys that jqmc restores from the checkpoint (“frozen on restart”, e.g. mcmc_seed, number_of_walkers, Dt, alat, E_scf) are left out. jqmc rejects a restart whose explicit value differs from the checkpoint, and some of them change during a run (E_scf of lrdmc-bra). The list comes from jqmc’s own restart policy (jqmc.jqmc_miscs.cli_parameters).

Every other parameter is passed unchanged.

Extending a finished calculation#

The caller decides whether a result is good enough. To add steps, start a new work chain from the remote_folder of the finished one, with the same code and resources:

builder = JqmcRestartWorkChain.get_builder()
builder.jqmc.code = orm.load_code("jqmc@<computer>")
builder.jqmc.parent_folder = node.outputs.remote_folder
builder.jqmc.parameters = orm.Dict(
    {
        "control": {"job_type": "mcmc"},
        "mcmc": {"num_mcmc_steps": 400000},  # 400 000 more steps
    }
)
builder.jqmc.metadata.options = {
    "resources": {"num_machines": 1, "num_mpiprocs_per_machine": 4},  # the same MPI layout as before
    "queue_name": "<queue>",
    "account": "<account>",
    "max_wallclock_seconds": 3600,
}
submit(builder)

The same applies to VMC: run a few optimization steps, inspect output_parameters["steps"], and extend with more num_opt_steps until the caller is satisfied.

Specification#

workchainaiida_jqmc.workflows.restart.JqmcRestartWorkChain

Run a JqmcCalculation until the requested number of steps is done. The ``jqmc.parameters`` input describes the *whole* calculation, exactly as for a single uninterrupted jqmc run: ``num_mcmc_steps`` (mcmc, lrdmc) or ``num_opt_steps`` (vmc) is the number of steps to perform in this work chain, counted on top of the parent checkpoint when ``jqmc.parent_folder`` is given. The work chain makes execution decisions only. Every physical or statistical parameter is passed to each job unchanged. It * continues from the latest checkpoint when a job stops on ``max_time``, * resubmits from the last good checkpoint when a job was cut off before jqmc ended (wall time, node failure), and then doubles ``max_time_margin``, * and stops on anything else (invalid input, exceptions in jqmc, NaN, …), leaving the decision to the caller. The outputs are those of the last job: an MCMC or LRDMC continuation restores the whole history of measurements from the checkpoint, so its energy and counter cover the whole run. A VMC job reports only its own optimization steps, so a VMC run split into several jobs returns ``output_parameters`` with the ``steps`` of every job (``merge_vmc_jobs``) and the ``output_hamiltonians`` of every job.

Inputs:

  • clean_workdir, Bool, optional – If True, work directories of all called calculation jobs will be cleaned at the end of execution.
  • handler_overrides, (Dict, NoneType), optional – Mapping where keys are process handler names and the values are a dictionary, where each dictionary can define the enabled and priority key, which can be used to toggle the values set on the original process handler declaration.
  • jqmc, Namespace
    • code, (AbstractCode, NoneType), optional – The Code to use for this job. This input is required, unless the remote_folder input is specified, which means an existing job is being imported and no code will actually be run.
    • hamiltonian, (SinglefileData, NoneType), optional – hamiltonian_data.h5 to start a new run from.
    • metadata, Namespace
      • call_link_label, str, optional, is_metadata – The label to use for the CALL link if the process is called by another process.
      • computer, (Computer, NoneType), optional, is_metadata – When using a “local” code, set the computer on which the calculation should be run.
      • description, (str, NoneType), optional, is_metadata – Description to set on the process node.
      • disable_cache, (bool, NoneType), optional, is_metadata – Do not consider the cache for this process, ignoring all other caching configuration rules.
      • dry_run, bool, optional, is_metadata – When set to True will prepare the calculation job for submission but not actually launch it.
      • label, (str, NoneType), optional, is_metadata – Label to set on the process node.
      • options, Namespace
        • account, (str, NoneType), optional, is_metadata – Set the account to use in for the queue on the remote computer
        • additional_retrieve_list, (list, tuple, NoneType), optional, is_metadata – List of relative file paths that should be retrieved in addition to what the plugin specifies.
        • all_hamiltonians, bool, optional, is_metadata – VMC: also store every hamiltonian_data_opt_step_*.h5 written (output_hamiltonians), so that an earlier step can be chosen; by default only the last one is stored.
        • append_text, str, optional, is_metadata – Set the calculation-specific append text, which is going to be appended in the scheduler-job script, just after the code execution
        • custom_scheduler_commands, str, optional, is_metadata – Set a (possibly multiline) string with the commands that the user wants to manually set for the scheduler. The difference of this option with respect to the prepend_text is the position in the scheduler submission file where such text is inserted: with this option, the string is inserted before any non-scheduler command
        • environment_variables, dict, optional, is_metadata – Set a dictionary of custom environment variables for this calculation
        • environment_variables_double_quotes, bool, optional, is_metadata – If set to True, use double quotes instead of single quotes to escape the environment variables specified in environment_variables.
        • import_sys_environment, bool, optional, is_metadata – If set to true, the submission script will load the system environment variables
        • input_filename, (str, NoneType), optional, is_metadata – Filename to which the input for the code that is to be run is written.
        • max_memory_kb, (int, NoneType), optional, is_metadata – Set the maximum memory (in KiloBytes) to be asked to the scheduler
        • max_time_margin, (int, NoneType), optional, is_metadata – Seconds reserved between jqmc’s max_time and the scheduler wall time (default: 10% of the wall time, clamped to [60, 1800]).
        • max_wallclock_seconds, (int, NoneType), optional, is_metadata – Set the wallclock in seconds asked to the scheduler
        • mpirun_extra_params, (list, tuple), optional, is_metadata – Set the extra params to pass to the mpirun (or equivalent) command after the one provided in computer.mpirun_command. Example: mpirun -np 8 extra_params[0] extra_params[1] … exec.x
        • output_filename, (str, NoneType), optional, is_metadata – Filename to which the content of stdout of the code that is to be run is written.
        • parser_name, (str, NoneType), optional, is_metadata – Set a string for the output parser. Can be None if no output plugin is available or needed
        • prepend_text, str, optional, is_metadata – Set the calculation-specific prepend text, which is going to be prepended in the scheduler-job script, just before the code execution
        • priority, (str, NoneType), optional, is_metadata – Set the priority of the job to be queued
        • qos, (str, NoneType), optional, is_metadata – Set the quality of service to use in for the queue on the remote computer
        • queue_name, (str, NoneType), optional, is_metadata – Set the name of the queue on the remote computer
        • rerunnable, (bool, NoneType), optional, is_metadata – Determines if the calculation can be requeued / rerun.
        • resources, dict, required, is_metadata – Set the dictionary of resources to be used by the scheduler plugin, like the number of nodes, cpus etc. This dictionary is scheduler-plugin dependent. Look at the documentation of the scheduler for more details.
        • retrieve_checkpoint, bool, optional, is_metadata – Also retrieve the checkpoint into the repository. It stays in the remote folder anyway.
        • scheduler_stderr, str, optional, is_metadata – Filename to which the content of stderr of the scheduler is written.
        • scheduler_stdout, str, optional, is_metadata – Filename to which the content of stdout of the scheduler is written.
        • stash, Namespace – Optional directives to stash files after the calculation job has completed.
          • dereference, (bool, NoneType), optional, is_metadata – Whether to follow symlinks while stashing or not, specific to StashMode.COMPRESS_* enums
          • fail_on_missing, (bool, NoneType), optional, is_metadata – If True, all files must be specified explicitly (no patterns) and all must exist, otherwise it results in calcjob failure. If False (default), patterns are allowed and missing files are skipped. Only affects copy and compress modes.
          • source_list, (tuple, list, NoneType), optional, is_metadata – Sequence of relative filepaths representing files in the remote directory that should be stashed.
          • stash_mode, (str, NoneType), optional, is_metadata – Mode with which to perform the stashing, should be value of aiida.common.datastructures.StashMode.
          • target_base, (str, NoneType), optional, is_metadata – The base location to where the files should be stashd. For example, for the copy stash mode, this should be an absolute filepath on the remote computer.
        • submit_script_filename, str, optional, is_metadata – Filename to which the job submission script is written.
        • unstash, Namespace – Optional directives to unstash files after upload.
          • source_list, (tuple, list, NoneType), optional, is_metadata – Sequence of relative filepaths representing files in the remote directory that should be unstashed.
          • unstash_target_mode, (str, NoneType), optional, is_metadata – Mode with which to perform the unstashing, should be value of aiida.common.datastructures.UnstashTargetMode.
        • withmpi, (bool, NoneType), optional, is_metadata – Set the calculation to use mpi
      • store_provenance, bool, optional, is_metadata – If set to False provenance will not be stored in the database.
    • monitors, Namespace – Add monitoring functions that can inspect output files while the job is running and decide to prematurely terminate the job.
    • parameters, Dict, required – The jqmc TOML input as a dict.
    • parent_folder, (RemoteData, NoneType), optional – Remote folder of a previous JqmcCalculation whose checkpoint is continued.
    • remote_folder, (RemoteData, NoneType), optional – Remote directory containing the results of an already completed calculation job without AiiDA. The inputs should be passed to the CalcJob as normal but instead of launching the actual job, the engine will recreate the input files and then proceed straight to the retrieve step where the files of this RemoteData will be retrieved as if it had been actually launched through AiiDA. If a parser is defined in the inputs, the results are parsed and attached as output nodes as usual.
  • max_iterations, Int, optional – Maximum number of iterations the work chain will restart the process to finish successfully.
  • metadata, Namespace
    • call_link_label, str, optional, is_metadata – The label to use for the CALL link if the process is called by another process.
    • description, (str, NoneType), optional, is_metadata – Description to set on the process node.
    • disable_cache, (bool, NoneType), optional, is_metadata – Do not consider the cache for this process, ignoring all other caching configuration rules.
    • label, (str, NoneType), optional, is_metadata – Label to set on the process node.
    • store_provenance, bool, optional, is_metadata – If set to False provenance will not be stored in the database.
  • on_unhandled_failure, (Str, NoneType), optional – Action to take when an unhandled failure occurs. Options: “abort” (default, fail immediately), “pause” (pause the workchain for inspection), “restart_once” (restart once then abort), “restart_and_pause” (restart once then pause if still failing).
  • pause_on_max_iterations, (Bool, NoneType), optional – If True, pause the workchain for inspection when max_iterations is reached (either globally or for a specific handler) instead of aborting. When resumed, iteration counters are reset to zero.

Outputs:

  • output_hamiltonian, SinglefileData, optional – VMC only: the last hamiltonian_data_opt_step_*.h5 written.
  • output_hamiltonians, Namespace – VMC with all_hamiltonians: every Hamiltonian written, as step_<N>.
  • output_parameters, Dict, required – Results and diagnostics parsed from the jqmc stdout.
  • remote_folder, RemoteData, required – Input files necessary to run the process will be stored in this folder node.
  • remote_stash, RemoteStashData, optional – Contents of the stash.source_list option are stored in this remote folder after job completion.
  • retrieved, FolderData, required – Files that are retrieved by the daemon will be stored in this node. By default the stdout and stderr of the scheduler will be added, but one can add more by specifying them in CalcInfo.retrieve_list.

Outline:

setup(Work out the target counter from the parent checkpoint and the requested steps.)
while(should_run_process)
    run_process(Run the next process, taking the input dictionary from the context at `self.ctx.inputs`.)
    inspect_process(Analyse the results of the previous process and call the handlers when necessary. If the process is excepted or killed, the work chain will abort. Otherwise any attached handlers will be called in order of their specified priority. If the process was failed and no handler returns a report indicating that the error was handled, it is considered an unhandled process failure. The behavior depends on the `on_unhandled_failure` input: - `abort` (default): Abort immediately with ERROR_UNHANDLED_FAILURE - `pause`: Pause the workchain for user inspection - `restart_once`: Restart once, then abort if it fails again - `restart_and_pause`: Restart once, then pause if it fails again In the case that at least one handler returned a report the following matrix determines the logic that is followed: Process  Handler    Handler     Action result   report?    exit code ----------------------------------------- Success      yes        == 0     Restart Success      yes        != 0     Abort Failed       yes        == 0     Restart Failed       yes        != 0     Abort If no handler returned a report and the process finished successfully, the work chain's work is considered done and it will move on to the next step that directly follows the `while` conditional, if there is one defined in the outline.)
results(The outputs of the last job; for a VMC run split into several jobs, the steps and the Hamiltonians of all.)