Skip to content

Commit

Permalink
Introduce SONATA support (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
ppodhajski committed Jan 8, 2020
1 parent 319efda commit 551fbb0
Show file tree
Hide file tree
Showing 13 changed files with 600 additions and 134 deletions.
1 change: 1 addition & 0 deletions .gitsubprojects
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- mode: cmake -*-
git_subproject(libsonata https://github.com/BlueBrain/libsonata.git ec58d16)
git_subproject(Servus https://github.com/HBPVIS/Servus.git 170bd93)
git_subproject(Lunchbox https://github.com/Eyescale/Lunchbox.git 9bd6a7d)
git_subproject(Keyv https://github.com/BlueBrain/Keyv.git 8340fa2)
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#

cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
project(Brion VERSION 3.0.0)
project(Brion VERSION 3.1.0)
set(Brion_VERSION_ABI 10)

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMake
Expand Down Expand Up @@ -43,6 +43,7 @@ common_find_package(PythonLibs)
common_find_package(Servus REQUIRED)
common_find_package(Sphinx 1.3)
common_find_package(vmmlib REQUIRED)
common_find_package(sonata REQUIRED)
option(BRION_USE_ZEROEQ "Use ZeroEQ for plugin backend and morphologyServer" OFF)
if(BRION_USE_ZEROEQ)
git_subproject(ZeroEQ https://github.com/HBPVIS/ZeroEQ.git 1e66ee3)
Expand Down
4 changes: 3 additions & 1 deletion brain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ set(BRAIN_SOURCES
set(BRAIN_PUBLIC_INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIRS})
set(BRAIN_LINK_LIBRARIES
PUBLIC Brion vmmlib
PRIVATE Lunchbox ${Boost_FILESYSTEM_LIBRARIES}
PRIVATE sonata::sonata_shared Lunchbox ${Boost_FILESYSTEM_LIBRARIES}
)

if(TARGET Keyv)
Expand All @@ -65,6 +65,8 @@ if(TARGET MVDTool)
list(APPEND BRAIN_LINK_LIBRARIES PRIVATE MVDTool)
endif()

#set(BRAIN_OMIT_EXPORT ON)

common_library(Brain)
if(TARGET MVDTool)
target_compile_definitions(Brain PUBLIC BRAIN_USE_MVD3)
Expand Down
43 changes: 43 additions & 0 deletions brain/circuit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@
#include "circuit.h"
#include "detail/circuit.h"

#include "synapses.h"
#include "synapsesStream.h"

#include <bbp/sonata/edges.h>

#include <servus/uint128_t.h>

#include <boost/algorithm/string.hpp>
Expand Down Expand Up @@ -525,4 +528,44 @@ SynapsesStream Circuit::getProjectedSynapses(
{
return SynapsesStream(*this, preGIDs, postGIDs, prefetch);
}

uint32_ts Circuit::getProjectedEfferentGIDs(
const GIDSet& preGIDs, const std::string& projection) const
{
const std::string projPath = _impl->getSynapseProjectionSource(projection);
if(projPath.find("sonata") == std::string::npos)
{
SynapsesStream ss = getExternalAfferentSynapses(preGIDs, projection);
auto future = ss.read(ss.getRemaining());
future.wait();
Synapses syn = future.get();
uint32_ts result (syn.preGIDs(), syn.preGIDs() + syn.size());
return result;
}
else
{
std::set<uint64_t> uniqueIds;
// Input ids must be decreased by 1
for(uint32_t oldId : preGIDs)
{
if(oldId > 0)
uniqueIds.insert(oldId - 1);
}

const size_ts nodeIds (uniqueIds.begin(), uniqueIds.end());
uint32_ts result;
const bbp::sonata::EdgeStorage edgeStorage (projPath);
for(const auto& name : edgeStorage.populationNames())
{
const bbp::sonata::EdgePopulation edges (projPath, "", name);
const bbp::sonata::Selection s = edges.efferentEdges(nodeIds);

for(auto gid : edges.targetNodeIDs(s))
{
result.push_back(static_cast<uint32_t>(gid) + 1);
}
}
return result;
}
}
}
10 changes: 10 additions & 0 deletions brain/circuit.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,16 @@ class Circuit
const GIDSet& preGIDs, const GIDSet& postGIDs,
SynapsePrefetch prefetch = SynapsePrefetch::none) const;

/**
* Return a list of efferent cells GIDs from a given projection
*
* @param preGIDs projection source cell IDs
* @param projection projection name
* @return list of efferent GIDs from inside the circuit
*/
BRAIN_API uint32_ts getProjectedEfferentGIDs(
const GIDSet& preGIDs, const std::string& projection) const;

class Impl; //!< @internal, public for inheritance MVD2/3 impls

private:
Expand Down
25 changes: 25 additions & 0 deletions brain/detail/circuit.h
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@ class Circuit::Impl
virtual URI getMorphologySource() const = 0;

virtual MorphologyCache* getMorphologyCache() const { return nullptr; }
virtual std::string getSynapseSource() const = 0;
virtual std::string getSynapseProjectionSource(const std::string& name) const = 0;
virtual SynapseCache* getSynapseCache() const { return nullptr; }
virtual const brion::SynapseSummary& getSynapseSummary() const = 0;
virtual const brion::Synapse& getSynapseAttributes(
Expand Down Expand Up @@ -679,6 +681,15 @@ class SonataCircuit : public Circuit::Impl
}

URI getMorphologySource() const final { return morphologySource; }
std::string getSynapseSource() const
{
return synapseSource.getPath();
}
std::string getSynapseProjectionSource(const std::string& name) const
{
(void)name;
LBTHROW(std::runtime_error("Unimplemented"));
}
const brion::SynapseSummary& getSynapseSummary() const final
{
LBTHROW(std::runtime_error("Unimplemented"));
Expand Down Expand Up @@ -768,6 +779,20 @@ class BBPCircuit : public Circuit::Impl
return nullptr;
}

std::string getSynapseSource() const
{
return _synapseSource.getPath();
}

std::string getSynapseProjectionSource(const std::string& name) const
{
auto it = _afferentProjectionSources.find(name);
if(it == _afferentProjectionSources.end())
LBTHROW(std::runtime_error("Projection " + name + " not found"))

return it->second.getPath();
}

SynapseCache* getSynapseCache() const final
{
if (_synapseCache)
Expand Down

0 comments on commit 551fbb0

Please sign in to comment.