brainpy.integrators.runner.IntegratorRunner#

class brainpy.integrators.runner.IntegratorRunner(target, inits=None, args=None, dyn_args=None, dt=None, fun_monitors=None, monitors=None, dyn_vars=None, jit=True, numpy_mon_after_run=True, progress_bar=True)[source]#

Structural runner for numerical integrators in brainpy.

Examples

Example to run an ODE integrator,

>>> import brainpy as bp
>>> import brainpy.math as bm
>>> a=0.7; b=0.8; tau=12.5
>>> dV = lambda V, t, w, I: V - V * V * V / 3 - w + I
>>> dw = lambda w, t, V, a, b: (V + a - b * w) / tau
>>> integral = bp.odeint(bp.JointEq([dV, dw]), method='exp_auto')
>>>
>>> runner = bp.integrators.IntegratorRunner(
>>>          integral,  # the simulation target
>>>          monitors=['V', 'w'],  # the variables to monitor
>>>          inits={'V': bm.random.rand(10),
>>>                 'w': bm.random.normal(size=10)},  # the initial values
>>>          args={'a': 1., 'b': 1.},  # update arguments
>>>          dyn_args={'I': bp.inputs.ramp_input(0, 4, 200)},  # each time each current input
>>> )
>>> runner.run(100.)
>>> bp.visualize.line_plot(runner.mon.ts, runner.mon.V, plot_ids=[0, 1, 4], show=True)

(Source code, png, hires.png, pdf)

../../../../_images/brainpy-integrators-runner-IntegratorRunner-1.png

Example to run an SDE intragetor,

>>> import brainpy as bp
>>> import brainpy.math as bm
>>> # stochastic Lorenz system
>>> sigma=10; beta=8 / 3; rho=28
>>> g = lambda x, y, z, t, p: (p * x, p * y, p * z)
>>> f = lambda x, y, z, t, p: [sigma * (y - x), x * (rho - z) - y, x * y - beta * z]
>>> lorenz = bp.sdeint(f, g, method='milstein')
>>>
>>> runner = bp.integrators.IntegratorRunner(
>>>   lorenz,
>>>   monitors=['x', 'y', 'z'],
>>>   inits=[1., 1., 1.], # initialize all variable to 1.
>>>   args={'p': 0.1},
>>>   dt=0.01
>>> )
>>> runner.run(100.)
>>>
>>> import matplotlib.pyplot as plt
>>> fig = plt.figure()
>>> ax = fig.gca(projection='3d')
>>> plt.plot(runner.mon.x.squeeze(), runner.mon.y.squeeze(), runner.mon.z.squeeze())
>>> ax.set_xlabel('x')
>>> ax.set_xlabel('y')
>>> ax.set_xlabel('z')
>>> plt.show()

(Source code)

__init__(target, inits=None, args=None, dyn_args=None, dt=None, fun_monitors=None, monitors=None, dyn_vars=None, jit=True, numpy_mon_after_run=True, progress_bar=True)[source]#

Initialization of structural runner for integrators.

Parameters
  • target (Integrator) – The target to run.

  • monitors (sequence of str) – The variables to monitor.

  • fun_monitors (dict) – The monitors with callable functions.

  • inits (sequence, dict) – The initial value of variables. With this parameter, you can easily control the number of variables to simulate. For example, if one of the variable has the shape of 10, then all variables will be an instance of brainpy.math.Variable with the shape of \((10,)\).

  • args (dict) – The equation arguments to update. Note that if one of the arguments are heterogeneous (i.e., a tensor), it means we should run multiple trials. However, you can set the number of the elements in the variables so that each pair of variables can corresponds to one set of arguments.

  • dyn_args (dict) – The dynamically changed arguments. This means this argument can control the argument dynamically changed. For example, if you want to inject a time varied currents into the HH neuron model, you can pack the currents into this dyn_args argument.

  • dt (float, int) –

  • dyn_vars (dict) –

  • jit (bool) –

  • progress_bar (bool) –

  • numpy_mon_after_run (bool) –

Methods

__init__(target[, inits, args, dyn_args, ...])

Initialization of structural runner for integrators.

build_monitors(return_without_idx, ...)

rtype

Callable

format_monitors()

run(duration[, start_t, eval_time])

The running function.

Attributes