sanafe 2.2.5__tar.gz → 2.2.7__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.
Files changed (113) hide show
  1. {sanafe-2.2.5 → sanafe-2.2.7}/CMakeLists.txt +34 -41
  2. {sanafe-2.2.5/sanafe.egg-info → sanafe-2.2.7}/PKG-INFO +1 -1
  3. {sanafe-2.2.5 → sanafe-2.2.7}/docs/conf.py +1 -1
  4. {sanafe-2.2.5 → sanafe-2.2.7}/plugins/neurofem.cpp +0 -2
  5. {sanafe-2.2.5 → sanafe-2.2.7}/pyproject.toml +20 -2
  6. {sanafe-2.2.5 → sanafe-2.2.7}/sanafe/__init__.py +1 -0
  7. {sanafe-2.2.5 → sanafe-2.2.7}/sanafe/_examples.py +8 -1
  8. {sanafe-2.2.5 → sanafe-2.2.7}/sanafe/data.py +10 -8
  9. {sanafe-2.2.5 → sanafe-2.2.7}/sanafe/fugu.py +35 -14
  10. sanafe-2.2.7/sanafe/lava.py +208 -0
  11. {sanafe-2.2.5 → sanafe-2.2.7}/sanafe/layers.py +15 -9
  12. {sanafe-2.2.5 → sanafe-2.2.7}/sanafe/tutorial.py +72 -59
  13. {sanafe-2.2.5 → sanafe-2.2.7}/sanafe/viz/performance.py +3 -0
  14. {sanafe-2.2.5 → sanafe-2.2.7}/sanafe/viz/potential.py +3 -1
  15. {sanafe-2.2.5 → sanafe-2.2.7}/sanafe/viz/raster.py +3 -1
  16. {sanafe-2.2.5 → sanafe-2.2.7}/sanafe/viz/styles.py +8 -7
  17. {sanafe-2.2.5 → sanafe-2.2.7/sanafe.egg-info}/PKG-INFO +1 -1
  18. {sanafe-2.2.5 → sanafe-2.2.7}/setup.py +18 -12
  19. {sanafe-2.2.5 → sanafe-2.2.7}/src/arch.cpp +2 -2
  20. {sanafe-2.2.5 → sanafe-2.2.7}/src/arg_parsing.cpp +1 -1
  21. {sanafe-2.2.5 → sanafe-2.2.7}/src/chip.cpp +13 -20
  22. {sanafe-2.2.5 → sanafe-2.2.7}/src/docstrings.hpp +7 -0
  23. {sanafe-2.2.5 → sanafe-2.2.7}/src/main.cpp +3 -3
  24. {sanafe-2.2.5 → sanafe-2.2.7}/src/mapped.cpp +5 -7
  25. {sanafe-2.2.5 → sanafe-2.2.7}/src/mapped.hpp +5 -3
  26. {sanafe-2.2.5 → sanafe-2.2.7}/src/message.cpp +5 -5
  27. {sanafe-2.2.5 → sanafe-2.2.7}/src/models.cpp +18 -17
  28. {sanafe-2.2.5 → sanafe-2.2.7}/src/netlist.cpp +16 -13
  29. {sanafe-2.2.5 → sanafe-2.2.7}/src/network.cpp +20 -11
  30. {sanafe-2.2.5 → sanafe-2.2.7}/src/network.hpp +2 -1
  31. {sanafe-2.2.5 → sanafe-2.2.7}/src/pipeline.cpp +2 -2
  32. {sanafe-2.2.5 → sanafe-2.2.7}/src/pymodule.cpp +4 -0
  33. {sanafe-2.2.5 → sanafe-2.2.7}/src/pytrace.hpp +1 -0
  34. {sanafe-2.2.5 → sanafe-2.2.7}/src/schedule.cpp +8 -1
  35. {sanafe-2.2.5 → sanafe-2.2.7}/src/yaml_arch.cpp +6 -1
  36. {sanafe-2.2.5 → sanafe-2.2.7}/src/yaml_common.cpp +8 -6
  37. {sanafe-2.2.5 → sanafe-2.2.7}/src/yaml_snn.cpp +10 -6
  38. {sanafe-2.2.5 → sanafe-2.2.7}/tests/python/test.py +1 -1
  39. sanafe-2.2.5/sanafe/lava.py +0 -104
  40. {sanafe-2.2.5 → sanafe-2.2.7}/LICENSE +0 -0
  41. {sanafe-2.2.5 → sanafe-2.2.7}/MANIFEST.in +0 -0
  42. {sanafe-2.2.5 → sanafe-2.2.7}/README.md +0 -0
  43. {sanafe-2.2.5 → sanafe-2.2.7}/docs/make_model_descriptions.py +0 -0
  44. {sanafe-2.2.5 → sanafe-2.2.7}/docs/make_references.py +0 -0
  45. {sanafe-2.2.5 → sanafe-2.2.7}/plugins/CMakeLists.txt +0 -0
  46. {sanafe-2.2.5 → sanafe-2.2.7}/plugins/hodgkin_huxley.cpp +0 -0
  47. {sanafe-2.2.5 → sanafe-2.2.7}/sanafe/examples/__init__.py +0 -0
  48. {sanafe-2.2.5 → sanafe-2.2.7}/sanafe/examples/dvs_challenge.npz +0 -0
  49. {sanafe-2.2.5 → sanafe-2.2.7}/sanafe/examples/example_chip.yaml +0 -0
  50. {sanafe-2.2.5 → sanafe-2.2.7}/sanafe/examples/example_snn.yaml +0 -0
  51. {sanafe-2.2.5 → sanafe-2.2.7}/sanafe/examples/loihi.yaml +0 -0
  52. {sanafe-2.2.5 → sanafe-2.2.7}/sanafe/examples/truenorth.yaml +0 -0
  53. {sanafe-2.2.5 → sanafe-2.2.7}/sanafe/examples/tutorial_arch.yaml +0 -0
  54. {sanafe-2.2.5 → sanafe-2.2.7}/sanafe/examples/tutorial_snn.yaml +0 -0
  55. {sanafe-2.2.5 → sanafe-2.2.7}/sanafe/viz/__init__.py +0 -0
  56. {sanafe-2.2.5 → sanafe-2.2.7}/sanafe.egg-info/SOURCES.txt +0 -0
  57. {sanafe-2.2.5 → sanafe-2.2.7}/sanafe.egg-info/dependency_links.txt +0 -0
  58. {sanafe-2.2.5 → sanafe-2.2.7}/sanafe.egg-info/requires.txt +0 -0
  59. {sanafe-2.2.5 → sanafe-2.2.7}/sanafe.egg-info/top_level.txt +0 -0
  60. {sanafe-2.2.5 → sanafe-2.2.7}/scripts/capstone2023/capstone_gui_runtime.py +0 -0
  61. {sanafe-2.2.5 → sanafe-2.2.7}/scripts/compare_spiketrains.py +0 -0
  62. {sanafe-2.2.5 → sanafe-2.2.7}/scripts/compress_spiketrain.py +0 -0
  63. {sanafe-2.2.5 → sanafe-2.2.7}/scripts/computer2026/combined.py +0 -0
  64. {sanafe-2.2.5 → sanafe-2.2.7}/scripts/computer2026/crossbar.py +0 -0
  65. {sanafe-2.2.5 → sanafe-2.2.7}/scripts/computer2026/indiveri.py +0 -0
  66. {sanafe-2.2.5 → sanafe-2.2.7}/scripts/computer2026/synapse.py +0 -0
  67. {sanafe-2.2.5 → sanafe-2.2.7}/scripts/create_tutorial.py +0 -0
  68. {sanafe-2.2.5 → sanafe-2.2.7}/scripts/icons2023/power_benchmark.py +0 -0
  69. {sanafe-2.2.5 → sanafe-2.2.7}/scripts/message_analysis.py +0 -0
  70. {sanafe-2.2.5 → sanafe-2.2.7}/scripts/misc_dvs_conversion.py +0 -0
  71. {sanafe-2.2.5 → sanafe-2.2.7}/scripts/net_to_yaml.py +0 -0
  72. {sanafe-2.2.5 → sanafe-2.2.7}/scripts/ongoing/detail.py +0 -0
  73. {sanafe-2.2.5 → sanafe-2.2.7}/scripts/ongoing/llm.py +0 -0
  74. {sanafe-2.2.5 → sanafe-2.2.7}/scripts/ongoing/neurofem.py +0 -0
  75. {sanafe-2.2.5 → sanafe-2.2.7}/scripts/ongoing/scaling.py +0 -0
  76. {sanafe-2.2.5 → sanafe-2.2.7}/scripts/plot_messages.py +0 -0
  77. {sanafe-2.2.5 → sanafe-2.2.7}/scripts/plot_raster.py +0 -0
  78. {sanafe-2.2.5 → sanafe-2.2.7}/scripts/queue_transient.py +0 -0
  79. {sanafe-2.2.5 → sanafe-2.2.7}/scripts/tcad2025/compare_nemo_perf.py +0 -0
  80. {sanafe-2.2.5 → sanafe-2.2.7}/scripts/tcad2025/demo_truenorth.py +0 -0
  81. {sanafe-2.2.5 → sanafe-2.2.7}/scripts/tcad2025/design_space_exploration.py +0 -0
  82. {sanafe-2.2.5 → sanafe-2.2.7}/scripts/tcad2025/dvs_gesture.py +0 -0
  83. {sanafe-2.2.5 → sanafe-2.2.7}/scripts/tcad2025/latin_squares.py +0 -0
  84. {sanafe-2.2.5 → sanafe-2.2.7}/scripts/tcad2025/random_network.py +0 -0
  85. {sanafe-2.2.5 → sanafe-2.2.7}/scripts/test_api.py +0 -0
  86. {sanafe-2.2.5 → sanafe-2.2.7}/scripts/test_pybind.py +0 -0
  87. {sanafe-2.2.5 → sanafe-2.2.7}/setup.cfg +0 -0
  88. {sanafe-2.2.5 → sanafe-2.2.7}/src/arch.hpp +0 -0
  89. {sanafe-2.2.5 → sanafe-2.2.7}/src/arg_parsing.hpp +0 -0
  90. {sanafe-2.2.5 → sanafe-2.2.7}/src/attribute.hpp +0 -0
  91. {sanafe-2.2.5 → sanafe-2.2.7}/src/chip.hpp +0 -0
  92. {sanafe-2.2.5 → sanafe-2.2.7}/src/core.cpp +0 -0
  93. {sanafe-2.2.5 → sanafe-2.2.7}/src/core.hpp +0 -0
  94. {sanafe-2.2.5 → sanafe-2.2.7}/src/fwd.hpp +0 -0
  95. {sanafe-2.2.5 → sanafe-2.2.7}/src/message.hpp +0 -0
  96. {sanafe-2.2.5 → sanafe-2.2.7}/src/models.hpp +0 -0
  97. {sanafe-2.2.5 → sanafe-2.2.7}/src/netlist.hpp +0 -0
  98. {sanafe-2.2.5 → sanafe-2.2.7}/src/pipeline.hpp +0 -0
  99. {sanafe-2.2.5 → sanafe-2.2.7}/src/plugins.cpp +0 -0
  100. {sanafe-2.2.5 → sanafe-2.2.7}/src/plugins.hpp +0 -0
  101. {sanafe-2.2.5 → sanafe-2.2.7}/src/print.cpp +0 -0
  102. {sanafe-2.2.5 → sanafe-2.2.7}/src/print.hpp +0 -0
  103. {sanafe-2.2.5 → sanafe-2.2.7}/src/pytrace.cpp +0 -0
  104. {sanafe-2.2.5 → sanafe-2.2.7}/src/schedule.hpp +0 -0
  105. {sanafe-2.2.5 → sanafe-2.2.7}/src/tile.cpp +0 -0
  106. {sanafe-2.2.5 → sanafe-2.2.7}/src/tile.hpp +0 -0
  107. {sanafe-2.2.5 → sanafe-2.2.7}/src/timestep.cpp +0 -0
  108. {sanafe-2.2.5 → sanafe-2.2.7}/src/timestep.hpp +0 -0
  109. {sanafe-2.2.5 → sanafe-2.2.7}/src/utils.cpp +0 -0
  110. {sanafe-2.2.5 → sanafe-2.2.7}/src/utils.hpp +0 -0
  111. {sanafe-2.2.5 → sanafe-2.2.7}/src/yaml_arch.hpp +0 -0
  112. {sanafe-2.2.5 → sanafe-2.2.7}/src/yaml_common.hpp +0 -0
  113. {sanafe-2.2.5 → sanafe-2.2.7}/src/yaml_snn.hpp +0 -0
