brainpy.DSRunner#
- class brainpy.DSRunner(target, inputs=(), monitors=None, numpy_mon_after_run=True, jit=True, dyn_vars=None, 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 tdi: 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 tdi: model.spike[:10], 'V10': lambda tdi: 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
.New in version 2.3.1.
- __init__(target, inputs=(), monitors=None, numpy_mon_after_run=True, jit=True, dyn_vars=None, dt=None, t0=0.0, progress_bar=True, data_first_axis=None, fun_inputs=None, fun_monitors=None)[source]#
Methods
__init__
(target[, inputs, monitors, ...])cpu
()Move all variable into the CPU device.
cuda
()Move all variables into the GPU device.
load_state_dict
(state_dict[, warn, compatible])Copy parameters and buffers from
state_dict
into this module and its descendants.load_states
(filename[, verbose])Load the model states.
nodes
([method, level, include_self])Collect all children nodes.
predict
([duration, inputs, reset_state, ...])Running a duration with the given target model.
register_implicit_nodes
(*nodes[, node_cls])register_implicit_vars
(*variables[, var_cls])reset_state
()Reset state of the
DSRunner
.run
(*args, **kwargs)Same as
predict()
.save_states
(filename[, variables])Save the model states.
state_dict
()Returns a dictionary containing a whole state of the module.
to
(device)Moves all variables into the given device.
tpu
()Move all variables into the TPU device.
train_vars
([method, level, include_self])The shortcut for retrieving all trainable variables.
tree_flatten
()Flattens the object as a PyTree.
tree_unflatten
(aux, dynamic_values)Unflatten the data to construct an object of this class.
unique_name
([name, type_])Get the unique name for this object.
vars
([method, level, include_self, ...])Collect all variables in this node and the children nodes.
Attributes
name
Name of the model.
target