DSRunner#
- class brainpy.DSRunner(target, inputs=(), monitors=None, numpy_mon_after_run=True, jit=True, dyn_vars=None, memory_efficient=False, dt=None, t0=0.0, progress_bar=True, data_first_axis=None, fun_inputs=None, fun_monitors=None)[source]#
The runner for
DynamicalSystem
.- Parameters:
target (DynamicalSystem) – The target model to run.
inputs (list, tuple, callable) –
The inputs for variables in the target model.
Note
This argument can be used to set the inputs to the
Variable
instances in thetarget
. If you peruse to give time-dependent inputs, please useDSRunner.predict()
orDSRunner.run()
function.It can be a list/tuple with the format of [(target, value, [type, operation])], where target is the input target, value is the input value, type is the input type (such as “fix”, “iter”, “func”), operation is the operation for inputs (such as “+”, “-”, “*”, “/”, “=”).
target
: should be a string orVariable
. Can be specified by the absolute access or relative access.value
: should be a scalar, vector, matrix.type
: should be a string. “fix” means the input value is a constant. “iter” means the input value can be changed over time. “func” mean the input is obtained through the functional call.operation
: should be a string, support +, -, *, /, =.Also, if you want to specify multiple inputs, just give multiple
(target, value, [type, operation])
, for example[(target1, value1), (target2, value2)]
.
It can also be a callable function which receives the shared argument. In this functional input, users can manually specify the inputs for the target variables. This input function should receive one argument
shared
which contains the shared arguments like timet
, time stepdt
, and indexi
.Changed in version 2.3.1:
fun_inputs
are merged intoinputs
.
fun_inputs (callable) –
The functional inputs. Manually specify the inputs for the target variables. This input function should receive one argument
shared
which contains the shared arguments like timet
, time stepdt
, and indexi
.Deprecated since version 2.3.1: Will be removed since version 2.4.0.
monitors (Optional, sequence of str, dict, Monitor) –
Variables to monitor.
A list of string. Like
monitors=['a', 'b', 'c']
.A list of string with index specification. Like
monitors=[('a', 1), ('b', [1,3,5]), 'c']
A dict with the explicit monitor target, like:
monitors={'a': model.spike, 'b': model.V}
A dict with the index specification, like:
monitors={'a': (model.spike, 0), 'b': (model.V, [1,2])}
A dict with the callable function, like
monitors={'a': lambda: model.spike[:5]}
Changed in version 2.3.1:
fun_monitors
are merged intomonitors
.fun_monitors (dict) –
Monitoring variables by a dict of callable functions. The dict
key
should be a string for the later retrieval byrunner.mon[key]
. The dictvalue
should be a callable function which receives two arguments:t
anddt
. .. code-block:fun_monitors = {'spike': lambda: model.spike[:10], 'V10': lambda: model.V[10]}
Deprecated since version 2.3.1: Will be removed since version 2.4.0.
jit (bool, dict) – The JIT settings. Using dict is able to set the jit mode at different phase, for instance,
jit={'predict': True, 'fit': False}
.progress_bar (bool) – Use progress bar to report the running progress or not?
dyn_vars (Optional, dict) – The dynamically changed variables. Instance of
Variable
. These variables together with variable retrieved from thetarget
constitute all dynamical variables in this runner.numpy_mon_after_run (bool) – When finishing the network running, transform the JAX arrays into numpy ndarray or not?
data_first_axis (str) –
Set the default data dimension arrangement. To indicate whether the first axis is the batch size (
data_first_axis='B'
) or the time length (data_first_axis='T'
). In order to be compatible with previous API, default is set to beFalse
.Added in version 2.3.1.
memory_efficient (bool) –
Whether using the memory-efficient way to just-in-time compile the given target. Default is False.
Added in version 2.3.8.
- predict(duration=None, inputs=None, reset_state=False, eval_time=False, shared_args=None, inputs_are_batching=None)[source]#
Running a duration with the given target model. See .predict() function for more details.
This function use the JIT compilation to accelerate the model simulation. Moreover, it can automatically monitor the node variables, states, inputs, and its output.
- Parameters:
duration (float) – The simulation time length. If you have provided
inputs
, there is no longer need to provideduration
.inputs (ArrayType, dict of ArrayType, sequence of ArrayType) –
The input data.
If the mode of
target
is instance ofBatchingMode
,inputs
must be a PyTree of data with two dimensions:(batch, time, ...)
whendata_first_axis='B'
, or(time, batch, ...)
whendata_first_axis='T'
.If the mode of
target
is instance ofNonBatchingMode
, theinputs
should be a PyTree of data with one dimension:(time, ...)
.
inputs_are_batching (bool) –
Whether the
inputs
are batching. If True, the batching axis is the first dimension.Deprecated since version 2.3.1: Will be removed after version 2.4.0.
reset_state (bool) – Whether reset the model states.
eval_time (bool) – Whether ro evaluate the running time.
shared_args (optional, dict) – The shared arguments across different layers.
- Returns:
output – The model output.
- Return type:
ArrayType, dict, sequence