Using Brian2WASM
brian2wasm enables running standard Brian 2 Python scripts, which are converted to WebAssembly for execution in a browser environment.
Standard Usage
To run a Brian 2 script with brian2wasm, use the following command:
python -m brian2wasm filename.py
Important
The
filename.pymust be a validBrian 2Python script.Do not include the
set_device()function in your script, asbrian2wasmautomatically handles this.
Note
Ensure your script adheres to Brian 2 syntax and conventions. Refer to the Brian 2 documentation for guidance.
Command-Line Options
brian2wasm supports the following optional command-line flags to customize its behavior:
–no-server
python -m brian2wasm filename.py --no-server
Important
Generates WebAssembly and HTML output files (e.g.,
filename.html,filename.js,filename.wasm) without launching a local preview server.Use this option if you want to manually serve or distribute the generated files.
Tip
This is useful for deploying the output to a web server or for further customization of the generated files.
–skip-install
python -m brian2wasm filename.py --skip-install
Important
Bypasses the check and activation of the Emscripten SDK (EMSDK).
Use this only if the EMSDK is already configured and available in your environment (e.g., via Pixi, Conda, or a manual installation).
Warning
Running with
--skip-installwithout a properly configured EMSDK will result in errors. Verify your EMSDK setup by runningemcc --versionbefore using this option.
Note
The generated WebAssembly files can be hosted on any standard web server or viewed locally by opening the filename.html file in a web browser.