Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
wget https://packages.apache.org/artifactory/arrow/$(lsb_release --id --short | tr 'A-Z' 'a-z')/apache-arrow-apt-source-latest-$(lsb_release --codename --short).deb
sudo apt install -y ./apache-arrow-apt-source-latest-$(lsb_release --codename --short).deb
sudo apt-get update
sudo apt-get install -y g++ make clang-tidy clang-format python3 python3-pip libarrow-dev libparquet-dev
sudo apt-get install -y g++ make clang-tidy clang-format python3 python3-pip libarrow-dev libparquet-dev emscripten
pip3 install pandas pyarrow pytest
- name: Build
run: make USE_ARROW=${{ matrix.arrow }}
Expand All @@ -32,3 +32,5 @@ jobs:
run: make tidy
- name: Run test
run: make USE_ARROW=${{ matrix.arrow }} test
- name: Build WebAssembly
run: make web
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
main
spikes.bin
web/main.js
web/main.wasm
web/main.data
test/__pycache__/
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,17 @@ submodule:
git submodule update --init --recursive

.PHONY: clean format tidy test submodule bench

WEB_DIR = web
WEB_TARGET = $(WEB_DIR)/main.js

$(WEB_TARGET): main.cpp
mkdir -p $(WEB_DIR)
em++ $< -O3 -std=c++20 -s WASM=1 -s MODULARIZE=1 \
-s EXPORTED_FUNCTIONS="['_run_simulation_c']" \
-s EXPORTED_RUNTIME_METHODS="['cwrap','FS']" \
--preload-file test -o $(WEB_TARGET)

web: $(WEB_TARGET)

.PHONY: web
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ make
This produces an executable named `main`. To enable Apache Arrow support pass
`USE_ARROW=1` (requires Arrow C++ libraries with `pkg-config` files).

### WebAssembly

Emscripten can build the simulator to WebAssembly. Install `em++` and run:

```bash
make web
```

The generated `web/` directory contains `main.js`, `main.wasm`, and a small
`index.html` that runs the example dataset in your browser.

## Running

Run the simulator by providing a connectome CSV file and lists of active and silent neurons. When built with Arrow support you may provide a Parquet file instead:
Expand Down
1 change: 1 addition & 0 deletions docs/AGENT_PROMPTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The project simulates spikes in a Drosophila connectome using a leaky integrate-
- Keep the simulator self contained in `main.cpp` unless new modules are justified.
- Unit tests live under `test/` and should be expanded when new features are added.
- Large datasets are provided via the optional `Drosophila_brain_model` submodule and should not be committed directly to the repository. Support for loading Parquet files via Apache Arrow is optional and can be enabled by building with `USE_ARROW=1`.
- WebAssembly builds can be generated with `make web` when Emscripten is available.

## Pull Request Guidance

Expand Down
6 changes: 6 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,12 @@ size_t run_simulation(const string &csv, const string &pq, const string &act,
return S.spikes.size();
}

extern "C" size_t run_simulation_c(const char *csv, const char *pq,
const char *act, const char *sil, size_t T) {
return run_simulation(csv ? string(csv) : "", pq ? string(pq) : "",
act ? string(act) : "", sil ? string(sil) : "", T);
}

#ifndef BENCH_LIB
int main(int argc, char **argv) {
string csv, pq, act, sil;
Expand Down
24 changes: 24 additions & 0 deletions web/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Drosophila WASM Demo</title>
</head>
<body>
<h1>Drosophila WebAssembly Demo</h1>
<button id="run">Run Example</button>
<pre id="out"></pre>
<script type="module">
import ModuleFactory from './main.js';
ModuleFactory().then(Module => {
document.getElementById('run').onclick = () => {
const run = Module.cwrap('run_simulation_c', 'number',
['string','string','string','string','number']);
const spikes = run('/test/test_connectome.csv', '',
'/test/active.txt', '/test/silent.txt', 10);
document.getElementById('out').textContent = 'Spikes: ' + spikes;
};
});
</script>
</body>
</html>