@@ -48,11 +48,6 @@ project(sana-fe)
48
48
 
49
49
  set(CMAKE_POSITION_INDEPENDENT_CODE ON)
50
50
  find_package(Threads REQUIRED)
51
- if(MSVC)
52
- add_compile_options(/W4 /WX /wd4127) # Disable warn on empty control
53
- else()
54
- add_compile_options(-Wall -pedantic -Werror)
55
- endif()
56
51
 
57
52
  # Set default debug levels for tracing
58
53
  if(NOT DEFINED DEBUG_LEVEL_ARCH)
@@ -96,28 +91,6 @@ foreach(category ARCH CHIP DESCRIPTION MODELS NET PLUGINS PYMODULE SCHEDULER)
96
91
  add_compile_definitions(DEBUG_LEVEL_${category}=${DEBUG_LEVEL_${category}})
97
92
  endforeach()
98
93
 
99
- # Set conditional defaults based on build type
100
- if(CMAKE_BUILD_TYPE STREQUAL "Release")
101
- # Release build defaults
102
- set(DEFAULT_STANDALONE_DEBUG ON)
103
- set(DEFAULT_STANDALONE_SOURCE OFF) # No source info in release
104
- set(DEFAULT_PYTHON_DEBUG OFF)
105
- set(DEFAULT_PYTHON_SOURCE OFF)
106
- else()
107
- # Debug/other build defaults
108
- set(DEFAULT_STANDALONE_DEBUG ON)
109
- set(DEFAULT_STANDALONE_SOURCE ON)
110
- set(DEFAULT_PYTHON_DEBUG ON)
111
- set(DEFAULT_PYTHON_SOURCE ON)
112
- endif()
113
-
114
- # Define options with conditional defaults
115
- option(ENABLE_STANDALONE_DEBUG "Enable debug prints for standalone build" ${DEFAULT_STANDALONE_DEBUG})
116
- option(ENABLE_SOURCE_INFO_STANDALONE "Include source info in standalone debug prints" ${DEFAULT_STANDALONE_SOURCE})
117
- option(ENABLE_PYTHON_DEBUG "Enable debug prints for Python build" ${DEFAULT_PYTHON_DEBUG})
118
- option(ENABLE_SOURCE_INFO_PYTHON "Include source info in standalone debug prints" ${DEFAULT_PYTHON_SOURCE})
119
- cmake_print_variables(ENABLE_STANDALONE_DEBUG ENABLE_SOURCE_INFO_STANDALONE ENABLE_PYTHON_DEBUG ENABLE_SOURCE_INFO_PYTHON)
120
-
121
94
  set(SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src")
122
95
  add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/plugins")
123
96
  cmake_print_variables(SRC_DIR)
@@ -269,6 +242,11 @@ if(PYTHON_BUILD_ENABLED)
269
242
  sanafecpp
270
243
  ${SOURCE_FILES}
271
244
  )
