Repository navigation
Size circuit simulations from their synapses, replay and spike files - #1241
Draft
eleftherioszisis wants to merge 24 commits into
Draft
eleftherioszisis wants to merge 24 commits into
eleftherioszisis wants to merge 24 commits into
Conversation
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## main #1241 +/- ##
==========================================
+ Coverage 86.43% 86.56% +0.12%
==========================================
Files 385 388 +3
Lines 24528 24786 +258
Branches 2820 2855 +35
==========================================
+ Hits 21202 21457 +255
- Misses 2776 2777 +1
- Partials 550 552 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
eleftherioszisis
force-pushed
the
number-synapses-from-edge-indices
branch
from
November 27, 2026 00:07
f166c82 to
db32908
Compare
The memory of a simulation depends on its synapses much more than on its neurons: the rCA1 hippocampus slice has about 8 times more synapses per neuron than SSCX, which an estimate from the number of neurons alone misses. Generation runs in the API service with the nodes of the circuit only, so the edge files are not available. The synapses onto the simulated cells are counted from the SONATA edge indices, which are read remotely with HTTP range requests and kept per circuit. The estimate is the larger of the per-cell rule and a memory model fitted on 18 runs of rCA1 and SSCX. Refs openbraininstitute/prod-circuit-simulation#265
The lib CI job runs ty with the released entitysdk, which has no Client.open_remote_file yet, and the staged circuit of a task is typed as optional. The remote file is typed as io.IOBase, so the check no longer depends on entitysdk.http_file. Refs openbraininstitute/prod-circuit-simulation#265
The first coefficients came from a NEURON build without CoreNEURON and took the 2.5x of the neurodamus docs for CoreNEURON, which gave 4 nodes to a job that runs on 2. In the simulation image, neurodamus frees the NEURON model before CoreNEURON loads, so CoreNEURON raises the peak by 1% to 11%, and a synapse costs 3.5 KB. With the synapses counted, the temporary 0.09 GB per cell is replaced by the original 0.03 as a floor. Refs openbraininstitute/prod-circuit-simulation#265
- Read the edge indices with Client.open_file (entitysdk 0.22): from the local asset store when it has the file, otherwise with range reads. - Do not trust the layout of an edges file. A population is counted per cell only if its target_to_source index is at most 32 MB and accounts for every edge; otherwise it is counted in total from the shape of source_node_id, and a node set gets its share of the cells times 2.5. All 2,926 circuits of staging and production were checked: synaptome writers give the index too few or too many rows, and nbS1 has 68 MB of index per population. - Keep the synapses by source population, and count the spiking sources and the spikes of the replay files generation writes, to record number_replayed_synapses and number_replay_spikes next to number_synapses, when entitysdk's Simulation has them. - Any error while counting records the neuron count only: it must not fail generation. Refs openbraininstitute/prod-circuit-simulation#265
…mage The model was fitted on 76 runs of neurodamus 4.2.11 and 4.3.0 in the production image (NEURON and CoreNEURON, rCA1 and SSCX, 1 to 16 ranks, replay, spike files, reports, LFP), within 0.85 to 1.09 of every run: - on every node: 34.9 MB per rank, 41.4 bytes per replay spike per rank (every rank reads all the spike files), 6.5 MB per rank with LFP; - split over the nodes: 5.55 MB per cell, 3.07 KB per synapse, 2.05 KB per replayed synapse, 1.04 times the LFP weights of the simulated cells; - times 1.15, 90% of a node usable, at least the 0.03 GB per cell SSCX ran with. The CA1 job 01a1cb34 gets the 2 nodes it ran on, and the model agrees it could not fit 1. SSCX keeps its nodes. Simulations without counted synapses keep 0.09 GB per cell. Instances get their ranks (cores) and, on cell_a, the nodes available: spike inputs no node can hold, and simulations needing more nodes than exist, are refused with an error instead of failing or waiting forever. docs/circuit-simulation-memory-measurements.md holds the measurements, the fit and its checks. Refs openbraininstitute/prod-circuit-simulation#265
- Generation: one method counts, and the caller decides that the counts are optional and logs a failure. The circuit config is parsed for the population sizes only when there are spike files. - circuit_synapses: one comprehension for the biophysical populations; one check per bound of the index; the cache drops the least recently used circuit. - replayed_synapses takes the replayed sources, not the whole ReplayCounts. - Estimator: the circuit is fetched once for all the recording arrays (generation refuses arrays of another circuit); LFP is checked once; one helper for the per-cell rules. No change in behaviour.
azure-terraform-deployment defines cell_b's small pool as Standard_D4s_v5 (4 vCPU), and launch-system starts one rank per core, so 4 ranks, not the 2 guessed. Its nodes are limited by the vCPU quota of the subscription, which is not in the repository, so cell_b gets no max_instances.
It is cached and shared by every simulation of a circuit. The dataclass is frozen, its mappings are MappingProxyType and its per-cell arrays are not writeable. read_synapses_per_cell builds the counts in local dicts and the CellSynapses at the end, and the count of a node set is the function synapses_by_source instead of methods.
Only what mutated it had to go: count_by_source and count read it, and stay methods of the frozen dataclass.
pydantic's frozen config replaces the frozen dataclass and its __post_init__: the fields cannot be replaced, the mappings and arrays are not wrapped.
docs/circuit-simulation-resources.md lists every constant of the estimate, the counting and the instances: its value, what it represents and how it was measured or chosen. The code keeps short docstrings and a pointer to it.
MemoryModel holds the terms as fields with the measured values as defaults, and computes the memory every node holds (per_node_gb) and the memory split over the nodes (split_gb). simulation_nodes uses the MEMORY_MODEL instance, or another model if given.
peak_memory_safety_factor says what the factor applies to. reserved_node_memory_fraction (0.1) is the share of a node's memory kept for the system, Slurm and MPI, instead of the share left (0.9).
BYTES_PER_KIB, BYTES_PER_MIB and BYTES_PER_GIB replace the 1024, 2**20 and 2**30 of the memory model and of the LFP weights: the estimate is in GiB, as memory_per_instance_gb.
MIB, KIB and BYTE are those units in GiB, the unit of the estimate, so each term reads as it was measured: 5.55 * MIB per cell, 3.07 * KIB per synapse, 41.4 * BYTE per spike and rank.
simulation_synapse_counts and replay_spike_files (obi_one/scientific/library/simulation_synapses.py) replace the task's _synapse_counts and _replay_counts; the task checks the circuit applies and calls them.
…service cache The simulations of a campaign share the staged circuit: the first reads the edge indices and saves the synapses per cell next to its config (synapses_per_cell.npz), the others load it. The module cache, its lock and its eviction go: nothing is kept in the service between requests, and each campaign reads the indices once. The file of the whole rCA1 circuit is 5.2 MB, saved in 11 ms and loaded in 9 ms.
eleftherioszisis
force-pushed
the
number-synapses-from-edge-indices
branch
from
November 27, 2026 11:20
2e0590e to
c42f6a4
Compare
It is an entitysdk helper (a directory listing and Client.open_file), so it sits with the other circuit helpers of db_sdk, with REMOTE_BLOCK_SIZE. circuit_staging's _asset_path_in becomes the public asset_path_in, which both use.
…tences Functions say what they return or do, classes and attributes what they hold, without getting longer. A test docstring still spoke of a cache.
It is how many times denser than average a subset may be (synapses per cell of a node set, or per source of the replayed sources), which is what the 2.5 was measured as.
share becomes worst_case_fraction_of_total (of a population counted only in total) and worst_case_fraction_of_weights (of the weight matrices).
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The memory of a neurodamus simulation comes from its synapses, its replay and its spike files much more than from its neurons. An rCA1 cell has 8 times the synapses of an SSCX cell, so the per-cell rule of SSCX let the CA1 job
01a1cb34run out of memory, and the temporary 0.09 GB per cell that replaced it triples every SSCX allocation. This PR records what drives memory at generation, and sizes the nodes with a model measured in the simulation image.number_synapses(onto the simulated cells),number_synapses_in_replay(estimated, whose source spikes in a spike stimulus) andnumber_spikes_in_replayon theSimulation, each only if entitysdk'sSimulationhas the field.Refs openbraininstitute/prod-circuit-simulation#265.
Model
Fitted on 76 runs of neurodamus 4.2.11 and 4.3.0 in the production image (NEURON and CoreNEURON, rCA1 and SSCX cells, 1 to 16 ranks, replay, large spike files, reports, LFP), launched as launch-system does. Every run is within 0.85 to 1.09 of it.
Times 1.15 (the largest measured peak is 1.09 times the fit), with 90% of a node usable. Instances now declare their
ranks_per_instance(192 onhpc7a.96xlarge, 176 onHB176rs_v4, 4 ont3a.xlarge; 2 on cell_b's small pool, not checked) and, on cell_a,max_instances(20 large, 12 small, fromaws-terraform-deploymentlaunch_system/pcs.tf).What it gives:
01a1cb34(9,587 cells, 219M synapses, 5.4% of CA3 replayed)On the 122 distinct circuits of staging and production simulated whole, the estimate gives the 0.03 rule's nodes to 112 (every SSCX, thalamus, MICrONS, H01, Allen and synaptome circuit) and more to the 10 rCA1 circuits whose synapses need them; fewer to none.
The measurements, the fit, every run against the model and these comparisons are in
docs/circuit-simulation-memory-measurements.md; how the estimate works is indocs/circuit-simulation-resources.md.Counting at generation
target_to_sourceindex of each edges file, read withClient.open_file(entitysdk 0.22), from the local asset store or with range reads. The layout is not trusted: a population is counted per cell only if its index is at most 32 MB and accounts for every edge; otherwise in total, from the shape ofsource_node_id, with a node set getting its share of the cells times 2.5. All 2,926 circuits of staging and production were checked: every counted population has the index, synaptome writers give it too few or too many rows, and nbS1 has 68 MB of index per population.get_entityit made before, plus two per LFP recording array.Dependencies and rollout
Client.open_file, released).uv.lockand the launch-script requirements pin it;make compile-deps,make check-depsandmake check-launch-depswere run against the private index and leave them unchanged.Simulationin entitycore and entitysdk:number_synapsesis in entitycore (Add number_synapses to Simulation entitycore#775, merged),number_synapses_in_replayandnumber_spikes_in_replayin Add number_synapses_in_replay and number_spikes_in_replay to Simulation entitycore#780; entitysdk has none of them yet (the change is ready, not opened). entitysdk 0.22 reads responses with fields it does not know, so the order of the releases does not matter for clients. Until entitysdk has the fields, generation records the neuron count only and the estimate stays at 0.09 GB per cell.Limits
Checks
tyclean on the changed code. 1,990 tests pass over the generation, library and app suites (the 3 collection errors are optional extras not installed locally).