Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monitoring variables once every few steps #515

Open
2 tasks done
CloudyDory opened this issue Oct 9, 2023 · 1 comment
Open
2 tasks done

Monitoring variables once every few steps #515

CloudyDory opened this issue Oct 9, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@CloudyDory
Copy link
Contributor

  • Check for duplicate requests.
  • Describe your goal, and if possible provide a code snippet with a motivating example.

Currently, the monitor of brainpy.DSRunner record the values of variables every at every timestep. However, sometimes it is not necessary to record the system's behavior at a very high temporal precision. When the simulation time is long, monitoring the variables at high temporal precision can lead to out of memory error. It might be helpful to add an option to record the values once every few steps to decrease the memory requirement.

@CloudyDory CloudyDory added the enhancement New feature or request label Oct 9, 2023
@chaoming0625
Copy link
Collaborator

This is a very good question. I have also considered it for a long time.

However, current BrainPy also supports the monitor every few steps. Here is an example:

import brainpy as bp
import brainpy.math as bm
import numpy as np


class EINet3(bp.DynSysGroup):
  def __init__(self):
    super().__init__()
    self.N = bp.dyn.LifRef(4000, V_rest=-60., V_th=-50., V_reset=-60., tau=20., tau_ref=5.,
                           V_initializer=bp.init.Normal(-55., 2.))
    self.delay = bp.VarDelay(self.N.spike, entries={'I': None})
    self.E = bp.dyn.ProjAlignPostMg1(comm=bp.dnn.EventJitFPHomoLinear(3200, 4000, prob=0.02, weight=0.6),
                                     syn=bp.dyn.Expon.desc(size=4000, tau=5.),
                                     out=bp.dyn.COBA.desc(E=0.),
                                     post=self.N)
    self.I = bp.dyn.ProjAlignPostMg1(comm=bp.dnn.EventJitFPHomoLinear(800, 4000, prob=0.02, weight=6.7),
                                     syn=bp.dyn.Expon.desc(size=4000, tau=10.),
                                     out=bp.dyn.COBA.desc(E=-80.),
                                     post=self.N)

  def update(self, input):
    spk = self.delay.at('I')
    self.E(spk[:3200])
    self.I(spk[3200:])
    self.delay(self.N(input))
    return self.N.spike.value

  def run(self, ids, inputs):
    for i, inp in zip(ids, inputs):
      bp.share.save(i=i, t=bm.get_dt() * i)
      self.update(inp)
    return self.N.spike.value


n_step_per_monitor = 10
indices = np.arange(10000).reshape(-1, n_step_per_monitor)
inputs = np.ones(indices.shape) * 20.
model = EINet3()
spks = bm.for_loop(model.run, (indices, inputs), progress_bar=True)
bp.visualize.raster_plot(indices[:, 0], spks, show=True)

The key is to customize the run function and give it to brainpy.math.for_loop. In the future we will consider it on DSRunner. Thanks. Contributions are welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants