Skip to content

Commit

Permalink
update delays for compatible with brainunit (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoming0625 authored Sep 10, 2024
1 parent 078ffbd commit ea47416
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
2 changes: 1 addition & 1 deletion brainstate/_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -1597,6 +1597,6 @@ def _get_delay(delay_time, delay_step):
delay_time = delay_step * environ.get_dt()
else:
assert delay_step is None, '"delay_step" should be None if "delay_time" is given.'
assert isinstance(delay_time, (int, float))
# assert isinstance(delay_time, (int, float))
delay_step = math.ceil(delay_time / environ.get_dt())
return delay_time, delay_step
2 changes: 2 additions & 0 deletions brainstate/_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ class ShapeDtype:
def __init__(self, shape, dtype):
self.shape = shape
self.dtype = dtype
self.ndim = len(shape)
self.size = np.prod(shape)

def __repr__(self):
return f'{self.dtype}{list(self.shape)}'
Expand Down
38 changes: 28 additions & 10 deletions brainstate/nn/_projection/_align_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

from typing import Optional, Union


import brainunit as u
from brainstate._module import (register_delay_of_target,
Projection,
Module,
Expand Down Expand Up @@ -278,11 +280,19 @@ def __init__(
self.comm = comm

# delay initialization
if delay is not None and delay > 0.:
delay_cls = register_delay_of_target(pre)
delay_cls.register_entry(self.name, delay)
self.delay = delay_cls
self.has_delay = True
if delay is not None:
if isinstance(delay, u.Quantity):
has_delay = delay.mantissa > 0.
else:
has_delay = delay > 0.
if has_delay:
delay_cls = register_delay_of_target(pre)
delay_cls.register_entry(self.name, delay)
self.delay = delay_cls
self.has_delay = True
else:
self.delay = None
self.has_delay = False
else:
self.delay = None
self.has_delay = False
Expand Down Expand Up @@ -502,11 +512,19 @@ def __init__(
self.out = out

# delay initialization
if delay is not None and delay > 0.:
delay_cls = register_delay_of_target(pre)
delay_cls.register_entry(self.name, delay)
self.delay = delay_cls
self.has_delay = True
if delay is not None:
if isinstance(delay, u.Quantity):
has_delay = delay.mantissa > 0.
else:
has_delay = delay > 0.
if has_delay:
delay_cls = register_delay_of_target(pre)
delay_cls.register_entry(self.name, delay)
self.delay = delay_cls
self.has_delay = True
else:
self.delay = None
self.has_delay = False
else:
self.delay = None
self.has_delay = False
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ See also the BDP ecosystem
^^^^^^^^^^^^^^^^^^^^^^^^^^


We are building the `BDP ecosystem <https://ecosystem-for-brain-dynamics.readthedocs.io/>`_:
We are building the `BDP ecosystem <https://ecosystem-for-brain-dynamics.readthedocs.io/>`_.



Expand Down

0 comments on commit ea47416

Please sign in to comment.