brainstate 0.1.9__py2.py3-none-any.whl → 0.1.10__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- brainstate/__init__.py +1 -1
- brainstate/environ.py +3 -3
- brainstate/nn/_delay.py +82 -3
- {brainstate-0.1.9.dist-info → brainstate-0.1.10.dist-info}/METADATA +1 -1
- {brainstate-0.1.9.dist-info → brainstate-0.1.10.dist-info}/RECORD +8 -8
- {brainstate-0.1.9.dist-info → brainstate-0.1.10.dist-info}/WHEEL +0 -0
- {brainstate-0.1.9.dist-info → brainstate-0.1.10.dist-info}/licenses/LICENSE +0 -0
- {brainstate-0.1.9.dist-info → brainstate-0.1.10.dist-info}/top_level.txt +0 -0
brainstate/__init__.py
CHANGED
brainstate/environ.py
CHANGED
@@ -402,13 +402,13 @@ def _get_float(precision: int):
|
|
402
402
|
|
403
403
|
@functools.lru_cache()
|
404
404
|
def _get_complex(precision: int):
|
405
|
-
if precision
|
405
|
+
if precision in [64, '64']:
|
406
406
|
return np.complex128
|
407
|
-
elif precision
|
407
|
+
elif precision in [32, '32']:
|
408
408
|
return np.complex64
|
409
409
|
elif precision in [16, '16', 'bf16']:
|
410
410
|
return np.complex64
|
411
|
-
elif precision
|
411
|
+
elif precision in [8, '8']:
|
412
412
|
return np.complex64
|
413
413
|
else:
|
414
414
|
raise ValueError(f'Unsupported precision: {precision}')
|
brainstate/nn/_delay.py
CHANGED
@@ -472,15 +472,94 @@ class Delay(Module):
|
|
472
472
|
|
473
473
|
class StateWithDelay(Delay):
|
474
474
|
"""
|
475
|
-
|
475
|
+
Delayed history buffer bound to a module state.
|
476
|
+
|
477
|
+
StateWithDelay is a specialized :py:class:`~.Delay` that attaches to a
|
478
|
+
concrete :py:class:`~brainstate._state.State` living on a target module
|
479
|
+
(for example a membrane potential ``V`` on a neuron). It automatically
|
480
|
+
maintains a rolling history of that state and exposes convenient helpers to
|
481
|
+
retrieve the value at a given delay either by step or by time.
|
482
|
+
|
483
|
+
In normal usage you rarely instantiate this class directly. It is created
|
484
|
+
implicitly when using the prefetch-delay helpers on a Dynamics module, e.g.:
|
485
|
+
|
486
|
+
- ``module.prefetch('V').delay.at(5.0 * u.ms)``
|
487
|
+
- ``module.prefetch_delay('V', 5.0 * u.ms)``
|
488
|
+
|
489
|
+
Both will construct a StateWithDelay bound to ``module.V`` under the hood
|
490
|
+
and register the requested delay, so you can retrieve the delayed value
|
491
|
+
inside your update rules.
|
492
|
+
|
493
|
+
Parameters
|
494
|
+
----------
|
495
|
+
target : :py:class:`~brainstate.graph.Node`
|
496
|
+
The module object that owns the state to track.
|
497
|
+
item : str
|
498
|
+
The attribute name of the target state on ``target`` (must be a
|
499
|
+
:py:class:`~brainstate._state.State`).
|
500
|
+
init : Callable, optional
|
501
|
+
Optional initializer used to fill the history buffer before ``t0``
|
502
|
+
when delays request values from the past that hasn't been simulated yet.
|
503
|
+
The callable receives ``(shape, dtype)`` and must return an array.
|
504
|
+
If not provided, zeros are used. You may also pass a scalar/array
|
505
|
+
literal via the underlying Delay API when constructing manually.
|
506
|
+
delay_method : {"rotation", "concat"}, default "rotation"
|
507
|
+
Internal buffering strategy (inherits behavior from :py:class:`~.Delay`).
|
508
|
+
"rotation" keeps a ring buffer; "concat" shifts by concatenation.
|
509
|
+
|
510
|
+
Attributes
|
511
|
+
----------
|
512
|
+
state : :py:class:`~brainstate._state.State`
|
513
|
+
The concrete state object being tracked.
|
514
|
+
history : :py:class:`~brainstate._state.ShortTermState`
|
515
|
+
Rolling time axis buffer with shape ``[length, *state.shape]``.
|
516
|
+
max_time : float
|
517
|
+
Maximum time span currently supported by the buffer.
|
518
|
+
max_length : int
|
519
|
+
Buffer length in steps (``ceil(max_time/dt)+1``).
|
520
|
+
|
521
|
+
Notes
|
522
|
+
-----
|
523
|
+
- This class inherits all retrieval utilities from :py:class:`~.Delay`:
|
524
|
+
use :py:meth:`retrieve_at_step` when you know the integer delay steps,
|
525
|
+
or :py:meth:`retrieve_at_time` for continuous-time queries with optional
|
526
|
+
linear/round interpolation.
|
527
|
+
- It is registered as an "after-update" hook on the owning Dynamics so the
|
528
|
+
buffer is updated automatically after each simulation step.
|
529
|
+
|
530
|
+
Examples
|
531
|
+
--------
|
532
|
+
Access a neuron's membrane potential 5 ms in the past:
|
533
|
+
|
534
|
+
>>> import brainunit as u
|
535
|
+
>>> import brainstate as bst
|
536
|
+
>>> lif = bst.nn.LIF(100)
|
537
|
+
>>> # Create a delayed accessor to V(t-5ms)
|
538
|
+
>>> v_delay = lif.prefetch_delay('V', 5.0 * u.ms)
|
539
|
+
>>> # Inside another module's update you can read the delayed value
|
540
|
+
>>> v_t_minus_5ms = v_delay()
|
541
|
+
|
542
|
+
Register multiple delay taps and index-specific delays:
|
543
|
+
|
544
|
+
>>> # Under the hood, a StateWithDelay is created and you can register
|
545
|
+
>>> # additional taps (in steps or time) via its Delay interface
|
546
|
+
>>> _ = lif.prefetch('V').delay.at(2.0 * u.ms) # additional delay
|
547
|
+
>>> # Direct access to buffer by steps (advanced)
|
548
|
+
>>> # lif._get_after_update('V-prefetch-delay').retrieve_at_step(3)
|
476
549
|
"""
|
477
550
|
|
478
551
|
__module__ = 'brainstate.nn'
|
479
552
|
|
480
553
|
state: State # state
|
481
554
|
|
482
|
-
def __init__(
|
483
|
-
|
555
|
+
def __init__(
|
556
|
+
self,
|
557
|
+
target: Node,
|
558
|
+
item: str,
|
559
|
+
init: Callable = None,
|
560
|
+
delay_method: Optional[str] = _DELAY_ROTATE,
|
561
|
+
):
|
562
|
+
super().__init__(None, init=init, delay_method=delay_method)
|
484
563
|
|
485
564
|
self._target = target
|
486
565
|
self._target_term = item
|
@@ -1,9 +1,9 @@
|
|
1
|
-
brainstate/__init__.py,sha256=
|
1
|
+
brainstate/__init__.py,sha256=lG0hJsHre06CcJMm_Em25hkKKFH9J8ZqnyGPq3iixZI,1451
|
2
2
|
brainstate/_compatible_import.py,sha256=kCJy0OIr2VAJHqyk2bdAZ1s2VAFKeEgOpfFosy9wi7A,4482
|
3
3
|
brainstate/_state.py,sha256=iZeLyjaCG39yXHh7y5LkOC2_MwkLgEnnKKr6puHkeME,56966
|
4
4
|
brainstate/_state_test.py,sha256=UqbXHhJNAHLehvVMnxnOUfWT1PVRWFawOvoyjJvGIRo,1586
|
5
5
|
brainstate/_utils.py,sha256=44Yy4cBlsSfZln7CEF8XfNCsZiIIDPPmC9LT17OOi5s,1610
|
6
|
-
brainstate/environ.py,sha256=
|
6
|
+
brainstate/environ.py,sha256=mVIb_4KUP7s26tBMIuEfoo47Q6lcnY_XlCIE5rRO5m8,17230
|
7
7
|
brainstate/environ_test.py,sha256=KYnPRv-ZgNDrvoTyNGuyO5ElLBoSFR4AN-B1hi2tp4k,1983
|
8
8
|
brainstate/mixin.py,sha256=88obor0L9qhoj4Kt_Q-dID9ZyPO-P7pasgbbykdWeoA,10651
|
9
9
|
brainstate/mixin_test.py,sha256=xhKEQMvpHQE74o_hQ88EID-mL_tSF7eStCSCVUfY5Tk,3463
|
@@ -57,7 +57,7 @@ brainstate/nn/_collective_ops_test.py,sha256=bZlWQDldsdaX89exbhnXPTP-sONrk6riii3
|
|
57
57
|
brainstate/nn/_common.py,sha256=N3AaSqRLDOtdynGE_xO03EJXvyh55G6O1q1ZrHKkhf8,6253
|
58
58
|
brainstate/nn/_conv.py,sha256=r77NK9xAUy4l6bh680wAlV69FzzQzLE56gcxlLKn5as,17947
|
59
59
|
brainstate/nn/_conv_test.py,sha256=Ekkra0Inn0aiBTJcF7orrrlpWXWs1Vv0xjcJxQ9GiDY,8624
|
60
|
-
brainstate/nn/_delay.py,sha256=
|
60
|
+
brainstate/nn/_delay.py,sha256=jMCvnYrivXJwAmZQBfLxM29wSlkgmW2FudXGT_yt8kk,23051
|
61
61
|
brainstate/nn/_delay_test.py,sha256=p0YbiqpqRe_ulhFr9qDmMt2qihXg5En9O_hWxAlHFVc,10158
|
62
62
|
brainstate/nn/_dropout.py,sha256=xiKeTsLdq5a3kCmhjf9XzuTc2VMjF6NEqJFLUqqKfKw,17357
|
63
63
|
brainstate/nn/_dropout_test.py,sha256=J0Ju3weOWWk6ZYkG7_3At8Kq-xnE5WK8_svfZBJAq04,4346
|
@@ -123,8 +123,8 @@ brainstate/util/pretty_repr.py,sha256=DVDwNRfXFrYe_j2HPJ9-1rur5tJ_YXMduImUOwjf7c
|
|
123
123
|
brainstate/util/pretty_table.py,sha256=qiEA3lSd9l4-Evia2KSu_KSw-F8p2BmyB7XepLpDVlk,105163
|
124
124
|
brainstate/util/scaling.py,sha256=Y4kYCr3dDmn808VUCY3i_L1XFLrUSOkRJykJukohCBA,7266
|
125
125
|
brainstate/util/struct.py,sha256=RBvB_LZyAWt6-3SHJnUfS3pE7D4pcEdrYEPbjw_fGfU,17005
|
126
|
-
brainstate-0.1.
|
127
|
-
brainstate-0.1.
|
128
|
-
brainstate-0.1.
|
129
|
-
brainstate-0.1.
|
130
|
-
brainstate-0.1.
|
126
|
+
brainstate-0.1.10.dist-info/licenses/LICENSE,sha256=RJ40fox7u2in2H8wvIS5DsPGlNHaA7JI024thFUlaZE,11348
|
127
|
+
brainstate-0.1.10.dist-info/METADATA,sha256=uZXs-VisW59P3ZC1GALwziVeF-XctLimfSfEbsIvvvI,3626
|
128
|
+
brainstate-0.1.10.dist-info/WHEEL,sha256=JNWh1Fm1UdwIQV075glCn4MVuCRs0sotJIq-J6rbxCU,109
|
129
|
+
brainstate-0.1.10.dist-info/top_level.txt,sha256=eQbGgKn0ptx7FDWuua0V0wr4K1VHi2iOUCYo3fUQBRA,11
|
130
|
+
brainstate-0.1.10.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|