larvaworld.lib.sim.subprocess_run

Classes

Exec

Subprocess execution wrapper for simulations.

Module Contents

class larvaworld.lib.sim.subprocess_run.Exec(mode: str, conf: dict, experiment: str, run_externally: bool = True, progressbar: Any | None = None, w_progressbar: Any | None = None, **kwargs: Any)

Subprocess execution wrapper for simulations.

Manages simulation execution either synchronously (in-process) or asynchronously (as external subprocess) for non-blocking operation.

run_externally = True
mode
conf
progressbar = None
w_progressbar = None
type
done = False
terminate() None
run(**kwargs: Any) None
check() bool
retrieve(res: pandas.DataFrame | list[larvaworld.lib.process.LarvaDataset] | None = None) pandas.DataFrame | tuple[dict[str, dict[str, Any]], dict[str, Any]] | None

Retrieve and process results from subprocess execution.

Collects simulation results from subprocess execution and processes them according to experiment type and mode.

Args:
res: Results from subprocess - can be:
  • pd.DataFrame: Single batch endpoint data (batch mode).

  • list[LarvaDataset]: Multiple dataset results (sim mode).

  • None: Load from disk based on self.conf (default for external runs).

Returns:

Processed results, type depends on self.mode: - For ‘batch’ mode: DataFrame with batch results or None if load fails. - For ‘sim’ mode: tuple of (entry_dict, fig_dict) where:

  • entry_dict: {id: {‘dataset’: list[LarvaDataset], ‘figs’: dict}}

  • fig_dict: Figure dictionary (currently None - TODO)

  • None: If results cannot be retrieved.

Example:
>>> # After external batch run completes:
>>> results = exec.retrieve()  # Loads from disk
>>> if isinstance(results, pd.DataFrame):
>>>     print(f"Batch results: {len(results)} rows")
>>>
>>> # For sim mode with manual results:
>>> datasets = [LarvaDataset(dir=path) for path in paths]
>>> entry, figs = exec.retrieve(res=datasets)
exec_run()