Skip to content

Commit 28d3612

Browse files
authored
corenrn permute for reports (#3587)
### Context Until now, corenrn reports were not really addressing corenrn permutations. They were not tested too since cell_permute is hardcoded to 0 in neurodamus. ### Scope This small pr fixes this to the root (where possible). - `compartment sets report`: in this case the report passes manually the node indexes. At the loading moment `NrnThread` is empty and I cannot do the node conversion on the spot (@nrnhines if you know of a better way I would actually prefer to permute immediately, when I load this file. I mean in `report_configuration_parser.cpp`. Let me know if you want a zoom call). For this reason the permutation is done in `get_compartment_set_vars_to_report` - **all the other reports**: use `cell_mapping`. We apply the permutation as soon as we load the indexes in memory thus nobody can uses stale values. This is done largely in `phase3.cpp`. ### Tests This was already successfully tested manually in neurodamus for all the reports (lfp included). - [ ] run tests with cell_permute 1 once the option can be passed to neurodamus ### Note This pr does not block nor is blocked by the neurodamus side. Current neurodamus has hardcoded `cell_permute = 0` and this pr should not change anything if cell_permute is 0
1 parent 71cb817 commit 28d3612

5 files changed

Lines changed: 27 additions & 10 deletions

File tree

src/coreneuron/io/nrn_filehandler.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
#include <cmath>
1515
#include <sys/stat.h>
1616

17-
#include "coreneuron/utils/nrn_assert.h"
1817
#include "coreneuron/io/nrnsection_mapping.hpp"
18+
#include "coreneuron/permute/node_permute.h"
19+
#include "coreneuron/sim/multicore.hpp"
20+
#include "coreneuron/utils/nrn_assert.h"
1921

2022
namespace coreneuron {
2123
/** Encapsulate low-level reading of coreneuron input data files.
@@ -114,7 +116,8 @@ class FileHandler {
114116
template <typename T>
115117
int read_mapping_info(T mapinfo,
116118
NrnThreadMappingInfo* ntmapping,
117-
std::shared_ptr<CellMapping> cmap) {
119+
std::shared_ptr<CellMapping> cmap,
120+
const NrnThread& nt) {
118121
int nsec, nseg, n_scan;
119122
size_t total_lfp_factors;
120123
int num_electrodes;
@@ -132,6 +135,10 @@ class FileHandler {
132135
auto sec = read_vector<int>(nseg);
133136
auto seg = read_vector<int>(nseg);
134137

138+
if (nt._permute) {
139+
node_permute(seg.data(), seg.size(), nt._permute);
140+
}
141+
135142
std::vector<double> lfp_factors;
136143
if (total_lfp_factors > 0) {
137144
lfp_factors = read_vector<double>(total_lfp_factors);

src/coreneuron/io/nrn_setup.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -944,11 +944,11 @@ void read_phase3(NrnThread& nt, UserParams& userParams) {
944944

945945
Phase3 p3;
946946
if (corenrn_embedded && !corenrn_file_mode) {
947-
p3.read_direct(ntmapping);
947+
p3.read_direct(ntmapping, nt);
948948
} else {
949949
auto& F = userParams.file_reader[nt.id];
950950
F.restore_checkpoint();
951-
p3.read_file(F, ntmapping);
951+
p3.read_file(F, ntmapping, nt);
952952
}
953953

954954
// make number #cells match with mapping size

src/coreneuron/io/phase3.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void (*nrn2core_get_dat3_secmapping_)(int i_c,
2626
std::vector<double>& data_lfp);
2727

2828
namespace coreneuron {
29-
void Phase3::read_file(FileHandler& F, NrnThreadMappingInfo* ntmapping) {
29+
void Phase3::read_file(FileHandler& F, NrnThreadMappingInfo* ntmapping, const NrnThread& nt) {
3030
int count = 0;
3131
F.read_mapping_cell_count(&count);
3232
/** for every neuron */
@@ -38,14 +38,14 @@ void Phase3::read_file(FileHandler& F, NrnThreadMappingInfo* ntmapping) {
3838
// read section-segment mapping for every section list
3939
for (int j = 0; j < nseclist; j++) {
4040
auto smap = std::make_shared<SecMapping>();
41-
F.read_mapping_info(smap, ntmapping, cmap);
41+
F.read_mapping_info(smap, ntmapping, cmap, nt);
4242
cmap->add_sec_map(smap);
4343
}
4444
ntmapping->add_cell_mapping(cmap);
4545
}
4646
}
4747

48-
void Phase3::read_direct(NrnThreadMappingInfo* ntmapping) {
48+
void Phase3::read_direct(NrnThreadMappingInfo* ntmapping, const NrnThread& nt) {
4949
int count;
5050
nrn2core_get_dat3_cell_count_(count);
5151
/** for every neuron */
@@ -75,6 +75,9 @@ void Phase3::read_direct(NrnThreadMappingInfo* ntmapping) {
7575
data_sec,
7676
data_seg,
7777
data_lfp);
78+
if (nt._permute) {
79+
node_permute(data_seg.data(), data_seg.size(), nt._permute);
80+
}
7881
auto smap = std::make_shared<SecMapping>();
7982
smap->type = section_type_from_string(sclname);
8083
for (int i_seg = 0; i_seg < n_seg; i_seg++) {

src/coreneuron/io/phase3.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
#pragma once
1010

1111
#include "coreneuron/io/nrn_filehandler.hpp"
12+
#include "coreneuron/sim/multicore.hpp"
13+
1214

1315
namespace coreneuron {
1416
struct NrnThreadMappingInfo;
1517

1618
class Phase3 {
1719
public:
18-
void read_file(FileHandler& F, NrnThreadMappingInfo* ntmapping);
19-
void read_direct(NrnThreadMappingInfo* ntmapping);
20+
void read_file(FileHandler& F, NrnThreadMappingInfo* ntmapping, const NrnThread& nt);
21+
void read_direct(NrnThreadMappingInfo* ntmapping, const NrnThread& nt);
2022
};
2123
} // namespace coreneuron

src/coreneuron/io/reports/report_handler.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "report_handler.hpp"
1212
#include "coreneuron/io/nrnsection_mapping.hpp"
1313
#include "coreneuron/mechanism/mech_mapping.hpp"
14+
#include "coreneuron/permute/node_permute.h"
1415
#include "coreneuron/utils/utils.hpp"
1516

1617
namespace coreneuron {
@@ -371,7 +372,11 @@ static VarsToReport get_compartment_set_vars_to_report(const NrnThread& nt,
371372
for (const auto& intersection_id: intersection_ids) {
372373
const auto gid = report.target[intersection_id];
373374
const auto section_id = report.point_section_ids[intersection_id];
374-
const auto compartment_id = report.point_compartment_ids[intersection_id];
375+
auto compartment_id = report.point_compartment_ids[intersection_id];
376+
if (nt._permute) {
377+
node_permute(&compartment_id, 1, nt._permute);
378+
}
379+
375380
if (old_gid != gid) {
376381
// clear cache for new gid. We know they are strictly ordered
377382
segment_id_2_node_id.clear();

0 commit comments

Comments
 (0)