wfl.fit package#

Submodules#

wfl.fit.ace module#

wfl.fit.ace.fit(fitting_configs, ACE_name, ace_fit_params, ace_fit_command=None, ref_property_prefix='REF_', skip_if_present=False, run_dir='.', dry_run=False, verbose=True, remote_info=None, remote_label=None, wait_for_results=True, isolated_atom_info_key='config_type', isolated_atom_info_value='default')#

Runs ace_fit on a set of fitting configs

Environment Variables

  • WFL_EXPYRE_INFO: JSON dict or name of file containing JSON with kwargs for RemoteInfo contructor to be used to run fitting in separate queued job

  • WFL_ACE_FIT_JULIA_THREADS: used to set JULIA_NUM_THREADS for ace_fit.jl, which will use julia multithreading (LSQ assembly)

  • WFL_ACE_FIT_BLAS_THREADS: used by ace_fit.jl for number of threads to set for BLAS multithreading in ace_fit

  • WFL_ACE_FIT_COMMAND: command to execute ace_fit.jl, e.g. julia $HOME/.julia/packages/ACE1pack/ChRvA/scripts/ace_fit.jl

Parameters
  • fitting_configs (ConfigSet) – set of configurations to fit

  • ACE_name (str) – name of ACE potential (i.e. stem for resulting .json file). Overwrites any filename given in ace_fit_params.

  • ace_fit_params (dict) – parameters for ACE1pack. Any file names (ACE, fitting configs) already present will be updated. See wfl.fit.ace.prepare_params() for other parameters that will be set automatically.

  • ace_fit_command (str, default None) – executable for ace_fit. e.g. julia $HOME/.julia/packages/ACE1pack/ChRvA/scripts/ace_fit.jl or similar. Alternatively set by WFL_ACE_FIT_COMMAND env var.

  • ref_property_prefix (str, default 'REF_') – string prefix added to atoms.info/arrays keys (energy, forces, virial, stress)

  • skip_if_present (bool, default False) – skip fitting if output is already present

  • run_dir (str or Path, default '.') – directory to run in

  • dry_run (bool, default False) – do a dry run, which returns the matrix size, rather than the potential name

  • verbose (bool, default True) – print verbose output

  • remote_info (dict or wfl.autoparallelize.RemoteInfo, or ‘_IGNORE’ or None) – If present and not None and not ‘_IGNORE’, RemoteInfo or dict with kwargs for RemoteInfo constructor which triggers running job in separately queued job on remote machine. If None, will try to use env var WFL_EXPYRE_INFO used (see above). ‘_IGNORE’ is for internal use, to ensure that remotely running job does not itself attempt to spawn another remotely running job.

  • remote_label (str, default None) – label to use to match in WFL_EXPYRE_INFO

  • wait_for_results (bool, default True) – wait for results of remotely executed job, otherwise return after starting job

  • isolated_atom_info_key (str, default "config_type") – key for Atoms.info to select isolated atoms by, if not given in ace_fit_params.

  • isolated_atom_info_value (str, default "default") – value of Atoms.info[isolated_atom_info_key] to match isolated atoms on “default” matches “isolated_atom” or “IsolatedAtom”.

Returns

  • ace_filename (Path of saved ACE json file (if not dry_run))

  • OR

  • size ((int, int) size of least-squares matrix (if dry_run))

wfl.fit.ace.prepare_configs(fitting_configs, ref_property_prefix='REF_')#

Prepare configs before fitting. Currently only converts stress to virial.

wfl.fit.ace.prepare_params(ACE_name, fitting_configs, ace_fit_params, run_dir='.', ref_property_prefix='REF_', isolated_atom_info_key='config_type', isolated_atom_info_value='default')#

Prepare ace_fit parameters so they are compatible with the rest of workflow. Runs ace_fit on a a set of fitting configs

Parameters
  • ACE_name (str) – name of ACE model, used as initial part of final potential JSON file, as well as other scratch files. Overrides any previous ‘ACE_fname’ in ace_fit_params

  • fitting_configs (ConfigSet) – set of configurations to fit

  • ace_fit_params (dict) –

    dict with all fitting parameters for ACE1pack, to be updated with

    • (energy|force|virial)_key (with ref_property_prefix)

    • ACE_fname

    • e0 values

    • per-config E/F/V weight if it contains "weights": { "from_sigma": <some_value> } * if <some_value> is True, each property’s weight will come from that property’s

      sigma. Otherwise, it is expected to be a string info dict key and all 3 weights will come from that info field value times the global E/F/V.

  • run_dir (str or Path, default '.') – path of directory to run in

  • ref_property_prefix (str, default 'REF_') – string prefix added to atoms.info/arrays keys (energy, forces, virial, stress)

Returns

ace_fit_params – with updated energy/force/virial keys, e0 values, and optional config_type weights

Return type

Dict

wfl.fit.ace.run_ace_fit(fitting_configs, ace_fit_params, skip_if_present=False, run_dir='.', ace_fit_command=None, dry_run=False, verbose=True, remote_info=None, remote_label=None, wait_for_results=True)#

Runs ace_fit on a a set of fitting configs

