Skip to content

compartment sets (corenrn)#3542

Merged
cattabiani merged 3 commits into
masterfrom
katta/compartment_sets_corenrn
Aug 22, 2025
Merged

compartment sets (corenrn)#3542
cattabiani merged 3 commits into
masterfrom
katta/compartment_sets_corenrn

Conversation

@cattabiani

@cattabiani cattabiani commented Jul 24, 2025

Copy link
Copy Markdown
Member

Why

This is the continuation of this #3507 to enable CompartmentSet reports in coreneuron. They are nested on top of Compartment reports. In fact, conceptually, they are a filtered version since we report the values typically found in a compartment report but only for some specific points; specified in an additional file. The specs are described here.

Neurodamus/neuron already handle most of this. However, coreneuron generates reports by itself (using libsonatareport) so we need to add support in coreneuron itself.

How

Qualitatively this is done in a few steps:

  • add a way to pass the points to coreneuron because it does not read compartment_sets.json by itself. This is done by adding a few lines of binary values to report.conf. A point is defined as a triplet: (gid, section_id, compartment_id) where:
  • gid is the usual gid of a cell
  • section_id is the progressive id of the sections. Local of each cell and it depends on the stection types that are on the cell. Qualitatively, it uniquely defines a section on the cell and you can always pass for example dend[16] <-> section_id.
  • compartment_id I am not 100% sure of how these ids are really taken. However I see that I can:
    • pick them from a seg (compartment) with soma[0](0.5).node_index()
    • they are non-repeating per thread and can identify a node. A node is an element in one of the basic neuron matrices
    • differently from the nodes, they are not contiguous. The mapping can be retrieveed from Memb_list.nodeindices where: Memb_list.nodeindices[i_node] = compartment_id.
    • reversing Memb_list.nodeindices allows me to retrieve the node id to, finally, pick the correct double* necessary for libsoantareport to work. This lazy mapping is done in fill_segment_id_2_node_id(. get_var( is in charge of calling this when necessary. The only thing left to manage this cache is to decide when to clear the cache (every new gid gets a new cache). Fortunately gids are progressive so this is already optimal.

Changelog

nrnreport.hpp

  • add CompartmentSet report type
  • remove TargetType and split it in Compartments and SectionType: no need to encode/decode 2 enums into 1 in a non-critical part of the code
  • add a few fields to ReportConfiguration to manage CompartmentSet report and the removal of TargetType

report_configuration_parser.cpp

  • simplify reading of report.conf
  • standardize the reading of binary vector<int> from report.conf with fill_vec_int
  • add a few nrn_assert: compartment reports cannot pick multiple variables for the same point

report_handler.cpp

  • standardized errors and asserts
  • reorder function position to make most of the functions local in this translation unit: they were never used outside
  • lazy caching with fill_segment_id_2_node_id. Moved out of get_var to carify its purpose. In some particular cases it may be useful to have it as a stand-alone function
  • remove check_section_type: if the ReportType is unknown we throw an error directly in create_report
  • reworked intersection_gids to create a list of ids to pick in report.target. CompartmentSet can easily have repeated gids (not a thing before) which were discarded before. This made the previous list badly suited for a 3-vector id system as in CompartmentSet. It could have been done without this change but this was by far the simplest, cleanest, and most elegant solution. The change for the existing functions is minimal. From:
for (const auto& gid: gids_to_report) {

to:

 for (const auto& intersection_id: intersection_ids) {
        const auto gid = report.target[intersection_id];
  • remove nodes_to_gids and map_gids which is, now, obsolete and inefficient. It requires a loop over all the nodes instead of picking only the good ones.
  • all_compartments is not part of the configuration (in a nice enum: Compartments)

report_handler.hpp

  • remove most of the member methods as they were used only in report_handler.cpp. Faster compilation.

test/external/CMakeLists.txt

  • updated external tests and its tag

@cattabiani cattabiani changed the base branch from master to katta/corenrn_reports July 24, 2025 11:26
@cattabiani cattabiani self-assigned this Jul 24, 2025
@github-actions

Copy link
Copy Markdown
Contributor

✔️ 07537fd -> artifacts URL

@codecov

codecov Bot commented Jul 24, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.12195% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.46%. Comparing base (8b46733) to head (ad20974).
⚠️ Report is 43 commits behind head on master.

Files with missing lines Patch % Lines
...eneuron/io/reports/report_configuration_parser.cpp 93.75% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3542      +/-   ##
==========================================
+ Coverage   68.45%   68.46%   +0.01%     
==========================================
  Files         685      685              
  Lines      116809   116720      -89     
==========================================
- Hits        79964    79917      -47     
+ Misses      36845    36803      -42     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@azure-pipelines

Copy link
Copy Markdown

✔️ ae12f47 -> Azure artifacts URL

@azure-pipelines

Copy link
Copy Markdown

✔️ deb88c4 -> Azure artifacts URL

@cattabiani cattabiani requested a review from JCGoran August 8, 2025 09:06
@cattabiani cattabiani marked this pull request as ready for review August 8, 2025 09:07
@azure-pipelines

Copy link
Copy Markdown

✔️ 6cc6885 -> Azure artifacts URL

@azure-pipelines

Copy link
Copy Markdown

✔️ a3f8170 -> Azure artifacts URL

@azure-pipelines

Copy link
Copy Markdown

✔️ bdb1d43 -> Azure artifacts URL

@azure-pipelines

Copy link
Copy Markdown

✔️ 9cd1774 -> Azure artifacts URL

@azure-pipelines

Copy link
Copy Markdown

✔️ 99def07 -> Azure artifacts URL

@azure-pipelines

Copy link
Copy Markdown

✔️ 4b6ef68 -> Azure artifacts URL

@azure-pipelines

Copy link
Copy Markdown

✔️ 8fb9c99 -> Azure artifacts URL

@azure-pipelines

Copy link
Copy Markdown

✔️ 3150c6d -> Azure artifacts URL

@cattabiani cattabiani requested a review from nrnhines August 20, 2025 07:07
@cattabiani cattabiani changed the base branch from katta/corenrn_reports to master August 20, 2025 07:13
@cattabiani cattabiani changed the base branch from master to katta/corenrn_reports August 20, 2025 07:14
@azure-pipelines

Copy link
Copy Markdown

✔️ a686c93 -> Azure artifacts URL

@azure-pipelines

Copy link
Copy Markdown

✔️ b94f686 -> Azure artifacts URL

Comment thread test/external/CMakeLists.txt Outdated
Base automatically changed from katta/corenrn_reports to master August 22, 2025 09:05
@cattabiani

cattabiani commented Aug 22, 2025

Copy link
Copy Markdown
Member Author

the merge of corenrn_reports into master added conflicts that I did not resolve correctly. Working on this...

@cattabiani cattabiani marked this pull request as draft August 22, 2025 09:44
@azure-pipelines

Copy link
Copy Markdown

✔️ 3e7ba4e -> Azure artifacts URL

@github-actions

Copy link
Copy Markdown
Contributor

✔️ 0871d38 -> artifacts URL

@github-actions

Copy link
Copy Markdown
Contributor

✔️ 3e7ba4e -> artifacts URL

@cattabiani cattabiani force-pushed the katta/compartment_sets_corenrn branch 2 times, most recently from b94f686 to 26d0828 Compare August 22, 2025 10:05
@cattabiani cattabiani force-pushed the katta/compartment_sets_corenrn branch from 26d0828 to 0d51ee6 Compare August 22, 2025 11:33
@sonarqubecloud

Copy link
Copy Markdown

@azure-pipelines

Copy link
Copy Markdown

✔️ ad20974 -> Azure artifacts URL

@github-actions

Copy link
Copy Markdown
Contributor

✔️ ad20974 -> artifacts URL

@cattabiani cattabiani marked this pull request as ready for review August 22, 2025 15:08
@cattabiani cattabiani merged commit 0d99051 into master Aug 22, 2025
43 checks passed
@cattabiani cattabiani deleted the katta/compartment_sets_corenrn branch August 22, 2025 15:37
cattabiani added a commit to openbraininstitute/neurodamus that referenced this pull request Sep 4, 2025
## Context

This should finally take care of the compartment sets for coreneuron

Fix: #345 #322

testing for:

neuronsimulator/nrn#3507
neuronsimulator/nrn#3542

## Scope

- [x] rework report handling (mostly in node and target_manager this time. i.e. removal of `_report_setup`)
- [x] new `CoreReportConfig` to finally handle in a proper way `report.conf`
- [x] remove `write_sim_config`, `update_report_conf`, `write_report_conf` and similar functions in `CoreConfig`. Use `CoreSimulationConfig` and `CoreReportConfig` instead
- [x] move `cell-permute` in another issue/pr. EDIT done: #367
- [x] scaling moved to `report_parameters.py`
- [x] `CumulativeError` moved in `pyutils`
- [x] `ReportParams` now has its own file alleviating the burden of the `node.py` file. `_report_build_params` (previously in `node.py`) is also inside the new file.
- [x] `target_type` is no more. We do not need encoding/decoding. We just write `sections` and `compartments` in the `report.conf` 
- [x] streamlined `enable_reports`. It is still a complex function but it should be easier to read and with less edge cases 
- [x] use the decorator `@cache_errors` to just fill a `CumulativeError` instead of raising an error and raise it at the end
- [x] `merge_dicts` (in `tests/utils.py`) allows for overrides and suppression of sections from the child dict with the special keywords: `override_field` and `delete_field`

### `report.conf` changes

- [x] `type_name` has been split into `sections` and `compartments`. No need to encode everything in an enum to decode later. This simplifies code and makes the `report.conf`. The code is slightly slower `0(1)` in a part of the code that was not performance-critical
- [x] `scaling` added at the end of the report line (after buffer size)
- [x] add 2 additional binary lines in case of a compartment set report to pass the exact positions of the compartment sets. They are necessary if and only if the report type is `compartment_set`. Having them when it is not or not having them when it is is an error.

## Testing

- [x] add integration-e2e tests in `test_reports.py`

## Testing
- [x] test various bug fixes in coreneuron
- [x] add lfp test. Check that it fails with neuron
- [x] fix integration-e2e
- [x] fix scientific
- [x] fix unit
NghiV1412 pushed a commit to ABL-Lab/neurodamus that referenced this pull request Dec 18, 2025
## Context

This should finally take care of the compartment sets for coreneuron

Fix: #345 #322

testing for:

neuronsimulator/nrn#3507
neuronsimulator/nrn#3542

## Scope

- [x] rework report handling (mostly in node and target_manager this time. i.e. removal of `_report_setup`)
- [x] new `CoreReportConfig` to finally handle in a proper way `report.conf`
- [x] remove `write_sim_config`, `update_report_conf`, `write_report_conf` and similar functions in `CoreConfig`. Use `CoreSimulationConfig` and `CoreReportConfig` instead
- [x] move `cell-permute` in another issue/pr. EDIT done: #367
- [x] scaling moved to `report_parameters.py`
- [x] `CumulativeError` moved in `pyutils`
- [x] `ReportParams` now has its own file alleviating the burden of the `node.py` file. `_report_build_params` (previously in `node.py`) is also inside the new file.
- [x] `target_type` is no more. We do not need encoding/decoding. We just write `sections` and `compartments` in the `report.conf` 
- [x] streamlined `enable_reports`. It is still a complex function but it should be easier to read and with less edge cases 
- [x] use the decorator `@cache_errors` to just fill a `CumulativeError` instead of raising an error and raise it at the end
- [x] `merge_dicts` (in `tests/utils.py`) allows for overrides and suppression of sections from the child dict with the special keywords: `override_field` and `delete_field`

### `report.conf` changes

- [x] `type_name` has been split into `sections` and `compartments`. No need to encode everything in an enum to decode later. This simplifies code and makes the `report.conf`. The code is slightly slower `0(1)` in a part of the code that was not performance-critical
- [x] `scaling` added at the end of the report line (after buffer size)
- [x] add 2 additional binary lines in case of a compartment set report to pass the exact positions of the compartment sets. They are necessary if and only if the report type is `compartment_set`. Having them when it is not or not having them when it is is an error.

## Testing

- [x] add integration-e2e tests in `test_reports.py`

## Testing
- [x] test various bug fixes in coreneuron
- [x] add lfp test. Check that it fails with neuron
- [x] fix integration-e2e
- [x] fix scientific
- [x] fix unit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants