Skip to content

Commit

Permalink
BRAYNS 557 - Fix sonata synapses (#354)
Browse files Browse the repository at this point in the history
Also
* Updates libsonata & morphio dependencies
* Removes usage of <boost/progress.hpp> for deprecation
  • Loading branch information
NadirRoGue authored Jun 22, 2023
1 parent 60e2f7b commit 568c0ba
Show file tree
Hide file tree
Showing 8 changed files with 533 additions and 832 deletions.
8 changes: 4 additions & 4 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ BreakBeforeBinaryOperators: false
BreakBeforeBraces: Allman # brace on new line
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: true
ColumnLimit: 120
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Expand All @@ -24,7 +25,7 @@ DerivePointerBinding: true
ExperimentalAutoDetectBinPacking: false
IndentCaseLabels: false
IndentFunctionDeclarationAfterType: true
IndentWidth: 4
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: false
Language: Cpp
MaxEmptyLinesToKeep: 1
Expand All @@ -46,6 +47,5 @@ SpacesInAngles: false # '< ' style
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false # '(' style
Standard: Cpp11
TabWidth: 4
UseTab: Never
...
TabWidth: 4
UseTab: Never
97 changes: 35 additions & 62 deletions apps/compartmentConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

#include <boost/filesystem.hpp>
#include <boost/program_options.hpp>
#include <boost/progress.hpp>

#include <chrono>

Expand Down Expand Up @@ -62,7 +61,7 @@ void requireEqualCollections(const T& a, const T& b)
REQUIRE_EQUAL(i, a.end());
REQUIRE_EQUAL(j, b.end());
}
}
} // namespace

/**
* Convert a compartment report to an HDF5 report.
Expand Down Expand Up @@ -108,25 +107,21 @@ int main(const int argc, char** argv)

if (vm.count("help") || vm.count("input") == 0)
{
std::cout << "Usage: " << argv[0]
<< " input-uri [output-uri=dummy://] [options]" << std::endl
std::cout << "Usage: " << argv[0] << " input-uri [output-uri=dummy://] [options]" << std::endl
<< std::endl
<< "Supported input and output URIs:" << std::endl
<< brion::CompartmentReport::getDescriptions()
<< std::endl
<< brion::CompartmentReport::getDescriptions() << std::endl
#ifdef BRION_USE_BBPTESTDATA
<< std::endl
<< " Test data set (only for input):\n test:"
<< std::endl
<< " Test data set (only for input):\n test:" << std::endl
#endif
<< std::endl
<< options << std::endl;
return EXIT_SUCCESS;
}
if (vm.count("version"))
{
std::cout << "Brion compartment report converter "
<< brion::Version::getString() << std::endl;
std::cout << "Brion compartment report converter " << brion::Version::getString() << std::endl;
return EXIT_SUCCESS;
}

Expand All @@ -136,8 +131,7 @@ int main(const int argc, char** argv)
}
catch (const po::error& e)
{
std::cerr << "Command line parse error: " << e.what() << std::endl
<< options << std::endl;
std::cerr << "Command line parse error: " << e.what() << std::endl << options << std::endl;
return EXIT_FAILURE;
}

Expand All @@ -151,29 +145,25 @@ int main(const int argc, char** argv)
return EXIT_FAILURE;
}

const size_t maxFrames = vm.count("maxFrames") == 1
? vm["maxFrames"].as<size_t>()
: std::numeric_limits<size_t>::max();
const size_t maxFrames =
vm.count("maxFrames") == 1 ? vm["maxFrames"].as<size_t>() : std::numeric_limits<size_t>::max();

std::string input = vm["input"].as<std::string>();
#ifdef BRION_USE_BBPTESTDATA
if (input == "test:")
{
input = std::string(BBP_TESTDATA) +
"/circuitBuilding_1000neurons/Neurodamus_output/voltages.bbp";
input = std::string(BBP_TESTDATA) + "/circuitBuilding_1000neurons/Neurodamus_output/voltages.bbp";
}
#endif
if (input == vm["output"].as<std::string>())
{
std::cerr << "Cowardly refusing to convert " << input << " onto itself"
<< std::endl;
std::cerr << "Cowardly refusing to convert " << input << " onto itself" << std::endl;
return EXIT_FAILURE;
}

brion::URI inURI(input);
brion::CompartmentReport in(inURI, brion::MODE_READ);
const std::chrono::high_resolution_clock::time_point loadTime1
= std::chrono::high_resolution_clock::now();
const std::chrono::high_resolution_clock::time_point loadTime1 = std::chrono::high_resolution_clock::now();

const double start = in.getStartTime();
const double step = in.getTimestep();
Expand All @@ -182,9 +172,8 @@ int main(const int argc, char** argv)
if (vm.count("dump"))
{
std::cout << "Compartment report " << inURI << ":" << std::endl
<< " " << (end - start) / step << " frames: " << start
<< ".." << end << " / " << step << " " << in.getTimeUnit()
<< std::endl
<< " " << (end - start) / step << " frames: " << start << ".." << end << " / " << step << " "
<< in.getTimeUnit() << std::endl
<< " " << in.getGIDs().size() << " neurons" << std::endl
<< " " << in.getFrameSize() << " compartments" << std::endl;
return EXIT_SUCCESS;
Expand All @@ -209,8 +198,7 @@ int main(const int argc, char** argv)
{
try
{
outURI.setPath(
boost::filesystem::canonical(inURI.getPath()).generic_string());
outURI.setPath(boost::filesystem::canonical(inURI.getPath()).generic_string());
}
catch (const boost::filesystem::filesystem_error&)
{
Expand All @@ -219,14 +207,12 @@ int main(const int argc, char** argv)
}
}

const std::chrono::high_resolution_clock::time_point loadTime2
= std::chrono::high_resolution_clock::now();
const std::chrono::duration<float> loadTimeSpan
= std::chrono::duration_cast<std::chrono::duration<float>>(loadTime2 - loadTime1);
const std::chrono::high_resolution_clock::time_point loadTime2 = std::chrono::high_resolution_clock::now();
const std::chrono::duration<float> loadTimeSpan =
std::chrono::duration_cast<std::chrono::duration<float>>(loadTime2 - loadTime1);
float loadTime = loadTimeSpan.count();

const std::chrono::high_resolution_clock::time_point writeTime1
= std::chrono::high_resolution_clock::now();
const std::chrono::high_resolution_clock::time_point writeTime1 = std::chrono::high_resolution_clock::now();

brion::CompartmentReport to(outURI, brion::MODE_OVERWRITE);
to.writeHeader(start, end, step, in.getDataUnit(), in.getTimeUnit());
Expand Down Expand Up @@ -257,23 +243,20 @@ int main(const int argc, char** argv)
}
}

const std::chrono::high_resolution_clock::time_point writeTime2
= std::chrono::high_resolution_clock::now();
const std::chrono::high_resolution_clock::time_point writeTime2 = std::chrono::high_resolution_clock::now();

const std::chrono::duration<float> writeTimeSpan
= std::chrono::duration_cast<std::chrono::duration<float>>(writeTime2 - writeTime1);
const std::chrono::duration<float> writeTimeSpan =
std::chrono::duration_cast<std::chrono::duration<float>>(writeTime2 - writeTime1);
float writeTime = writeTimeSpan.count();
// Adding step / 2 to the window to avoid off by 1 errors during truncation
const size_t nFrames = (end - start + step * 0.5) / step;
boost::progress_display progress(nFrames);

for (size_t frameIndex = 0; frameIndex < nFrames; ++frameIndex)
{
// Making the timestamp fall in the middle of the frame
const double timestamp = start + frameIndex * step + step * 0.5;

const std::chrono::high_resolution_clock::time_point loadPivot1
= std::chrono::high_resolution_clock::now();
const std::chrono::high_resolution_clock::time_point loadPivot1 = std::chrono::high_resolution_clock::now();

brion::floatsPtr data;
try
Expand All @@ -286,10 +269,9 @@ int main(const int argc, char** argv)
::exit(EXIT_FAILURE);
}

const std::chrono::high_resolution_clock::time_point loadPivot2
= std::chrono::high_resolution_clock::now();
const std::chrono::duration<float> loadPivotSpan
= std::chrono::duration_cast<std::chrono::duration<float>>(loadPivot2 - loadPivot1);
const std::chrono::high_resolution_clock::time_point loadPivot2 = std::chrono::high_resolution_clock::now();
const std::chrono::duration<float> loadPivotSpan =
std::chrono::duration_cast<std::chrono::duration<float>>(loadPivot2 - loadPivot1);
loadTime += loadPivotSpan.count();

if (!data)
Expand All @@ -300,8 +282,7 @@ int main(const int argc, char** argv)

const brion::floats& values = *data.get();

const std::chrono::high_resolution_clock::time_point witePivot1
= std::chrono::high_resolution_clock::now();
const std::chrono::high_resolution_clock::time_point witePivot1 = std::chrono::high_resolution_clock::now();

if (isFrameSorted)
{
Expand Down Expand Up @@ -329,31 +310,24 @@ int main(const int argc, char** argv)
return EXIT_FAILURE;
}

const std::chrono::high_resolution_clock::time_point witePivot2
= std::chrono::high_resolution_clock::now();
const std::chrono::duration<float> writePivotSpan
= std::chrono::duration_cast<std::chrono::duration<float>>(witePivot2 - witePivot1);
const std::chrono::high_resolution_clock::time_point witePivot2 = std::chrono::high_resolution_clock::now();
const std::chrono::duration<float> writePivotSpan =
std::chrono::duration_cast<std::chrono::duration<float>>(witePivot2 - witePivot1);
writeTime += writePivotSpan.count();
++progress;
}

const std::chrono::high_resolution_clock::time_point flushPivot1
= std::chrono::high_resolution_clock::now();
const std::chrono::high_resolution_clock::time_point flushPivot1 = std::chrono::high_resolution_clock::now();
to.flush();
const std::chrono::high_resolution_clock::time_point flushPivot2
= std::chrono::high_resolution_clock::now();
const std::chrono::duration<float> flushPivotSpan
= std::chrono::duration_cast<std::chrono::duration<float>>(flushPivot2 - flushPivot1);
const std::chrono::high_resolution_clock::time_point flushPivot2 = std::chrono::high_resolution_clock::now();
const std::chrono::duration<float> flushPivotSpan =
std::chrono::duration_cast<std::chrono::duration<float>>(flushPivot2 - flushPivot1);
writeTime += flushPivotSpan.count();

std::cout << "Converted " << inURI << " to " << outURI << " (in "
<< size_t(loadTime) << " out " << size_t(writeTime) << " ms, "
<< gids.size() << " cells X " << nFrames << " frames)"
<< std::endl;
std::cout << "Converted " << inURI << " to " << outURI << " (in " << size_t(loadTime) << " out "
<< size_t(writeTime) << " ms, " << gids.size() << " cells X " << nFrames << " frames)" << std::endl;

if (vm.count("compare"))
{
progress.restart(nFrames);
brion::CompartmentReport result(outURI, brion::MODE_READ);

REQUIRE_EQUAL(in.getStartTime(), result.getStartTime());
Expand Down Expand Up @@ -396,7 +370,6 @@ int main(const int argc, char** argv)
REQUIRE_EQUAL((*frame1)[o1], (*frame2)[o2]);
}
}
++progress;
}
}

Expand Down
75 changes: 28 additions & 47 deletions apps/spikeConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#define STREAM_FRAME_LENGTH_MS 10

#include <boost/program_options.hpp>
#include <boost/progress.hpp>

namespace po = boost::program_options;

Expand Down Expand Up @@ -66,25 +65,21 @@ int main(int argc, char* argv[])

if (vm.count("help") || vm.count("input") == 0)
{
std::cout
<< "Usage: " << std::string(argv[0])
<< " input-uri [output-uri=spikes.out] [options]" << std::endl
<< std::endl
<< "Supported input and output URIs:" << std::endl
<< brion::SpikeReport::getDescriptions()
<< std::endl
std::cout << "Usage: " << std::string(argv[0]) << " input-uri [output-uri=spikes.out] [options]" << std::endl
<< std::endl
<< "Supported input and output URIs:" << std::endl
<< brion::SpikeReport::getDescriptions() << std::endl
#ifdef BRION_USE_BBPTESTDATA
<< std::endl
<< " Test data set (only for input):\n test:" << std::endl
<< std::endl
<< " Test data set (only for input):\n test:" << std::endl
#endif
<< std::endl
<< options << std::endl;
<< std::endl
<< options << std::endl;
return EXIT_SUCCESS;
}
if (vm.count("version"))
{
std::cout << "Brion spike report converter "
<< brion::Version::getString() << std::endl;
std::cout << "Brion spike report converter " << brion::Version::getString() << std::endl;
return EXIT_SUCCESS;
}

Expand All @@ -94,76 +89,62 @@ int main(int argc, char* argv[])
}
catch (const po::error& e)
{
std::cerr << "Command line parse error: " << e.what() << std::endl
<< options << std::endl;
std::cerr << "Command line parse error: " << e.what() << std::endl << options << std::endl;
return EXIT_FAILURE;
}

std::string input = vm["input"].as<std::string>();
#ifdef BRION_USE_BBPTESTDATA
if (input == "test:")
{
input = std::string(BBP_TESTDATA) +
"/circuitBuilding_1000neurons/Neurodamus_output/out.dat";
input = std::string(BBP_TESTDATA) + "/circuitBuilding_1000neurons/Neurodamus_output/out.dat";
}
#endif
if (input == vm["output"].as<std::string>())
{
std::cerr << "Cowardly refusing to convert " << input << " onto itself"
<< std::endl;
std::cerr << "Cowardly refusing to convert " << input << " onto itself" << std::endl;
return EXIT_FAILURE;
}

try
{
float readTime = 0.f, writeTime = 0.f;
const std::chrono::high_resolution_clock::time_point p1
= std::chrono::high_resolution_clock::now();
const std::chrono::high_resolution_clock::time_point p1 = std::chrono::high_resolution_clock::now();

brion::SpikeReport in(brion::URI(input), brion::MODE_READ);

const std::chrono::high_resolution_clock::time_point p2
= std::chrono::high_resolution_clock::now();
const std::chrono::high_resolution_clock::time_point p2 = std::chrono::high_resolution_clock::now();

const std::chrono::duration<float> p1p2
= std::chrono::duration_cast<std::chrono::duration<float>>(p2 - p1);
const std::chrono::duration<float> p1p2 = std::chrono::duration_cast<std::chrono::duration<float>>(p2 - p1);
readTime += p1p2.count();

brion::SpikeReport out(brion::URI(vm["output"].as<std::string>()),
brion::MODE_WRITE);
brion::SpikeReport out(brion::URI(vm["output"].as<std::string>()), brion::MODE_WRITE);

const std::chrono::high_resolution_clock::time_point p3
= std::chrono::high_resolution_clock::now();
const std::chrono::high_resolution_clock::time_point p3 = std::chrono::high_resolution_clock::now();

const std::chrono::duration<float> p2p3
= std::chrono::duration_cast<std::chrono::duration<float>>(p3 - p2);
const std::chrono::duration<float> p2p3 = std::chrono::duration_cast<std::chrono::duration<float>>(p3 - p2);
writeTime += p2p3.count();

const float step = 10.f; // ms, arbitrary value
while (in.getState() == brion::SpikeReport::State::ok)
{
const std::chrono::high_resolution_clock::time_point rl1
= std::chrono::high_resolution_clock::now();
const std::chrono::high_resolution_clock::time_point rl1 = std::chrono::high_resolution_clock::now();
const auto spikes = in.readUntil(in.getCurrentTime() + step).get();
const std::chrono::high_resolution_clock::time_point rl2
= std::chrono::high_resolution_clock::now();
const std::chrono::duration<float> rlspan
= std::chrono::duration_cast<std::chrono::duration<float>>(rl2 - rl1);
const std::chrono::high_resolution_clock::time_point rl2 = std::chrono::high_resolution_clock::now();
const std::chrono::duration<float> rlspan =
std::chrono::duration_cast<std::chrono::duration<float>>(rl2 - rl1);
readTime += rlspan.count();

const std::chrono::high_resolution_clock::time_point wl1
= std::chrono::high_resolution_clock::now();
const std::chrono::high_resolution_clock::time_point wl1 = std::chrono::high_resolution_clock::now();
out.write(spikes);
const std::chrono::high_resolution_clock::time_point wl2
= std::chrono::high_resolution_clock::now();
const std::chrono::duration<float> wlspan
= std::chrono::duration_cast<std::chrono::duration<float>>(wl2 - wl1);
const std::chrono::high_resolution_clock::time_point wl2 = std::chrono::high_resolution_clock::now();
const std::chrono::duration<float> wlspan =
std::chrono::duration_cast<std::chrono::duration<float>>(wl2 - wl1);
writeTime += wlspan.count();
}

std::cout << "Converted " << input << " => "
<< vm["output"].as<std::string>() << " in " << readTime
<< " + " << writeTime << " ms" << std::endl;
std::cout << "Converted " << input << " => " << vm["output"].as<std::string>() << " in " << readTime << " + "
<< writeTime << " ms" << std::endl;
}
catch (const std::exception& exception)
{
Expand Down
Loading

0 comments on commit 568c0ba

Please sign in to comment.