|
CellModules
|
Public Member Functions | |
| def | __init__ (self, Callable simuRunner, dict|list[dict] params, int replicat=1, list[int] conditions=[0], int|str|None batch_size_level=None, int|None cacheSize=200, bool withTqdm=False, bool parallel=True, bool autoIndex=True, bool autoConcat=True) |
| def | __iter__ (self) |
| Union[pd.DataFrame, List[pd.DataFrame]] | get (self) |
Public Attributes | |
| simuRunner | |
| parallel | |
| autoConcat | |
| autoIndex | |
| WithParam | |
| WithCondition | |
| WithReplicat | |
| withTqdm | |
| realBatchSize | |
| argsIter | |
| i | |
| end | |
| cacheSize | |
| pbars | |
| total | |
Private Member Functions | |
| def | _feedProcess (self, pool, futures, n=1) |
| def | _autoConcat (self, datas) |
| def | _init_pbars (self, nbParam, nbCondition, nbReplicat) |
| def | _updateBar (self) |
| def | _postProcess (self, datas, id_param, id_cond, replicat) |
| def | _combine (self, params, conditions, replicat) |
| def | _batched (self, iterable, n) |
| def | _close_pbars (self) |
Initializes the MultiSimu instance for running multiple simulations with various parameters, conditions, and replicates.
Parameters
----------
: **simuRunner** : callable
The function to run the simulation. It should accept the parameters and conditions as input.
: **params** : dict or list of dict
The parameters for the simulation. If a single dictionary is provided, it is wrapped in a list. Each dictionary represents a distinct set of parameters for a simulation run.
: **replicat** : int, optional, default=1
The number of replicates to run for each parameter and condition combination.
: **conditions** : list, optional, default=[0]
A list of conditions to apply to each simulation run.
: **batch_size_level** : int or str, optional, default=None
Determines the size of the batches returned by the iterator. It can be an integer specifying the number of batches, or a string indicating the batch level ('param', 'replicat', or 'condition').
: **cacheSize** : int or None, optional, default=200
The size of the cache for the number of simulations to pre-fetch in parallel.
: **withTqdm** : bool, optional, default=False
If True, progress bars will be displayed using `tqdm` to show the progress of parameter, condition, and replicate iterations.
: **parallel** : bool, optional, default=True
If True, simulations will be run in parallel using multiprocessing. If False, simulations will be run sequentially.
: **autoIndex** : bool, optional, default=True
If True, adds index columns (ID_PARAMETER, ID_CONDITION, ID_REPLICAT) to the output data for identification.
: **autoConcat** : bool, optional, default=True
If True, concatenates the results from different simulations into a single pandas DataFrame.
Raises
------
: **KeyError**
- If `params` is neither a list of dictionaries nor a single dictionary.
- If `conditions` is not a list.
Example
-------
```python
def dataCatcherOnStep(simu):
return simu.cells.countState()
def run_simu(params,condition,replicat):
steps = list(range(0,2501,10))
MOI, confluence = condition
params['input']['Scenario']['infection'] = [[0,MOI]]
params['input']['Scenario']['initConfluence'] = confluence
data = Simu(params).compute(dataCatcherOnStep,steps)
data.index *= params['input']['Scenario']['dt']
return data
paramsTest = [params1,params2]
conditions = [(0,0.1),
(5,0.15),
(10,0.2)]
def storeData(datas):
pass
for d in MultiSimu(run_simu,paramsTest,replicat = 5, conditions=conditions, batch_size_level='param', withTqdm=True):
storeData(d)
# or simple usage for replicate :
def dataCatcherOnStep(simu):
return simu.cells.countState()
def run_simu(params):
steps = list(range(0,2501,10))
data = Simu(params).compute(dataCatcherOnStep,steps)
data.index *= params['input']['Scenario']['dt']
return data
data = MultiSimu(run_simu,params,replicat=5).get()
```
Definition at line 8 of file MultiSimu.py.
| def pythonlib.MultiSimu.MultiSimu.__init__ | ( | self, | |
| Callable | simuRunner, | ||
| dict | list[dict] | params, | ||
| int | replicat = 1, |
||
| list[int] | conditions = [0], |
||
| int | str | None | batch_size_level = None, |
||
| int | None | cacheSize = 200, |
||
| bool | withTqdm = False, |
||
| bool | parallel = True, |
||
| bool | autoIndex = True, |
||
| bool | autoConcat = True |
||
| ) |
Definition at line 91 of file MultiSimu.py.
| def pythonlib.MultiSimu.MultiSimu.__iter__ | ( | self | ) |
Definition at line 141 of file MultiSimu.py.
|
private |
Definition at line 176 of file MultiSimu.py.
|
private |
Definition at line 248 of file MultiSimu.py.
|
private |
Definition at line 254 of file MultiSimu.py.
|
private |
Definition at line 232 of file MultiSimu.py.
|
private |
Definition at line 130 of file MultiSimu.py.
|
private |
Definition at line 188 of file MultiSimu.py.
|
private |
Definition at line 215 of file MultiSimu.py.
|
private |
Definition at line 205 of file MultiSimu.py.
| Union[pd.DataFrame, List[pd.DataFrame]] pythonlib.MultiSimu.MultiSimu.get | ( | self | ) |
Retrieve all simulation results at once.
Returns
-------
: Union[pd.DataFrame, List[pd.DataFrame]]
Returns a single pandas DataFrame if there is only one batch of results.
Returns a list of pandas DataFrames if there are multiple batches of results.
Definition at line 162 of file MultiSimu.py.
| pythonlib.MultiSimu.MultiSimu.argsIter |
Definition at line 123 of file MultiSimu.py.
| pythonlib.MultiSimu.MultiSimu.autoConcat |
Definition at line 107 of file MultiSimu.py.
| pythonlib.MultiSimu.MultiSimu.autoIndex |
Definition at line 108 of file MultiSimu.py.
| pythonlib.MultiSimu.MultiSimu.cacheSize |
Definition at line 128 of file MultiSimu.py.
| pythonlib.MultiSimu.MultiSimu.end |
Definition at line 127 of file MultiSimu.py.
| pythonlib.MultiSimu.MultiSimu.i |
Definition at line 126 of file MultiSimu.py.
| pythonlib.MultiSimu.MultiSimu.parallel |
Definition at line 106 of file MultiSimu.py.
| pythonlib.MultiSimu.MultiSimu.pbars |
Definition at line 190 of file MultiSimu.py.
| pythonlib.MultiSimu.MultiSimu.realBatchSize |
Definition at line 121 of file MultiSimu.py.
| pythonlib.MultiSimu.MultiSimu.simuRunner |
Definition at line 105 of file MultiSimu.py.
| pythonlib.MultiSimu.MultiSimu.total |
Definition at line 202 of file MultiSimu.py.
| pythonlib.MultiSimu.MultiSimu.WithCondition |
Definition at line 112 of file MultiSimu.py.
| pythonlib.MultiSimu.MultiSimu.WithParam |
Definition at line 111 of file MultiSimu.py.
| pythonlib.MultiSimu.MultiSimu.WithReplicat |
Definition at line 113 of file MultiSimu.py.
| pythonlib.MultiSimu.MultiSimu.withTqdm |
Definition at line 114 of file MultiSimu.py.