stochastic
RL4CRN.utils.stochastic
Lightweight wrappers around GPU-accelerated SSA runs.
This module provides a convenience function to run stochastic simulations
(via StochasticSimulationsNew.MultiGPUsupport.SSA) over many parameter/input
configurations and return a summarized pandas DataFrame suitable for quick
analysis and plotting.
Key idea
- The backend SSA typically returns raw per-trajectory samples (including metadata like GPU/thread indices).
quick_measurement_SSAgroups the raw output by time and parameter columns, and computes mean and standard deviation trajectories for selected species, yielding a compact table (often with MultiIndex columns:(species, 'mean'),(species, 'std')).
The returned summary is designed to be compatible with downstream plotting
helpers such as plot_simulation_summary.
quick_measurement_SSA(crn, parameters, parameter_names, t_fin=100, n_trajectories=100, max_threads=10000, t_step=0.1, t_control_step=-1, species_to_measure=None, max_value=1000000.0)
Run GPU-accelerated SSA for multiple parameter settings and return a compact summary.
This is a thin wrapper around SSA(...) that:
- distributes parameter sets across available GPUs,
- runs many SSA trajectories per parameter set, and
- aggregates the raw results into mean/std trajectories per (time, inputs).
| PARAMETER | DESCRIPTION |
|---|---|
crn
|
Parsed CRN object consumed by the SSA backend.
Expected to expose
|
parameters
|
Parameter/input configurations to simulate.
Commonly used for input combinations, e.g.
TYPE:
|
parameter_names
|
Names corresponding to each entry in a parameter tuple.
These become grouping columns in the output (e.g.
TYPE:
|
t_fin
|
Final simulation time (end of time horizon).
TYPE:
|
n_trajectories
|
Number of independent SSA trajectories per parameter configuration.
TYPE:
|
max_threads
|
Maximum number of GPU threads used by the backend. (Passed through to the SSA implementation if applicable.)
TYPE:
|
t_step
|
Sampling timestep for recording trajectories.
TYPE:
|
t_control_step
|
Control/update interval if the backend supports time-varying inputs.
Use
TYPE:
|
species_to_measure
|
Subset of species names to keep and summarize.
TYPE:
|
max_value
|
Divergence/overflow clamp passed to the SSA backend. If states exceed this value, the backend may flag divergence.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
tuple[pandas.DataFrame, bool]:
|
Notes
- The function assumes the raw SSA dataframe includes:
- species columns (matching
crn.species), - grouping columns (e.g.,
timeand parameter/input columns), - optional metadata columns such as
thread_index,iteration_index,gpu, - a boolean
has_divergedcolumn used to detect unstable simulations.
- species columns (matching
- The aggregation is performed via:
raw_df.groupby(group_cols)[target_species].agg(['mean','std']).reset_index().