diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e69078..db6da92 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------- -# nest python vis +# nest in situ vis # # Copyright (c) 2017 RWTH Aachen University, Germany, # Virtual Reality & Immersive Visualisation Group. @@ -19,13 +19,18 @@ # limitations under the License. #------------------------------------------------------------------------------- -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.8.2) -project(nest_python_vis) +project(nest_in_situ_vis) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) set(CMAKE_CXX_STANDARD 17) +find_package(Boost REQUIRED COMPONENTS python) + +find_package(PythonInterp) +find_package(PythonLibs) + include(catch) include(ConfigureFiles) @@ -37,6 +42,15 @@ enable_testing() include(GenerateExportHeader) +include(py.test) + include(WarningLevels) -add_subdirectory(nest_python_vis) +find_package(conduit) +set_target_properties(conduit + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CONDUIT_INCLUDE_DIRS}/..") + +add_subdirectory(niv) +add_subdirectory(pyniv) +add_subdirectory(pytest_utilities) +add_subdirectory(demo) diff --git a/CPPLINT.cfg b/CPPLINT.cfg index 76cc427..9c180f6 100644 --- a/CPPLINT.cfg +++ b/CPPLINT.cfg @@ -1,5 +1,5 @@ set noparent -filter=-readability/check +filter=-readability/check,-build/c++ linelength=80 extensions=c,cpp,h,hpp headers=h,hpp diff --git a/README.md b/README.md index 1f1406b..0e71830 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,107 @@ # nest in situ vis - *nest in situ vis* is Copyright (c) 2017 RWTH Aachen University, Germany, Virtual Reality & Immersive Visualization Group. +## Overview + +*nest in situ vis* (`niv`) is (the yet prototypical implementation of) a library facilitating in situ visualization for the [nest simulator](http://www.nest-simulator.org). + +With `niv` data can be collected in nest's recording backends and transported to a visualization process. Currently, only on-node transport to a separate visualization process is provided using shared memory. + + +## Building + + +### Requirements + +* a customized nest simulator with nestio and a conduit recording backend +* [conduit 0.2.1](https://github.com/LLNL/conduit/tree/v0.2.1) +* Boost python and boost interprocess v1.64.0 +* Python 2.7.13 +* CMake 3.8.2 (or above) +* gcc 5.3 (or above) + + +### Compiling the Library + +* In a teminal, `cd to `niv`'s root directory + +``` +mkdir build +cd build +cmake .. \ + -DCONDUIT_DIR= \ + -DBOOST_ROOT= \ + -DPYTHON_INCLUDE_DIR= \ + -DPYTHON_LIBRARY= +make +``` + +### Compiling the Custom Nest Simulator + +These are hints for compiling nest (not included in this repository). + +* In a terminal, `cd` to nest's root directory + +``` +mkdir build +cd build +cmake ../.. \ + -Dwith-conduit= \ + -Dniv_DIR= \ + -DPYTHON_INCLUDE_DIR= \ + -DPYTHON_LIBRARY= \ + -DCMAKE_INSTALL_PREFIX:PATH= +make +make install +``` + + +### Generating the Demo Runners + +* In a teminal, `cd to `niv`'s root directory + +``` +cd build +cmake . -DNEST_DIR= +chmod +x chmod +x demo/nest_python_vis/*.sh +``` + + +## Running the Demo + +You'll need two terminals. + +* in both, `cd` to `/demo/nest_python_vis` + +* in the first + +``` +./run_vis.sh +``` + +* in the second + +``` +./run_sim.sh +``` + +* in the visualization app press "Start" +* in the simulation app press "nest.Simulate(20)" + + +## Releasing Shared Memory if Something Breaks + +If one of the two apps crashes, shared memory might still exist. Consequently, the visualization will throw an exception. In order to manually release the shared memory: + +* in a terminal `cd` to `niv`s build directory + +``` +niv/helper_apps/niv-shared-memory destroy +``` + ## License Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,3 +115,8 @@ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + + +## Acknowledgements + +`niv` is developed in the Human Brain Project. This project has received funding from the European Union’s Horizon 2020 research and innovation programme under grant agreement No 720270 (HBP SGA1). diff --git a/cmake/ConfigureFiles.cmake b/cmake/ConfigureFiles.cmake index 01b3872..a3594b7 100644 --- a/cmake/ConfigureFiles.cmake +++ b/cmake/ConfigureFiles.cmake @@ -1,17 +1,16 @@ #------------------------------------------------------------------------------- -# Project Phoenix +# nest in situ vis # # Copyright (c) 2017 RWTH Aachen University, Germany, # Virtual Reality & Immersive Visualisation Group. #------------------------------------------------------------------------------- -# License -# only for this file +# License # -# Licensed under the 3-Clause BSD License (the "License"); +# Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# https://opensource.org/licenses/BSD-3-Clause +# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/cmake/FindConduit.cmake b/cmake/FindConduit.cmake new file mode 100644 index 0000000..362f318 --- /dev/null +++ b/cmake/FindConduit.cmake @@ -0,0 +1,90 @@ +############################################################################### +# Copyright (c) 2014-2017, Lawrence Livermore National Security, LLC. +# +# Produced at the Lawrence Livermore National Laboratory +# +# LLNL-CODE-666778 +# +# All rights reserved. +# +# This file is part of Conduit. +# +# For details, see https://lc.llnl.gov/conduit/. +# +# Please also read conduit/LICENSE +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the disclaimer below. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the disclaimer (as noted below) in the +# documentation and/or other materials provided with the distribution. +# +# * Neither the name of the LLNS/LLNL nor the names of its contributors may +# be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY, +# LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY +# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +############################################################################### +# +# Setup Conduit +# +############################################################################### +# +# Expects CONDUIT_DIR to point to a Conduit installations. +# +# This file defines the following CMake variables: +# CONDUIT_FOUND - If Conduit was found +# CONDUIT_INCLUDE_DIRS - The Conduit include directories +# +# If found, the conduit CMake targets will also be imported. +# The main conduit library targets are: +# conduit +# conduit_relay +# conduit_relay_mpi (if conduit was built with mpi support) +# conduit_blueprint +# +############################################################################### + +############################################################################### +# Check for CONDUIT_DIR +############################################################################### +if(NOT CONDUIT_DIR) + MESSAGE(FATAL_ERROR "Could not find Conduit. Conduit requires explicit CONDUIT_DIR.") +endif() + +if(NOT EXISTS ${CONDUIT_DIR}/lib/cmake/conduit.cmake) + MESSAGE(FATAL_ERROR "Could not find Conduit CMake include file (${CONDUIT_DIR}/lib/cmake/conduit.cmake)") +endif() + +############################################################################### +# Import Conduit's CMake targets +############################################################################### +include(${CONDUIT_DIR}/lib/cmake/conduit.cmake) + +############################################################################### +# Set remaning CMake variables +############################################################################### +# we found Conduit +set(CONDUIT_FOUND TRUE) +# provide location of the headers in CONDUIT_INCLUDE_DIRS +set(CONDUIT_INCLUDE_DIRS ${CONDUIT_DIR}/include/conduit) + + + + diff --git a/cmake/WarningLevels.cmake b/cmake/WarningLevels.cmake index 4df9c09..75bad0c 100644 --- a/cmake/WarningLevels.cmake +++ b/cmake/WarningLevels.cmake @@ -1,17 +1,16 @@ #------------------------------------------------------------------------------- -# Project Phoenix +# nest in situ vis # # Copyright (c) 2017 RWTH Aachen University, Germany, # Virtual Reality & Immersive Visualisation Group. #------------------------------------------------------------------------------- -# License -# only for this file +# License # -# Licensed under the 3-Clause BSD License (the "License"); +# Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# https://opensource.org/licenses/BSD-3-Clause +# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, @@ -40,7 +39,6 @@ set(WARNING_LEVELS_RWTH_GCC -Wmissing-braces -pedantic -pedantic-errors - -Wno-c++98-compat ) set(WARNING_LEVELS_RWTH_MSVC @@ -104,26 +102,32 @@ macro(SET_WARNING_LEVELS_RWTH TARGET) if(IS_CLANG) target_compile_options(${TARGET} PRIVATE ${WARNING_LEVELS_RWTH_CLANG}) if (CMAKE_AUTOMOC) + if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_autogen/moc_compilation.cpp) set_source_files_properties( ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_autogen/moc_compilation.cpp PROPERTIES COMPILE_FLAGS ${WARNING_LEVELS_RWTH_CLANG_QT_MOC_OVERRIDE}) endif () + endif() target_compile_options(${TARGET} PRIVATE "-include${SUPPRESS_WARNING_HEADER_FILE}") elseif(IS_GCC) target_compile_options(${TARGET} PRIVATE ${WARNING_LEVELS_RWTH_GCC}) if (CMAKE_AUTOMOC) + if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_autogen/moc_compilation.cpp) set_source_files_properties( ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_autogen/moc_compilation.cpp PROPERTIES COMPILE_FLAGS ${WARNING_LEVELS_RWTH_GCC_QT_MOC_OVERRIDE}) endif () + endif() target_compile_options(${TARGET} PRIVATE "-include${SUPPRESS_WARNING_HEADER_FILE}") elseif(IS_MSVC) target_compile_options(${TARGET} PRIVATE ${WARNING_LEVELS_RWTH_MSVC}) if (CMAKE_AUTOMOC) + if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_autogen/moc_compilation.cpp) set_source_files_properties( ${CMAKE_CURRENT_BINARY_DIR}/${target}_autogen/moc_compilation.cpp PROPERTIES COMPILE_FLAGS ${WARNING_LEVELS_RWTH_MSVC_QT_MOC_OVERRIDE}) endif () + endif() target_compile_options(${TARGET} PRIVATE "/FI ${SUPPRESS_WARNING_HEADER_FILE}") else() message(WARNING "SET_WARNING_LEVELS_RWTH not implemented for your compiler. " diff --git a/cmake/catch.cmake b/cmake/catch.cmake index 95c7343..b6e4607 100644 --- a/cmake/catch.cmake +++ b/cmake/catch.cmake @@ -1,17 +1,16 @@ #------------------------------------------------------------------------------- -# Project Phoenix +# nest in situ vis # # Copyright (c) 2017 RWTH Aachen University, Germany, # Virtual Reality & Immersive Visualisation Group. #------------------------------------------------------------------------------- -# License -# only for this file +# License # -# Licensed under the 3-Clause BSD License (the "License"); +# Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# https://opensource.org/licenses/BSD-3-Clause +# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, @@ -22,6 +21,7 @@ include(WarningLevels) + set_property(GLOBAL PROPERTY USE_FOLDERS ON) @@ -81,15 +81,6 @@ function(ADD_TEST_CATCH) file(GLOB ADD_TEST_CATCH_CATCH_MAIN_ABSOLUTE ${ADD_TEST_CATCH_CATCH_MAIN}) list(REMOVE_ITEM ADD_TEST_CATCH_SOURCES ${ADD_TEST_CATCH_CATCH_MAIN_ABSOLUTE}) - # add aggregate test target - ADD_TEST_CATCH_INTERNAL_("${ADD_TEST_CATCH_NAME}" - "${ADD_TEST_CATCH_SOURCES}" - "${ADD_TEST_CATCH_HEADERS}" - "${ADD_TEST_CATCH_INCLUDE_DIRECTORIES}" - "${ADD_TEST_CATCH_LINK_LIBRARIES};${ADD_TEST_CATCH_NAME}_catch_main" - "${ADD_TEST_CATCH_PATH_TO_ADD}" - ) - # add test for each test source file foreach(TEST_SOURCE_FILE ${ADD_TEST_CATCH_SOURCES}) get_filename_component(TEST_NAME ${TEST_SOURCE_FILE} NAME_WE) diff --git a/cmake/cpplint.cmake b/cmake/cpplint.cmake index 0e214fe..9856c1c 100644 --- a/cmake/cpplint.cmake +++ b/cmake/cpplint.cmake @@ -1,17 +1,16 @@ #------------------------------------------------------------------------------- -# Project Phoenix +# nest in situ vis # # Copyright (c) 2017 RWTH Aachen University, Germany, # Virtual Reality & Immersive Visualisation Group. #------------------------------------------------------------------------------- -# License -# only for this file +# License # -# Licensed under the 3-Clause BSD License (the "License"); +# Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# https://opensource.org/licenses/BSD-3-Clause +# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/cmake/npv-config.cmake.in b/cmake/niv-config.cmake.in similarity index 72% rename from cmake/npv-config.cmake.in rename to cmake/niv-config.cmake.in index 60012b5..f74c3c7 100644 --- a/cmake/npv-config.cmake.in +++ b/cmake/niv-config.cmake.in @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------- -# nest python vis +# nest in situ vis # # Copyright (c) 2017 RWTH Aachen University, Germany, # Virtual Reality & Immersive Visualisation Group. @@ -19,21 +19,19 @@ # limitations under the License. #------------------------------------------------------------------------------- - - -# - Config file for the npv package +# - Config file for the niv package # It defines the following variables -# NPV_INCLUDE_DIRS - include directories for Project Phoenix -# NPV_LIBRARIES - libraries to link against +# NIV_INCLUDE_DIRS - include directories for nest in situ vis +# NIV_LIBRARIES - libraries to link against # Compute paths -get_filename_component(NPV_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) -set(NPV_INCLUDE_DIRS "@CONF_INCLUDE_DIRS@") +get_filename_component(NIV_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) +set(NIV_INCLUDE_DIRS "@CONF_INCLUDE_DIRS@") # Our library dependencies (contains definitions for IMPORTED targets) -if(NOT TARGET npv) - include("${NPV_CMAKE_DIR}/npv-targets.cmake") +if(NOT TARGET niv) + include("${NIV_CMAKE_DIR}/niv-targets.cmake") endif() -# These are IMPORTED targets created by npv-targets.cmake -set(NPV_LIBRARIES npv) +# These are IMPORTED targets created by niv-targets.cmake +set(NIV_LIBRARIES niv) diff --git a/cmake/py.test.cmake b/cmake/py.test.cmake new file mode 100644 index 0000000..0694fe1 --- /dev/null +++ b/cmake/py.test.cmake @@ -0,0 +1,56 @@ +#------------------------------------------------------------------------------- +# nest in situ vis +# +# Copyright (c) 2017 RWTH Aachen University, Germany, +# Virtual Reality & Immersive Visualisation Group. +#------------------------------------------------------------------------------- +# License +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#------------------------------------------------------------------------------- + +find_package(PythonInterp) +if(NOT PYTHON_EXECUTABLE) + message(SEND_ERROR + " ERROR: Could not find any python interpreter. + Having a python interpreter is a mandatory requirement for cpplint. + CMake will not generate the project without it. ") +endif() + +find_file(PY_TEST_COMMAND py.test + PATHS $ENV{PATH} $ENV{PY_TEST_DIR} +) +if(NOT PY_TEST_COMMAND) + message(SEND_ERROR + " ERROR: Could not find py.test. + Having py.test is a mandatory requirement. + CMake will not generate the project without it. + Add its location to the environments variables PATH or CPPLINT_DIR.") +endif() + +function(ADD_TEST_PY_TEST) + set(options ) + set(oneValueArgs NAME PYTHONPATH) + set(multiValueArgs ) + cmake_parse_arguments(ADD_TEST_PY_TEST + "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) + + add_test(NAME "${ADD_TEST_PY_TEST_NAME}" + COMMAND ${PYTHON_EXECUTABLE} -B ${PY_TEST_COMMAND} -p no:cacheprovider + ${ADD_TEST_PY_TEST_UNPARSED_ARGUMENTS} + + ) + set_property(TEST ${ADD_TEST_PY_TEST_NAME} PROPERTY ENVIRONMENT + "PYTHONPATH=${ADD_TEST_PY_TEST_PYTHONPATH}:$PYTHONPATH" + ) +endfunction() diff --git a/cmake/suppress_warnings.hpp.in b/cmake/suppress_warnings.hpp.in index ff289aa..70c97e0 100644 --- a/cmake/suppress_warnings.hpp.in +++ b/cmake/suppress_warnings.hpp.in @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// Project Phoenix +// nest in situ vis // // Copyright (c) 2017 RWTH Aachen University, Germany, // Virtual Reality & Immersive Visualisation Group. @@ -19,14 +19,15 @@ // limitations under the License. //------------------------------------------------------------------------------ -#ifndef PROJECT_PHOENIX_SUPPRESS_WARNINGS_ -#define PROJECT_PHOENIX_SUPPRESS_WARNINGS_ +#ifndef NEST_IN_SITU_VIS_SUPPRESS_WARNINGS_ +#define NEST_IN_SITU_VIS_SUPPRESS_WARNINGS_ #if defined __clang__ -#define SUPPRESS_WARNINGS_BEGIN \ - _Pragma("clang diagnostic push") \ - _Pragma("clang diagnostic ignored \"-Wall\"") \ - _Pragma("clang diagnostic ignored \"-Wextra\"") +#define SUPPRESS_WARNINGS_BEGIN \ + _Pragma("clang diagnostic push") \ + _Pragma("clang diagnostic ignored \"-Wall\"") \ + _Pragma("clang diagnostic ignored \"-Wextra\"") \ + _Pragma("clang diagnostic ignored \"-Wc++98-compat-pedantic\"") #define SUPPRESS_WARNINGS_END _Pragma("clang diagnostic pop") #elif defined _MSC_VER @@ -42,4 +43,4 @@ #endif -#endif // PROJECT_PHOENIX_SUPPRESS_WARNINGS_ +#endif // NEST_IN_SITU_VIS_SUPPRESS_WARNINGS_ diff --git a/demo/CMakeLists.txt b/demo/CMakeLists.txt new file mode 100644 index 0000000..f7ef20d --- /dev/null +++ b/demo/CMakeLists.txt @@ -0,0 +1,22 @@ +#------------------------------------------------------------------------------- +# nest in situ vis +# +# Copyright (c) 2017 RWTH Aachen University, Germany, +# Virtual Reality & Immersive Visualisation Group. +#------------------------------------------------------------------------------- +# License +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#------------------------------------------------------------------------------- + +add_subdirectory(nest_python_vis) diff --git a/demo/nest_python_vis/CMakeLists.txt b/demo/nest_python_vis/CMakeLists.txt new file mode 100644 index 0000000..ff3fb9b --- /dev/null +++ b/demo/nest_python_vis/CMakeLists.txt @@ -0,0 +1,35 @@ +#------------------------------------------------------------------------------- +# nest in situ vis +# +# Copyright (c) 2017 RWTH Aachen University, Germany, +# Virtual Reality & Immersive Visualisation Group. +#------------------------------------------------------------------------------- +# License +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#------------------------------------------------------------------------------- + +set(NEST_PYTHON_VIS_SOURCE nest_python_vis.py) +set(NEST_SIM_SOURCE nest_sim.py) + +file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/run_vis.sh + CONTENT "PYTHONPATH=$:$ ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${NEST_PYTHON_VIS_SOURCE}" + ) + +set(NEST_DIR + CACHE PATH "Path to installed nest") +file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/run_sim.sh + CONTENT +"source ${NEST_DIR}/bin/nest_vars.sh +PYTHONPATH=$:$PYTHONPATH ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${NEST_SIM_SOURCE}" + ) diff --git a/demo/nest_python_vis/nest_python_vis.py b/demo/nest_python_vis/nest_python_vis.py new file mode 100644 index 0000000..5eda3e7 --- /dev/null +++ b/demo/nest_python_vis/nest_python_vis.py @@ -0,0 +1,94 @@ +#------------------------------------------------------------------------------- +# nest in situ vis +# +# Copyright (c) 2017 RWTH Aachen University, Germany, +# Virtual Reality & Immersive Visualisation Group. +#------------------------------------------------------------------------------- +# License +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#------------------------------------------------------------------------------- + +import sys + +import pyniv + +from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QGridLayout, QPushButton +from PyQt5.QtCore import QTimer + +class MainWindow: + def __init__(self): + self.receiver = pyniv.ConduitReceiver() + self.SetupWindow() + self.SetupUpdateTimer() + + + def SetupWindow(self): + self.label_V_m = QLabel("V_m:") + self.value_V_m = QLabel("{:0.3f} mV".format(0.0)) + + self.label_g_ex = QLabel("g_ex:") + self.value_g_ex = QLabel("{:0.3f}".format(0.0)) + + self.label_g_in = QLabel("g_ex:") + self.value_g_in = QLabel("{:0.3f}".format(0.0)) + + self.start_button = QPushButton("Start") + self.start_button.clicked.connect(self.StartButtonClicked) + + self.layout = QGridLayout() + self.layout.addWidget(self.label_V_m, 0, 0) + self.layout.addWidget(self.value_V_m, 0, 1) + self.layout.addWidget(self.label_g_ex, 1, 0) + self.layout.addWidget(self.value_g_ex, 1, 1) + self.layout.addWidget(self.label_g_in, 2, 0) + self.layout.addWidget(self.value_g_in, 2, 1) + + self.layout.addWidget(self.start_button, 3, 0, 1, 2) + + self.window = QWidget() + self.window.setLayout(self.layout) + self.window.show() + + def SetupUpdateTimer(self): + self.update_timer = QTimer() + self.update_timer.timeout.connect(self.UpdateValue) + + + def StartButtonClicked(self): + self.start_button.setEnabled(False) + self.receiver.Start() + self.update_timer.start(0.01) + self.UpdateValue() + + def Show(self): + self.window.show() + + def UpdateValue(self): + self.value_V_m.setText("{:0.3f} mV".format(self.receiver.Get("V_m"))) + self.value_g_ex.setText("{:0.3f}".format(self.receiver.Get("g_ex"))) + self.value_g_in.setText("{:0.3f}".format(self.receiver.Get("g_in"))) + + self.value_V_m.update() + self.window.update() + +def main(argv): + app = QApplication(argv) + + w = MainWindow() + w.Show() + + return app.exec_() + +if __name__ == "__main__": + main(sys.argv) diff --git a/demo/nest_python_vis/nest_sim.py b/demo/nest_python_vis/nest_sim.py new file mode 100644 index 0000000..5af7183 --- /dev/null +++ b/demo/nest_python_vis/nest_sim.py @@ -0,0 +1,123 @@ +#------------------------------------------------------------------------------- +# nest in situ vis +# +# Copyright (c) 2017 RWTH Aachen University, Germany, +# Virtual Reality & Immersive Visualisation Group. +#------------------------------------------------------------------------------- +# License +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#------------------------------------------------------------------------------- + +import sys +import nest +import numpy + +from PyQt5.QtWidgets import QApplication, QPushButton +from PyQt5.QtCore import QTimer + +class Simulation: + def __init__(self): + self.ConfigureNest() + self.CreateNeuron() + self.CreateAndConnectMultimeters() + self.CreateAndConnectSpikeGenerators() + + def ConfigureNest(self): + nest.ResetKernel() + nest.SetKernelStatus({"overwrite_files": True, + "data_path": "", + "data_prefix": ""}) + nest.SetDefaults('static_synapse', {'delay': 0.1}) + + def CreateNeuron(self): + neuron_params={"tau_syn_ex": 1.0, + "V_reset": -70.0} + self.neuron = nest.Create("iaf_cond_alpha", + params=neuron_params) + + def CreateAndConnectMultimeters(self): + self.CreateAndConnectConduitMultimeter() + self.CreateAndConnectScreenMultimeter() + + def CreateAndConnectConduitMultimeter(self): + multimeter_conduit_params = {"interval": 0.1, + "record_from": ["V_m", "g_ex", "g_in"], + "record_to": ["conduit"], + "label": "multimeter_conduit"} + multimeter_conduit = nest.Create("multimeter", + params=multimeter_conduit_params) + nest.Connect(multimeter_conduit, self.neuron) + + def CreateAndConnectScreenMultimeter(self): + multimeter_screen_params = {"interval": 0.1, + "record_from": ["V_m", "g_ex", "g_in"], + "record_to": ["screen"], + "label": "my_screen_multimeter"} + multimeter_screen = nest.Create("multimeter", + params=multimeter_screen_params) + nest.Connect(multimeter_screen, self.neuron) + + def CreateAndConnectSpikeGenerators(self): + self.CreateAndConnectExitatorySpikeGenerator() + self.CreateAndConnectInhibitorySpikeGenerator() + + def CreateAndConnectExitatorySpikeGenerator(self): + spikes_ex_params = {"spike_times": numpy.array([1.0, 5.0, 10.0, 15.0, 20.0, 50.0])} + spikes_ex = nest.Create("spike_generator", + params=spikes_ex_params) + nest.Connect(spikes_ex, self.neuron, syn_spec={"weight": 40.0}) + + def CreateAndConnectInhibitorySpikeGenerator(self): + spikes_in_params = {"spike_times": numpy.array([4.0, 8.0, 13.0, 18.0, 23.0, 53.0])} + spikes_in = nest.Create("spike_generator", + params=spikes_in_params) + nest.Connect(spikes_in, self.neuron, syn_spec={"weight": -20.0}) + + def Simulate(self, time): + nest.Simulate(time) + + +class MainWindow: + def __init__(self): + self.SetupWindow() + self.simulation = Simulation() + self.simulation.Simulate(0.2) + + def SetupWindow(self): + self.simulate_button = QPushButton("nest.Simulate(20)") + self.simulate_button.clicked.connect(self.SimulateButtonClicked) + + def SimulateButtonClicked(self): + self.simulate_button.setEnabled(False) + QApplication.processEvents() + + self.simulation.Simulate(20) + + QApplication.processEvents() + self.simulate_button.setEnabled(True) + + def Show(self): + self.simulate_button.show() + + +def main(argv): + app = QApplication(argv) + + w = MainWindow() + w.Show() + + return app.exec_() + +if __name__ == "__main__": + main(sys.argv) diff --git a/nest_python_vis/CMakeLists.txt b/niv/CMakeLists.txt similarity index 66% rename from nest_python_vis/CMakeLists.txt rename to niv/CMakeLists.txt index 6b4ba38..3a0f319 100644 --- a/nest_python_vis/CMakeLists.txt +++ b/niv/CMakeLists.txt @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------- -# nest python vis +# nest in situ vis # # Copyright (c) 2017 RWTH Aachen University, Germany, # Virtual Reality & Immersive Visualisation Group. @@ -19,34 +19,38 @@ # limitations under the License. #------------------------------------------------------------------------------- -file(GLOB NPV_SOURCES src/*.cpp) -file(GLOB NPV_HEADERS src/*.hpp) -file(GLOB NPV_API_HEADERS include/npv/*.hpp) +file(GLOB NIV_SOURCES src/*.cpp) +file(GLOB NIV_HEADERS src/*.hpp) +file(GLOB NIV_API_HEADERS include/niv/*.hpp) -add_library(npv - ${NPV_SOURCES} - ${NPV_HEADERS} - ${NPV_API_HEADERS} -) -target_include_directories(npv +add_library(niv + ${NIV_SOURCES} + ${NIV_HEADERS} + ${NIV_API_HEADERS} + ) +target_include_directories(niv PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include PUBLIC ${CMAKE_CURRENT_BINARY_DIR} -) + ) +target_link_libraries(niv + conduit + ) -generate_export_header(npv - EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/include/npv/export.hpp +generate_export_header(niv + EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/include/niv/export.hpp ) -set_warning_levels_RWTH(npv - SUPPRESS_WARNINGS_HEADER ${CMAKE_CURRENT_BINARY_DIR}/include/npv/suppress_warnings.hpp +set_warning_levels_RWTH(niv + SUPPRESS_WARNINGS_HEADER ${CMAKE_CURRENT_BINARY_DIR}/include/niv/suppress_warnings.hpp ) -add_test_cpplint(NAME "npv--cpplint" - ${NPV_SOURCES} - ${NPV_HEADERS} - ${NPV_API_HEADERS} +add_test_cpplint(NAME "niv--cpplint" + ${NIV_SOURCES} + ${NIV_HEADERS} + ${NIV_API_HEADERS} ) -generate_configure_files(npv) +generate_configure_files(niv) add_subdirectory(tests) +add_subdirectory(helper_apps) diff --git a/niv/helper_apps/CMakeLists.txt b/niv/helper_apps/CMakeLists.txt new file mode 100644 index 0000000..037766a --- /dev/null +++ b/niv/helper_apps/CMakeLists.txt @@ -0,0 +1,27 @@ +#------------------------------------------------------------------------------- +# nest in situ vis +# +# Copyright (c) 2017 RWTH Aachen University, Germany, +# Virtual Reality & Immersive Visualisation Group. +#------------------------------------------------------------------------------- +# License +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#------------------------------------------------------------------------------- + +add_executable(niv-shared-memory + src/shared_memory.cpp + ) +target_link_libraries(niv-shared-memory + niv + ) diff --git a/niv/helper_apps/src/shared_memory.cpp b/niv/helper_apps/src/shared_memory.cpp new file mode 100644 index 0000000..aa55b4a --- /dev/null +++ b/niv/helper_apps/src/shared_memory.cpp @@ -0,0 +1,93 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ + +#include +#include +#include + +#include "conduit/conduit_node.hpp" +#include "conduit/conduit_schema.hpp" + +#include "niv/shared_memory.hpp" + +conduit::Node AnyNode() { + conduit::Node node; + node["A"]["B"]["E"] = 1.1; + node["A"]["C"]["F"] = 2.1; + node["A"]["C"]["G"] = 2.2; + node["A"]["D"]["H"] = 3.1; + node["A"]["D"]["I"] = 3.2; + node["A"]["D"]["J"] = 3.3; + return node; +} + +void StoreSchema(const conduit::Node& node, niv::SharedMemory* shared_memory) { + conduit::Schema schema; + node.schema().compact_to(schema); + shared_memory->Store(schema.to_json()); +} + +void StoreData(const conduit::Node& node, niv::SharedMemory* shared_memory) { + std::vector data; + node.serialize(data); + shared_memory->Store(data); +} + +void FillWithData(niv::SharedMemory* shared_memory) { + conduit::Node node{AnyNode()}; + StoreSchema(node, shared_memory); + StoreData(node, shared_memory); +} + +void Create() { + niv::SharedMemory shared_memory{niv::SharedMemory::Create()}; + FillWithData(&shared_memory); +} + +void Fill() { + niv::SharedMemory shared_memory{niv::SharedMemory::Access()}; + FillWithData(&shared_memory); +} + +void Destroy() { + niv::SharedMemory s{niv::SharedMemory::Access()}; + s.Destroy(); +} + +int Command(char* command) { + if (std::string(command) == std::string("create")) { + Create(); + return EXIT_SUCCESS; + } else if (std::string(command) == "fill") { + Fill(); + } else if (std::string(command) == std::string("destroy")) { + Destroy(); + return EXIT_SUCCESS; + } + return EXIT_FAILURE; +} + +int main(int argc, char** argv) { + if (argc == 2) { + return Command(argv[1]); + } + return EXIT_FAILURE; +} diff --git a/niv/include/niv/conduit_receiver.hpp b/niv/include/niv/conduit_receiver.hpp new file mode 100644 index 0000000..3e061e9 --- /dev/null +++ b/niv/include/niv/conduit_receiver.hpp @@ -0,0 +1,48 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ + +#ifndef NIV_INCLUDE_NIV_CONDUIT_RECEIVER_HPP_ +#define NIV_INCLUDE_NIV_CONDUIT_RECEIVER_HPP_ + +#include +#include + +#include "conduit/conduit_node.hpp" + +#include "niv/receiving_relay_shared_memory.hpp" +#include "niv/shared_memory_segment.hpp" + +namespace niv { + +class ConduitReceiver { + public: + void Start(); + double Get(const std::string& path) const; + + private: + niv::ReceivingRelaySharedMemory relay_{ + std::make_unique()}; + conduit::Node node_; +}; + +} // namespace niv + +#endif // NIV_INCLUDE_NIV_CONDUIT_RECEIVER_HPP_ diff --git a/nest_python_vis/include/npv/npv.hpp b/niv/include/niv/niv.hpp similarity index 80% rename from nest_python_vis/include/npv/npv.hpp rename to niv/include/niv/niv.hpp index bf75323..6cce4f0 100644 --- a/nest_python_vis/include/npv/npv.hpp +++ b/niv/include/niv/niv.hpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// nest python vis +// nest in situ vis // // Copyright (c) 2017 RWTH Aachen University, Germany, // Virtual Reality & Immersive Visualisation Group. @@ -19,15 +19,13 @@ // limitations under the License. //------------------------------------------------------------------------------ -#ifndef NEST_PYTHON_VIS_INCLUDE_NPV_NPV_HPP_ -#define NEST_PYTHON_VIS_INCLUDE_NPV_NPV_HPP_ +#ifndef NIV_INCLUDE_NIV_NIV_HPP_ +#define NIV_INCLUDE_NIV_NIV_HPP_ -#include +namespace niv { -namespace npv { +char const* Greet(); -std::string Greet(); +} // namespace niv -} // namespace npv - -#endif // NEST_PYTHON_VIS_INCLUDE_NPV_NPV_HPP_ +#endif // NIV_INCLUDE_NIV_NIV_HPP_ diff --git a/niv/include/niv/receiving_relay_shared_memory.hpp b/niv/include/niv/receiving_relay_shared_memory.hpp new file mode 100644 index 0000000..0193274 --- /dev/null +++ b/niv/include/niv/receiving_relay_shared_memory.hpp @@ -0,0 +1,46 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ + +#ifndef NIV_INCLUDE_NIV_RECEIVING_RELAY_SHARED_MEMORY_HPP_ +#define NIV_INCLUDE_NIV_RECEIVING_RELAY_SHARED_MEMORY_HPP_ + +#include + +#include "conduit/conduit_node.hpp" + +#include "niv/relay_shared_memory.hpp" +#include "niv/shared_memory.hpp" + +namespace niv { + +class ReceivingRelaySharedMemory : public RelaySharedMemory { + public: + explicit ReceivingRelaySharedMemory( + std::unique_ptr shared_memory); + virtual ~ReceivingRelaySharedMemory() = default; + + void Receive(conduit::Node* node); + void Listen(conduit::Node* node); +}; + +} // namespace niv + +#endif // NIV_INCLUDE_NIV_RECEIVING_RELAY_SHARED_MEMORY_HPP_ diff --git a/niv/include/niv/relay_shared_memory.hpp b/niv/include/niv/relay_shared_memory.hpp new file mode 100644 index 0000000..8144d61 --- /dev/null +++ b/niv/include/niv/relay_shared_memory.hpp @@ -0,0 +1,42 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ + +#ifndef NIV_INCLUDE_NIV_RELAY_SHARED_MEMORY_HPP_ +#define NIV_INCLUDE_NIV_RELAY_SHARED_MEMORY_HPP_ + +#include + +#include "niv/shared_memory.hpp" + +namespace niv { + +class RelaySharedMemory { + public: + virtual ~RelaySharedMemory() = default; + + protected: + explicit RelaySharedMemory(std::unique_ptr shared_memory); + std::unique_ptr shared_memory_; +}; + +} // namespace niv + +#endif // NIV_INCLUDE_NIV_RELAY_SHARED_MEMORY_HPP_ diff --git a/niv/include/niv/sending_relay_shared_memory.hpp b/niv/include/niv/sending_relay_shared_memory.hpp new file mode 100644 index 0000000..d168a12 --- /dev/null +++ b/niv/include/niv/sending_relay_shared_memory.hpp @@ -0,0 +1,49 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ + +#ifndef NIV_INCLUDE_NIV_SENDING_RELAY_SHARED_MEMORY_HPP_ +#define NIV_INCLUDE_NIV_SENDING_RELAY_SHARED_MEMORY_HPP_ + +#include + +#include "conduit/conduit_node.hpp" + +#include "niv/relay_shared_memory.hpp" +#include "niv/shared_memory.hpp" + +namespace niv { + +class SendingRelaySharedMemory : public RelaySharedMemory { + public: + explicit SendingRelaySharedMemory( + std::unique_ptr shared_memory); + virtual ~SendingRelaySharedMemory() = default; + + void Send(const conduit::Node& node); + + private: + void SendData(const conduit::Node& node); + void SendSchema(const conduit::Node& node); +}; + +} // namespace niv + +#endif // NIV_INCLUDE_NIV_SENDING_RELAY_SHARED_MEMORY_HPP_ diff --git a/niv/include/niv/shared_memory.hpp b/niv/include/niv/shared_memory.hpp new file mode 100644 index 0000000..cdcd76e --- /dev/null +++ b/niv/include/niv/shared_memory.hpp @@ -0,0 +1,75 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ + +#ifndef NIV_INCLUDE_NIV_SHARED_MEMORY_HPP_ +#define NIV_INCLUDE_NIV_SHARED_MEMORY_HPP_ + +#include +#include +#include + +#include "boost/interprocess/allocators/allocator.hpp" +#include "boost/interprocess/managed_shared_memory.hpp" + +#include "conduit/conduit_core.hpp" + +namespace niv { + +class SharedMemory { + public: + class Create {}; + class Access {}; + + using ManagedSharedMemory = boost::interprocess::managed_shared_memory; + using SegmentManager = ManagedSharedMemory::segment_manager; + template + using Allocator = boost::interprocess::allocator; + using DataVector = std::vector>; + using SchemaString = std::vector>; + + explicit SharedMemory(const Create&); + explicit SharedMemory(const Access&); + virtual ~SharedMemory() = default; + + void Destroy(); + + std::size_t GetFreeSize() const; + + void Store(const std::vector& data); + void Store(const std::string& schema); + std::vector GetData() const; + conduit::uint8* GetRawData() const; + std::string GetSchema() const; + + static constexpr const char* SegmentName() { return "niv-shared-memory"; } + static constexpr const char* DataVectorName() { return "DataVector"; } + static constexpr const char* SchemaStringName() { return "SchemaString"; } + static constexpr std::size_t InitialSize() { return 65536u; } + + protected: + ManagedSharedMemory segment_; + DataVector* data_vector_{nullptr}; + SchemaString* schema_string_{nullptr}; +}; + +} // namespace niv + +#endif // NIV_INCLUDE_NIV_SHARED_MEMORY_HPP_ diff --git a/niv/include/niv/shared_memory_access.hpp b/niv/include/niv/shared_memory_access.hpp new file mode 100644 index 0000000..68dc8d6 --- /dev/null +++ b/niv/include/niv/shared_memory_access.hpp @@ -0,0 +1,37 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ + +#ifndef NIV_INCLUDE_NIV_SHARED_MEMORY_ACCESS_HPP_ +#define NIV_INCLUDE_NIV_SHARED_MEMORY_ACCESS_HPP_ + +#include "niv/shared_memory.hpp" + +namespace niv { + +class SharedMemoryAccess : public SharedMemory { + public: + SharedMemoryAccess(); + virtual ~SharedMemoryAccess() = default; +}; + +} // namespace niv + +#endif // NIV_INCLUDE_NIV_SHARED_MEMORY_ACCESS_HPP_ diff --git a/niv/include/niv/shared_memory_segment.hpp b/niv/include/niv/shared_memory_segment.hpp new file mode 100644 index 0000000..61c9fa0 --- /dev/null +++ b/niv/include/niv/shared_memory_segment.hpp @@ -0,0 +1,48 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ + +#ifndef NIV_INCLUDE_NIV_SHARED_MEMORY_SEGMENT_HPP_ +#define NIV_INCLUDE_NIV_SHARED_MEMORY_SEGMENT_HPP_ + +#include + +#include + +#include "boost/interprocess/allocators/allocator.hpp" +#include "boost/interprocess/managed_shared_memory.hpp" + +#include "conduit/conduit_core.hpp" + +#include "niv/shared_memory.hpp" + +namespace niv { + +class SharedMemorySegment : public SharedMemory { + public: + SharedMemorySegment(); + ~SharedMemorySegment(); + + private: +}; + +} // namespace niv + +#endif // NIV_INCLUDE_NIV_SHARED_MEMORY_SEGMENT_HPP_ diff --git a/niv/src/conduit_receiver.cpp b/niv/src/conduit_receiver.cpp new file mode 100644 index 0000000..4e15be3 --- /dev/null +++ b/niv/src/conduit_receiver.cpp @@ -0,0 +1,34 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ + +#include "niv/conduit_receiver.hpp" + +#include + +namespace niv { + +void ConduitReceiver::Start() { relay_.Listen(&node_); } + +double ConduitReceiver::Get(const std::string& path) const { + return node_.fetch(path).as_double(); +} + +} // namespace niv diff --git a/nest_python_vis/src/npv.cpp b/niv/src/niv.cpp similarity index 87% rename from nest_python_vis/src/npv.cpp rename to niv/src/niv.cpp index 472b09d..5174553 100644 --- a/nest_python_vis/src/npv.cpp +++ b/niv/src/niv.cpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// nest python vis +// nest in situ vis // // Copyright (c) 2017 RWTH Aachen University, Germany, // Virtual Reality & Immersive Visualisation Group. @@ -19,12 +19,10 @@ // limitations under the License. //------------------------------------------------------------------------------ -#include "npv/npv.hpp" +#include "niv/niv.hpp" -#include +namespace niv { -namespace npv { +char const* Greet() { return "G'day!"; } -std::string Greet() { return "G'day!"; } - -} // namespace npv +} // namespace niv diff --git a/niv/src/receiving_relay_shared_memory.cpp b/niv/src/receiving_relay_shared_memory.cpp new file mode 100644 index 0000000..9830240 --- /dev/null +++ b/niv/src/receiving_relay_shared_memory.cpp @@ -0,0 +1,48 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ + +#include "niv/receiving_relay_shared_memory.hpp" + +#include +#include + +#include "conduit/conduit_node.hpp" +#include "conduit/conduit_schema.hpp" + +namespace niv { + +ReceivingRelaySharedMemory::ReceivingRelaySharedMemory( + std::unique_ptr shared_memory) + : RelaySharedMemory{std::move(shared_memory)} {} + +void ReceivingRelaySharedMemory::Receive(conduit::Node* node) { + auto schema = shared_memory_->GetSchema(); + auto data = shared_memory_->GetData(); + node->set_data_using_schema(conduit::Schema(schema), data.data()); +} + +void ReceivingRelaySharedMemory::Listen(conduit::Node* node) { + auto schema = shared_memory_->GetSchema(); + auto raw_data = shared_memory_->GetRawData(); + node->set_external_data_using_schema(conduit::Schema(schema), raw_data); +} + +} // namespace niv diff --git a/niv/src/relay_shared_memory.cpp b/niv/src/relay_shared_memory.cpp new file mode 100644 index 0000000..9d3877e --- /dev/null +++ b/niv/src/relay_shared_memory.cpp @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ + +#include "niv/relay_shared_memory.hpp" + +#include +#include + +#include "niv/shared_memory_segment.hpp" + +namespace niv { + +RelaySharedMemory::RelaySharedMemory( + std::unique_ptr shared_memory) + : shared_memory_{std::move(shared_memory)} {} + +} // namespace niv diff --git a/niv/src/sending_relay_shared_memory.cpp b/niv/src/sending_relay_shared_memory.cpp new file mode 100644 index 0000000..4e681c1 --- /dev/null +++ b/niv/src/sending_relay_shared_memory.cpp @@ -0,0 +1,54 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ + +#include "niv/sending_relay_shared_memory.hpp" + +#include +#include +#include + +#include "conduit/conduit_node.hpp" +#include "conduit/conduit_schema.hpp" + +namespace niv { + +SendingRelaySharedMemory::SendingRelaySharedMemory( + std::unique_ptr shared_memory) + : RelaySharedMemory{std::move(shared_memory)} {} + +void SendingRelaySharedMemory::Send(const conduit::Node& node) { + SendData(node); + SendSchema(node); +} + +void SendingRelaySharedMemory::SendData(const conduit::Node& node) { + std::vector data; + node.serialize(data); + shared_memory_->Store(data); +} + +void SendingRelaySharedMemory::SendSchema(const conduit::Node& node) { + conduit::Schema schema; + node.schema().compact_to(schema); + shared_memory_->Store(schema.to_json()); +} + +} // namespace niv diff --git a/niv/src/shared_memory.cpp b/niv/src/shared_memory.cpp new file mode 100644 index 0000000..d3f184a --- /dev/null +++ b/niv/src/shared_memory.cpp @@ -0,0 +1,72 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ + +#include "niv/shared_memory.hpp" + +#include +#include +#include + +namespace niv { + +SharedMemory::SharedMemory(const Create&) + : segment_{boost::interprocess::create_only, SegmentName(), InitialSize()}, + data_vector_{segment_.construct(DataVectorName())( + DataVector::allocator_type(segment_.get_segment_manager()))}, + schema_string_{segment_.construct(SchemaStringName())( + SchemaString::allocator_type(segment_.get_segment_manager()))} {} +SharedMemory::SharedMemory(const Access&) + : segment_{boost::interprocess::open_only, SegmentName()}, + data_vector_{segment_.find(DataVectorName()).first}, + schema_string_{segment_.find(SchemaStringName()).first} {} + +void SharedMemory::Destroy() { + segment_.destroy(DataVectorName()); + segment_.destroy(SchemaStringName()); + boost::interprocess::shared_memory_object::remove(SegmentName()); +} + +std::size_t SharedMemory::GetFreeSize() const { + return segment_.get_free_memory(); +} + +void SharedMemory::Store(const std::vector& data) { + data_vector_->assign(data.begin(), data.end()); +} + +void SharedMemory::Store(const std::string& schema) { + schema_string_->assign(schema.begin(), schema.end()); +} + +std::vector SharedMemory::GetData() const { + return std::vector{data_vector_->begin(), + data_vector_->end()}; +} + +conduit::uint8* SharedMemory::GetRawData() const { + return data_vector_->data(); +} + +std::string SharedMemory::GetSchema() const { + return std::string{schema_string_->begin(), schema_string_->end()}; +} + +} // namespace niv diff --git a/nest_python_vis/tests/src/test-npv.cpp b/niv/src/shared_memory_access.cpp similarity index 85% rename from nest_python_vis/tests/src/test-npv.cpp rename to niv/src/shared_memory_access.cpp index ea04254..edbb51c 100644 --- a/nest_python_vis/tests/src/test-npv.cpp +++ b/niv/src/shared_memory_access.cpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// nest python vis +// nest in situ vis // // Copyright (c) 2017 RWTH Aachen University, Germany, // Virtual Reality & Immersive Visualisation Group. @@ -19,8 +19,10 @@ // limitations under the License. //------------------------------------------------------------------------------ -#include "catch/catch.hpp" +#include "niv/shared_memory_access.hpp" -#include "npv/npv.hpp" +namespace niv { -TEST_CASE("NPV shall greet.", "[npv]") { CHECK(npv::Greet() == "G'day!"); } +SharedMemoryAccess::SharedMemoryAccess() : SharedMemory{Access()} {} + +} // namespace niv diff --git a/niv/src/shared_memory_segment.cpp b/niv/src/shared_memory_segment.cpp new file mode 100644 index 0000000..c1f8e43 --- /dev/null +++ b/niv/src/shared_memory_segment.cpp @@ -0,0 +1,32 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ + +#include "niv/shared_memory_segment.hpp" + +#include + +namespace niv { + +SharedMemorySegment::SharedMemorySegment() : SharedMemory{Create()} {} + +SharedMemorySegment::~SharedMemorySegment() { Destroy(); } + +} // namespace niv diff --git a/niv/tests/CMakeLists.txt b/niv/tests/CMakeLists.txt new file mode 100644 index 0000000..f1cf95d --- /dev/null +++ b/niv/tests/CMakeLists.txt @@ -0,0 +1,42 @@ +#------------------------------------------------------------------------------- +# nest in situ vis +# +# Copyright (c) 2017 RWTH Aachen University, Germany, +# Virtual Reality & Immersive Visualisation Group. +#------------------------------------------------------------------------------- +# License +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#------------------------------------------------------------------------------- + +file(GLOB NIV_TEST_SOURCES src/*.cpp) +file(GLOB NIV_TEST_HEADERS src/*.hpp) +file(GLOB NIV_TEST_UTILITIES_TEST_SOURCES test_utilities/tests/src/*.cpp) +file(GLOB NIV_TEST_UTILITIES_HEADERS test_utilities/*.hpp) + + +add_test_catch(NAME "niv-tests" + SOURCES ${NIV_TEST_SOURCES} ${NIV_TEST_UTILITIES_TEST_SOURCES} + HEADERS ${NIV_TEST_HEADERS} ${NIV_TEST_UTILITIES_HEADERS} + CATCH_MAIN src/tests.cpp + INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR} + LINK_LIBRARIES niv + PATH_TO_ADD ${PROJECT_BINARY_DIR}/niv + ) +add_test_cpplint(NAME "niv-tests--cpplint" + ${NIV_TEST_SOURCES} + ${NIV_TEST_HEADERS} + ${NIV_TEST_UTILITIES_TEST_SOURCES} + ${NIV_TEST_UTILITIES_HEADERS} + ) + diff --git a/nest_python_vis/tests/catch/LICENSE.txt b/niv/tests/catch/LICENSE.txt similarity index 100% rename from nest_python_vis/tests/catch/LICENSE.txt rename to niv/tests/catch/LICENSE.txt diff --git a/nest_python_vis/tests/catch/catch.hpp b/niv/tests/catch/catch.hpp similarity index 100% rename from nest_python_vis/tests/catch/catch.hpp rename to niv/tests/catch/catch.hpp diff --git a/niv/tests/src/test_conduit_receiver.cpp b/niv/tests/src/test_conduit_receiver.cpp new file mode 100644 index 0000000..ebf0ff6 --- /dev/null +++ b/niv/tests/src/test_conduit_receiver.cpp @@ -0,0 +1,53 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ + +#include + +#include "catch/catch.hpp" + +#include "conduit/conduit_node.hpp" + +#include "niv/conduit_receiver.hpp" +#include "niv/sending_relay_shared_memory.hpp" +#include "niv/shared_memory_access.hpp" + +SCENARIO("Conduit data is received by a conduit receiver", + "[niv][niv::ConduitReceiver]") { + GIVEN("A ConduitReceiver") { + niv::ConduitReceiver receiver; + + WHEN("I send some data") { + conduit::Node data; + data["A"]["B"] = 17.0; + data["A"]["C"] = 42.0; + + niv::SendingRelaySharedMemory relay( + std::make_unique()); + relay.Send(data); + + THEN("I receive the data") { + receiver.Start(); + REQUIRE(receiver.Get("A/B") == 17.0); + REQUIRE(receiver.Get("A/C") == 42.0); + } + } + } +} diff --git a/niv/tests/src/test_relay_shared_memory.cpp b/niv/tests/src/test_relay_shared_memory.cpp new file mode 100644 index 0000000..b07e5aa --- /dev/null +++ b/niv/tests/src/test_relay_shared_memory.cpp @@ -0,0 +1,156 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ + +#include + +#include "catch/catch.hpp" + +#include "conduit/conduit_node.hpp" + +#include "niv/receiving_relay_shared_memory.hpp" +#include "niv/sending_relay_shared_memory.hpp" +#include "niv/shared_memory_access.hpp" +#include "niv/shared_memory_segment.hpp" + +namespace { +conduit::Node AnyNode() { + conduit::Node node; + node["A"]["B"]["E"] = 1.1; + node["A"]["C"]["F"] = 2.1; + node["A"]["C"]["G"] = 2.2; + node["A"]["D"]["H"] = 3.1; + node["A"]["D"]["I"] = 3.2; + node["A"]["D"]["J"] = 3.3; + return node; +} + +void REQUIRE_EQ(const conduit::Node& left, const conduit::Node& right) { + REQUIRE(left["A"]["B"]["E"].as_double() == right["A"]["B"]["E"].as_double()); + REQUIRE(left["A"]["C"]["F"].as_double() == right["A"]["C"]["F"].as_double()); + REQUIRE(left["A"]["C"]["G"].as_double() == right["A"]["C"]["G"].as_double()); + REQUIRE(left["A"]["D"]["H"].as_double() == right["A"]["D"]["H"].as_double()); + REQUIRE(left["A"]["D"]["I"].as_double() == right["A"]["D"]["I"].as_double()); + REQUIRE(left["A"]["D"]["J"].as_double() == right["A"]["D"]["J"].as_double()); +} + +conduit::Node& AnyLeaf(conduit::Node* node) { return (*node)["A"]["D"]["H"]; } + +constexpr double kAnyOtherValue{42.0f}; + +} // namespace + +SCENARIO("Communicate a conduit node from shared mem segment to access", + "[niv][nvi::RelaySharedMemory]") { + GIVEN( + "A conduit node with some data, a sending shared memory segment relay, a " + "receiving shared memory access relay, and a receiving node") { + conduit::Node any_node{::AnyNode()}; + niv::SendingRelaySharedMemory sending_relay{ + std::make_unique()}; + niv::ReceivingRelaySharedMemory receiving_relay{ + std::make_unique()}; + conduit::Node receiving_node; + + WHEN("I send the data via the sending relay") { + sending_relay.Send(any_node); + + THEN("I receive the data on the receiving relay") { + receiving_relay.Receive(&receiving_node); + REQUIRE_EQ(receiving_node, any_node); + } + + WHEN("I change one value and send again") { + ::AnyLeaf(&any_node) = ::kAnyOtherValue; + sending_relay.Send(any_node); + + THEN("I receive the data on the receiving relay") { + receiving_relay.Receive(&receiving_node); + REQUIRE_EQ(receiving_node, any_node); + } + } + + WHEN("I listen to the data on the receiving relay") { + receiving_relay.Listen(&receiving_node); + THEN("I receive the data on the receiving relay") { + REQUIRE_EQ(receiving_node, any_node); + } + + WHEN("I change one value and send again") { + ::AnyLeaf(&any_node) = ::kAnyOtherValue; + sending_relay.Send(any_node); + + THEN("I receive the data on the receiving relay") { + REQUIRE_EQ(receiving_node, any_node); + } + } + } + } + } +} + +SCENARIO("Communicate a conduit node from shared mem access to segment", + "[niv][nvi::RelaySharedMemory]") { + GIVEN( + "A conduit node with some data, a sending shared memory access relay, a " + "receiving shared memory segment relay, and a receiving node") { + niv::ReceivingRelaySharedMemory receiving_relay{ + std::make_unique()}; + conduit::Node receiving_node; + conduit::Node any_node{::AnyNode()}; + niv::SendingRelaySharedMemory sending_relay{ + std::make_unique()}; + + WHEN("I send the data via the sending relay") { + sending_relay.Send(any_node); + + THEN("I receive the data on the receiving relay") { + receiving_relay.Receive(&receiving_node); + REQUIRE_EQ(receiving_node, any_node); + } + + WHEN("I change one value and send again") { + ::AnyLeaf(&any_node) = ::kAnyOtherValue; + sending_relay.Send(any_node); + + THEN("I receive the data on the receiving relay") { + receiving_relay.Receive(&receiving_node); + REQUIRE_EQ(receiving_node, any_node); + } + } + + WHEN("I listen to the data on the receiving relay") { + receiving_relay.Listen(&receiving_node); + THEN("I receive the data on the receiving relay") { + REQUIRE_EQ(receiving_node, any_node); + } + + WHEN("I change one value and send again") { + ::AnyLeaf(&any_node) = ::kAnyOtherValue; + sending_relay.Send(any_node); + + THEN("I receive the data on the receiving relay") { + REQUIRE_EQ(receiving_node, any_node); + } + } + } + } + } +} diff --git a/niv/tests/src/test_shared_memory_access.cpp b/niv/tests/src/test_shared_memory_access.cpp new file mode 100644 index 0000000..4eb4002 --- /dev/null +++ b/niv/tests/src/test_shared_memory_access.cpp @@ -0,0 +1,64 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ + +#include +#include + +#include "catch/catch.hpp" + +#include "niv/shared_memory_access.hpp" +#include "niv/shared_memory_segment.hpp" + +SCENARIO("Shared memory access", "[niv][niv::SharedMemoryAccess]") { + GIVEN("No shared memory segment") { + THEN("Creating a shared memory access throws an exception.") { + REQUIRE_THROWS_WITH([]() { niv::SharedMemoryAccess segment_access; }(), + "No such file or directory"); + } + } + + GIVEN("A shared memory segment with some data in it") { + niv::SharedMemorySegment segment; + std::vector some_data{1u, 2u, 3u}; + segment.Store(some_data); + std::string some_schema{"foo bar"}; + segment.Store(some_schema); + + WHEN("I create shared memory access") { + THEN("It does not throw an exception") { + REQUIRE_NOTHROW([]() { niv::SharedMemoryAccess segment_access; }()); + } + niv::SharedMemoryAccess segment_access; + + WHEN("I read the data from shared memory access") { + auto read_data = segment_access.GetData(); + THEN("I get the original data") { REQUIRE(read_data == some_data); } + } + + WHEN("I read the schema from shared memory access") { + auto read_schema = segment_access.GetSchema(); + THEN("I get the original schema") { + REQUIRE(read_schema == some_schema); + } + } + } + } +} diff --git a/niv/tests/src/test_shared_memory_segment.cpp b/niv/tests/src/test_shared_memory_segment.cpp new file mode 100644 index 0000000..fab68b4 --- /dev/null +++ b/niv/tests/src/test_shared_memory_segment.cpp @@ -0,0 +1,82 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ + +#include +#include + +#include "catch/catch.hpp" + +#include "niv/shared_memory_segment.hpp" + +SCENARIO("Shared memory creation", "[niv][niv::SharedMemorySegment]") { + GIVEN("A shared memory segment") { + niv::SharedMemorySegment segment; + WHEN("I ask it for its free size") { + auto free_size_after_creation = segment.GetFreeSize(); + THEN("it is > 0") { REQUIRE(free_size_after_creation > 0); } + } + + WHEN("I retrieve data from the new segment") { + auto retrieved_data = segment.GetData(); + THEN("it is empty") { REQUIRE(retrieved_data.size() == 0); } + } + + WHEN("I store data in the segment") { + std::vector some_data{1u, 2u, 3u}; + auto free_size_before = segment.GetFreeSize(); + segment.Store(some_data); + auto free_size_after = segment.GetFreeSize(); + THEN("we have less free space in the segment") { + REQUIRE(free_size_after < free_size_before); + } + THEN("I can retrieve the data") { + auto retrieved_data = segment.GetData(); + REQUIRE(retrieved_data == some_data); + } + } + + WHEN("I retrieve the schema from the new segment") { + auto retrieved_schema = segment.GetSchema(); + THEN("it is empty") { REQUIRE(retrieved_schema.size() == 0); } + } + + WHEN("I store a schema in the segment") { + std::string some_schema{"foo bar"}; + auto free_size_before = segment.GetFreeSize(); + segment.Store(some_schema); + auto free_size_after = segment.GetFreeSize(); + THEN("we have less free space in the segment") { + REQUIRE(free_size_after < free_size_before); + } + THEN("I can retrieve it") { + auto retrieved_schema = segment.GetSchema(); + REQUIRE(retrieved_schema == some_schema); + } + } + + WHEN("I request a second shared memory segment") { + THEN("It throws an exception") { + REQUIRE_THROWS_WITH([]() { niv::SharedMemorySegment segment2; }(), + "File exists"); + } + } + } +} diff --git a/nest_python_vis/tests/src/tests.cpp b/niv/tests/src/tests.cpp similarity index 98% rename from nest_python_vis/tests/src/tests.cpp rename to niv/tests/src/tests.cpp index 890f1ae..f45a0ae 100644 --- a/nest_python_vis/tests/src/tests.cpp +++ b/niv/tests/src/tests.cpp @@ -1,5 +1,5 @@ //------------------------------------------------------------------------------ -// nest python vis +// nest in situ vis // // Copyright (c) 2017 RWTH Aachen University, Germany, // Virtual Reality & Immersive Visualisation Group. diff --git a/niv/tests/test_utilities/cout_capture.hpp b/niv/tests/test_utilities/cout_capture.hpp new file mode 100644 index 0000000..b5fbb7d --- /dev/null +++ b/niv/tests/test_utilities/cout_capture.hpp @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ + +#ifndef NIV_TESTS_TEST_UTILITIES_COUT_CAPTURE_HPP_ +#define NIV_TESTS_TEST_UTILITIES_COUT_CAPTURE_HPP_ + +#include +#include +#include + +#include "catch/catch.hpp" + +namespace test_utilities { + +class CoutCapture { + public: + CoutCapture() { original_rdbuf_ = std::cout.rdbuf(cout_stream_.rdbuf()); } + ~CoutCapture() { std::cout.rdbuf(original_rdbuf_); } + + bool operator==(const std::string& other) const { + return cout_stream_.str() == other; + } + + std::string ToString() const { return "\"" + cout_stream_.str() + "\""; } + + private: + std::streambuf* original_rdbuf_; + std::stringstream cout_stream_; +}; + +} // namespace test_utilities + +namespace Catch { + +template <> +struct StringMaker { + static std::string convert(const test_utilities::CoutCapture& cout_capture) { + return cout_capture.ToString(); + } +}; + +} // namespace Catch + +#endif // NIV_TESTS_TEST_UTILITIES_COUT_CAPTURE_HPP_ diff --git a/niv/tests/test_utilities/tests/src/test_cout_capture.cpp b/niv/tests/test_utilities/tests/src/test_cout_capture.cpp new file mode 100644 index 0000000..b306734 --- /dev/null +++ b/niv/tests/test_utilities/tests/src/test_cout_capture.cpp @@ -0,0 +1,73 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ + +#include + +#include "catch/catch.hpp" + +#include "test_utilities/cout_capture.hpp" + +SCENARIO("CoutCapture captures standard output", "[tests][test::utils]") { + GIVEN("a CoutCapture") { + test_utilities::CoutCapture cout_capture; + + WHEN("I print something to cout") { + std::cout << "something"; + THEN("'something' is captured") { REQUIRE(cout_capture == "something"); } + WHEN("I add else to cout") { + std::cout << " else"; + THEN("'something else' is captures") { + REQUIRE(cout_capture == "something else"); + } + } + WHEN("I then use another CoutCapture and print foo") { + test_utilities::CoutCapture another_cout_capture; + std::cout << "foo"; + THEN("only 'foo' should be captured") { + REQUIRE(another_cout_capture == "foo"); + } + } + } + WHEN("I print two lines to cout") { + std::cout << "two" << std::endl; + std::cout << "lines"; + THEN("two lines are captured") { REQUIRE(cout_capture == "two\nlines"); } + } + } +} + +SCENARIO( + "CoutCapture captures standard output respecting the scope of the " + "CoutCapture", + "[tests][test::utils]") { + WHEN("I use CoutCapture in different scopes") { + test_utilities::CoutCapture cout_capture; + std::cout << "something"; + { + test_utilities::CoutCapture another_cout_capture; + std::cout << "foo"; + } + std::cout << " else"; + THEN("the scope is respected") { + REQUIRE(cout_capture == "something else"); + } + } +} diff --git a/pyniv/CMakeLists.txt b/pyniv/CMakeLists.txt new file mode 100644 index 0000000..fbce4ef --- /dev/null +++ b/pyniv/CMakeLists.txt @@ -0,0 +1,48 @@ +#------------------------------------------------------------------------------- +# nest in situ vis +# +# Copyright (c) 2017 RWTH Aachen University, Germany, +# Virtual Reality & Immersive Visualisation Group. +#------------------------------------------------------------------------------- +# License +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#------------------------------------------------------------------------------- + + + +file(GLOB PYNIV_SOURCES src/*.cpp) + +python_add_module(pyniv + ${PYNIV_SOURCES} +) +target_link_libraries(pyniv niv) + +target_include_directories(pyniv + PRIVATE ${Boost_INCLUDE_DIRS} + PRIVATE ${PYTHON_INCLUDE_DIRS} + ) +target_link_libraries(pyniv + ${Boost_LIBRARIES} + ${PYTHON_LIBRARIES} + ) + +set_warning_levels_RWTH(pyniv + SUPPRESS_WARNINGS_HEADER ${CMAKE_CURRENT_BINARY_DIR}/include/pyniv/suppress_warnings.hpp +) + +add_test_cpplint(NAME "pyniv--cpplint" + ${PYNIV_SOURCES} +) + +add_subdirectory(tests) diff --git a/pyniv/src/conduit_data.cpp b/pyniv/src/conduit_data.cpp new file mode 100644 index 0000000..34d84d3 --- /dev/null +++ b/pyniv/src/conduit_data.cpp @@ -0,0 +1,50 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ + +#include "conduit_data.hpp" + +#include + +#include "pyniv.hpp" + +namespace pyniv { + +ConduitData::ConduitData() { + node_["V_m"] = 1.2; + std::cout << "Ptr. to conduit node: " << Pointer() << std::endl; +} + +void ConduitData::Set(const char* attribute, double value) { + node_[attribute] = value; +} + +std::size_t ConduitData::Pointer() const { + return reinterpret_cast(&node_); +} + +template <> +void expose() { + class_("ConduitData") + .def("Set", &ConduitData::Set) + .def("Pointer", &ConduitData::Pointer); +} + +} // namespace pyniv diff --git a/pyniv/src/conduit_data.hpp b/pyniv/src/conduit_data.hpp new file mode 100644 index 0000000..33f6518 --- /dev/null +++ b/pyniv/src/conduit_data.hpp @@ -0,0 +1,47 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ + +#ifndef PYNIV_SRC_CONDUIT_DATA_HPP_ +#define PYNIV_SRC_CONDUIT_DATA_HPP_ + +#include "conduit/conduit.hpp" + +namespace pyniv { + +class ConduitData { + public: + ConduitData(); + ~ConduitData() = default; + ConduitData(const ConduitData&) = default; + ConduitData(ConduitData&&) = default; + + void Set(const char* attribute, double value); + std::size_t Pointer() const; + + const conduit::Node& GetNode() const { return node_; } + + private: + conduit::Node node_; +}; + +} // namespace pyniv + +#endif // PYNIV_SRC_CONDUIT_DATA_HPP_ diff --git a/pyniv/src/conduit_data_sender.cpp b/pyniv/src/conduit_data_sender.cpp new file mode 100644 index 0000000..ad085c6 --- /dev/null +++ b/pyniv/src/conduit_data_sender.cpp @@ -0,0 +1,39 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ + +#include "conduit_data_sender.hpp" + +#include "conduit_data.hpp" +#include "pyniv.hpp" + +namespace pyniv { + +void ConduitDataSender::Send(const ConduitData& data) { + relay_.Send(data.GetNode()); +} + +template <> +void expose() { + class_("ConduitDataSender") + .def("Send", &ConduitDataSender::Send, args("data")); +} + +} // namespace pyniv diff --git a/pyniv/src/conduit_data_sender.hpp b/pyniv/src/conduit_data_sender.hpp new file mode 100644 index 0000000..8fa5a83 --- /dev/null +++ b/pyniv/src/conduit_data_sender.hpp @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ + +#ifndef PYNIV_SRC_CONDUIT_DATA_SENDER_HPP_ +#define PYNIV_SRC_CONDUIT_DATA_SENDER_HPP_ + +#include "niv/sending_relay_shared_memory.hpp" +#include "niv/shared_memory_access.hpp" + +#include "conduit_data.hpp" + +namespace pyniv { + +class ConduitDataSender { + public: + void Send(const ConduitData& data); + + private: + niv::SendingRelaySharedMemory relay_{ + std::make_unique()}; + conduit::Node node_; +}; + +} // namespace pyniv + +#endif // PYNIV_SRC_CONDUIT_DATA_SENDER_HPP_ diff --git a/pyniv/src/conduit_receiver.cpp b/pyniv/src/conduit_receiver.cpp new file mode 100644 index 0000000..73943e5 --- /dev/null +++ b/pyniv/src/conduit_receiver.cpp @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ + +#include "niv/conduit_receiver.hpp" + +#include "pyniv.hpp" + +namespace pyniv { + +template <> +void expose() { + class_("ConduitReceiver") + .def("Start", &niv::ConduitReceiver::Start) + .def("Get", &niv::ConduitReceiver::Get, args("path")); +} + +} // namespace pyniv diff --git a/pyniv/src/pyniv.cpp b/pyniv/src/pyniv.cpp new file mode 100644 index 0000000..f0f7a70 --- /dev/null +++ b/pyniv/src/pyniv.cpp @@ -0,0 +1,35 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ + +#include "pyniv.hpp" + +#include "niv/conduit_receiver.hpp" +#include "niv/niv.hpp" + +#include "conduit_data.hpp" +#include "conduit_data_sender.hpp" + +BOOST_PYTHON_MODULE(pyniv) { + def("Greet", niv::Greet); + pyniv::expose(); + pyniv::expose(); + pyniv::expose(); +} diff --git a/pyniv/src/pyniv.hpp b/pyniv/src/pyniv.hpp new file mode 100644 index 0000000..360bb67 --- /dev/null +++ b/pyniv/src/pyniv.hpp @@ -0,0 +1,42 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ + +#ifndef PYNIV_SRC_PYNIV_HPP_ +#define PYNIV_SRC_PYNIV_HPP_ + +SUPPRESS_WARNINGS_BEGIN +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#include "boost/python.hpp" +SUPPRESS_WARNINGS_END + +using boost::python::args; +using boost::python::class_; +using boost::python::def; +using boost::python::init; + +namespace pyniv { + +template +void expose(); + +} // namespace pyniv + +#endif // PYNIV_SRC_PYNIV_HPP_ diff --git a/nest_python_vis/tests/CMakeLists.txt b/pyniv/tests/CMakeLists.txt similarity index 69% rename from nest_python_vis/tests/CMakeLists.txt rename to pyniv/tests/CMakeLists.txt index 81bb9dc..dcf1703 100644 --- a/nest_python_vis/tests/CMakeLists.txt +++ b/pyniv/tests/CMakeLists.txt @@ -1,5 +1,5 @@ #------------------------------------------------------------------------------- -# nest python vis +# nest in situ vis # # Copyright (c) 2017 RWTH Aachen University, Germany, # Virtual Reality & Immersive Visualisation Group. @@ -19,19 +19,11 @@ # limitations under the License. #------------------------------------------------------------------------------- -file(GLOB NPV_TEST_SOURCES src/*.cpp) -file(GLOB NPV_TEST_HEADERS src/*.hpp) -add_test_catch(NAME "NPV-tests" - SOURCES ${NPV_TEST_SOURCES} - HEADERS ${NPV_TEST_HEADERS} - CATCH_MAIN src/tests.cpp - INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR} - LINK_LIBRARIES npv - PATH_TO_ADD ${PROJECT_BINARY_DIR}/npv -) -add_test_cpplint(NAME "npv-tests--cpplint" - ${NPV_TEST_SOURCES} - ${NPV_TEST_HEADERS} -) +file(GLOB PYNIV_TEST_SOURCES src/*.py) + +add_test_py_test(NAME test_pyniv + ${CMAKE_CURRENT_SOURCE_DIR} + PYTHONPATH "$:$" +) diff --git a/pyniv/tests/src/test_pynpv.py b/pyniv/tests/src/test_pynpv.py new file mode 100644 index 0000000..3f8fd95 --- /dev/null +++ b/pyniv/tests/src/test_pynpv.py @@ -0,0 +1,60 @@ +#------------------------------------------------------------------------------- +# nest in situ vis +# +# Copyright (c) 2017 RWTH Aachen University, Germany, +# Virtual Reality & Immersive Visualisation Group. +#------------------------------------------------------------------------------- +# License +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#------------------------------------------------------------------------------- + +import ctypes +import sys +import time + +import pyniv + +import pytest_utilities + +def test_pypvt(): + assert True + +def test_cout_capture(capsys): + print("hello") + sys.stderr.write("world\n") + out, err = capsys.readouterr() + assert out == "hello\n" + assert err == "world\n" + print ("next") + out, err = capsys.readouterr() + assert out == "next\n" + +def test_pyniv_greet(): + assert pyniv.Greet() == "G'day!" + +def test_pyniv_receive_via_shared_mem_segment_relay(): + r = pyniv.ConduitReceiver() + + d = pyniv.ConduitData() + s = pyniv.ConduitDataSender() + s.Send(d) + + r.Start() + + assert r.Get("V_m") == 1.2 + + d.Set("V_m", 42.0) + s.Send(d) + + assert r.Get("V_m") == 42.0 diff --git a/pytest_utilities/CMakeLists.txt b/pytest_utilities/CMakeLists.txt new file mode 100644 index 0000000..acecd98 --- /dev/null +++ b/pytest_utilities/CMakeLists.txt @@ -0,0 +1,44 @@ +#------------------------------------------------------------------------------- +# nest in situ vis +# +# Copyright (c) 2017 RWTH Aachen University, Germany, +# Virtual Reality & Immersive Visualisation Group. +#------------------------------------------------------------------------------- +# License +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#------------------------------------------------------------------------------- + +file(GLOB PYTEST_UTILITIES_SOURCES src/*.cpp) + +find_package(Boost REQUIRED COMPONENTS python) +find_package(PythonInterp) +find_package(PythonLibs) + +python_add_module(pytest_utilities + ${PYTEST_UTILITIES_SOURCES} +) + +target_include_directories(pytest_utilities PRIVATE ${Boost_INCLUDE_DIRS}) +target_link_libraries(pytest_utilities ${Boost_LIBRARIES}) + +target_include_directories(pytest_utilities PRIVATE ${PYTHON_INCLUDE_DIRS}) +target_link_libraries(pytest_utilities ${PYTHON_LIBRARIES}) + +set_warning_levels_RWTH(pytest_utilities + SUPPRESS_WARNINGS_HEADER ${CMAKE_CURRENT_BINARY_DIR}/include/pytest_utilities/suppress_warnings.hpp +) + +add_test_cpplint(NAME "pytest_utilities--cpplint" + ${PYTEST_UTILITIES_SOURCES} +) diff --git a/pytest_utilities/src/cout_capture.cpp b/pytest_utilities/src/cout_capture.cpp new file mode 100644 index 0000000..65fc1b3 --- /dev/null +++ b/pytest_utilities/src/cout_capture.cpp @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// nest in situ vis +// +// Copyright (c) 2017 RWTH Aachen University, Germany, +// Virtual Reality & Immersive Visualisation Group. +//------------------------------------------------------------------------------ +// License +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +//------------------------------------------------------------------------------ + +#include +#include + +SUPPRESS_WARNINGS_BEGIN +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#include "boost/python.hpp" +SUPPRESS_WARNINGS_END + +namespace test_utilities { + +class CoutCapture { + public: + CoutCapture() { original_rdbuf_ = std::cout.rdbuf(cout_stream_.rdbuf()); } + ~CoutCapture() { std::cout.rdbuf(original_rdbuf_); } + + bool operator==(const std::string& other) const { + return cout_stream_.str() == other; + } + + std::string ToString() const { return "\"" + cout_stream_.str() + "\""; } + + private: + std::streambuf* original_rdbuf_; + std::stringstream cout_stream_; +}; + +} // namespace test_utilities + +BOOST_PYTHON_MODULE(pytest_utilities) { + using boost::python::class_; + using boost::python::def; + using boost::python::init; + + class_("CoutCapture") + .def("ToString", &test_utilities::CoutCapture::ToString); +}