Description of problem
Our aim is to teach a network with natural images. We can do this by concatenating a large number of input files as a preprocessing step. Nevertheless, memory limitations and fluency call for a more flexible solution.
We are building simulations with potentially up to ten thousand input files that should be processed sequentially using the same network with the cpp_standalone backend. The network itself does not change: the number of neurons and synapses are fixed. However, their connection weights evolve through learning.
Here the system gets retina ganglion cell spike indices and times in the from of preprocessed retina output:
spk_generator_sp = spikes_data["spikes_0"][0]
spk_generator_ti = spikes_data["spikes_0"][1]
spk_generator = b2.SpikeGeneratorGroup(
number_of_neurons, spk_generator_sp, spk_generator_ti
)
separately for ON and OFF ganglion cells.
The only change is in the input spikes from the SpikeGeneratorGroup. For example, for 10,000 input files and a runtime of 1 second, we would like the first simulation to use the first input file, simulate for 1s, keep the complete network state, replace the SpikeGeneratorGroup spikes with those from the second input file, simulate for 1s, and so on. In other words, we want the simulations to behave as if they were one continuous simulation consisting of 10,000 sequential 1-second segments, with the input changing between segments but the network state being preserved. Kind of streaming the input.
To achieve this, we initially tried to update the SpikeGeneratorGroup with its set_spikes() method:
# (Network setup omitted)
target_directory = ”/our/target/dir/”
for n, input_file in enumerate(input_files):
start_time = n * runtime * second
on_data = load_data(on_input_file)
off_data = load_data(off_input_file)
spike_generator1.set_spikes(
on_data["spikes_0"][0],
on_data["spikes_0"][1] + start_time,
sorted=True,
)
spike_generator2.set_spikes(
off_data["spikes_0"][0],
off_data["spikes_0"][1] + start_time,
sorted=True,
)
b2.run(runtime, report="text")
#End of loop
b2.device.build(
directory=target_directory,
run=False,
compile=True,
) # Same result with or without clean=True
b2.device.run()
With this approach we run into different problems.
The first problem is that, for a large enough number of input files, we get the error
“/bin/sh: Argument list too long
make: *** [makefile:23: make.deps] Error 127
This seems to be related to how Make handles the list of source files. The generated Makefile contains:
make.deps: $(SRCS) $(H_SRCS)
$(CXX) $(CXXFLAGS) -MM $(SRCS) > make.deps
$(SRCS) contains a list of source files (up to ten thousand in our case), which leads the expanded command to hit the ARG_MAX limit in Linux, hence the error /bin/sh: Argument list too long. We cannot rely on increasing ARG_MAX on the HPC system where we will be running our simulations.
The second problem is that this strategy dilates compilation times so much that almost nullifies the advantages of switching to the cpp backend over python.
As a general solution, we were wondering whether we could compile a network without specifying in advance what input files will be presented to it. Our understanding is that changing input spikes with set_spikes(), then calling b2.run(self.runtime, report=“text”) will make data part of the generated standalone simulation/program rather than being supplied to a persistent compiled model at runtime. Would it be possible instead to compile a network independently of its future SpikeGeneratorGroup inputs, and subsequently provide arbitrary spike indices/times to the already-compiled model at runtime? If not, what is the best way to implement such a workflow? Our main goal is to avoid generating and compiling a new piece of simulation code for every input file.
Minimal code to reproduce problem
See section above for relevant code.
What you have already tried
An interim workaround for us is either to run the simulations with the Python backend (which is slower) or to concatenate the 5000 input files into a single large input file and then run the simulation with the cpp backend, as suggested in the documentation.
Full traceback of error
(relevant part; skipped repetitive compiler output)
/bin/sh: Argument list too long
make: *** [makefile:23: make.deps]
Error 127 make: *** Waiting for unfinished jobs…
ERROR Brian 2 encountered an unexpected error. If you think this is a bug in Brian 2, please report this issue either to the discourse forum at http://brian.discourse.group/, or to the issue tracker at https://github.com/brian-team/brian2/issues. Please include this file with debug information in your report: /tmp/brian_debug_iice5b24.log Additionally, you can also include a copy of the script that was run, available at: /tmp/brian_script_5o2uxdau.py You can also include a copy of the redirected std stream outputs, available at ‘/tmp/brian_stdout_ea0ry_gg.log’ and ‘/tmp/brian_stderr_mob_o25f.log’. Thanks! [brian2]
Traceback (most recent call last):
File “/opt2/git_repos/smart/docs/examples/example_plasticity_training.py”, line 91, in run_with_overrides(run_pipeline) ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File “/opt2/git_repos/smart/docs/examples/example_plasticity_training.py”, line 72, in run_with_overrides run_pipeline() ~~~~~~~~~~~~^^
File “/opt2/git_repos/smart/docs/examples/example_plasticity_training.py”, line 82, in run_pipeline sim_results = session.simulation.simulate()
File “/opt2/git_repos/smart/smart/simulation/simulation_module.py”, line 1097, in simulate results = self._run_simulation_in_cxsystem( anatomy_path, …<2 lines>… unit_position_df=unit_positions, )
File “/opt2/git_repos/smart/smart/simulation/simulation_module.py”, line 992, in _run_simulation_in_cxsystem results = CM.run()
File “/home/francescangelo/.cache/pypoetry/virtualenvs/smart-wO9jYNL1-py3.14/lib/python3.14/site-packages/cxsystem2/core/cxsystem.py”, line 562, in run b2.device.build(directory=target_directory, run=False, compile=True, clean=True) ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/francescangelo/.cache/pypoetry/virtualenvs/smart-wO9jYNL1-py3.14/lib/python3.14/site-packages/brian2/devices/cpp_standalone/device.py”, line 1642, in build self.compile_source(directory, compiler, debug, clean) ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/francescangelo/.cache/pypoetry/virtualenvs/smart-wO9jYNL1-py3.14/lib/python3.14/site-packages/brian2/devices/cpp_standalone/device.py”, line 1193, in compile_source raise RuntimeError(error_message) RuntimeError: Project compilation failed (error code: 512).
Francescangelo Vedele & Simo Vanni