braintrace 0.2.1__tar.gz → 0.2.2__tar.gz
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.
- {braintrace-0.2.1 → braintrace-0.2.2}/PKG-INFO +6 -4
- {braintrace-0.2.1 → braintrace-0.2.2}/README.md +1 -0
- {braintrace-0.2.1 → braintrace-0.2.2}/braintrace/__init__.py +5 -3
- braintrace-0.2.1/braintrace/api_contract_test.py → braintrace-0.2.2/braintrace/__init___test.py +65 -19
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm}/_common.py +1 -1
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm}/_common_test.py +2 -2
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm}/base.py +56 -5
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm}/base_test.py +25 -2
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm}/d_rtrl_test.py +80 -228
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm}/e_prop.py +3 -6
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm}/e_prop_test.py +32 -6
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm}/graph_executor.py +18 -60
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm}/graph_executor_test.py +1 -1
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm}/io_dim_vjp.py +28 -10
- braintrace-0.2.2/braintrace/_algorithm/io_dim_vjp_test.py +423 -0
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm}/oracle_test.py +29 -13
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm}/ostl.py +10 -7
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm}/ostl_test.py +44 -8
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm}/osttp.py +8 -4
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm}/osttp_test.py +33 -5
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm}/otpe.py +5 -6
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm}/otpe_test.py +30 -4
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm}/ottt.py +5 -6
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm}/ottt_test.py +30 -4
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm}/param_dim_vjp.py +83 -68
- braintrace-0.2.2/braintrace/_algorithm/param_dim_vjp_test.py +459 -0
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm}/pp_prop.py +2 -3
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm}/pp_prop_test.py +31 -5
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm/tests}/approx_correctness_test.py +2 -2
- braintrace-0.2.2/braintrace/_algorithm/tests/conv_vmap_correctness_test.py +327 -0
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm/tests}/cross_check_test.py +3 -3
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm/tests}/diagnostic_exploration_test.py +2 -5
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm/tests}/exact_correctness_test.py +2 -2
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm/tests}/public_api_test.py +1 -1
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm/tests}/scan_fusion_test.py +2 -2
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm/tests}/transform_correctness_test.py +3 -3
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm}/vjp_base.py +14 -2
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm}/vjp_base_test.py +5 -5
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm}/vjp_graph_executor.py +35 -32
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm}/vjp_graph_executor_test.py +1 -1
- braintrace-0.2.2/braintrace/_compile.py +300 -0
- braintrace-0.2.2/braintrace/_compile_test.py +435 -0
- {braintrace-0.2.1/braintrace/_etrace_compiler → braintrace-0.2.2/braintrace/_compiler}/__init__.py +10 -7
- {braintrace-0.2.1/braintrace/_etrace_compiler → braintrace-0.2.2/braintrace/_compiler}/base.py +2 -2
- {braintrace-0.2.1/braintrace/_etrace_compiler → braintrace-0.2.2/braintrace/_compiler}/base_test.py +13 -9
- {braintrace-0.2.1/braintrace/_etrace_compiler → braintrace-0.2.2/braintrace/_compiler}/diagnostics_test.py +1 -1
- {braintrace-0.2.1/braintrace/_etrace_compiler → braintrace-0.2.2/braintrace/_compiler}/graph.py +15 -1
- {braintrace-0.2.1/braintrace/_etrace_compiler → braintrace-0.2.2/braintrace/_compiler}/graph_test.py +1 -1
- {braintrace-0.2.1/braintrace/_etrace_compiler → braintrace-0.2.2/braintrace/_compiler}/hid_param_op.py +2 -1
- {braintrace-0.2.1/braintrace/_etrace_compiler → braintrace-0.2.2/braintrace/_compiler}/hid_param_op_test.py +4 -4
- {braintrace-0.2.1/braintrace/_etrace_compiler → braintrace-0.2.2/braintrace/_compiler}/hidden_group.py +272 -13
- {braintrace-0.2.1/braintrace/_etrace_compiler → braintrace-0.2.2/braintrace/_compiler}/hidden_group_test.py +268 -4
- {braintrace-0.2.1/braintrace/_etrace_compiler → braintrace-0.2.2/braintrace/_compiler}/hidden_pertubation.py +3 -2
- {braintrace-0.2.1/braintrace/_etrace_compiler → braintrace-0.2.2/braintrace/_compiler}/hidden_pertubation_test.py +2 -2
- {braintrace-0.2.1/braintrace/_etrace_compiler → braintrace-0.2.2/braintrace/_compiler}/model4test.py +1 -1
- {braintrace-0.2.1/braintrace/_etrace_compiler → braintrace-0.2.2/braintrace/_compiler}/module_info.py +1 -1
- {braintrace-0.2.1/braintrace/_etrace_compiler → braintrace-0.2.2/braintrace/_compiler}/module_info_test.py +1 -1
- braintrace-0.2.2/braintrace/_compiler/report.py +231 -0
- braintrace-0.2.2/braintrace/_compiler/report_test.py +53 -0
- {braintrace-0.2.1/braintrace/_etrace_compiler → braintrace-0.2.2/braintrace/_compiler}/scenario_catalog_test.py +4 -4
- {braintrace-0.2.1/braintrace/_etrace_compiler → braintrace-0.2.2/braintrace/_compiler/tests}/cell_relation_guardrail_test.py +1 -1
- {braintrace-0.2.1/braintrace/_etrace_compiler → braintrace-0.2.2/braintrace/_compiler/tests}/compiler_oracle_test.py +1 -1
- {braintrace-0.2.1/braintrace/_etrace_compiler → braintrace-0.2.2/braintrace/_compiler/tests}/compiler_property_test.py +2 -2
- braintrace-0.2.2/braintrace/_docs_examples_test.py +247 -0
- {braintrace-0.2.1 → braintrace-0.2.2}/braintrace/_etrace_model_test.py +1 -1
- {braintrace-0.2.1 → braintrace-0.2.2}/braintrace/_grad_exponential.py +3 -3
- braintrace-0.2.2/braintrace/_grad_exponential_test.py +82 -0
- {braintrace-0.2.1 → braintrace-0.2.2}/braintrace/_legacy/_ops.py +5 -5
- braintrace-0.2.2/braintrace/_legacy/_ops_test.py +185 -0
- {braintrace-0.2.1 → braintrace-0.2.2}/braintrace/_legacy/_params.py +7 -7
- braintrace-0.2.1/braintrace/_legacy/_legacy_test.py → braintrace-0.2.2/braintrace/_legacy/_params_test.py +6 -134
- {braintrace-0.2.1 → braintrace-0.2.2}/braintrace/_misc.py +1 -1
- braintrace-0.2.2/braintrace/_misc_test.py +163 -0
- {braintrace-0.2.1/braintrace/_etrace_op → braintrace-0.2.2/braintrace/_op}/__init__.py +2 -2
- {braintrace-0.2.1/braintrace/_etrace_op → braintrace-0.2.2/braintrace/_op}/_primitive_test.py +1 -1
- {braintrace-0.2.1/braintrace/_etrace_op → braintrace-0.2.2/braintrace/_op}/_registries_test.py +4 -4
- {braintrace-0.2.1/braintrace/_etrace_op → braintrace-0.2.2/braintrace/_op}/conv.py +2 -2
- {braintrace-0.2.1/braintrace/_etrace_op → braintrace-0.2.2/braintrace/_op}/conv_test.py +5 -5
- {braintrace-0.2.1/braintrace/_etrace_op → braintrace-0.2.2/braintrace/_op}/dense.py +1 -1
- {braintrace-0.2.1/braintrace/_etrace_op → braintrace-0.2.2/braintrace/_op}/dense_test.py +8 -8
- {braintrace-0.2.1/braintrace/_etrace_op → braintrace-0.2.2/braintrace/_op}/elemwise.py +26 -10
- {braintrace-0.2.1/braintrace/_etrace_op → braintrace-0.2.2/braintrace/_op}/elemwise_test.py +6 -6
- {braintrace-0.2.1/braintrace/_etrace_op → braintrace-0.2.2/braintrace/_op}/lora.py +1 -1
- {braintrace-0.2.1/braintrace/_etrace_op → braintrace-0.2.2/braintrace/_op}/lora_test.py +4 -4
- {braintrace-0.2.1/braintrace/_etrace_op → braintrace-0.2.2/braintrace/_op}/op_rule_oracle_test.py +7 -7
- {braintrace-0.2.1/braintrace/_etrace_op → braintrace-0.2.2/braintrace/_op}/sparse.py +2 -2
- {braintrace-0.2.1/braintrace/_etrace_op → braintrace-0.2.2/braintrace/_op}/sparse_test.py +7 -7
- {braintrace-0.2.1 → braintrace-0.2.2}/braintrace/_state_managment.py +0 -1
- braintrace-0.2.2/braintrace/_state_managment_test.py +108 -0
- {braintrace-0.2.1 → braintrace-0.2.2}/braintrace/_version.py +1 -1
- {braintrace-0.2.1 → braintrace-0.2.2}/braintrace/nn/_conv.py +1 -1
- {braintrace-0.2.1 → braintrace-0.2.2}/braintrace/nn/_conv_test.py +1 -1
- {braintrace-0.2.1 → braintrace-0.2.2}/braintrace/nn/_linear.py +29 -6
- {braintrace-0.2.1 → braintrace-0.2.2}/braintrace/nn/_linear_test.py +119 -1
- {braintrace-0.2.1 → braintrace-0.2.2}/braintrace/nn/_readout.py +4 -4
- {braintrace-0.2.1 → braintrace-0.2.2}/braintrace/nn/_readout_test.py +1 -1
- {braintrace-0.2.1 → braintrace-0.2.2}/braintrace/nn/_rnn.py +8 -8
- {braintrace-0.2.1 → braintrace-0.2.2}/braintrace/nn/_rnn_test.py +2 -2
- {braintrace-0.2.1 → braintrace-0.2.2}/braintrace.egg-info/PKG-INFO +6 -4
- braintrace-0.2.2/braintrace.egg-info/SOURCES.txt +121 -0
- {braintrace-0.2.1 → braintrace-0.2.2}/braintrace.egg-info/requires.txt +4 -3
- {braintrace-0.2.1 → braintrace-0.2.2}/pyproject.toml +49 -7
- braintrace-0.2.1/braintrace/_compile.py +0 -153
- braintrace-0.2.1/braintrace/_compile_test.py +0 -125
- braintrace-0.2.1/braintrace/legacy_deprecation_test.py +0 -53
- braintrace-0.2.1/braintrace.egg-info/SOURCES.txt +0 -112
- {braintrace-0.2.1 → braintrace-0.2.2}/LICENSE +0 -0
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm}/__init__.py +0 -0
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm}/d_rtrl.py +0 -0
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm}/oracle.py +0 -0
- {braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm}/oracle_models.py +0 -0
- {braintrace-0.2.1 → braintrace-0.2.2}/braintrace/_compatible_imports.py +0 -0
- {braintrace-0.2.1 → braintrace-0.2.2}/braintrace/_compatible_imports_test.py +0 -0
- {braintrace-0.2.1/braintrace/_etrace_compiler → braintrace-0.2.2/braintrace/_compiler}/diagnostics.py +0 -0
- {braintrace-0.2.1/braintrace/_etrace_compiler → braintrace-0.2.2/braintrace/_compiler}/scenario_catalog.py +0 -0
- {braintrace-0.2.1 → braintrace-0.2.2}/braintrace/_input_data.py +0 -0
- {braintrace-0.2.1 → braintrace-0.2.2}/braintrace/_input_data_test.py +0 -0
- {braintrace-0.2.1 → braintrace-0.2.2}/braintrace/_legacy/__init__.py +0 -0
- {braintrace-0.2.1/braintrace/_etrace_op → braintrace-0.2.2/braintrace/_op}/_primitive.py +0 -0
- {braintrace-0.2.1/braintrace/_etrace_op → braintrace-0.2.2/braintrace/_op}/_registries.py +0 -0
- {braintrace-0.2.1/braintrace/_etrace_op → braintrace-0.2.2/braintrace/_op}/op_rule_oracle.py +0 -0
- {braintrace-0.2.1 → braintrace-0.2.2}/braintrace/_typing.py +0 -0
- {braintrace-0.2.1 → braintrace-0.2.2}/braintrace/nn/__init__.py +0 -0
- {braintrace-0.2.1 → braintrace-0.2.2}/braintrace/py.typed +0 -0
- {braintrace-0.2.1 → braintrace-0.2.2}/braintrace.egg-info/dependency_links.txt +0 -0
- {braintrace-0.2.1 → braintrace-0.2.2}/braintrace.egg-info/top_level.txt +0 -0
- {braintrace-0.2.1 → braintrace-0.2.2}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: braintrace
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: Enabling Scalable Online Learning for Brain Dynamics.
|
|
5
5
|
Author-email: BrainTrace Developers <chao.brain@qq.com>
|
|
6
6
|
License: Apache-2.0 license
|
|
@@ -26,10 +26,9 @@ Classifier: Topic :: Software Development :: Libraries
|
|
|
26
26
|
Requires-Python: >=3.11
|
|
27
27
|
Description-Content-Type: text/markdown
|
|
28
28
|
License-File: LICENSE
|
|
29
|
-
Requires-Dist: brainstate>=0.
|
|
29
|
+
Requires-Dist: brainstate>=0.5.2
|
|
30
30
|
Requires-Dist: brainunit
|
|
31
|
-
Requires-Dist:
|
|
32
|
-
Requires-Dist: brainpy-state
|
|
31
|
+
Requires-Dist: brainpy.state
|
|
33
32
|
Requires-Dist: braintools
|
|
34
33
|
Provides-Extra: cpu
|
|
35
34
|
Requires-Dist: jax[cpu]; extra == "cpu"
|
|
@@ -41,10 +40,12 @@ Provides-Extra: tpu
|
|
|
41
40
|
Requires-Dist: jax[tpu]; extra == "tpu"
|
|
42
41
|
Provides-Extra: testing
|
|
43
42
|
Requires-Dist: pytest; extra == "testing"
|
|
43
|
+
Requires-Dist: pytest-cov; extra == "testing"
|
|
44
44
|
Requires-Dist: jax[cpu]; extra == "testing"
|
|
45
45
|
Requires-Dist: hypothesis; extra == "testing"
|
|
46
46
|
Provides-Extra: dev
|
|
47
47
|
Requires-Dist: pytest; extra == "dev"
|
|
48
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
48
49
|
Requires-Dist: jax[cpu]; extra == "dev"
|
|
49
50
|
Requires-Dist: hypothesis; extra == "dev"
|
|
50
51
|
Requires-Dist: mypy>=1.8; extra == "dev"
|
|
@@ -64,6 +65,7 @@ Dynamic: license-file
|
|
|
64
65
|
<a href="https://brainx.chaobrain.com/braintrace/"><img alt="Documentation" src="https://readthedocs.org/projects/braintrace/badge/?version=latest"></a>
|
|
65
66
|
<a href="https://badge.fury.io/py/braintrace"><img alt="PyPI version" src="https://badge.fury.io/py/braintrace.svg"></a>
|
|
66
67
|
<a href="https://github.com/chaobrain/braintrace/actions/workflows/CI.yml"><img alt="Continuous Integration" src="https://github.com/chaobrain/braintrace/actions/workflows/CI.yml/badge.svg"></a>
|
|
68
|
+
<a href="https://codecov.io/gh/chaobrain/braintrace"><img alt="Code Coverage" src="https://codecov.io/gh/chaobrain/braintrace/branch/main/graph/badge.svg"></a>
|
|
67
69
|
</p>
|
|
68
70
|
|
|
69
71
|
[``braintrace``](https://github.com/chaobrain/braintrace) provides online learning algorithms for biological neural networks.
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
<a href="https://brainx.chaobrain.com/braintrace/"><img alt="Documentation" src="https://readthedocs.org/projects/braintrace/badge/?version=latest"></a>
|
|
12
12
|
<a href="https://badge.fury.io/py/braintrace"><img alt="PyPI version" src="https://badge.fury.io/py/braintrace.svg"></a>
|
|
13
13
|
<a href="https://github.com/chaobrain/braintrace/actions/workflows/CI.yml"><img alt="Continuous Integration" src="https://github.com/chaobrain/braintrace/actions/workflows/CI.yml/badge.svg"></a>
|
|
14
|
+
<a href="https://codecov.io/gh/chaobrain/braintrace"><img alt="Code Coverage" src="https://codecov.io/gh/chaobrain/braintrace/branch/main/graph/badge.svg"></a>
|
|
14
15
|
</p>
|
|
15
16
|
|
|
16
17
|
[``braintrace``](https://github.com/chaobrain/braintrace) provides online learning algorithms for biological neural networks.
|
|
@@ -70,7 +70,7 @@ from typing import TYPE_CHECKING
|
|
|
70
70
|
|
|
71
71
|
from . import nn
|
|
72
72
|
from ._compile import compile
|
|
73
|
-
from .
|
|
73
|
+
from ._algorithm import (
|
|
74
74
|
ETraceAlgorithm,
|
|
75
75
|
EligibilityTrace,
|
|
76
76
|
ETraceGraphExecutor,
|
|
@@ -91,7 +91,7 @@ from ._etrace_algorithms import (
|
|
|
91
91
|
KappaFilter,
|
|
92
92
|
PresynapticTrace,
|
|
93
93
|
)
|
|
94
|
-
from .
|
|
94
|
+
from ._compiler import (
|
|
95
95
|
ETraceGraph,
|
|
96
96
|
compile_etrace_graph,
|
|
97
97
|
HiddenParamOpRelation,
|
|
@@ -106,10 +106,11 @@ from ._etrace_compiler import (
|
|
|
106
106
|
ModuleInfo,
|
|
107
107
|
extract_module_info,
|
|
108
108
|
CompilationRecord,
|
|
109
|
+
CompilationReport,
|
|
109
110
|
DiagnosticKind,
|
|
110
111
|
DiagnosticLevel,
|
|
111
112
|
)
|
|
112
|
-
from .
|
|
113
|
+
from ._op import (
|
|
113
114
|
ETPPrimitive,
|
|
114
115
|
matmul,
|
|
115
116
|
element_wise,
|
|
@@ -198,6 +199,7 @@ __all__ = [
|
|
|
198
199
|
|
|
199
200
|
# compiler diagnostics
|
|
200
201
|
'CompilationRecord',
|
|
202
|
+
'CompilationReport',
|
|
201
203
|
'DiagnosticKind',
|
|
202
204
|
'DiagnosticLevel',
|
|
203
205
|
|
braintrace-0.2.1/braintrace/api_contract_test.py → braintrace-0.2.2/braintrace/__init___test.py
RENAMED
|
@@ -13,10 +13,18 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
# ==============================================================================
|
|
15
15
|
|
|
16
|
-
"""
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
"""Tests for the ``braintrace`` package root (``braintrace/__init__.py``).
|
|
17
|
+
|
|
18
|
+
Two concerns, both owned by the package root:
|
|
19
|
+
|
|
20
|
+
* **Public-API contract** — every ``braintrace.__all__`` symbol resolves to a
|
|
21
|
+
usable object; public algorithms run a minimal end-to-end step; documented
|
|
22
|
+
error paths fire on their real triggers; legacy/nn deprecations warn; and the
|
|
23
|
+
implementation facts that drifted from CLAUDE.md (F-17) stay pinned.
|
|
24
|
+
* **Legacy deprecation forwarding** — the v0.1.x shims served lazily by
|
|
25
|
+
``__getattr__`` warn on access, stay out of ``__all__``, and appear in
|
|
26
|
+
``__dir__``.
|
|
27
|
+
"""
|
|
20
28
|
|
|
21
29
|
import brainstate
|
|
22
30
|
import jax
|
|
@@ -24,8 +32,13 @@ import jax.numpy as jnp
|
|
|
24
32
|
import pytest
|
|
25
33
|
|
|
26
34
|
import braintrace
|
|
27
|
-
|
|
35
|
+
import braintrace._legacy as legacy
|
|
36
|
+
from braintrace._algorithm.oracle_models import tanh_rnn
|
|
37
|
+
|
|
28
38
|
|
|
39
|
+
# ===========================================================================
|
|
40
|
+
# Public-API contract
|
|
41
|
+
# ===========================================================================
|
|
29
42
|
|
|
30
43
|
# --- Task 1: every __all__ symbol resolves to a non-None object --------------
|
|
31
44
|
|
|
@@ -130,18 +143,12 @@ def test_dynamic_weight_assignment_raises_not_supported():
|
|
|
130
143
|
|
|
131
144
|
# --- Task 5: weight inside control flow raises NotImplementedError -----------
|
|
132
145
|
|
|
133
|
-
@pytest.mark.xfail(
|
|
134
|
-
strict=True,
|
|
135
|
-
reason="F-SCAN-WEIGHT: the weight-in-control-flow guard intends to raise "
|
|
136
|
-
"NotImplementedError, but its error-message construction at "
|
|
137
|
-
"base.py:133 indexes invar_to_hidden_path with the *weight* var "
|
|
138
|
-
"(absent from that hidden-path map), so a KeyError escapes instead. "
|
|
139
|
-
"The guard fires, but the wrong exception type surfaces.",
|
|
140
|
-
)
|
|
141
146
|
def test_weight_used_inside_scan_raises_not_implemented():
|
|
142
|
-
"""check_unsupported_op
|
|
143
|
-
|
|
144
|
-
|
|
147
|
+
"""check_unsupported_op raises NotImplementedError when a weight var is used
|
|
148
|
+
within a control-flow op. Previously (F-SCAN-WEIGHT) the message construction
|
|
149
|
+
indexed the hidden-path map with the weight var and a KeyError escaped instead;
|
|
150
|
+
the message now renders the weight variable directly, so the intended
|
|
151
|
+
NotImplementedError surfaces."""
|
|
145
152
|
|
|
146
153
|
class ScanModel(brainstate.nn.Module):
|
|
147
154
|
def __init__(self):
|
|
@@ -193,8 +200,8 @@ def test_nn_unknown_name_raises_attribute_error():
|
|
|
193
200
|
# --- Task 7: lock the drifted implementation facts (F-17) --------------------
|
|
194
201
|
|
|
195
202
|
def test_ostl_is_two_classes_not_a_factory():
|
|
196
|
-
from braintrace.
|
|
197
|
-
from braintrace.
|
|
203
|
+
from braintrace._algorithm.param_dim_vjp import ParamDimVjpAlgorithm
|
|
204
|
+
from braintrace._algorithm.io_dim_vjp import IODimVjpAlgorithm
|
|
198
205
|
assert isinstance(braintrace.OSTLRecurrent, type)
|
|
199
206
|
assert isinstance(braintrace.OSTLFeedforward, type)
|
|
200
207
|
assert issubclass(braintrace.OSTLRecurrent, ParamDimVjpAlgorithm)
|
|
@@ -202,7 +209,7 @@ def test_ostl_is_two_classes_not_a_factory():
|
|
|
202
209
|
|
|
203
210
|
|
|
204
211
|
def test_iodim_lives_in_io_dim_vjp_module():
|
|
205
|
-
from braintrace.
|
|
212
|
+
from braintrace._algorithm.io_dim_vjp import IODimVjpAlgorithm
|
|
206
213
|
assert braintrace.IODimVjpAlgorithm is IODimVjpAlgorithm
|
|
207
214
|
assert braintrace.pp_prop is braintrace.ES_D_RTRL # aliases
|
|
208
215
|
|
|
@@ -212,3 +219,42 @@ def test_expected_rnn_cells_exist():
|
|
|
212
219
|
for cell in ('ValinaRNNCell', 'GRUCell', 'MGUCell', 'LSTMCell', 'URLSTMCell',
|
|
213
220
|
'MinimalRNNCell', 'MiniGRU', 'MiniLSTM', 'LRUCell'):
|
|
214
221
|
assert hasattr(nn, cell), f"missing cell: {cell}"
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
# ===========================================================================
|
|
225
|
+
# Legacy v0.1.x deprecation forwarding
|
|
226
|
+
# ===========================================================================
|
|
227
|
+
|
|
228
|
+
_LEGACY_NAMES = [
|
|
229
|
+
'ETraceOp', 'MatMulOp', 'ElemWiseOp', 'ConvOp', 'SpMatMulOp', 'LoraOp',
|
|
230
|
+
'ETraceParam', 'ElemWiseParam', 'NonTempParam',
|
|
231
|
+
'FakeETraceParam', 'FakeElemWiseParam',
|
|
232
|
+
]
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
@pytest.mark.parametrize('name', _LEGACY_NAMES)
|
|
236
|
+
def test_legacy_access_warns_and_returns_class(name):
|
|
237
|
+
with pytest.warns(DeprecationWarning):
|
|
238
|
+
obj = getattr(braintrace, name)
|
|
239
|
+
assert obj is getattr(legacy, name)
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
@pytest.mark.parametrize('name', _LEGACY_NAMES)
|
|
243
|
+
def test_legacy_names_not_in_all(name):
|
|
244
|
+
assert name not in braintrace.__all__
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
def test_from_import_warns():
|
|
248
|
+
with pytest.warns(DeprecationWarning):
|
|
249
|
+
from braintrace import MatMulOp # noqa: F401
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def test_unknown_attribute_raises_attribute_error():
|
|
253
|
+
with pytest.raises(AttributeError):
|
|
254
|
+
_ = braintrace.ThisNameDoesNotExist
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def test_legacy_names_in_dir():
|
|
258
|
+
d = dir(braintrace)
|
|
259
|
+
for name in _LEGACY_NAMES:
|
|
260
|
+
assert name in d
|
|
@@ -20,9 +20,9 @@ import jax
|
|
|
20
20
|
import jax.numpy as jnp
|
|
21
21
|
import numpy.testing as npt
|
|
22
22
|
import pytest
|
|
23
|
-
import
|
|
23
|
+
import brainunit as u
|
|
24
24
|
|
|
25
|
-
from braintrace.
|
|
25
|
+
from braintrace._algorithm._common import (
|
|
26
26
|
FixedRandomFeedback,
|
|
27
27
|
KappaFilter,
|
|
28
28
|
PresynapticTrace,
|
{braintrace-0.2.1/braintrace/_etrace_algorithms → braintrace-0.2.2/braintrace/_algorithm}/base.py
RENAMED
|
@@ -23,7 +23,7 @@ from typing import Dict, Any, Optional
|
|
|
23
23
|
|
|
24
24
|
import brainstate
|
|
25
25
|
|
|
26
|
-
from braintrace.
|
|
26
|
+
from braintrace._compiler import ETraceGraph, CompilationReport
|
|
27
27
|
from .graph_executor import ETraceGraphExecutor
|
|
28
28
|
from .._typing import Path
|
|
29
29
|
|
|
@@ -131,6 +131,28 @@ class ETraceAlgorithm(brainstate.nn.Module):
|
|
|
131
131
|
"""
|
|
132
132
|
return self.graph_executor.graph
|
|
133
133
|
|
|
134
|
+
@property
|
|
135
|
+
def report(self) -> CompilationReport:
|
|
136
|
+
"""Structured, read-only report of the compiled eligibility-trace graph.
|
|
137
|
+
|
|
138
|
+
Returns
|
|
139
|
+
-------
|
|
140
|
+
CompilationReport
|
|
141
|
+
A view over :attr:`graph`.
|
|
142
|
+
|
|
143
|
+
Raises
|
|
144
|
+
------
|
|
145
|
+
RuntimeError
|
|
146
|
+
If accessed before the graph has been compiled.
|
|
147
|
+
"""
|
|
148
|
+
if not self.is_compiled:
|
|
149
|
+
raise RuntimeError(
|
|
150
|
+
'The eligibility-trace graph is not compiled yet. Build the '
|
|
151
|
+
'learner with braintrace.compile(...) (or call .compile_graph(...)) '
|
|
152
|
+
'before accessing .report.'
|
|
153
|
+
)
|
|
154
|
+
return CompilationReport(self.graph)
|
|
155
|
+
|
|
134
156
|
@property
|
|
135
157
|
def executor(self) -> ETraceGraphExecutor:
|
|
136
158
|
"""
|
|
@@ -222,6 +244,18 @@ class ETraceAlgorithm(brainstate.nn.Module):
|
|
|
222
244
|
The input arguments.
|
|
223
245
|
"""
|
|
224
246
|
|
|
247
|
+
# ``vmap_new_states`` / ``vmap2_new_states`` run an eager *discovery
|
|
248
|
+
# probe* that executes the surrounding ``init`` (including this call)
|
|
249
|
+
# once against throwaway, un-batched states before the real mapped
|
|
250
|
+
# pass. Compiling there would bind the executor to those probe states
|
|
251
|
+
# (which are discarded and left untagged), so the subsequent
|
|
252
|
+
# ``brainstate.nn.Vmap(..., vmap_states='new')`` would not cover them
|
|
253
|
+
# and writing a batched value raises ``BatchAxisError``. Defer to the
|
|
254
|
+
# real mapped pass, which creates the 'new'-tagged batched states.
|
|
255
|
+
_in_probe = getattr(brainstate.transform, 'in_new_state_probe', None)
|
|
256
|
+
if _in_probe is not None and _in_probe():
|
|
257
|
+
return
|
|
258
|
+
|
|
225
259
|
if not self.is_compiled:
|
|
226
260
|
# --- invalidate cached state splits --- #
|
|
227
261
|
self._param_states = None
|
|
@@ -261,11 +295,28 @@ class ETraceAlgorithm(brainstate.nn.Module):
|
|
|
261
295
|
"""
|
|
262
296
|
return self.graph_executor.state_id_to_path
|
|
263
297
|
|
|
264
|
-
def show_graph(
|
|
265
|
-
|
|
266
|
-
|
|
298
|
+
def show_graph(
|
|
299
|
+
self,
|
|
300
|
+
verbose: bool = True,
|
|
301
|
+
return_msg: bool = False,
|
|
302
|
+
) -> None | str:
|
|
303
|
+
"""Display the eligibility-trace graph.
|
|
304
|
+
|
|
305
|
+
Delegates to :meth:`ETraceGraphExecutor.show_graph`.
|
|
306
|
+
|
|
307
|
+
Parameters
|
|
308
|
+
----------
|
|
309
|
+
verbose : bool, optional
|
|
310
|
+
If True (default), print the summary to stdout.
|
|
311
|
+
return_msg : bool, optional
|
|
312
|
+
If True, return the summary string. Default False.
|
|
313
|
+
|
|
314
|
+
Returns
|
|
315
|
+
-------
|
|
316
|
+
None or str
|
|
317
|
+
The summary string if ``return_msg`` is True, else None.
|
|
267
318
|
"""
|
|
268
|
-
self.graph_executor.show_graph()
|
|
319
|
+
return self.graph_executor.show_graph(verbose=verbose, return_msg=return_msg)
|
|
269
320
|
|
|
270
321
|
def __call__(self, *args) -> Any:
|
|
271
322
|
"""
|
|
@@ -21,8 +21,8 @@ import brainstate
|
|
|
21
21
|
import jax.numpy as jnp
|
|
22
22
|
|
|
23
23
|
import braintrace
|
|
24
|
-
from braintrace.
|
|
25
|
-
from braintrace.
|
|
24
|
+
from braintrace._algorithm import ETraceAlgorithm, EligibilityTrace
|
|
25
|
+
from braintrace._algorithm.graph_executor import ETraceGraphExecutor
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
# ---------------------------------------------------------------------------
|
|
@@ -580,5 +580,28 @@ class TestETraceAlgorithmTwoLayerIntegration(unittest.TestCase):
|
|
|
580
580
|
self.assertGreaterEqual(len(algo.hidden_states), 2)
|
|
581
581
|
|
|
582
582
|
|
|
583
|
+
def test_report_before_compile_raises():
|
|
584
|
+
import brainstate, pytest, braintrace
|
|
585
|
+
from braintrace._algorithm.oracle_models import tanh_rnn
|
|
586
|
+
model = tanh_rnn(n_in=3, n_rec=4, seed=0).factory()
|
|
587
|
+
brainstate.nn.init_all_states(model, batch_size=1)
|
|
588
|
+
algo = braintrace.D_RTRL(model)
|
|
589
|
+
with pytest.raises(RuntimeError):
|
|
590
|
+
_ = algo.report
|
|
591
|
+
|
|
592
|
+
|
|
593
|
+
def test_report_after_compile_matches_show_graph():
|
|
594
|
+
import brainstate, jax.numpy as jnp, braintrace
|
|
595
|
+
from braintrace import CompilationReport
|
|
596
|
+
from braintrace._algorithm.oracle_models import tanh_rnn
|
|
597
|
+
model = tanh_rnn(n_in=3, n_rec=4, seed=0).factory()
|
|
598
|
+
brainstate.nn.init_all_states(model, batch_size=1)
|
|
599
|
+
algo = braintrace.D_RTRL(model)
|
|
600
|
+
algo.compile_graph(jnp.ones((3,), 'float32'))
|
|
601
|
+
assert isinstance(algo.report, CompilationReport)
|
|
602
|
+
# show_graph(return_msg=True) is exactly report.to_str(1)
|
|
603
|
+
assert algo.show_graph(verbose=False, return_msg=True) == algo.report.to_str(1)
|
|
604
|
+
|
|
605
|
+
|
|
583
606
|
if __name__ == '__main__':
|
|
584
607
|
unittest.main()
|