Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/clang_format_check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ jobs:
- name: Fetch repository
uses: actions/checkout@v4
with:
fetch-depth: 2
fetch-depth: 0

- name: Install packages
run: sudo apt-get update && sudo apt-get install python3-venv

- name: check_clang_format
run: ci/check_clang_format.sh
run: |
git fetch origin master
ci/check_clang_format.sh
8 changes: 7 additions & 1 deletion ci/check_clang_format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ set +u # ignore errors in virtualenv's activate
source "$VENV/bin/activate"
set -u

changes=$(git-clang-format 'HEAD~1' $DIRS_TO_FORMAT)
git branch --all
git merge-base HEAD remotes/origin/master

changes_from="$(git merge-base HEAD remotes/origin/master)"
echo "Changes from: $changes_from"
git-clang-format --diff $changes_from HEAD $DIRS_TO_FORMAT
changes=$(git-clang-format --diff $changes_from HEAD $DIRS_TO_FORMAT)
if [[ $(echo "$changes" | grep -n1 'changed files') ]]; then
echo "The following files require changes to pass the current clang-format"
echo "$changes"
Expand Down
85 changes: 52 additions & 33 deletions include/bbp/sonata/compartment_sets.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,55 +30,75 @@ class CompartmentSets;
struct CompartmentLocation {
public:
uint64_t nodeId = 0;
uint64_t sectionIndex = 0;
uint64_t sectionId = 0;
double offset = 0.0;

/// Comparator. Used to compare vectors in CompartmentSet. More idiomatic than defining a
/// comaprator on the fly
bool operator==(const CompartmentLocation& other) const {
return nodeId == other.nodeId && sectionIndex == other.sectionIndex &&
offset == other.offset;
return nodeId == other.nodeId && sectionId == other.sectionId && offset == other.offset;
}

bool operator!=(const CompartmentLocation& other) const {
return !(*this == other);
}

bool operator<(const CompartmentLocation& other) const {
if (nodeId != other.nodeId)
return nodeId < other.nodeId;
if (sectionId != other.sectionId)
return sectionId < other.sectionId;
return offset < other.offset;
}

bool operator>(const CompartmentLocation& other) const {
return other < *this;
}

bool operator<=(const CompartmentLocation& other) const {
return !(other < *this);
}

bool operator>=(const CompartmentLocation& other) const {
return !(*this < other);
}
};

/// Ostream << operator used by catch2 when there are problems for example
inline std::ostream& operator<<(std::ostream& os, const CompartmentLocation& cl) {
os << "CompartmentLocation("
<< "nodeId: " << cl.nodeId << ", "
<< "sectionIndex: " << cl.sectionIndex << ", "
<< "sectionId: " << cl.sectionId << ", "
<< "offset: " << cl.offset << ")";
return os;
}

