Changes for Brian 1 users¶
In most cases, Brian 2 works in a very similar way to Brian 1 but there are some important differences to be aware of. The major distinction is that in Brian 2 you need to be more explicit about the definition of your simulation in order to avoid inadvertent errors. In some cases, you will now get a warning in other even an error – often the error/warning message describes a way to resolve the issue.
Specific examples how to convert code from Brian 1 can be found in the document Detailed Brian 1 to Brian 2 conversion notes.
The unit system now extends to arrays, e.g.
np.arange(5) * mV will retain
the units of volts and not discard them as Brian 1 did. Brian 2 is therefore
also more strict in checking the units. For example, if the state variable
v uses the unit of volt, the statement
G.v = np.rand(len(G)) / 1000.
will now raise an error. For consistency, units are returned everywhere, e.g.
in monitors. If
mon records a state variable v,
mon.t will return a
time in seconds and
mon.v the stored values of
v in units of volts.
If you need a pure numpy array without units for further processing, there
are several options: if it is a state variable or a recorded variable in a
monitor, appending an underscore will refer to the variable values without
mon.t_ returns pure floating point values. Alternatively, you
can remove units by diving by the unit (e.g.
mon.t / second) or by
explicitly converting it (
Here’s an overview showing a few expressions and their respective values in Brian 1 and Brian 2:
|Expression||Brian 1||Brian 2|
|1 * mV||1.0 * mvolt||1.0 * mvolt|
|np.array(1) * mV||0.001||1.0 * mvolt|
|np.array() * mV||array([ 0.001])||array([1.]) * mvolt|
|np.mean(np.arange(5) * mV)||0.002||2.0 * mvolt|
|np.arange(2) * mV||array([ 0. , 0.001])||array([ 0., 1.]) * mvolt|
|(np.arange(2) * mV) >= 1 * mV||array([False, True], dtype=bool)||array([False, True], dtype=bool)|
|(np.arange(2) * mV) >= 1 * mV||False||False|
|(np.arange(2) * mV) >= 1 * mV||DimensionMismatchError||True|
The following packages have not (yet) been ported to Brian 1. If your simulation critically depends on them, you should consider staying with Brian 1 for now.
In Brian 2, we have tried to keep the number of classes/functions to a minimum, but make
each of them flexible enough to encompass a large number of use cases. A lot of the classes
and functions that existed in Brian 1 have therefore been removed.
The following table lists (most of) the classes that existed in Brian 1 but do no longer
exist in Brian 2. You can consult it when you get a
NameError while converting an
existing script from Brian 1. The third column links to a document with further explanation
and the second column gives either:
- the equivalent class in Brian 2 (e.g.
StateMonitorcan record multiple variables now and therefore replaces
- the name of a Brian 2 class in square brackets (e.g. [
STDP), this means that the class can be used as a replacement but needs some additional code (e.g. explicitly specified STDP equations). The “More details” document should help you in making the necessary changes;
- “string expression”, if the functionality of a previously existing class can
be expressed using the general string expression framework (e.g.
threshold=VariableThreshold('Vt', 'V')can be replaced by
threshold='V > Vt');
- a link to the relevant github issue if no equivalent class/function does exist so far in Brian 2;
- a remark such as “obsolete” if the particular class/function is no longer needed.
List of detailed instructions¶
- Detailed Brian 1 to Brian 2 conversion notes
- Neural models (Brian 1 –> 2 conversion)
- Synapses (Brian 1 –> 2 conversion)
- Inputs (Brian 1 –> 2 conversion)
- Monitors (Brian 1 –> 2 conversion)
- Networks and clocks (Brian 1 –> 2 conversion)
- Preferences (Brian 1 –> 2 conversion)
- Multicompartmental models (Brian 1 –> 2 conversion)
- Library models (Brian 1 –> 2 conversion)
- Brian Hears