{
  "name": "Brian2 execution modes: requirements and documented tradeoffs",
  "description": "Compares the three ways Brian2 can run a simulation (numpy, Cython and C++ standalone): how each is selected, what it needs, and the tradeoff the official Brian 2 documentation states for it. Compiled by CASRAI from the computation and installation pages of the Brian 2 documentation, read 2026-11-20.",
  "page": "https://casrai.org/guides/brian2",
  "publisher": "CASRAI",
  "license": "https://creativecommons.org/licenses/by/4.0/",
  "dateModified": "2026-11-25T12:35:00Z",
  "temporalCoverage": null,
  "spatialCoverage": null,
  "columns": [
    {
      "name": "Execution mode",
      "unit": "",
      "description": ""
    },
    {
      "name": "How it is selected",
      "unit": "",
      "description": ""
    },
    {
      "name": "What it needs",
      "unit": "",
      "description": ""
    },
    {
      "name": "Documented tradeoff",
      "unit": "",
      "description": ""
    }
  ],
  "rows": [
    {
      "Execution mode": "Runtime, numpy target",
      "How it is selected": "Set prefs.codegen.target = 'numpy' at the start of the script",
      "What it needs": "No compilation",
      "Documented tradeoff": "Runtime mode has a potentially big overhead for each simulated time step, in return for combining the simulation with arbitrary Python code"
    },
    {
      "Execution mode": "Runtime, Cython target",
      "How it is selected": "Default 'auto' setting for codegen.target; falls back to Python if compilation is not possible",
      "What it needs": "Cython and a C++ compiler (the conda package installs a compiler on Linux and macOS; Windows needs Microsoft Build Tools)",
      "Documented tradeoff": "Strongly recommended for speed; for short simulations it can appear slower than numpy; compiled code is cached on disk"
    },
    {
      "Execution mode": "C++ standalone device",
      "How it is selected": "Call set_device('cpp_standalone') after the import and before the simulation code",
      "What it needs": "A C++ compiler to build the generated C++ project, which is compiled separately",
      "Documented tradeoff": "In general faster, but cannot be used for all kinds of simulations and not all Brian features work; state variables and synaptic indices are not accessible during setup"
    }
  ],
  "sources": [
    {
      "title": "Brian 2 documentation: Computational methods and efficiency",
      "url": "https://brian2.readthedocs.io/en/stable/user/computation.html",
      "accessed": "2026-11-20"
    },
    {
      "title": "Brian 2 documentation: Installation",
      "url": "https://brian2.readthedocs.io/en/stable/introduction/install.html",
      "accessed": "2026-11-20"
    }
  ]
}