Skip to content

Commit

Permalink
Allow probing of point state by tag. (#2417)
Browse files Browse the repository at this point in the history
This concludes the introduction of 'labels' for synapse identification /
placements started back in
PR #1504 by @noraabiakar. Labels are now used when probing a synapse's
state.
  • Loading branch information
thorstenhater authored Oct 18, 2024
1 parent 76120d1 commit f302088
Show file tree
Hide file tree
Showing 11 changed files with 253 additions and 153 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:
strategy:
fail-fast: false
env:
CC: gcc-11
CXX: g++-11
CC: gcc-12
CXX: g++-12
steps:
- name: Get build dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion arbor/cable_cell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ struct cable_cell_impl {
cell_lid_type first = lid;

for (const auto& loc: locs) {
placed<Item> p{loc, lid++, item};
placed<Item> p{loc, lid++, item, label};
mm.push_back(p);
}
auto range = lid_range(first, lid);
Expand Down
68 changes: 45 additions & 23 deletions arbor/fvm_lowered_cell_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <arbor/assert.hpp>
#include <arbor/common_types.hpp>
#include <arbor/cable_cell.hpp>
#include <arbor/cable_cell_param.hpp>
#include <arbor/recipe.hpp>
#include <arbor/util/any_visitor.hpp>
Expand Down Expand Up @@ -882,15 +883,15 @@ void resolve_probe(const cable_probe_density_state_cell& p, probe_resolution_dat
}

inline
auto point_info_of(cell_lid_type target,
auto point_info_of(cell_tag_type target,
cell_lid_type lid,
int mech_index,
const mlocation_map<synapse>& instances,
const std::vector<arb_index_type>& multiplicity) {

auto opt_i = util::binary_search_index(instances, target, [](auto& item) { return item.lid; });
auto opt_i = util::binary_search_index(instances, lid, [](auto& item) { return item.lid; });
if (!opt_i) throw arbor_internal_error("inconsistent mechanism state");

return cable_probe_point_info {target,
return cable_probe_point_info {std::move(target),
lid,
multiplicity.empty() ? 1u: multiplicity.at(mech_index),
instances[*opt_i].loc};
}
Expand All @@ -903,6 +904,7 @@ void resolve_probe(const cable_probe_point_state& p, probe_resolution_data<B>& R
const auto& mech = p.mechanism;
const auto& state = p.state;
const auto& target = p.target;
const auto& t_hash = hash_value(target);
const auto& data = R.mechanism_state(mech, state);
if (!R.mech_instance_by_name.count(mech)) return;
const auto mech_id = R.mech_instance_by_name.at(mech)->mechanism_id();
Expand All @@ -913,17 +915,27 @@ void resolve_probe(const cable_probe_point_state& p, probe_resolution_data<B>& R
// Convert cell-local target number to cellgroup target number.
const auto& divs = R.M.target_divs;
auto cell = R.cell_idx;
auto cg = target + divs.at(cell);
if (cg >= divs.at(cell + 1)) return;

const auto& handle = R.handles.at(cg);
if (handle.mech_id != mech_id) return;
auto mech_index = handle.mech_index;
R.result.push_back(fvm_probe_scalar{{data + mech_index},
point_info_of(target,
mech_index,
synapses.at(mech),
R.M.mechanisms.at(mech).multiplicity)});
auto cg_lo = divs.at(cell);
auto cg_hi = divs.at(cell + 1);
const auto& [lr_beg, lr_end] = R.cell
.synapse_ranges()
.equal_range(t_hash);
for (auto lr = lr_beg; lr != lr_end; ++lr) {
const auto& [lid_beg, lid_end] = lr->second;
for (auto lid = lid_beg; lid != lid_end; ++lid) {
auto cg = lid + cg_lo;
if (cg >= cg_hi) continue;
const auto& handle = R.handles.at(cg);
if (handle.mech_id != mech_id) return;
auto mech_index = handle.mech_index;
R.result.push_back(fvm_probe_scalar{{data + mech_index},
point_info_of(target,
lid,
mech_index,
synapses.at(mech),
R.M.mechanisms.at(mech).multiplicity)});
}
}
}

template <typename B>
Expand All @@ -944,25 +956,35 @@ void resolve_probe(const cable_probe_point_state_cell& p, probe_resolution_data<
auto cell_targets_beg = R.M.target_divs.at(R.cell_idx);
auto cell_targets_end = R.M.target_divs.at(R.cell_idx + 1);

fvm_probe_multi r;
std::vector<cable_probe_point_info> metadata;
const auto& decor = R.cell.decorations();

fvm_probe_multi result;
std::vector<cable_probe_point_info> metadata;
cell_lid_type lid = 0;
for (auto target: util::make_span(cell_targets_beg, cell_targets_end)) {
const auto& handle = R.handles.at(target);
if (handle.mech_id != mech_id) continue;

auto mech_index = handle.mech_index;
r.raw_handles.push_back(data + mech_index);
result.raw_handles.push_back(data + mech_index);

// Convert to cell-local target index.
const auto& ins = placed_instances.at(lid);
auto lid = target - cell_targets_beg;
auto tag = decor.tag_of(ins.tag);

metadata.push_back(point_info_of(target - cell_targets_beg, // Convert to cell-local target index.
metadata.push_back(point_info_of(tag,
lid,
mech_index,
placed_instances,
multiplicity));
++lid;
}

r.metadata = std::move(metadata);
r.shrink_to_fit();
R.result.push_back(std::move(r));

result.metadata = std::move(metadata);
result.shrink_to_fit();
R.result.push_back(std::move(result));
}

template <typename B>
Expand Down
25 changes: 21 additions & 4 deletions arbor/include/arbor/cable_cell.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ using cable_sample_range = std::pair<const double*, const double*>;
//
// Metadata for point process probes.
struct ARB_SYMBOL_VISIBLE cable_probe_point_info {
cell_lid_type target; // Target number of point process instance on cell.
cell_tag_type target; // Target tag of point process instance on cell.
cell_lid_type lid; // Target lid of point process instance on cell.
unsigned multiplicity; // Number of combined instances at this site.
mlocation loc; // Point on cell morphology where instance is placed.
};
Expand Down Expand Up @@ -109,6 +110,7 @@ struct ARB_SYMBOL_VISIBLE cable_probe_density_state {
};

// Value of state variable `state` in density mechanism `mechanism` across components of the cell.
//
// Sample value type: `cable_sample_range`
// Sample metadata type: `mcable_list`
struct ARB_SYMBOL_VISIBLE cable_probe_density_state_cell {
Expand All @@ -117,16 +119,30 @@ struct ARB_SYMBOL_VISIBLE cable_probe_density_state_cell {
};

// Value of state variable `key` in point mechanism `source` at target `target`.
//
// Sample value type: `double`
// Sample metadata type: `cable_probe_point_info`
struct ARB_SYMBOL_VISIBLE cable_probe_point_state {
cell_lid_type target;
cell_tag_type target;
std::string mechanism;
std::string state;

// Engage in minimal hygeine. Ideally, we'd disable all nullptr constructors.
cable_probe_point_state(std::nullptr_t, std::string, std::string) = delete;
cable_probe_point_state() = delete;

constexpr cable_probe_point_state(cell_tag_type t, std::string m, std::string s):
target(std::move(t)), mechanism(std::move(m)), state(std::move(s)) {}
constexpr cable_probe_point_state(const cable_probe_point_state&) = default;
constexpr cable_probe_point_state(cable_probe_point_state&&) = default;
constexpr cable_probe_point_state& operator=(const cable_probe_point_state&) = default;
constexpr cable_probe_point_state& operator=(cable_probe_point_state&&) = default;
};

// Value of state variable `key` in point mechanism `source` at every target with this mechanism.
// Metadata has one entry of type cable_probe_point_info for each matched (possibly coalesced) instance.
// Value of state variable `key` in point mechanism `source` at every target
// with this mechanism. Metadata has one entry of type cable_probe_point_info
// for each matched (possibly coalesced) instance.
//
// Sample value type: `cable_sample_range`
// Sample metadata type: `std::vector<cable_probe_point_info>`
struct ARB_SYMBOL_VISIBLE cable_probe_point_state_cell {
Expand Down Expand Up @@ -224,6 +240,7 @@ struct placed {
mlocation loc;
cell_lid_type lid;
T item;
hash_type tag;
};

// Note: lid fields of elements of mlocation_map used in cable_cell are strictly increasing.
Expand Down
Loading

0 comments on commit f302088

Please sign in to comment.