anypytools.AnyPyProcess

class anypytools.AnyPyProcess(num_processes=4, anybodycon_path=None, timeout=3600, silent=False, ignore_errors=None, warnings_to_include=None, fatal_warnings=False, return_task_info=None, keep_logfiles=False, logfile_prefix=None, python_env=None, debug_mode=0, use_gui=False, priority=16384, interactive_mode=False, **kwargs)[source]

Class for configuring batch process jobs of AnyBody models.

This is the main interface to control the AnyBody console application from python. The class stores all the configuration about how AnyBody is run. It has one important method start_macro which launches the AnyBody with a given anyscript macro.

Parameters
  • num_processes (int, optional) – Number of anybody models to start in parallel. This defaults to the number of logical CPU cores in the computer.

  • anybodycon_path (str, optional) – Overwrite the default anybodycon.exe file to use in batch processing. Defaults to what is found in the windows registry.

  • timeout (int, optional) – Maximum time (i seconds) a model can run until it is terminated. Defaults to 3600 sec (1 hour).

  • silent (bool, optional) – Set to True to suppress any output such as progress bar and error messages. (Defaults to False).

  • ignore_errors (list of str, optional) – List of AnyBody Errors substrings to ignore when running the models. (Defaults to None)

  • warnings_to_include (list of str, optional) – List of strings that are matched to warnings in the model output. If a warning with that string is found the warning is returned in the output. (Defaults to None)

  • fatal_warnings (bool, optional) – Treat warnings as errors. This only triggers for specific warnings given by warnings_to_include argument.

  • keep_logfiles (bool, optional) – If True logfile will never be removed. Even if a simulations successeds without error. (Defautls to False)

  • logfile_prefix (str, optional) – String which will be prefixed to the generated log files. This can be used to assign a more meaningfull name to a batch of logfiles. (Defaults to None)

  • python_env (pathlike, optional) – Path to a python environment/installation that the AnyBody Modeling System should use for Python Hooks. This will added the PYTHONHOME environment variable and prepended to the PATH before starting the AnyBody Console application. (Defaults to None, which will use the default Python installation on the computer.)

  • debug_mode (int, optional) – Sets the debug mode flag for the AnyBodyConsole appplication (e.g. the /deb <number> flag)

  • use_gui (bool, optional) – Swictch to use the GUI instead of the console version of AMS. This works by replacing the ‘anybodycon’ part of the executable with ‘anybody’ of the anybodycon_path arguments. I.e. “…/anybdoycon.exe” becomes “…/anybody.exe”

  • interactive_mode (bool, optional) – If set to True, AnyBody will be started in iteractive mode, and will not shutdown autmaticaly after running the macro. This automatically enables the use_gui argument (Defaults to False)

  • priority (int, optional) – The priority of the subprocesses. This can be on of the following: anypytools.IDLE_PRIORITY_CLASS, anypytools.BELOW_NORMAL_PRIORITY_CLASS, anypytools.NORMAL_PRIORITY_CLASS, anypytools.HIGH_PRIORITY_CLASS Default is BELOW_NORMAL_PRIORITY_CLASS.

Returns

An instance of the AnyPyProcess object for running batch processing, parameter studies and pertubation jobs.

Return type

AnyPyProcess

Example

The following example shows how to instantiate a AnyPyProcess object.

>>> app = AnyPyProcess(num_processes=8)

The app object has methods for launching macros, saving results etc.

>>> macro = ['load "MyModel.any"', 'operation Main.MyStudy.Kinematics', 'run']
>>> app.start_macro(macro)
load_results(filename)[source]

Load previously saved results.

Besides reloading results the function can be used to continue a partial finished processing process.

Parameters

filename (str) – filename of the file where processing was stored.

Returns

A list with the output from each macro executed. This maybe empty the macros did not output any data.

Return type

list

Examples

Results are easily reloaded:

>>> app = AnyPyProcess()
>>> results = app.load_results('saved_results.db')

Continue processing unfinished batches:

>>> app.load_results('unfinished_results.db')
>>> results = app.start_macro() # rerun unfinished
save_results(filename, append=False)[source]

Save resently processed results.

Save results for later reloading or to continue processing unfished results at a later time.

Parameters
  • filename (str) – filename of the file where processing was stored.

  • append (bool) – If true append data to what ever is already saved. This allows for saving data in batches.

Returns

Return type

None

Examples

>>> macro = ['load "model1.any"', 'operation Main.RunApplication', 'run']
>>> app.start_macro(macro)
>>> app.save_results('saved_data.db')
save_to_hdf5(filename, batch_name=None)[source]

Save cached results to hdf5 file.

Parameters
  • filename (str) – filename where data should be stored

  • batch_name (str) – Name of the group in the HDF5 file to save the data within. If not specified the group hash value of the macro will be used.

Returns

Return type

None

start_macro(macrolist=None, folderlist=None, search_subdirs=None, logfile=None)[source]

Start a batch processing job.

Runs a list of AnyBody Macro commands in the current directory, or in the folders specified by folderlist. If search_subdirs is a regular expression the folderlist will be expanded to include all subdirectories that match the regular expression

Parameters
  • macrolist (list of macrocommands, optional) – List of anyscript macro commands. This may also be obmitted in which case the previous macros will be re-run.

  • folderlist (list of str, optional) – List of folders in which to excute the macro commands. If None the current working directory is used. This may also be a list of tuples to specify a name to appear in the output

  • search_subdirs (str, optional) – Regular expression used to extend the folderlist with all the subdirectories that match the regular expression. Defaults to None: No subdirectories are included.

  • logfile (str, optional) – If specified an explicit name will be used for the log files generated. Otherwise, random names are used for logfiles

Returns

A list with the output from each macro executed. This maybe empty the macros did not output any data.

Return type

list

Examples

>>> macro = [['load "model1.any"', 'operation Main.RunApplication', 'run'],
             ['load "model2.any"', 'operation Main.RunApplication', 'run'],
             ['load "model3.any"', 'operation Main.RunApplication', 'run']]
>>> folderlist = [('path1/', 'name1'), ('path2/', 'name2')]
>>> app.start_macro(macro, folderlist, search_subdirs = "*.main.any")