batch

class batchpy.batch.Batch(name, path='', saveresult=True)[source]

The batchpy batch class

A batch can contain several runs of computations. Using batchpy these batches can be easily defined using python files (to support version control) and run.

The computation results can be stored in memory or saved to disk per run. When the result of a run is saved it is cleared from memory which allows for computations which would require more memory then available if all runs were to be executed at once.

Parameters:

name : string

A name for the batch

path : string, optional

A optional path to store results, if not provided the current path is chosen.

saveresult : boolean, optional

Save the results to disk or not, this argument is passed to all runs.

Examples

>>> batch = batchpy.Batch('mybatch')
add_run(runclass, parameters)[source]

Adds a run

Parameters:

runclass : Run() subclass

A class reference which creates an object when supplied the parameters.

parameters : dict

A dictionary of parameters to be supplied to the run() method of the runclass.

Examples

>>> batch.add_run(Myrun,{'A':1,'B':[1,2,3],'C':'spam'})
>>> batch()
add_factorial_runs(runclass, parameters)[source]

Adds a full factorial design of runs based on parameter lists

Parameters:

runclass : batchpy.run.Run() subclass

A class reference which creates an object when supplied the parameters.

parameters : dict

A dictionary of lists of parameters to be supplied to the run() method of the runclass.

Examples

>>> batch.add_factorial_runs(Myrun,{'par1':[0,1,2],'par2':[5.0,7.1]})
>>> 
>>> # is equivalent with:
>>> batch.add_run(Myrun,{par1:0,par2:5.0})
>>> batch.add_run(Myrun,{par1:0,par2:7.1})
>>> batch.add_run(Myrun,{par1:1,par2:5.0})
>>> batch.add_run(Myrun,{par1:1,par2:7.1})
>>> batch.add_run(Myrun,{par1:2,par2:5.0})
>>> batch.add_run(Myrun,{par1:2,par2:7.1})
add_resultrun(id)[source]

Adds saved runs by id

Parameters:

id : string or list of strings

The id of the run.

Examples

>>> batch.add_resultrun('3ecc784a9d5cf26eb6420de2a43f04b310073925')
get_runs_with(**kwargs)[source]

Returns a list of runs with the specified parameter values

Parameters:

kwargs : anything

Keyword arguments of parameter values . Several conditions can be appended to a parameter: __eq: equal, same as appending nothing __ne: not equal __ge: greater or equal __le: less or equal

Returns:

runs : list

a list of runs

Examples

>>> batch = batchpy.Batch('mybatch')
>>> batch.add_factorial_runs(Myrun,{'par1':[0,1,2],'par2':[5.0,7.1]})
>>> runs = batch.get_runs_with(par1=0)
>>> print(runs)
>>> runs = batch.get_runs_with(par1__ge=1,par2=5.0)
>>> print(runs)
__call__(runs=-1, verbose=1)[source]

Runs the remainder of the batch or a specified run

Parameters:

runs : int or list of ints, optional

Indices of the runs to be executed, -1 for all runs

verbose : int, optional

Integer determining the amount of printed output 0/1/2

save_ids(filename=None, format='npy')[source]

Saves all ids in the batch to a python file with an ids list

Parameters:

filename : str, optional

The filename of the output file. If no filename is supplied a file is created in the _res folder, named batchname_ids.npy or batchname_ids.py depending on the format argument. If a filename is supplied, the format argument is ignored and the filename extension is used to determine the format.

format : str, optional

The format to save the ids to, ‘npy’/’py’. By default, a .npy file is created, the ids can be retrieved with ids = np.load('batchname_ids.npy'). If the ‘py’ format is supplied the ids are written to a python file in a list.

Examples

>>> batch.save_ids()

In another interpreter:

>>> import numpy as np
>>> ids = np.load('_res/mybatch_ids.npy')
>>> print(ids)
savepath

Property returning the path where files are saved