API reference#

Calculations#

CalcJob for one run of the jqmc command-line program.

class aiida_jqmc.calculations.jqmc.JqmcCalculation(*args, **kwargs)#

Run jqmc <input.toml> for one of the job types mcmc, vmc, lrdmc-bra or lrdmc-tau.

The plugin only wires files and wall time. Every physical or statistical parameter is taken verbatim from the parameters input.

  • New run: give hamiltonian (hamiltonian_data.h5).

  • Restart: give parent_folder (the remote_folder of a previous JqmcCalculation). The checkpoint is symlinked, control.restart is set, and the step counters stored in the checkpoint keep accumulating, i.e. num_mcmc_steps / num_opt_steps are additional steps. The job type, the number of MPI processes and the number of walkers must not change, because the checkpoint is stored per MPI rank. Keys that jqmc restores from the checkpoint (“frozen on restart”) may be omitted.

  • control.max_time is set to max_wallclock_seconds - max_time_margin so that jqmc stops gracefully and writes its checkpoint before the scheduler kills the job; max_wallclock_seconds is therefore required.

  • control.verbosity defaults to "high", so that output_parameters holds every diagnostic the parser knows (optimizer diagnostics, top coordinates, block statistics, environment); give "low" to override.

Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

StateMachine

classmethod define(spec)#

Define inputs, outputs and exit codes.

prepare_for_submission(folder)#

Write the TOML input and link the Hamiltonian or the parent checkpoint.

CalcJob for one run of the jqmc-tool command-line program.

class aiida_jqmc.calculations.tool.JqmcToolCalculation(*args, **kwargs)#

Run one jqmc-tool subcommand: a conversion or the post-processing of checkpoints.

command selects the subcommand (see SUBCOMMANDS) and options holds its options verbatim. The plugin only wires the files:

  • conversions (trexio convert-to, hamiltonian conv-wf) read input_file and produce output_hamiltonian;

  • qe reads a Quantum ESPRESSO output directory: the one entry of parent_folders (e.g. the remote_folder of a PwCalculation) is linked whole (or input_folder, a FolderData, is copied), and save_path points inside it at prefix.save or its parent (out for aiida-quantumespresso); it produces output_hamiltonian;

  • post-processing (compute-energy, compute-force, extrapolate-energy) reads the checkpoint restart.h5 of each parent_folders entry (a JqmcCalculation remote_folder) and reports the parsed stdout in output_parameters.

Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

StateMachine

classmethod define(spec)#

Define inputs, outputs and exit codes.

prepare_for_submission(folder)#

Link the input file or the checkpoints and build the command line.

Parsers#

Parser for aiida_jqmc.calculations.jqmc.JqmcCalculation.

The log is parsed by jqmc.output_parser. This module only maps its result onto AiiDA outputs and exit codes. It reports what jqmc printed and does not judge whether the values are physically sensible.

class aiida_jqmc.parsers.jqmc.JqmcParser(node)#

Turn the jqmc stdout into output_parameters (and output_hamiltonian for VMC).

Parameters:

node (CalcJobNode)

parse(retrieved_temporary_folder=None, **kwargs)#

Parse the retrieved files.

Parameters:

retrieved_temporary_folder (str | None)

Return type:

ExitCode | None

aiida_jqmc.parsers.jqmc.add_plugin_fields(results)#

What the plugin adds to the dict of jqmc.output_parser: parser_jqmc (with its warning) and non_finite_values, the NaN or infinite values replaced by None so that AiiDA can store the dict.

Parameters:

results (dict)

Return type:

dict

aiida_jqmc.parsers.jqmc.finite_or_none(value, path, replaced)#

value with every NaN or infinite float replaced by None (AiiDA cannot store them); replaced collects the paths, e.g. energy or steps.3.energy.

Parameters:
aiida_jqmc.parsers.jqmc.parser_jqmc(results)#

The jqmc whose output_parser read the log (on the AiiDA host), and a warning when it is not the jqmc that ran.

Parameters:

results (dict)

Return type:

dict

Parser for aiida_jqmc.calculations.tool.JqmcToolCalculation.

The stdout is parsed by jqmc.output_parser. As for jqmc itself, the parser reports what jqmc-tool printed and does not judge the values.

