resultbag.py

class jcmwave.Resultbag(filepath, keys=None)

This class provides a handle to store and access computational results and logs. It can be passed as a parameter to jcmwave.solve() and jcmwave.daemon.wait() such that new computational results are automatically added to the resultbag and the numerical computations of results that are already included in the resultbag are skipped. Example:

resultbag=jcmwave.Resultbag('resultbag.db')
jcmwave.solve('project.jcmp', keys = keys, resultbag = resultbag)    
result = resultbag.get_result(keys)
Parameters:
  • filepath (filepath) – Path to a file that saves the content of the fieldbag. The path can be given relative to the script that creates the resultbag. If file does not exist it will be created. Whenever some result is added, the file is automatically updated. If the file exists, the resultbag is loaded from the file.
  • keys (optional) (dictionary) – Prototype of parameter dictionary for templated jcmt-files or list of fieldnames. If keys is present, when adding or getting results the keys dictionary is filtered to the prototypic dictionary, such that other fieldnames in keys dictionary are ignored.
add(keys=None, id=None, result=None, log={})

Add results and log for specific keys

Internal method used by jcmwave.solve() or jcmwave.daemon.wait()

backup(backup_path=None)

Purpose: Create a backup of the resultbag. If no backup_path is provided, it is derived from the resultbag’s name.

Usage: resultbag.backup(backup_path=’resultbag_bkp.db’)

check_result(keys)

Check if results for specific keys exist. Example:

exists=resultbag.check_result(keys)
Parameters:keys (dict) – Parameter dictionary for templated jcmt-files.
Returns:bool (true if results exist)
check_source_files(files)

Check if source files are unchanged

Internal method used by jcmwave.solve() or jcmwave.daemon.wait()

get_keys_by_job_id(id)

Get keys of job id

Internal method used by jcmwave.solve() or jcmwave.daemon.wait()

get_log(keys)

Get log for specific keys. Example:

log=resultbag.get_log(keys)
Parameters:keys (dict) – Parameter dictionary for templated jcmt-files.
Returns:log dict
get_result(keys)

Get results for specific keys. Example:

result=resultbag.get_result(keys)
Parameters:keys (dict) – Parameter dictionary for templated jcmt-files.
Returns:result list
get_tag(keys)

Purpose: Get md5 tag of keys dict. Usefull e.g. for creating unique folder names for workingdir option of jcmwave_solve

Usage: tag=resultbag.get_tag(keys)

Parameters:keys (dict) – Parameter dictionary for templated jcmt-files.
Returns:string
has_results()
Check if any results are registered
has_any=resultbag.has_results()
Returns:bool (true if any results are registered)
ignore_source_files(ignore=True)

Set flag to ignore dependency of resultbag on source files

is_running(keys)

Check if computation of keys is running

Internal method used by jcmwave.solve() or jcmwave.daemon.wait()

release(id)

Release job id

Internal method used by jcmwave.solve() or jcmwave.daemon.wait()

release_all()

In daemon mode jcmwave.solve associates the job to a keys dict. Once the computation is running additional computations with the same corresponding keys dict are skipped. The jobid-keys association is released by jcmwave.daemon.wait after the computation has finished. In case of a scripting error in Matlab the jcmwave.daemon.wait() command may not be reached such that the associations are not released and new jobs are not started. In this case call release_all(). Example:

resultbag.release_all()  
remove(fun)

Remove result and log for keys meeting certain criteria. Example:

resultbag.remove(lambda keys: keys['somefield'] > 0) 
Parameters:fun (function) – boolean function with keys as argument
remove_result(keys)

Remove result and log for specific keys. Example:

resultbag.remove_result(keys) 
Parameters:keys (dict) – Parameter dictionary for templated jcmt-files.
reset()

Purpose: Clear all results in resultbag. Usage: resultbag.reset()

set_job_id(keys, id)

Set job id of keys dict

Internal method used by jcmwave.solve() or jcmwave.daemon.wait()

set_source_files(files)

Set source files of results

Internal method used by jcmwave.solve() or jcmwave.daemon.wait()