-
Notifications
You must be signed in to change notification settings - Fork 1
CompartmentSets #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
97c36dd
make install -e work
cattabiani fad6ae6
wip
cattabiani d1f5220
nodesets in correct folder
cattabiani b0b3871
new license?
cattabiani 48ea649
add compartment_sets_file to SimulationConfig
cattabiani 543dc90
WIP
cattabiani f7d3c0c
empty CompartmentSets. It should pass CI
cattabiani 5b2bfb4
WIP
cattabiani 9475c90
before clang-format
cattabiani a68a388
formatted, WIP
cattabiani bf2b6d9
fix clang-format9?
cattabiani bb7ca75
CompartmentLocation
cattabiani 807ce4c
before python api for compartmentSet
cattabiani b529ff4
WIP decoupled iterator
cattabiani b993670
WIP
cattabiani 3aed13c
WIP
cattabiani 03b4a39
CompartmentSet ready for python api
cattabiani 4f8e417
added pybinds and tests for CompartmentSet
cattabiani 5566239
Merge branch 'master' into katta/install_dev
cattabiani e5bd13a
completed detail::CompartmentSets
cattabiani 07a7bf8
add equality CompartmentSet
cattabiani 6b76b22
done ctests
cattabiani 64c0622
done with pytests. no format
cattabiani 02295b5
format?
cattabiani 0bbaa3a
remove test
cattabiani 8f3c6ce
some fixes from Mike
cattabiani f79a012
format
cattabiani c56031a
gid -> node_id
cattabiani bdf9596
format
cattabiani b84755e
more Mike's comments resolved
cattabiani d0ac13a
format
cattabiani 4fb9a1b
remove glob
cattabiani 2bce919
fixup! selection.contains: ranges are not sorted for sure
cattabiani c909944
format
cattabiani 9d76a4c
keys -> names
cattabiani b91ed52
py::str -> fmt::format
cattabiani ed789f6
format
cattabiani d4b729a
remove iter copy and deepcopy
cattabiani 6ada577
CompartmentLocation unification impl and public api
cattabiani 452be67
format
cattabiani 54586c5
values -> getAllCompartmentSets
cattabiani 32f0779
format
cattabiani 4ff96a2
simplify CompartmentLocation to plain struct
cattabiani bb0353c
format
cattabiani 6208c8e
remove commented code
cattabiani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,189 @@ | ||
| #pragma once | ||
|
|
||
| #include <bbp/sonata/nodes.h> | ||
|
|
||
| #include <nlohmann/json.hpp> | ||
|
|
||
| namespace bbp { | ||
| namespace sonata { | ||
| namespace detail { | ||
| class CompartmentSetFilteredIterator; | ||
| class CompartmentSet; | ||
| class CompartmentSets; | ||
| } // namespace detail | ||
|
|
||
| /** | ||
| * CompartmentLocation. | ||
| * | ||
| * This struct uniquely identifies a compartment by a set of node_id, section_index and offset: | ||
| * | ||
| * - node_id: Global ID of the cell (Neuron) to which the compartment belongs. No | ||
| * overlaps among populations. | ||
| * - section_index: 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. | ||
| * - offset: Offset of the compartment along the section. The offset is a value between 0 and 1 | ||
| * | ||
| * Note: it cannot go inside CompartmentSet because then CompartmentSetFilteredIterator needs the | ||
| * full definition of CompartmentSet and CompartmentSet needs the full definition of | ||
| * CompartmentSetFilteredIterator. | ||
| */ | ||
| struct CompartmentLocation { | ||
| public: | ||
| uint64_t nodeId = 0; | ||
| uint64_t sectionIndex = 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; | ||
| } | ||
|
|
||
| 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 << ", " | ||
| << "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: | ||
| std::unique_ptr<detail::CompartmentSetFilteredIterator> impl_; | ||
| }; | ||
|
|
||
|
|
||
| /** | ||
| * CompartmentSet public API. | ||
| * | ||
| * This class represents a set of compartment locations associated with a neuron population. | ||
| * Each compartment is uniquely defined by a (node_id, section_index, offset) triplet. | ||
| * This API supports filtering based on a node_id selection. | ||
| */ | ||
| class SONATA_API CompartmentSet | ||
| { | ||
| public: | ||
| CompartmentSet() = delete; | ||
|
|
||
| explicit CompartmentSet(const std::string& json_content); | ||
| explicit CompartmentSet(std::shared_ptr<detail::CompartmentSet>&& impl); | ||
|
|
||
| std::pair<CompartmentSetFilteredIterator, CompartmentSetFilteredIterator> filtered_crange( | ||
| Selection selection = Selection({})) const; | ||
|
|
||
| /// Size of the set, optionally filtered by selection | ||
| std::size_t size(const Selection& selection = Selection({})) const; | ||
|
|
||
| // Is empty? | ||
| bool empty() const; | ||
|
|
||
| /// Population name | ||
| const std::string& population() const; | ||
|
|
||
| /// Access element by index. It returns a copy! | ||
| CompartmentLocation operator[](std::size_t index) const; | ||
|
|
||
| Selection nodeIds() const; | ||
|
|
||
| CompartmentSet filter(const Selection& selection = Selection({})) const; | ||
|
|
||
| /// Serialize to JSON string | ||
| std::string toJSON() const; | ||
|
|
||
| bool operator==(const CompartmentSet& other) const; | ||
| bool operator!=(const CompartmentSet& other) const; | ||
|
|
||
| private: | ||
| std::shared_ptr<detail::CompartmentSet> impl_; | ||
| }; | ||
|
|
||
|
|
||
| /** | ||
| * @class CompartmentSets | ||
| * @brief A container class that manages a collection of named CompartmentSet objects. | ||
| * | ||
| * This class provides methods for accessing, querying, and serializing a collection of | ||
| * compartment sets identified by string keys. It supports construction from a JSON string | ||
| * or a file, and encapsulates its internal implementation using the PIMPL idiom. | ||
| * | ||
| * The class is non-copyable but movable, and offers value-style accessors for ease of use. | ||
| */ | ||
| class SONATA_API CompartmentSets | ||
| { | ||
| public: | ||
|
|
||
| CompartmentSets(const std::string& content); | ||
| CompartmentSets(std::unique_ptr<detail::CompartmentSets>&& impl); | ||
| CompartmentSets(detail::CompartmentSets&& impl); | ||
| CompartmentSets(CompartmentSets&&) noexcept; | ||
| CompartmentSets(const CompartmentSets& other) = delete; | ||
| CompartmentSets& operator=(CompartmentSets&&) noexcept; | ||
| ~CompartmentSets(); | ||
|
|
||
| /// Create new CompartmentSets from file. In this way we distinguish from | ||
| /// the basic string constructor. | ||
| static CompartmentSets fromFile(const std::string& path); | ||
|
|
||
| /// Access element by key (throws if not found) | ||
| CompartmentSet getCompartmentSet(const std::string& key) const; | ||
|
|
||
| /// Number of compartment sets | ||
| std::size_t size() const; | ||
|
|
||
| /// Is empty? | ||
| bool empty() const; | ||
|
|
||
| /// Check if key exists | ||
| bool contains(const std::string& key) const; | ||
|
|
||
| /// Get names of CompartmentSet(s) as a vector | ||
| std::vector<std::string> names() const; | ||
|
|
||
| /// Get all compartment sets as vector | ||
| std::vector<CompartmentSet> getAllCompartmentSets() const; | ||
|
|
||
| /// Get items (key + compartment set) as vector of pairs | ||
| std::vector<std::pair<std::string, CompartmentSet>> items() const; | ||
|
|
||
| /// Serialize all compartment sets to JSON string | ||
| std::string toJSON() const; | ||
|
|
||
| bool operator==(const CompartmentSets& other) const; | ||
| bool operator!=(const CompartmentSets& other) const; | ||
|
|
||
| private: | ||
| std::unique_ptr<detail::CompartmentSets> impl_; | ||
| }; | ||
|
|
||
| } // namespace sonata | ||
| } // namespace bbp | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.