class aiida_jqmc.parsers.tool.JqmcToolParser(node)#

Turn the jqmc-tool stdout into output_parameters or output_hamiltonian.

Parameters:

node (CalcJobNode)

parse(**kwargs)#

Parse the retrieved files.

Return type:

ExitCode | None

aiida_jqmc.parsers.tool.add_tool_fields(results, stderr)#

What the plugin adds to a jqmc-tool result: environment (the version and git commit jqmc-tool prints on stderr for every subcommand), warnings (the plugin’s) and the fields of add_plugin_fields().

Parameters:
Return type:

dict

Work chains#

Run one jqmc calculation to completion, across as many jobs as needed.

class aiida_jqmc.workflows.restart.JqmcRestartWorkChain(*args, **kwargs)#

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.

Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

StateMachine

classmethod define(spec)#

Define inputs, outputs and the outline.

setup()#

Work out the target counter from the parent checkpoint and the requested steps.

handle_unfinished(node)#

A job ended normally (e.g. stopped on max_time) before the target was reached.

handle_interrupted(node)#

A job was cut off before jqmc ended: resubmit from the last good checkpoint.

results()#

The outputs of the last job; for a VMC run split into several jobs, the steps and the Hamiltonians of all.

aiida_jqmc.workflows.restart.merge_vmc_jobs(**jobs)#

The output_parameters of one VMC optimization run in several jobs (continuations, job_000 first).

Each job reports only its own steps and timings. The merged dict is that of the last job, except:

  • steps: those of every job (a step done twice keeps its later record);

  • dumped_hamiltonians: those of every job, in order;

  • total_opt_time_sec: the sum over the jobs, and opt_timing_breakdown: per step, averaged over all steps;

  • num_jobs, and warnings of every job (plus one when the jobs ran different jqmc commits).

Parameters:

jobs (Dict)

Return type:

Dict

Output schemas#

JSON Schemas of output_parameters of JqmcCalculation and JqmcToolCalculation.

The schemas describe every field that jqmc.output_parser extracts and the plugin stores, with its type, unit and meaning, so that a driver (for example an AI agent) can read the results without reading the log. Every object is closed (additionalProperties: false): the tests validate the outputs of real logs against these schemas, so a field added in jqmc without a description here fails them.

A key whose line was not printed is present with value None; the values are what jqmc printed, with no judgement of whether they are physically sensible.

Use output_parameters_schema() and tool_output_parameters_schema().

aiida_jqmc.schemas.output_parameters_schema(job_type)#

JSON Schema of output_parameters of a JqmcCalculation of job_type.

Parameters:

job_type (str)

Return type:

dict

aiida_jqmc.schemas.tool_commands_with_parameters()#

jqmc-tool subcommands whose JqmcToolCalculation has output_parameters.

Return type:

list[str]

aiida_jqmc.schemas.tool_output_parameters_schema(command)#

JSON Schema of output_parameters of a JqmcToolCalculation running command.

Parameters:

command (str)

Return type:

dict

Statistics (run-length and convergence numbers)#

Run-length estimates from finished calculations, for the caller to use or not.

These helpers compute numbers; they decide nothing. A caller (an AI agent or a person) that wants an energy error bar of a given size can ask how many more steps the central-limit scaling error ~ 1/sqrt(N) predicts, and then extend the calculation with JqmcRestartWorkChain if it agrees with the estimate. The scaling assumes that the binning already captures the autocorrelation; check that the error bar is stable against the binning before trusting it.

aiida_jqmc.statistics.additional_steps_for_target_error(accumulated_steps, warmup_steps, current_error, target_error)#

Additional measurements that bring current_error down to target_error.

Only the accumulated_steps - warmup_steps measurements after the warmup enter the estimate: N_needed = ceil(N_used * (current_error / target_error)**2).

Returns:

N_needed - N_used (0 when the target is already reached).

Return type:

int

Parameters:
  • accumulated_steps (int)

  • warmup_steps (int)

  • current_error (float)

  • target_error (float)

aiida_jqmc.statistics.crossing(values, observed, target)#

Where the piecewise-linear interpolation of observed(values) reaches target.

The points are sorted by value. Returns the value of the first crossing between two neighbouring points (an exact hit returns that point’s value), or None when target is not bracketed.