Parameters
  • fitting_configs (list(Atoms)) – set of configurations to fit

  • ace_fit_params (dict) – dict with all fitting parameters for ACE1pack. Any file names (ACE, fitting configs) already present will be updated.

  • skip_if_present (bool, default False) – skip fitting if output is already present

  • run_dir (str or Path, default '.') – directory to run in

  • ace_fit_command (str, default None.) – executable for ace_fit. e.g. julia $HOME/.julia/packages/ACE1pack/ChRvA/scripts/ace_fit.jl or similar. Alternatively set by WFL_ACE_FIT_COMMAND.

  • dry_run (bool, default False) – do a dry run, which returns the matrix size, rather than the potential file path

  • verbose (bool, default True) – print verbose output

  • remote_info (dict or wfl.autoparallelize.RemoteInfo, or ‘_IGNORE’ or None) – If present and not None and not ‘_IGNORE’, RemoteInfo or dict with kwargs for RemoteInfo constructor which triggers running job in separately queued job on remote machine. If None, will try to use env var WFL_EXPYRE_INFO used (see below). ‘_IGNORE’ is for internal use, to ensure that remotely running job does not itself attempt to spawn another remotely running job.

  • remote_label (str, default None) – label to use to match in WFL_EXPYRE_INFO

  • wait_for_results (bool, default True) – wait for results of remotely executed job, otherwise return after starting job

Returns

  • ace_filename (Path of saved ACE json file (if not dry_run))

  • OR

  • size ((int, int) size of least-squares matrix (if dry_run))

  • Environment Variables

  • ———————

  • WFL_EXPYRE_INFO (JSON dict or name of file containing JSON with kwargs for RemoteInfo) – contructor to be used to run fitting in separate queued job

  • WFL_ACE_FIT_JULIA_THREADS (used to set JULIA_NUM_THREADS for ace_fit.jl, which will use julia multithreading (LSQ assembly))

  • WFL_ACE_FIT_BLAS_THREADS (used by ace_fit.jl for number of threads to set for BLAS multithreading in ace_fit)

  • WFL_ACE_FIT_COMMAND (path to ace_fit.jl, e.g. “julia $HOME/.julia/packages/ACE1pack/ChRvA/scripts/ace_fit.jl”.)

wfl.fit.error module#

wfl.fit.mace module#

wfl.fit.mace.fit(fitting_configs, mace_name, mace_fit_params, mace_fit_cmd=None, ref_property_prefix='REF_', prev_checkpoint_file=None, valid_configs=None, test_configs=None, skip_if_present=True, run_dir='.', verbose=True, dry_run=False, remote_info=None, remote_label=None, wait_for_results=True)#

Fit MACE model.

Environment Variables

  • WFL_MACE_FIT_COMMAND: command to execute mace fit, e.g. ``python $HOME/mace/scripts/run_train.py ``

Parameters
  • fitting_configs (ConfigSet) – set of configurations to fit (mace param “train_file”)

  • mace_name (str) – name of MACE label

  • mace_fit_params (dict) – parameters for fitting a MACE model.

  • mace_fit_cmd (str, default None.) – command for excecuting the MACE fitting. (For example, “python ~/path_to_mace_cripts/run_train.py”) Alternatively set by WFL_MACE_FIT_COMMAND env var.

  • ref_property_prefix (str, default “REF_”) – string prefix added to atoms.info/arrays keys (energy, forces, virial, stress)

  • prev_checkpoint_file (str, default None) – Previous checkpoint file to restart from.

  • valid_configs (ConfigSet, default None) – set of configurations to validate (mace param “valid_file”)

  • test_configs (ConfigSet, default None) – set of configurtions to test (mace param “test_file”)

  • skip_if_present (bool, default True) – skip if final MACE file exists in expected place

  • run_dir (str, default '.') – directory to run fitting in

  • verbose (bool default True) – verbose output

  • dry_run (bool, default False) – do a dry run, and returns fitting command including keywords

  • remote_info (dict or wfl.autoparallelize.utils.RemoteInfo, or '_IGNORE' or None) – If present and not None and not ‘_IGNORE’, RemoteInfo or dict with kwargs for RemoteInfo constructor which triggers running job in separately queued job on remote machine. If None, will try to use env var WFL_EXPYRE_INFO used (see below). ‘_IGNORE’ is for internal use, to ensure that remotely running job does not itself attempt to spawn another remotely running job.

  • remote_label (str, default None) – label to match in WFL_EXPYRE_INFO

  • wait_for_results (bool, default True) – wait for results of remotely executed job, otherwise return after starting job

wfl.fit.utils module#

wfl.fit.utils.ace_fit_jl_path()#
wfl.fit.utils.copy_properties(configs, ref_property_keys, stress_to_virial=True, force=True)#

Copies properties from wherever they are to ‘CALC_*’ where fitting code will be told to look for them

Parameters
  • configs (list(Atoms)) – fitting configurations

  • ref_property_keys (str / dict / None, default None) – where to find properties: str used as a prefix to ASE properties ‘energy’, ‘forces’, ‘virial’, ‘hessian’; dict with each of those as key and actual info/arrays key as value, and None for attached calculator (e.g. SinglePointCalculator)

  • stress_to_virial (bool, default True) – copy from stress to virial

  • forces (bool, default True) – overwrite existing info/arrays items

Returns

ref_property_keys – each ASE property as key and corresponding info/array key as value

Return type

dict

wfl.fit.utils.fix_stress_virial(configs, ref_property_keys, stress_key)#

convert from stress to 3x3 virial, workaround until fitting code accepts stress

Parameters
  • configs (list(Atoms)) – fitting configurations

  • ref_property_keys (dict) – dict with each ASE property key as keys and corresponding info/array keys as values

  • stress_key (str) – key for stress property

Module contents#