245
+ if(MSVC)
246
+ target_compile_options(sanafecpp PRIVATE /W4 /WX /wd4127)
247
+ else()
248
+ target_compile_options(sanafecpp PRIVATE -Wall -pedantic -Werror)
249
+ endif()
272
250
  target_link_libraries(sanafecpp PUBLIC ryml::ryml)
273
251
  target_link_libraries(sanafecpp PUBLIC booksim)
274
252
  target_link_libraries(sanafecpp PRIVATE ${CMAKE_DL_LIBS})
@@ -278,12 +256,12 @@ if(PYTHON_BUILD_ENABLED)
278
256
  endif()
279
257
  target_link_libraries(sanafecpp PRIVATE Threads::Threads)
280
258
 
281
- if(ENABLE_PYTHON_DEBUG)
282
- target_compile_definitions(sanafecpp PRIVATE ENABLE_DEBUG_PRINTS)
283
- if(ENABLE_SOURCE_INFO_PYTHON)
284
- target_compile_definitions(sanafecpp PRIVATE ENABLE_SOURCE_INFO)
285
- endif()
286
- endif()
259
+ # ENABLE_PYTHON_DEBUG: OFF in Release, ON otherwise
260
+ # ENABLE_SOURCE_INFO_PYTHON: OFF in Release, ON otherwise
261
+ target_compile_definitions(sanafecpp PRIVATE
262
+ $<$<NOT:$<CONFIG:Release>>:ENABLE_DEBUG_PRINTS>
263
+ $<$<NOT:$<CONFIG:Release>>:ENABLE_SOURCE_INFO>
264
+ )
287
265
  install(TARGETS sanafecpp
288
266
  LIBRARY DESTINATION "${CMAKE_SOURCE_DIR}"
289
267
  RUNTIME DESTINATION "${CMAKE_SOURCE_DIR}")