class SONATA_API CompartmentSetFilteredIterator {
public:
using iterator_category = std::forward_iterator_tag;
using value_type = CompartmentLocation;
using difference_type = std::ptrdiff_t;
using pointer = const CompartmentLocation*;
using reference = const CompartmentLocation&;

explicit CompartmentSetFilteredIterator(
std::unique_ptr<detail::CompartmentSetFilteredIterator> impl);
CompartmentSetFilteredIterator(const CompartmentSetFilteredIterator& other);
CompartmentSetFilteredIterator& operator=(const CompartmentSetFilteredIterator& other);
CompartmentSetFilteredIterator(CompartmentSetFilteredIterator&&) noexcept;
CompartmentSetFilteredIterator& operator=(CompartmentSetFilteredIterator&&) noexcept;
~CompartmentSetFilteredIterator();

const CompartmentLocation& operator*() const;
const CompartmentLocation* operator->() const;

CompartmentSetFilteredIterator& operator++(); // prefix ++
CompartmentSetFilteredIterator operator++(int); // postfix ++
bool operator==(const CompartmentSetFilteredIterator& other) const;
bool operator!=(const CompartmentSetFilteredIterator& other) const;

private:
class SONATA_API CompartmentSetFilteredIterator
{
public:
using iterator_category = std::forward_iterator_tag;
using value_type = CompartmentLocation;
using difference_type = std::ptrdiff_t;
using pointer = const CompartmentLocation*;
using reference = const CompartmentLocation&;

explicit CompartmentSetFilteredIterator(
std::unique_ptr<detail::CompartmentSetFilteredIterator> impl);
CompartmentSetFilteredIterator(const CompartmentSetFilteredIterator& other);
CompartmentSetFilteredIterator& operator=(const CompartmentSetFilteredIterator& other);
CompartmentSetFilteredIterator(CompartmentSetFilteredIterator&&) noexcept;
CompartmentSetFilteredIterator& operator=(CompartmentSetFilteredIterator&&) noexcept;
~CompartmentSetFilteredIterator();

const CompartmentLocation& operator*() const;
const CompartmentLocation* operator->() const;

CompartmentSetFilteredIterator& operator++(); // prefix ++
CompartmentSetFilteredIterator operator++(int); // postfix ++
bool operator==(const CompartmentSetFilteredIterator& other) const;
bool operator!=(const CompartmentSetFilteredIterator& other) const;

private:
std::unique_ptr<detail::CompartmentSetFilteredIterator> impl_;
};

Expand Down Expand Up @@ -140,8 +160,7 @@ class SONATA_API CompartmentSet
*/
class SONATA_API CompartmentSets
{
public:

public:
CompartmentSets(const std::string& content);
CompartmentSets(std::unique_ptr<detail::CompartmentSets>&& impl);
CompartmentSets(detail::CompartmentSets&& impl);
Expand Down Expand Up @@ -181,9 +200,9 @@ class SONATA_API CompartmentSets
bool operator==(const CompartmentSets& other) const;
bool operator!=(const CompartmentSets& other) const;

private:
private:
std::unique_ptr<detail::CompartmentSets> impl_;
};

} // namespace sonata
} // namespace bbp
} // namespace bbp
5 changes: 4 additions & 1 deletion include/bbp/sonata/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,11 @@ class SONATA_API SimulationConfig
*/
struct Report {
enum class Sections { invalid = -1, soma, axon, dend, apic, all };
enum class Type { invalid = -1, compartment, lfp, summation, synapse };
enum class Type { invalid = -1, compartment, lfp, summation, synapse, compartment_set };
enum class Scaling { invalid = -1, none, area };
enum class Compartments { invalid = -1, center, all };


/// Node sets on which to report
std::string cells;
/// Sections on which to report. Default value: "soma"
Expand All @@ -398,6 +399,8 @@ class SONATA_API SimulationConfig
/// For compartment type, select compartments to report.
/// Default value: "center"(for sections: soma), "all"(for other sections)
Compartments compartments;
/// Name of the compartment set (from compartment_set.json) used for generating the report.
std::string compartment_set;
/// The simulation variable to access. The variables available are model dependent. For
/// summation type, it supports multiple variables by comma separated strings. E.g. “ina”,
/// "AdEx.V_M, v", "i_membrane, IClamp".
Expand Down
22 changes: 16 additions & 6 deletions python/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,19 +551,23 @@ PYBIND11_MODULE(_libsonata, m) {
py::class_<CompartmentLocation>(m, "CompartmentLocation")
.def("__eq__", &CompartmentLocation::operator==)
.def("__ne__", &CompartmentLocation::operator!=)
.def("__lt__", &CompartmentLocation::operator<)
.def("__le__", &CompartmentLocation::operator<=)
.def("__gt__", &CompartmentLocation::operator>)
.def("__ge__", &CompartmentLocation::operator>=)
.def("__repr__",
[](const CompartmentLocation& self) {
return fmt::format("CompartmentLocation({}, {}, {})",
self.nodeId,
self.sectionIndex,
self.sectionId,
self.offset);
})
.def("__str__",
[](const CompartmentLocation& self) { return py::str(py::repr(py::cast(self))); })
.def_readonly("node_id", &CompartmentLocation::nodeId, DOC_COMPARTMENTLOCATION(nodeId))
.def_readonly("section_index",
&CompartmentLocation::sectionIndex,
DOC_COMPARTMENTLOCATION(sectionIndex))
.def_readonly("section_id",
&CompartmentLocation::sectionId,
DOC_COMPARTMENTLOCATION(sectionId))
.def_readonly("offset", &CompartmentLocation::offset, DOC_COMPARTMENTLOCATION(offset));

py::class_<CompartmentSet>(m, "CompartmentSet")
Expand Down Expand Up @@ -632,7 +636,7 @@ PYBIND11_MODULE(_libsonata, m) {

py::class_<CompartmentSets>(m, "CompartmentSets")
.def(py::init<const std::string&>())
.def_static("fromFile", &CompartmentSets::fromFile, py::arg("path"))
.def_static("from_file", &CompartmentSets::fromFile, py::arg("path"))
.def("__contains__",
&CompartmentSets::contains,
py::arg("key"),
Expand Down Expand Up @@ -869,6 +873,9 @@ PYBIND11_MODULE(_libsonata, m) {
.def_readonly("cells",
&SimulationConfig::Report::cells,
DOC_SIMULATIONCONFIG(Report, cells))
.def_readonly("compartment_set",
&SimulationConfig::Report::compartment_set,
DOC_SIMULATIONCONFIG(Report, compartmentSet))
.def_readonly("sections",
&SimulationConfig::Report::sections,
DOC_SIMULATIONCONFIG(Report, sections))
Expand Down Expand Up @@ -898,6 +905,7 @@ PYBIND11_MODULE(_libsonata, m) {
DOC_SIMULATIONCONFIG(Report, enabled));

py::enum_<SimulationConfig::Report::Sections>(report, "Sections")
.value("invalid", SimulationConfig::Report::Sections::invalid)
.value("soma",
SimulationConfig::Report::Sections::soma,
DOC_SIMULATIONCONFIG(Report, Sections, soma))
Expand All @@ -918,13 +926,15 @@ PYBIND11_MODULE(_libsonata, m) {
.value("compartment", SimulationConfig::Report::Type::compartment)
.value("lfp", SimulationConfig::Report::Type::lfp)
.value("summation", SimulationConfig::Report::Type::summation)
.value("synapse", SimulationConfig::Report::Type::synapse);
.value("synapse", SimulationConfig::Report::Type::synapse)
.value("compartment_set", SimulationConfig::Report::Type::compartment_set);

py::enum_<SimulationConfig::Report::Scaling>(report, "Scaling")
.value("none", SimulationConfig::Report::Scaling::none)
.value("area", SimulationConfig::Report::Scaling::area);

py::enum_<SimulationConfig::Report::Compartments>(report, "Compartments")
.value("invalid", SimulationConfig::Report::Compartments::invalid)
.value("center", SimulationConfig::Report::Compartments::center)
.value("all", SimulationConfig::Report::Compartments::all);

Expand Down
4 changes: 3 additions & 1 deletion python/generated/docstrings.h
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ static const char *__doc_bbp_sonata_NodeSets_toJSON = R"doc(Return the nodesets

static const char *__doc_bbp_sonata_CompartmentLocation_nodeId = R"doc(Id of the node.)doc";

static const char *__doc_bbp_sonata_CompartmentLocation_sectionIndex = R"doc(Absolute section index. Progressive index that uniquely identifies the section. There is a mapping between neuron section names (i.e. dend[10]) and this index.)doc";
static const char *__doc_bbp_sonata_CompartmentLocation_sectionId = R"doc(Absolute section id. Progressive index that uniquely identifies the section. It is different from the relative section index. There is a mapping between neuron section names (i.e. dend[10]) and this index.)doc";

static const char *__doc_bbp_sonata_CompartmentLocation_offset = R"doc(Offset of the compartment along the section)doc";

Expand Down Expand Up @@ -1156,6 +1156,8 @@ static const char *__doc_bbp_sonata_SimulationConfig_Report_Type_synapse = R"doc

static const char *__doc_bbp_sonata_SimulationConfig_Report_cells = R"doc(Node sets on which to report)doc";

static const char *__doc_bbp_sonata_SimulationConfig_Report_compartmentSet = R"doc(Compartment set on which to report)doc";

static const char *__doc_bbp_sonata_SimulationConfig_Report_compartments =
R"doc(For compartment type, select compartments to report. Default value:
"center"(for sections: soma), "all"(for other sections))doc";
Expand Down
Loading
Loading