Skip to content

Add intra-population edges to test circuit, fix external edge merge bug#54

Open
cattabiani wants to merge 7 commits into
katta/id_mapping_nested_dictsfrom
katta/add-intra-population-edges
Open

Add intra-population edges to test circuit, fix external edge merge bug#54
cattabiani wants to merge 7 commits into
katta/id_mapping_nested_dictsfrom
katta/add-intra-population-edges

Conversation

@cattabiani
Copy link
Copy Markdown
Contributor

@cattabiani cattabiani commented May 22, 2026

Summary

Adds intra-population edges (A→A, B→B) to the split_subcircuit test circuit and fixes a bug in _copy_filtered_edges exposed by the new edge topology.

Test data changes

  • A→A edges: A3→A4, A4→A3, A1→A2, A0→A4, A5→A1
  • B→B edges: B0→B2, B3→B4
  • C→C: intentionally omitted to test the case where no intra-population edge file exists

Updated circuit_config.json, circuit_config_subcircuit.json, and regenerated edges.h5. All test assertions updated to reflect the new external populations and edge counts.

Bug fix: source ID lookup in multi-source external populations

The problem

_copy_filtered_edges used to concatenate all source DataFrames into one:

src_concat = pd.concat(id_mapping.data[write_edge_config.src_mapping].values())

This is conceptually wrong. The sources come from different ID spaces (e.g., the parent's external_A population vs the local A population). When two sources happen to share the same local node ID, the concatenated DataFrame has duplicate index values, and .loc[id] returns multiple rows — corrupting the edge file.

Concrete example

When extracting c4 from c3_c2_c1, the external_A population has two sources:

  • "external_A": node 2 (inherited from parent) → new_id 0
  • "A": node 2 (newly removed) → new_id 1

The concat produces index [2, 2]. When processing the parent's external_A__C edge (src=2, tgt=3), the lookup src_concat.loc[2] returns both rows, appending [0, 1] to source_node_id but only [3] to target_node_id.

The fix

Removed src_concat entirely. Each input now resolves its own source DataFrame directly via source_filter. For single-source populations (the common case), the single entry is used directly. For multi-source populations, an assertion enforces that source_filter is always provided.

Why it wasn't triggered before

The bug requires intra-population edges (A→A) so that removed A nodes become external_A via the same-population path. Without them, external nodes were only discovered through inter-population edges, and the local ID collision never occurred.

c2_c1 c3_c1 c3_c2_c1 c4_c1 c4_c2_c1 c4_c3_c1 c4_c3_c2_c1 Original_c1

@cattabiani cattabiani changed the base branch from main to katta/id_mapping_nested_dicts May 22, 2026 13:09
…xternal edge merge

- Add A->A and B->B edges to test circuit (C->C intentionally omitted
  to test the no-edge-file case)
- Update test assertions for new external populations and edge counts
- Fix bug in _copy_filtered_edges: when source_filter is active, pass
  only the filtered source DataFrame to _write_masked_edges to prevent
  duplicate index lookups when multiple sources share local node IDs
@cattabiani cattabiani force-pushed the katta/add-intra-population-edges branch from f210971 to c52599d Compare May 22, 2026 13:18
The concat of multiple source DataFrames is conceptually wrong — sources
come from different ID spaces and should never be merged for lookup.
Now each input resolves its own source_df directly, and an assertion
ensures multi-source populations always provide a source_filter.
@cattabiani cattabiani requested review from chr-pok and mgeplf May 22, 2026 13:52
@cattabiani cattabiani self-assigned this May 22, 2026
@cattabiani cattabiani marked this pull request as ready for review May 22, 2026 13:52
@cattabiani cattabiani changed the title add intra population edges Add intra-population edges to test circuit, fix external edge merge bug May 22, 2026
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.

1 participant