@@ -291,11 +269,17 @@ message(STATUS "Simulator files will be copied to project directory")
291
269
  endif()
292
270
 
293
271
  if(STANDALONE_BUILD_ENABLED)
272
+
294
273
  add_executable(sim "${SRC_DIR}/main.cpp")
295
274
  list(FILTER SOURCE_FILES EXCLUDE REGEX "pymodule.cpp")
296
275
  list(FILTER SOURCE_FILES EXCLUDE REGEX "pytrace.cpp")
297
276
  target_sources(sim PRIVATE ${SOURCE_FILES})
298
277
 
278
+ if(MSVC)
279
+ target_compile_options(sim PRIVATE /W4 /WX /wd4127)
280
+ else()
281
+ target_compile_options(sim PRIVATE -Wall -pedantic -Werror)
282
+ endif()
299
283
  target_link_libraries(sim PUBLIC ryml::ryml)
300
284
  target_link_libraries(sim PUBLIC booksim)
301
285
  target_link_libraries(sim PRIVATE ${CMAKE_DL_LIBS})
@@ -305,12 +289,12 @@ if(STANDALONE_BUILD_ENABLED)
305
289
  endif()
306
290
  target_link_libraries(sim PRIVATE Threads::Threads)
307
291
 
308
- if(ENABLE_STANDALONE_DEBUG)
309
- target_compile_definitions(sim PRIVATE ENABLE_DEBUG_PRINTS)
310
- if(ENABLE_SOURCE_INFO_STANDALONE)
311
- target_compile_definitions(sim PRIVATE ENABLE_SOURCE_INFO)
312
- endif()
313
- endif()
292
+ # ENABLE_STANDALONE_DEBUG: ON in all configs
293
+ # ENABLE_SOURCE_INFO_STANDALONE: OFF in Release, ON otherwise
294
+ target_compile_definitions(sim PRIVATE
295
+ ENABLE_DEBUG_PRINTS
296
+ $<$<NOT:$<CONFIG:Release>>:ENABLE_SOURCE_INFO>
297
+ )
314
298
  install(TARGETS sim
315
299
  LIBRARY DESTINATION "${CMAKE_SOURCE_DIR}"
316
300
  RUNTIME DESTINATION "${CMAKE_SOURCE_DIR}")
@@ -320,7 +304,13 @@ endif()
320
304
  if(ENABLE_TESTING)
321
305
  list(FILTER SOURCE_FILES EXCLUDE REGEX "pymodule.cpp")
322
306
  list(FILTER SOURCE_FILES EXCLUDE REGEX "pytrace.cpp")
323
- add_library(sanafe SHARED ${SOURCE_FILES} ${HEADER_FILES})
307
+ add_library(sanafe STATIC ${SOURCE_FILES} ${HEADER_FILES})
308
+
309
+ if(MSVC)
310
+ target_compile_options(sanafe PRIVATE /W4 /WX /wd4127)
311
+ else()
312
+ target_compile_options(sanafe PRIVATE -Wall -pedantic -Werror)
313
+ endif()
324
314
  target_link_libraries(sanafe PUBLIC ryml::ryml)
325
315
  target_link_libraries(sanafe PUBLIC booksim)
326
316
  target_link_libraries(sanafe PRIVATE ${CMAKE_DL_LIBS})
@@ -328,9 +318,12 @@ if(ENABLE_TESTING)
328
318
  target_include_directories(sanafe PUBLIC
329
319
  ${CMAKE_SOURCE_DIR}/src
330
320
  )
331
- target_compile_definitions(sanafe PRIVATE ENABLE_DEBUG_PRINTS)
321
+ target_compile_definitions(sanafe PRIVATE
322
+ $<$<NOT:$<CONFIG:Release>>:ENABLE_DEBUG_PRINTS>
323
+ )
332
324
 
333
325
  message(STATUS "Testing enabled")
326
+ enable_testing()
334
327
  include(CTest)
335
328
  add_subdirectory(tests)
336
329
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sanafe
3
- Version: 2.2.5
3
+ Version: 2.2.7
4
4
  Summary: SANA-FE: Simulating Advanced Neuromorphic Architectures for Fast Exploration
