diff --git a/CMakeLists.txt b/CMakeLists.txt index 31220fe87030cc1f0658c3b2fa2e13ab736c0fcd..3a036adb393a89179638f3184df65caf954abab4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -242,7 +242,7 @@ add_custom_target( dist COMMENT "Creating a source distribution from ${MODULE_NAME}..." ) -add_subdirectory(demos) +add_subdirectory(examples) if ( BUILD_SHARED_LIBS ) # When building shared libraries, also create a module for loading at runtime diff --git a/demos/brunel_simulation/CMakeLists.txt b/examples/CMakeLists.txt similarity index 55% rename from demos/brunel_simulation/CMakeLists.txt rename to examples/CMakeLists.txt index 6fd813ebf9dbf4b4c0e2db0852fcc1879ec51b1a..ca7ba80c448f8a5f3b629d289b2b15cc03a41a30 100644 --- a/demos/brunel_simulation/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -19,19 +19,22 @@ # limitations under the License. #------------------------------------------------------------------------------- -get_filename_component(NEST_DIR ${with-nest} DIRECTORY) +option(EXAMPLE_BRUNEL_SIMULATION "Build the brunel simulation" ON) +option(EXAMPLE_IZHIKEVICH_SIMULATION "Build the izhikevich simulation" ON) +option(EXAMPLE_QVTK_VISUALIZATION "Build the QVTK visualization demo" OFF) + +include(cmake/PythonExample.cmake) + +if (${EXAMPLE_BRUNEL_SIMULATION}) + add_subdirectory(brunel) +endif (${EXAMPLE_BRUNEL_SIMULATION}) + +if (${EXAMPLE_IZHIKEVICH_SIMULATION}) + add_subdirectory(izhikevich) +endif (${EXAMPLE_IZHIKEVICH_SIMULATION}) + +if (${EXAMPLE_QVTK_VISUALIZATION}) + add_subdirectory(QVTK-Demo) +endif (${EXAMPLE_QVTK_VISUALIZATION}) -set(SCRIPT_FILENAME "${CMAKE_CURRENT_BINARY_DIR}/run_sim.sh") -execute_process( - COMMAND ${NEST_CONFIG} --python-executable - RESULT_VARIABLE RES_VAR - OUTPUT_VARIABLE PYTHON_EXECUTABLE - OUTPUT_STRIP_TRAILING_WHITESPACE -) -message(STATUS "PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE}") -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/run_sim.sh.in ${SCRIPT_FILENAME}) -file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/brunel_example.py ${CMAKE_CURRENT_SOURCE_DIR}/nest_sim.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) -add_custom_target(brunel_simulation ALL chmod "+x" "run_sim.sh" - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - DEPENDS ${SCRIPT_FILENAME} ${CMAKE_CURRENT_BINARY_DIR}/brunel_example.py ${CMAKE_CURRENT_SOURCE_DIR}/nest_sim.py) diff --git a/demos/QVTK-Demo/CMakeLists.txt b/examples/QVTK-Demo/CMakeLists.txt similarity index 100% rename from demos/QVTK-Demo/CMakeLists.txt rename to examples/QVTK-Demo/CMakeLists.txt diff --git a/demos/QVTK-Demo/Readme.txt b/examples/QVTK-Demo/Readme.txt similarity index 100% rename from demos/QVTK-Demo/Readme.txt rename to examples/QVTK-Demo/Readme.txt diff --git a/demos/QVTK-Demo/qvtk-app/CMakeLists.txt b/examples/QVTK-Demo/qvtk-app/CMakeLists.txt similarity index 100% rename from demos/QVTK-Demo/qvtk-app/CMakeLists.txt rename to examples/QVTK-Demo/qvtk-app/CMakeLists.txt diff --git a/demos/QVTK-Demo/qvtk-app/include/qvtk_app/application.hpp b/examples/QVTK-Demo/qvtk-app/include/qvtk_app/application.hpp similarity index 100% rename from demos/QVTK-Demo/qvtk-app/include/qvtk_app/application.hpp rename to examples/QVTK-Demo/qvtk-app/include/qvtk_app/application.hpp diff --git a/demos/QVTK-Demo/qvtk-app/src/application.cpp b/examples/QVTK-Demo/qvtk-app/src/application.cpp similarity index 100% rename from demos/QVTK-Demo/qvtk-app/src/application.cpp rename to examples/QVTK-Demo/qvtk-app/src/application.cpp diff --git a/demos/QVTK-Demo/qvtk-app/src/main.cpp b/examples/QVTK-Demo/qvtk-app/src/main.cpp similarity index 100% rename from demos/QVTK-Demo/qvtk-app/src/main.cpp rename to examples/QVTK-Demo/qvtk-app/src/main.cpp diff --git a/demos/QVTK-Demo/qvtk-lib/CMakeLists.txt b/examples/QVTK-Demo/qvtk-lib/CMakeLists.txt similarity index 100% rename from demos/QVTK-Demo/qvtk-lib/CMakeLists.txt rename to examples/QVTK-Demo/qvtk-lib/CMakeLists.txt diff --git a/demos/QVTK-Demo/qvtk-lib/include/qvtk-lib/animate.hpp b/examples/QVTK-Demo/qvtk-lib/include/qvtk-lib/animate.hpp similarity index 100% rename from demos/QVTK-Demo/qvtk-lib/include/qvtk-lib/animate.hpp rename to examples/QVTK-Demo/qvtk-lib/include/qvtk-lib/animate.hpp diff --git a/demos/QVTK-Demo/qvtk-lib/include/qvtk-lib/data_stream.hpp b/examples/QVTK-Demo/qvtk-lib/include/qvtk-lib/data_stream.hpp similarity index 100% rename from demos/QVTK-Demo/qvtk-lib/include/qvtk-lib/data_stream.hpp rename to examples/QVTK-Demo/qvtk-lib/include/qvtk-lib/data_stream.hpp diff --git a/demos/QVTK-Demo/qvtk-lib/include/qvtk-lib/interaction.hpp b/examples/QVTK-Demo/qvtk-lib/include/qvtk-lib/interaction.hpp similarity index 100% rename from demos/QVTK-Demo/qvtk-lib/include/qvtk-lib/interaction.hpp rename to examples/QVTK-Demo/qvtk-lib/include/qvtk-lib/interaction.hpp diff --git a/demos/QVTK-Demo/qvtk-lib/include/qvtk-lib/main_widget.hpp b/examples/QVTK-Demo/qvtk-lib/include/qvtk-lib/main_widget.hpp similarity index 100% rename from demos/QVTK-Demo/qvtk-lib/include/qvtk-lib/main_widget.hpp rename to examples/QVTK-Demo/qvtk-lib/include/qvtk-lib/main_widget.hpp diff --git a/demos/QVTK-Demo/qvtk-lib/include/qvtk-lib/main_window.hpp b/examples/QVTK-Demo/qvtk-lib/include/qvtk-lib/main_window.hpp similarity index 100% rename from demos/QVTK-Demo/qvtk-lib/include/qvtk-lib/main_window.hpp rename to examples/QVTK-Demo/qvtk-lib/include/qvtk-lib/main_window.hpp diff --git a/demos/QVTK-Demo/qvtk-lib/include/qvtk-lib/point_data.hpp b/examples/QVTK-Demo/qvtk-lib/include/qvtk-lib/point_data.hpp similarity index 100% rename from demos/QVTK-Demo/qvtk-lib/include/qvtk-lib/point_data.hpp rename to examples/QVTK-Demo/qvtk-lib/include/qvtk-lib/point_data.hpp diff --git a/demos/QVTK-Demo/qvtk-lib/include/qvtk-lib/visualize.hpp b/examples/QVTK-Demo/qvtk-lib/include/qvtk-lib/visualize.hpp similarity index 100% rename from demos/QVTK-Demo/qvtk-lib/include/qvtk-lib/visualize.hpp rename to examples/QVTK-Demo/qvtk-lib/include/qvtk-lib/visualize.hpp diff --git a/demos/QVTK-Demo/qvtk-lib/src/animate.cpp b/examples/QVTK-Demo/qvtk-lib/src/animate.cpp similarity index 100% rename from demos/QVTK-Demo/qvtk-lib/src/animate.cpp rename to examples/QVTK-Demo/qvtk-lib/src/animate.cpp diff --git a/demos/QVTK-Demo/qvtk-lib/src/data_stream.cpp b/examples/QVTK-Demo/qvtk-lib/src/data_stream.cpp similarity index 100% rename from demos/QVTK-Demo/qvtk-lib/src/data_stream.cpp rename to examples/QVTK-Demo/qvtk-lib/src/data_stream.cpp diff --git a/demos/QVTK-Demo/qvtk-lib/src/interaction.cpp b/examples/QVTK-Demo/qvtk-lib/src/interaction.cpp similarity index 100% rename from demos/QVTK-Demo/qvtk-lib/src/interaction.cpp rename to examples/QVTK-Demo/qvtk-lib/src/interaction.cpp diff --git a/demos/QVTK-Demo/qvtk-lib/src/main_widget.cpp b/examples/QVTK-Demo/qvtk-lib/src/main_widget.cpp similarity index 100% rename from demos/QVTK-Demo/qvtk-lib/src/main_widget.cpp rename to examples/QVTK-Demo/qvtk-lib/src/main_widget.cpp diff --git a/demos/QVTK-Demo/qvtk-lib/src/main_window.cpp b/examples/QVTK-Demo/qvtk-lib/src/main_window.cpp similarity index 100% rename from demos/QVTK-Demo/qvtk-lib/src/main_window.cpp rename to examples/QVTK-Demo/qvtk-lib/src/main_window.cpp diff --git a/demos/QVTK-Demo/qvtk-lib/src/point_data.cpp b/examples/QVTK-Demo/qvtk-lib/src/point_data.cpp similarity index 100% rename from demos/QVTK-Demo/qvtk-lib/src/point_data.cpp rename to examples/QVTK-Demo/qvtk-lib/src/point_data.cpp diff --git a/demos/QVTK-Demo/qvtk-lib/src/visualize.cpp b/examples/QVTK-Demo/qvtk-lib/src/visualize.cpp similarity index 100% rename from demos/QVTK-Demo/qvtk-lib/src/visualize.cpp rename to examples/QVTK-Demo/qvtk-lib/src/visualize.cpp diff --git a/demos/CMakeLists.txt b/examples/brunel/CMakeLists.txt similarity index 74% rename from demos/CMakeLists.txt rename to examples/brunel/CMakeLists.txt index 406fe9e6e986f14f50b815e53eacb80d1dafea05..4129a5e8806173e490a9aa19e79ce728daca456c 100644 --- a/demos/CMakeLists.txt +++ b/examples/brunel/CMakeLists.txt @@ -19,15 +19,8 @@ # limitations under the License. #------------------------------------------------------------------------------- -option(BUILD_BRUNEL_SIMULATION "Build the brunel simulation" ON) -option(BUILD_QVTK_DEMO "Build the QVTK visualization demo" OFF) - -if (${BUILD_BRUNEL_SIMULATION}) - add_subdirectory(brunel_simulation) -endif (${BUILD_BRUNEL_SIMULATION}) - -if (${BUILD_QVTK_DEMO}) - add_subdirectory(QVTK-Demo) -endif (${BUILD_QVTK_DEMO}) - - +add_python_example( + NAME brunel + PYTHON_FILES nest_sim.py brunel_example.py + ENTRY_POINT nest_sim.py +) \ No newline at end of file diff --git a/demos/brunel_simulation/brunel_example.py b/examples/brunel/brunel_example.py similarity index 100% rename from demos/brunel_simulation/brunel_example.py rename to examples/brunel/brunel_example.py diff --git a/demos/brunel_simulation/nest_sim.py b/examples/brunel/nest_sim.py similarity index 100% rename from demos/brunel_simulation/nest_sim.py rename to examples/brunel/nest_sim.py diff --git a/examples/cmake/PythonExample.cmake b/examples/cmake/PythonExample.cmake new file mode 100644 index 0000000000000000000000000000000000000000..6a3776d8defda528be2861e6cc05d899fb5f618a --- /dev/null +++ b/examples/cmake/PythonExample.cmake @@ -0,0 +1,31 @@ +get_filename_component(NEST_DIR ${with-nest} DIRECTORY) + +execute_process( + COMMAND ${NEST_CONFIG} --python-executable + RESULT_VARIABLE RES_VAR + OUTPUT_VARIABLE PYTHON_EXECUTABLE + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +set(SOURCE_SCRIPT_FILE + ${CMAKE_CURRENT_LIST_DIR}/run_example.sh.in +) + +function(ADD_PYTHON_EXAMPLE) +set(options) +set(oneValueArgs NAME ENTRY_POINT) +set(multiValueArgs PYTHON_FILES) +cmake_parse_arguments(APE "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + +set(TARGET_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/run_${APE_NAME}_example.sh") +configure_file(${SOURCE_SCRIPT_FILE} ${TARGET_SCRIPT_FILE}) + +add_custom_target( + ${APE_NAME}_example + ALL + COMMAND chmod "+x" ${TARGET_SCRIPT_FILE} + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${APE_PYTHON_FILES} ${CMAKE_CURRENT_BINARY_DIR} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + DEPENDS ${TARGET_SCRIPT_FILE} ${APE_PYTHON_FILES}) + +endfunction(ADD_PYTHON_EXAMPLE) \ No newline at end of file diff --git a/demos/brunel_simulation/run_sim.sh.in b/examples/cmake/run_example.sh.in similarity index 66% rename from demos/brunel_simulation/run_sim.sh.in rename to examples/cmake/run_example.sh.in index dd5c5c1b65105d5bd99b67e3b61314d2e362be64..bf784f91d6a14cfb2be60c60b86cbee8e13ac203 100644 --- a/demos/brunel_simulation/run_sim.sh.in +++ b/examples/cmake/run_example.sh.in @@ -1,3 +1,3 @@ #!/bin/bash source ${NEST_DIR}/nest_vars.sh -LD_LIBRARY_PATH=$NEST_MODULE_PATH:$LD_LIBRARY_PATH ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/nest_sim.py \ No newline at end of file +LD_LIBRARY_PATH=$NEST_MODULE_PATH:$LD_LIBRARY_PATH ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/${APE_ENTRY_POINT} \ No newline at end of file diff --git a/examples/izhikevich/CMakeLists.txt b/examples/izhikevich/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..d6961202e1c6aef27dbb588c305173e4389ba3d3 --- /dev/null +++ b/examples/izhikevich/CMakeLists.txt @@ -0,0 +1,26 @@ +#------------------------------------------------------------------------------- +# nest-streaming-module +# +# Copyright (c) 2018 RWTH Aachen University, Germany, +# Virtual Reality & Immersive Visualization 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_python_example( + NAME izhikevich + PYTHON_FILES izhikevich.py + ENTRY_POINT izhikevich.py +) \ No newline at end of file diff --git a/examples/izhikevich/izhikevich.py b/examples/izhikevich/izhikevich.py new file mode 100644 index 0000000000000000000000000000000000000000..0c966f0c6379fd5b0571f0bd4bca75b8f9a05c63 --- /dev/null +++ b/examples/izhikevich/izhikevich.py @@ -0,0 +1,41 @@ +import nest +nest.Install("streamingmodule") + +population = nest.Create("izhikevich", 1) +spike_detector = nest.Create("spike_detector", 1) +nest.SetStatus(spike_detector, {"record_to": ["streaming"]}) +nest.Connect(population, spike_detector) + +# regular spiking +nest.SetStatus(population, {"a": 0.02, + "b": 0.2, + "c": -65.0, + "d": 8.0, + "U_m": 0.0, + "V_m": -75.0, + "I_e": 6.0}) +nest.Simulate(4000) +nest.SetStatus(population, {"I_e": 0.0}) +nest.Simulate(500) + +# fast spiking +nest.SetStatus(population, {"a": 0.1, + "b": 0.2, + "c": -65.0, + "d": 2.0, + "U_m": 0.0, + "V_m": -75.0, + "I_e": 6.0}) +nest.Simulate(4000) +nest.SetStatus(population, {"I_e": 0.0}) +nest.Simulate(500) + +# chattering +nest.SetStatus(population, {"a": 0.02, + "b": 0.2, + "c": -50.0, + "d": 2.0, + "U_m": 0.0, + "V_m": -75.0, + "I_e": 6.0}) +nest.Simulate(4000) \ No newline at end of file