diff --git a/Dockerfile b/Dockerfile index a8db0618eca26ac302a71505a18f1ed1134c47c6..c9450455389cdbb05e95083d259215aabba5d89f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:latest +FROM ubuntu:18.04 ARG DEBIAN_FRONTEND=noninteractive RUN apt-get update && apt-get install -y \ cmake g++ make ninja-build python3 python3-dev python3-pip python3-numpy python3-scipy python3-matplotlib \ @@ -40,16 +40,18 @@ RUN cmake \ /libpqxx RUN ninja && ninja install -COPY . /insite -WORKDIR /insite-build +COPY src /insite-module +WORKDIR /insite-module-build RUN cmake \ -G Ninja \ -Dwith-nest=/nest-install/bin/nest-config \ -DCMAKE_BUILD_TYPE=Release \ - /insite + /insite-module RUN ninja && ninja install ENV PGPASSWORD=postgres +COPY example /example + EXPOSE 8000 -ENTRYPOINT "/insite-build/run_brunel_simulation.sh" -CMD 1000 2500 2 \ No newline at end of file +ENTRYPOINT ["/insite-module-build/run_simulation.sh"] +CMD ["/example/brunel_simulation.py"] \ No newline at end of file diff --git a/examples/brunel_simulation.py b/example/brunel_simulation.py similarity index 98% rename from examples/brunel_simulation.py rename to example/brunel_simulation.py index 6dc936c0ed5798313acec20fad053c3274c315ca..c37d0c9d2171f5abd6d3031cd41342072040070c 100644 --- a/examples/brunel_simulation.py +++ b/example/brunel_simulation.py @@ -74,7 +74,7 @@ startbuild = time.time() dt = 0.1 # the resolution in ms simtime = float(sys.argv[1]) if len( - sys.argv) > 1 else 10000.0 # Simulation time in ms + sys.argv) > 1 else 100.0 # Simulation time in ms delay = 1.5 # synaptic delay in ms @@ -91,7 +91,7 @@ epsilon = 0.1 # connection probability # recorded from order = int(sys.argv[2]) if len( - sys.argv) > 2 else 2500 # Should be square, otherwise the position grid becomes invalid + sys.argv) > 2 else 25 # Should be square, otherwise the position grid becomes invalid NE = 4 * order # number of excitatory neurons NI = 1 * order # number of inhibitory neurons N_neurons = NE + NI # number of neurons in total diff --git a/examples/run_brunel_simulation.sh.in b/examples/run_brunel_simulation.sh.in deleted file mode 100755 index be009df14365664f74531417bc418b9698628679..0000000000000000000000000000000000000000 --- a/examples/run_brunel_simulation.sh.in +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -source @NEST_INSTALL_PREFIX@/bin/nest_vars.sh -export LD_LIBRARY_PATH=$NEST_MODULE_PATH:/usr/local/lib/:$LD_LIBRARY_PATH -# python3 @CMAKE_SOURCE_DIR@/examples/brunel_simulation.py $1 $2 # Uncomment this to run normally -time mpirun -n $3 --mca btl_vader_single_copy_mechanism none --allow-run-as-root -x PYTHONPATH python3 @CMAKE_SOURCE_DIR@/examples/brunel_simulation.py $1 $2 \ No newline at end of file diff --git a/insite-nest-module.tar b/insite-nest-module.tar deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/CMakeLists.txt b/src/CMakeLists.txt similarity index 99% rename from CMakeLists.txt rename to src/CMakeLists.txt index 3ee9ac482e30cca4d307d9c021d11224af35d421..9b1cccc06dfd8115f5ab3c5b830d6efefb181bfe 100644 --- a/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -343,8 +343,8 @@ if ( ( NOT CMAKE_CROSSCOMPILING ) endif () configure_file( - ${CMAKE_SOURCE_DIR}/examples/run_brunel_simulation.sh.in - ${CMAKE_BINARY_DIR}/run_brunel_simulation.sh + ${CMAKE_SOURCE_DIR}/scripts/run_simulation.sh.in + ${CMAKE_BINARY_DIR}/run_simulation.sh @ONLY ) diff --git a/data_storage.cpp b/src/data_storage.cpp similarity index 98% rename from data_storage.cpp rename to src/data_storage.cpp index 4ed7af7cdcedea4ff215bdef2f069af059474bb9..9e41c745e6c6d8f08b6672a53d2759ea345b5d95 100644 --- a/data_storage.cpp +++ b/src/data_storage.cpp @@ -59,7 +59,7 @@ std::vector<uint64_t> DataStorage::GetNeuronIds() { void DataStorage::AddSpike(double simulation_time, std::uint64_t gid) { std::unique_lock<std::mutex> lock(spike_mutex_); - constexpr auto spike_occured_before = [](const Spike& lhs, const Spike& rhs) { + const auto spike_occured_before = [](const Spike& lhs, const Spike& rhs) { return lhs.simulation_time < rhs.simulation_time; }; const Spike spike{simulation_time, gid}; diff --git a/data_storage.hpp b/src/data_storage.hpp similarity index 100% rename from data_storage.hpp rename to src/data_storage.hpp diff --git a/http_server.cpp b/src/http_server.cpp similarity index 100% rename from http_server.cpp rename to src/http_server.cpp diff --git a/http_server.hpp b/src/http_server.hpp similarity index 100% rename from http_server.hpp rename to src/http_server.hpp diff --git a/insitemodule.cpp b/src/insitemodule.cpp similarity index 100% rename from insitemodule.cpp rename to src/insitemodule.cpp diff --git a/insitemodule.h b/src/insitemodule.h similarity index 100% rename from insitemodule.h rename to src/insitemodule.h diff --git a/neuron_info.hpp b/src/neuron_info.hpp similarity index 100% rename from neuron_info.hpp rename to src/neuron_info.hpp diff --git a/recording_backend_insite.cpp b/src/recording_backend_insite.cpp similarity index 81% rename from recording_backend_insite.cpp rename to src/recording_backend_insite.cpp index 63a59929870df327f5d3d76b46f6bff45645ca28..68ac4a513b90544e5ed8d8613ea7185fa93f3bbe 100644 --- a/recording_backend_insite.cpp +++ b/src/recording_backend_insite.cpp @@ -37,6 +37,86 @@ RecordingBackendInsite::RecordingBackendInsite() : data_storage_("tgest"), database_connection_("postgresql://postgres@" + ReadDatabaseHost()), http_server_("http://0.0.0.0:" + get_port_string(), &data_storage_, "postgresql://postgres@" + ReadDatabaseHost()) { + + if (nest::kernel().mpi_manager.get_rank() == 0) { + pqxx::work txn(database_connection_); + + txn.exec(R"db_query( +DROP TABLE IF EXISTS nest_simulation_node CASCADE; +DROP TABLE IF EXISTS nest_multimeter CASCADE; +DROP TABLE IF EXISTS nest_neuron CASCADE; +DROP TABLE IF EXISTS nest_neuron_multimeter CASCADE; + +CREATE TABLE nest_simulation_node ( + id SERIAL PRIMARY KEY NOT NULL UNIQUE, + address VARCHAR(50), + current_simulation_time FLOAT +); + +CREATE TABLE nest_multimeter ( + id INT PRIMARY KEY NOT NULL UNIQUE, + attributes VARCHAR(50) ARRAY +); + +CREATE TABLE nest_neuron ( + id INT PRIMARY KEY NOT NULL UNIQUE, + simulation_node_id INT, + population_id INT, + position FLOAT[], + FOREIGN KEY (simulation_node_id) REFERENCES nest_simulation_node (id) +); + +CREATE TABLE nest_neuron_multimeter ( + neuron_id INT NOT NULL, + multimeter_id INT NOT NULL, + PRIMARY KEY (neuron_id,multimeter_id), + FOREIGN KEY (neuron_id) REFERENCES nest_neuron (id), + FOREIGN KEY (multimeter_id) REFERENCES nest_multimeter (id) +); + +DROP TABLE IF EXISTS arbor_simulation_node CASCADE; +DROP TABLE IF EXISTS arbor_cell CASCADE; +DROP TABLE IF EXISTS arbor_cell_property CASCADE; +DROP TABLE IF EXISTS arbor_attribute CASCADE; +DROP TABLE IF EXISTS arbor_probe CASCADE; + +CREATE TABLE arbor_simulation_node ( + id INT PRIMARY KEY NOT NULL UNIQUE, + address VARCHAR(50), + current_simulation_time FLOAT +); + +CREATE TABLE arbor_cell ( + id INT PRIMARY KEY NOT NULL UNIQUE +); + +CREATE TABLE arbor_cell_property ( + cell_id INT NOT NULL, + property VARCHAR(50) NOT NULL, + PRIMARY KEY (cell_id, property), + FOREIGN KEY (cell_id) REFERENCES arbor_cell (id) +); + +CREATE TABLE arbor_attribute ( + id INT PRIMARY KEY NOT NULL UNIQUE, + name VARCHAR(50) NOT NULL +); + +CREATE TABLE arbor_probe ( + id INT PRIMARY KEY NOT NULL UNIQUE, + cell_id INT NOT NULL, + segment_id INT NOT NULL, + position FLOAT, + attribute_id INT NOT NULL, + simulation_node_id INT, + FOREIGN KEY (simulation_node_id) REFERENCES arbor_simulation_node (id), + FOREIGN KEY (cell_id) REFERENCES arbor_cell (id), + FOREIGN KEY (attribute_id) REFERENCES arbor_attribute (id) +); + )db_query"); + txn.commit(); + } + pqxx::work txn(database_connection_); simulation_node_id_ = txn.exec1( "INSERT INTO nest_simulation_node (address) " diff --git a/recording_backend_insite.h b/src/recording_backend_insite.h similarity index 100% rename from recording_backend_insite.h rename to src/recording_backend_insite.h diff --git a/src/scripts/run_simulation.sh.in b/src/scripts/run_simulation.sh.in new file mode 100755 index 0000000000000000000000000000000000000000..2acb1db49362fdc5adfe9ffbb7da31935463428b --- /dev/null +++ b/src/scripts/run_simulation.sh.in @@ -0,0 +1,24 @@ +#!/bin/bash +# Usage: run_simulation.sh file_path mpi_nodes + +source @NEST_INSTALL_PREFIX@/bin/nest_vars.sh +export LD_LIBRARY_PATH=$NEST_MODULE_PATH:/usr/local/lib/:$LD_LIBRARY_PATH + +if [ "$#" -eq 1 ]; then + python3 $1 +elif [ "$#" -eq 2 ]; then + mpirun -n $2 --mca btl_vader_single_copy_mechanism none --allow-run-as-root -x PYTHONPATH python3 $1 +else + echo "$0 $*" + echo "Usage: $0 file_path [mpi_nodes]" +fi + +# ls /nest-simulation +# if [ -f "/nest-simulation/simulation.py" ]; then +# echo "/nest-simulation/simulation.py exists" +# else +# echo "/nest-simulation/simulation.py does not exist" +# fi + +# # Uncomment this to run normally +# time @CMAKE_SOURCE_DIR@/examples/brunel_simulation.py $1 $2 \ No newline at end of file diff --git a/sli/example.sli b/src/sli/example.sli similarity index 100% rename from sli/example.sli rename to src/sli/example.sli diff --git a/sli/insitemodule-init.sli b/src/sli/insitemodule-init.sli similarity index 100% rename from sli/insitemodule-init.sli rename to src/sli/insitemodule-init.sli diff --git a/sli/test_recording_backend_socket.sli b/src/sli/test_recording_backend_socket.sli similarity index 100% rename from sli/test_recording_backend_socket.sli rename to src/sli/test_recording_backend_socket.sli