Parameters:
Return type:

float | None

aiida_jqmc.statistics.energy_slope(energies, errors)#

Weighted least-squares slope of the energy per optimization step, and its standard error.

Model E_k = a + b k with weights 1 / sigma_k**2 (non-positive errors take the median positive error), as jqmc_workflow’s plateau criterion uses it.

Parameters:
Return type:

tuple[float, float]

aiida_jqmc.statistics.error_of_error(error, num_blocks)#

Statistical uncertainty of an error bar estimated from num_blocks blocks: sigma / sqrt(2 (b - 1)).

For independent, normally distributed block averages the relative uncertainty of the sample standard error is about 1 / sqrt(2 (b - 1)).

Parameters:
Return type:

float

aiida_jqmc.statistics.extrapolation_error_factor(lattice_spacings, polynomial_order)#

Error bar of the a -> 0 extrapolated value relative to the (equal) error bar of each point.

The fit is E(a) = E_0 + E_2 a^2 + ... + E_{2p} a^{2p} (p = polynomial_order) by least squares with equal weights; the factor is sqrt([(X^T X)^{-1}]_{00}) for the design matrix X.

Parameters:
Return type:

float

aiida_jqmc.statistics.steps_to_target_error(calculation, target_error)#

Additional steps for a finished MCMC or LRDMC calculation (or its restart work chain).

The counter and the energy error come from output_parameters, the warmup from the input of the job (jqmc’s default when not given). For a work chain pass the work chain node: its outputs are those of the last job.

Returns:

Additional num_mcmc_steps to request when extending the calculation.

Return type:

int

Parameters:
  • calculation (ProcessNode)

  • target_error (float)

aiida_jqmc.statistics.vmc_indicators(calculations, window=10)#

Numbers a caller can use to judge a VMC optimization, over its last window steps.

calculations are VMC calculations (or their restart work chains) in order, e.g. an optimization and its continuations; their steps are joined.

Returns:

steps (step numbers in the window), signal_to_noise_mean and signal_to_noise_last (largest generalized-force S/N of each step), energy_slope and energy_slope_error (Ha per step), and energy_last / energy_last_error.

Return type:

dict

Parameters:
  • calculations (list[ProcessNode])

  • window (int)

aiida_jqmc.statistics.vmc_sampling_steps_for_target_error(calculation, target_error)#

num_mcmc_steps per optimization step for a target energy error of each VMC step.

Uses the last optimization step of a finished VMC calculation (e.g. a short pilot): its sampling steps, warmup and energy error.

Returns:

The total num_mcmc_steps (warmup included) to give each step.

Return type:

int

Parameters:
  • calculation (ProcessNode)

  • target_error (float)

Orbital tiling#

Read orbital-tiling provenance from a Hamiltonian produced by jQMC.

The converter remains the sole owner of coset selection, orbital phases, normalization and supercell construction. This module only asks jQMC to deserialize its own output and translates the resulting physical structure and metadata into AiiDA data types.

aiida_jqmc.tiling.inspect_tiled_hamiltonian(path, *, stdout='', source=None, requested=None)#

Return converter-owned tiling metadata and the physical QMC structure.

Loading and validation are delegated to the jQMC release that parses the HDF5. A non-tiled result is an error because this function is called only for a conversion that explicitly requested tiling.

Parameters:
Return type:

tuple[dict[str, Any], StructureData]

aiida_jqmc.tiling.is_tiled_hamiltonian(path)#

Return whether the determinant uses jQMC’s tiled orbital container.

Parameters:

path (str | Path)

Return type:

bool

Utilities#

Helpers for preparing JqmcCalculation inputs.

aiida_jqmc.utils.parameters_from_toml(source)#

Turn a jqmc CLI input (TOML file or dict) into parameters for JqmcCalculation.

The control keys that the plugin sets itself (restart, restart_chk, hamiltonian_h5, max_time) are removed and returned separately, so that nothing is dropped silently: the Hamiltonian becomes the hamiltonian input, the checkpoint the parent_folder input, and max_time follows from the wall time. Every other key is kept unchanged.

Returns:

(parameters, removed), removed being {key: value}.

Return type:

tuple

Parameters:

source (str | Path | dict)