5
5
  Author-email: James Boyle <james.boyle@utexas.edu>
6
6
  License: GPL-3.0
@@ -1,6 +1,6 @@
1
1
  project = 'SANA-FE'
2
2
  author = 'James Boyle'
3
- release = '2.2.5'
3
+ release = '2.2.7'
4
4
 
5
5
  extensions = [
6
6
  'sphinx.ext.autodoc',
@@ -18,8 +18,6 @@
18
18
  #include "plugins.hpp"
19
19
  #include "print.hpp"
20
20
 
21
- //#include <iostream>
22
-
23
21
  class NeuroFEMModel : public sanafe::PipelineUnit
24
22
  {
25
23
  public:
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "sanafe"
7
- version = "2.2.5"
7
+ version = "2.2.7"
8
8
  description = "SANA-FE: Simulating Advanced Neuromorphic Architectures for Fast Exploration"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -33,4 +33,22 @@ packages = { find = {} }
33
33
  sanafe = ["examples/*.yaml", "examples/dvs_challenge.npz"]
34
34
 
35
35
  [tool.cibuildwheel]
36
- skip = ["*-win32", "*_i686"]
36
+ skip = ["*-win32", "*_i686"]
37
+
38
+ [tool.pylint."messages control"]
39
+ disable = [
40
+ "too-few-public-methods",
41
+ "too-many-arguments",
42
+ "too-many-instance-attributes",
43
+ "too-many-locals",
44
+ "too-many-branches",
45
+ "too-many-positional-arguments",
46
+ "too-many-statements",
47
+ "too-many-lines",
48
+ "too-many-public-methods",
49
+ "fixme",
50
+ "import-error",
51
+ "no-member",
52
+ "no-name-in-module",
53
+ "duplicate-code",
54
+ ]
@@ -1,3 +1,4 @@
1
+ """Top-level SANA-FE module"""
1
2
  # Import pybind11 (C++) kernel under top-level
2
3
  from sanafecpp import *
3
4
 
@@ -1,5 +1,12 @@
1
+ # Copyright (c) 2026 - The University of Texas at Austin
2
+ # This work was produced under contract #2317831 to National Technology and
3
+ # Engineering Solutions of Sandia, LLC which is under contract
4
+ # No. DE-NA0003525 with the U.S. Department of Energy.
5
+ """
6
+ Example SNNs and Architectures.
7
+ """
1
8
  from importlib.resources import files
2
- from . import load_arch, load_net
9
+ from sanafecpp import load_arch, load_net
3
10
 
4
11
  def load_example():
5
12
  """Load a bundled example architecture and SNN."""
@@ -1,3 +1,7 @@
1
+ # Copyright (c) 2026 - The University of Texas at Austin
2
+ # This work was produced under contract #2317831 to National Technology and
3
+ # Engineering Solutions of Sandia, LLC which is under contract
4
+ # No. DE-NA0003525 with the U.S. Department of Energy.
1
5
  """
2
6
  Convert SANA-FE trace outputs into useful formats.
3
7
 
@@ -11,7 +15,7 @@ Each function accepts whatever type is most convenient:
11
15
  from __future__ import annotations
12
16
 
13
17
  from pathlib import Path
14
- from typing import Any, Iterable, Sequence
18
+ from typing import Any, Sequence
15
19
 
16
20
  import numpy as np
17
21
  import pandas as pd
@@ -36,10 +40,10 @@ def _looks_like_perf_dict(source: Any) -> bool:
36
40
 
37
41
  def spikes_to_raster(
38
42
  source: Any,
39
- groups: Optional[Sequence[str]] = None,
40
- time_range: Optional[Tuple[int, int]] = None,
41
- n_timesteps: Optional[int] = None,
42
- ) -> Tuple[np.ndarray, list[str], np.ndarray]:
43
+ groups: Sequence[str] | None = None,
44
+ time_range: tuple[int, int] | None = None,
45
+ n_timesteps: int | None = None,
46
+ ) -> tuple[np.ndarray, list[str], np.ndarray]:
43
47
  """Convert a spike trace into a dense 2D raster matrix.
44
48
 
45
49
  Args:
@@ -72,8 +76,6 @@ def spikes_to_raster(
72
76
  ValueError: If no spike trace data can be found in ``source``, or if
73
77
  ``groups`` contains unknown group names.
74
78
  """
75
- from sanafe.data import spikes_to_dataframe # avoid circular import in snippet
76
-
77
79
  df = spikes_to_dataframe(source)
78
80
 
79
81
  all_groups = sorted(df["group"].unique())
@@ -110,7 +112,7 @@ def spikes_to_raster(
110
112
  neuron_ids.append(nid)
111
113
 
112
114
  matrix = np.zeros((len(neuron_ids), len(timesteps)), dtype=bool)
113
- if len(df) and len(neuron_ids) and len(timesteps):
115
+ if len(df) and neuron_ids and timesteps:
114
116
  rows = df["neuron_id"].map(row_of).to_numpy()
115
117
  cols = df["timestep"].to_numpy() - t_start
116
118
  valid = (rows >= 0) & (cols >= 0) & (cols < len(timesteps))
@@ -12,20 +12,35 @@ basic spike and voltage probes.
12
12
 
13
13
  # TODO: support recordInGraph
14
14
  # TODO: read from arch object in the future
15
- from fugu.backends import Backend
16
15
  from collections import defaultdict
17
- import sanafe
16
+
17
+ from fugu.backends import Backend
18
18
  import pandas as pd
19
19
 
20
+ import sanafe
21
+
22
+ # pylint: disable=invalid-name,no-self-argument,attribute-defined-outside-init
20
23
  class sanafe_Backend(Backend):
24
+ """SANA-FE Fugu backend"""
21
25
  _net = None
22
26
  _arch = None
23
27
 
28
+ def __init__(self):
29
+ self.net = None
30
+ self.fugu_name_to_neuron_number = None
31
+ self.input_map = None
32
+ self.arch_name = None
33
+ self.arch = None
34
+ self.debug_mode = None
35
+ self.return_potentials = False
36
+ self.record = False
37
+ self.ds_format = False
38
+
24
39
  def _map_to_cores(self):
25
40
  """
26
41
  Assigns neurons to cores based on capacity and hardware compatibility.
27
42
  """
28
- MAX_NEURONS_PER_CORE = 1024
43
+ max_neurons_per_core = 1024
29
44
  cores = self.arch.cores()
30
45
  total_cores = len(cores)
31
46
  neurons_per_core = {i: 0 for i in range(total_cores)}
@@ -33,10 +48,10 @@ class sanafe_Backend(Backend):
33
48
  current_core_id = 0
34
49
  # We assume self.node_map contains {fugu_id: sanafe_neuron_object}
35
50
  for fugu_node_id, neuron in self.node_map.items():
36
- if neurons_per_core[current_core_id] >= MAX_NEURONS_PER_CORE:
51
+ if neurons_per_core[current_core_id] >= max_neurons_per_core:
37
52
  # There is space in the core
38
53
  current_core_id += 1
39
- assert(current_core_id < total_cores)
54
+ assert current_core_id < total_cores
40
55
  neurons_per_core[current_core_id] += 1
41
56
 
42
57
  # Assign spike inputs to custom hardware
@@ -79,10 +94,10 @@ class sanafe_Backend(Backend):
79
94
  self.brick_groups = defaultdict(list)
80
95
  neurons_to_record = set()
81
96
  input_neurons = set()
82
- record_all = True if self.record == "all" else False
97
+ record_all = self.record == "all"
83
98
 
84
99
  # --- STEP 2: Create input spike trains and outputs probes ---
85
- for brick_id, props in self.fugu_circuit.nodes.data():
100
+ for _, props in self.fugu_circuit.nodes.data():
86
101
  if props.get("layer") == "input":
87
102
  for timestep, neurons in enumerate(props['brick']):
88
103
  for n in neurons:
@@ -160,13 +175,16 @@ class sanafe_Backend(Backend):
160
175
  src.connect_to_neuron(dst, props)
161
176
 
162
177
 
163
- def compile(self, scaffold, compile_args={}):
178
+ def compile(self, scaffold, compile_args=None):
164
179
  """
165
180
  Compile Fugu scaffold as SANA-FE network
166
181
  Args:
167
182
  scaffold: The Fugu scaffold containing one or more bricks
168
- compile_args (Dict, optional): Arguments controlling compilation. Defaults to {}.
183
+ compile_args (Dict, optional): Arguments controlling compilation. Defaults to None.
169
184
  """
185
+ if compile_args is None:
186
+ compile_args = {}
187
+
170
188
  # creates neuron populations and synapses
171
189
  self.scaffold = scaffold
172
190
  self.fugu_circuit = scaffold.circuit
@@ -212,7 +230,8 @@ class sanafe_Backend(Backend):
212
230
  chip = sanafe.SpikingChip(self.arch)
213
231
  chip.load(self.net)
214
232
 
215
- with open("spikes.csv", "w") as spike_trace, open("potentials.csv", "w") as potential_trace:
233
+ with (open("spikes.csv", "w", encoding="utf-8") as spike_trace,
234
+ open("potentials.csv", "w", encoding="utf-8") as potential_trace):
216
235
  chip.sim(n_steps, spike_trace=spike_trace, potential_trace=potential_trace)
217
236
 
218
237
  # Parse output data
@@ -260,14 +279,16 @@ class sanafe_Backend(Backend):
260
279
  Resets time-step to 0 and resets neuron/synapse properties
261
280
  """
262
281
  self._build_network()
263
- pass
264
282
 
265
- def set_properties(self, properties={}):
283
+ def set_properties(self, properties=None):
266
284
  """
267
285
  Set properties for specific neurons and synapses
268
286
  Args:
269
- properties (dict, optional): dictionary of properties for bricks. Defaults to {}.
287
+ properties (dict, optional): dictionary of properties for bricks. Defaults to None.
270
288
  """
289
+ if properties is None:
290
+ properties = {}
291
+
271
292
  for brick in properties:
272
293
  if brick != 'compile_args':
273
294
  brick_id = self.brick_to_number[brick]
@@ -279,7 +300,7 @@ class sanafe_Backend(Backend):
279
300
  Reset input spike trains
280
301
  """
281
302
  # Clean out old spike structures.
282
- for n, node in self.fugu_graph.nodes.data():
303
+ for _, node in self.fugu_graph.nodes.data():
283
304
  if 'spikes' in node:
284
305
  del node['spikes'] # Allow list to be built from scratch.
285
306
  # When run() is called, network will be rebuilt with new spike times.
@@ -0,0 +1,208 @@
1
+ # Copyright (c) 2026 - The University of Texas at Austin
2
+ # This work was produced under contract #2317831 to National Technology and
3
+ # Engineering Solutions of Sandia, LLC which is under contract
4
+ # No. DE-NA0003525 with the U.S. Department of Energy.
5
+ # Implemented by Lance Lui as part of the capstone senior design project
6
+ """
7
+ Lava to SANA-FE Backend
8
+
9
+ This module converts LAVA processes or serialization
10
+ object to the SNN representation runnable on SANA-FE
11
+
12
+ keep this file structure-
13
+ lava
14
+ ├── src
15
+ │ ├── lava
16
+ │ │ ├── utils
17
+ │ │ │ ├── sanafe.py
18
+ │ │ │ │...
19
+ │ │ │...
20
+ │ │...
21
+ │...
22
+ SANAFE
23
+ ├── sim.py
24
+ │...
25
+ """
26
+ # As part of this backend, we have to access private Lava class details
27
+ # pylint: disable=protected-access
28
+
29
+ import lava
30
+ import sanafe
31
+
32
+
33
+ # Structural keys from Lava proc_params that describe the process shape
34
+ # rather than neuron model behavior. These are consumed during network
35
+ # construction and should NOT be forwarded as model_attributes.
36
+ _STRUCTURAL_KEYS = {"shape"}
37
+
38
+
39
+ def _extract_params(process):
40
+ """Extract shape and model attributes from a Lava process.
41
+
42
+ Splits ``proc_params._parameters`` into structural information (the
43
+ neuron count derived from *shape*) and everything else, which is
44
+ passed through to SANA-FE as ``model_attributes``.
45
+
46
+ Args:
47
+ process: A Lava ``AbstractProcess`` instance.
48
+
49
+ Returns:
50
+ tuple: (neuron_count, model_attributes_dict)
51
+ """
52
+ params = process.proc_params._parameters
53
+ dim = params["shape"]
54
+ neuron_count = dim[0] * (dim[1] if len(dim) > 1 else 1)
55
+
56
+ model_attributes = {
57
+ k: v for k, v in params.items() if k not in _STRUCTURAL_KEYS
58
+ }
59
+ return neuron_count, model_attributes
60
+
61
+
62
+ def _greedy_map_to_arch(network, arch):
63
+ """Map every neuron in *network* to cores in *arch* using a greedy policy.
64
+
65
+ Neurons are assigned to cores in the order they appear across groups.
66
+ Each core is filled up to its ``max_neurons_supported`` limit before
67
+ moving on to the next core.
68
+
69
+ Args:
70
+ network (sanafe.Network): The network whose neurons will be mapped.
71
+ arch (sanafe.Architecture): Target architecture (e.g. from
72
+ ``sanafe.load_loihi()``).
73
+
74
+ Raises:
75
+ RuntimeError: If the architecture runs out of cores before all
76
+ neurons have been placed.
77
+ """
78
+ # Build a flat list of all cores across all tiles
79
+ all_cores = []
80
+ for tile in arch.tiles:
81
+ for core in tile.cores:
82
+ all_cores.append(core)
83
+
84
+ core_idx = 0
85
+ neurons_on_current_core = 0
86
+ max_neurons = all_cores[core_idx].max_neurons_supported \
87
+ if hasattr(all_cores[core_idx], "max_neurons_supported") else 1024
88
+
89
+ for group_name in network.groups:
90
+ group = network.groups[group_name]
91
+ for neuron in group:
92
+ if neurons_on_current_core >= max_neurons:
93
+ core_idx += 1
94
+ if core_idx >= len(all_cores):
95
+ raise RuntimeError(
96
+ f"Architecture has only {len(all_cores)} cores, "
97
+ f"which cannot hold all neurons in the network."
98
+ )
99
+ neurons_on_current_core = 0
100
+ max_neurons = (
101
+ all_cores[core_idx].max_neurons_supported
102
+ if hasattr(all_cores[core_idx], "max_neurons_supported")
103
+ else 1024
104
+ )
105
+ neuron.map_to_core(all_cores[core_idx])
106
+ neurons_on_current_core += 1
107
+
108
+
109
+ def serial_to_sanafe(
110
+ filename,
111
+ arch=None,
112
+ save_path="converted_network.yaml",
113
+ ):
114
+ """Load a serialized Lava process file and convert it to a SANA-FE network.
115
+
116
+ If the serialized object is a single ``AbstractProcess``, it is
117
+ forwarded to :func:`process_to_sanafe`. Otherwise each element in
118
+ the serialized list is turned into a neuron group and consecutive
119
+ groups are connected pairwise.
120
+
121
+ Args:
122
+ filename (str): Path to the serialized Lava process file.
123
+ arch (sanafe.Architecture, optional): Target architecture for
124
+ hardware mapping. Defaults to ``sanafe.load_loihi()``.
125
+ save_path (str, optional): Where to save the resulting SANA-FE
126
+ network. Defaults to ``"converted_network.yaml"``.
127
+
128
+ Returns:
129
+ sanafe.Network: The constructed (and mapped) network.
130
+ """
131
+ p = lava.utils.serialization.load(filename)
132
+
133
+ # Single process shortcut
134
+ if isinstance(p[0], lava.magma.core.process.process.AbstractProcess):
135
+ return process_to_sanafe(p[0], arch=arch, save_path=save_path)
136
+
137
+ if arch is None:
138
+ arch = sanafe.load_loihi()
139
+
140
+ network = sanafe.Network()
141
+ groups = []
142
+
143
+ for i, proc in enumerate(p[0]):
144
+ neuron_count, model_attrs = _extract_params(proc)
145
+ group = network.create_neuron_group(
146
+ f"layer_{i}",
147
+ neuron_count,
148
+ model_attributes=model_attrs,
149
+ )
150
+ groups.append(group)
151
+
152
+ # Connect to the previous group (sequential topology)
153
+ if len(groups) > 1:
154
+ groups[-2].connect_neurons_dense(groups[-1], {})
155
+
156
+ _greedy_map_to_arch(network, arch)
157
+ network.save(save_path)
158
+ return network
159
+
160
+
161
+ def process_to_sanafe(
162
+ process,
163
+ arch=None,
164
+ save_path="converted_network.yaml",
165
+ ):
166
+ """Convert a live Lava ``AbstractProcess`` to a SANA-FE network.
167
+
168
+ The process shape is interpreted as (*rows*, *cols*); each column
169
+ becomes a separate neuron group and consecutive groups are connected.
170
+
171
+ Args:
172
+ process (AbstractProcess): A Lava process instance.
173
+ arch (sanafe.Architecture, optional): Target architecture for
174
+ hardware mapping. Defaults to ``sanafe.load_loihi()``.
175
+ save_path (str, optional): Where to save the resulting SANA-FE
176
+ network. Defaults to ``"converted_network.yaml"``.
177
+
178
+ Returns:
179
+ sanafe.Network: The constructed (and mapped) network.
180
+ """
181
+ if arch is None:
182
+ arch = sanafe.load_loihi()
183
+
184
+ network = sanafe.Network()
185
+ params = process.proc_params._parameters
186
+ dim = params["shape"]
187
+ rows = dim[0]
188
+ cols = dim[1] if len(dim) > 1 else 1
189
+
190
+ model_attrs = {
191
+ k: v for k, v in params.items() if k not in _STRUCTURAL_KEYS
192
+ }
193
+
194
+ groups = []
195
+ for col_idx in range(cols):
196
+ group = network.create_neuron_group(
197
+ f"group_{col_idx}",
198
+ rows,
199
+ model_attributes=model_attrs,
200
+ )
201
+ groups.append(group)
202
+
203
+ if len(groups) > 1:
204
+ groups[-2].connect_neurons_dense(groups[-1], {})
205
+
206
+ _greedy_map_to_arch(network, arch)
207
+ network.save(save_path)
208
+ return network
@@ -1,3 +1,7 @@
1
+ # Copyright (c) 2026 - The University of Texas at Austin
2
+ # This work was produced under contract #2317831 to National Technology and
3
+ # Engineering Solutions of Sandia, LLC which is under contract
4
+ # No. DE-NA0003525 with the U.S. Department of Energy.
1
5
  """
2
6
  SANA-FE Neural Network Layers Module
3
7
 
@@ -19,6 +23,8 @@ Example:
19
23
  >>> conv1 = layers.Conv2D(net, input_layer, conv_weights, stride_width=1)
20
24
  >>> dense1 = layers.Dense(net, conv1, 128, dense_weights)
21
25
  """
26
+ from typing import Any
27
+ # pylint: disable=unsubscriptable-object
22
28
 
23
29
  class Layer:
24
30
  """
@@ -45,10 +51,9 @@ class Layer:
45
51
 
46
52
  def __init__(self):
47
53
  """Initialize base layer with empty neuron group."""
48
- self.group = None
49
- return
54
+ self.group: Any = None
50
55
 
51
- def __getitem__(self, key):
56
+ def __getitem__(self, key: str):
52
57
  """
53
58
  Access neuron(s) by index or slice.
54
59
 
@@ -80,7 +85,6 @@ class Layer:
80
85
  while i < len(self.group):
81
86
  yield self.group[i]
82
87
  i += 1
83
- return
84
88
 
85
89
 
86
90
  class Input2D(Layer):
@@ -111,7 +115,8 @@ class Input2D(Layer):
111
115
 
112
116
  _count = 0
113
117
 
114
- def __init__(self, snn, width, height, channels=1, **kwargs):
118
+ def __init__(self, snn, width: int, height: int, channels:int = 1,
119
+ **kwargs):
115
120
  """
116
121
  Create 2D input layer with specified dimensions.
117
122
 
@@ -173,8 +178,9 @@ class Conv2D(Layer):
173
178
 
174
179
  _count = 0
175
180
 
176
- def __init__(self, snn, prev_layer, weights, stride_width=1,
177
- stride_height=1, pad_width=0, pad_height=0, **kwargs):
181
+ def __init__(self, snn, prev_layer, weights, stride_width:int = 1,
182
+ stride_height: int = 1, pad_width: int = 0,
183
+ pad_height: int = 0, **kwargs):
178
184
  """
179
185
  Create 2D convolutional layer.
180
186
 
@@ -283,7 +289,7 @@ class Dense(Layer):
283
289
 
284
290
  _count = 0
285
291
 
286
- def __init__(self, snn, prev_layer, neuron_count, weights, **kwargs):
292
+ def __init__(self, snn, prev_layer, neuron_count: int, weights, **kwargs):
287
293
  """
288
294
  Create fully-connected layer.
289
295
 
@@ -322,4 +328,4 @@ class Dense(Layer):
322
328
  attributes = {"w": weights.flatten()}
323
329
  prev_layer.group.connect_neurons_dense(self.group, attributes)
324
330
 
325
- Dense._count += 1
331
+ Dense._count += 1