Multiprocessing
sample_many_runs(params, initial_states, t_max, t_eval, num_runs, n_jobs=None, collective_variable=None, rng=default_rng(), progress_bar=False)
Sample multiple runs of the model specified by params.
Parameters:
-
params(Parameters) –Either CNVM or CNTM Parameters. If a NetworkGenerator is used, a new network will be sampled for every run.
-
initial_states(ArrayLike) –Array of initial states, shape = (num_initial_states, num_agents), or single initial state, shape = (num_agents,). Num_runs simulations will be executed for each initial state.
-
t_max(float) –End time.
-
t_eval(ArrayLike) –Array of time points where the solution should be saved, or number "n" in which case the solution is stored equidistantly at "n" time points.
-
num_runs(int) –Number of samples.
-
n_jobs(int, default:None) –If "None", no multiprocessing is applied. If "-1", all available CPUs will be used.
-
collective_variable(CollectiveVariable, default:None) –If collective variable is specified, the projected trajectory will be returned instead of the full trajectory.
-
rng(Generator, default:default_rng()) –Random number generator.
-
progress_bar(bool, default:False) –Whether to print the progress. If multiprocessing is used, only the progress of the first subprocess is printed.
Returns:
-
t_out, x_out : tuple[NDArray, NDArray]–(t_out, x_out), time_out.shape = (num_timesteps,), x_out.shape = (num_initial_states, num_runs, num_timesteps, num_agents), or x_out.shape = (num_runs, num_timesteps, num_agents) if only a single initial state was given.
Source code in sponet/multiprocessing.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |