Skip to content

Fix baseexport: serialize hetero delays, capture resolved integrator, handle NetworkOperation#76

Open
Sanchit2662 wants to merge 3 commits intobrian-team:masterfrom
Sanchit2662:fix/baseexport-delays-integrator-networkop
Open

Fix baseexport: serialize hetero delays, capture resolved integrator, handle NetworkOperation#76
Sanchit2662 wants to merge 3 commits intobrian-team:masterfrom
Sanchit2662:fix/baseexport-delays-integrator-networkop

Conversation

@Sanchit2662
Copy link
Copy Markdown

@Sanchit2662 Sanchit2662 commented Mar 24, 2026

Summary

I was going through the baseexport collector and found three issues that were silently breaking things.

The first one was in collect_Synapses. The delay was only being serialized when it was a scalar value (single delay for all synapses). If you had per-synapse delays like S.delay = 'rand() * 5*ms', that condition would be false and the entire delay array would just get dropped from the export with no warning. The fix is literally removing that condition. obj.delay[:] works fine for both scalar and array cases, so there was no reason to guard it in the first place.

The second one was in collect_NeuronGroup and collect_SpatialNeuron. When a user doesn't specify a method explicitly, Brian2 still picks one at runtime (like exact or exponential_euler) but we were just storing None in the export. There was even a TODO comment there acknowledging it. I fixed it by looking at the StateUpdater object's method_choice during the contained objects loop, where the runtime-resolved method is actually available. It gets stored as resolved_method so an importer can explicitly set the same integrator rather than relying on Brian2's auto-selection which might differ across versions.

The third one was NetworkOperation. If you had a @network_operation in your network, the exporter would just crash with a NotImplementedError. I added NetworkOperation to supported_objs so it no longer blows up, wrote a collect_NetworkOperation function that captures the scheduling metadata (name, dt, when, eorder), and added a logger warning so the user knows the function body itself isn't captured. It's honest about what it can and can't do rather than just crashing.

… handle NetworkOperation

Signed-off-by: Sanchit2662 <sanchit2662@gmail.com>
@Sanchit2662
Copy link
Copy Markdown
Author

Hi @mstimberg , please review the changes.

@mstimberg
Copy link
Copy Markdown
Member

Hi @Sanchit2662. These additions do sound useful, but did you actually try running your code? There is an incorrect import, and I don't think the obj.delay[:] access will work in practice. Actually, heterogeneous delays were already captured in the serialization thanks to the generic "initializer" mechanism. E.g. for your example, the basexporter dictionary would contain:

{'index': 'True',
'source': 'synapses_pre',
'type': 'initializer',
'value': 'rand() * 5*ms',
'variable': 'delay'}

inside the 'initializers_connectors' key.

Signed-off-by: Sanchit2662 <sanchit2662@gmail.com>
@Sanchit2662
Copy link
Copy Markdown
Author

Hi @mstimberg , I have made the changes.

@mstimberg
Copy link
Copy Markdown
Member

Hi @Sanchit2662. Could you please merge latest master into this branch. The test suite should not be failing any more then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants