Migrating to braintools 1.0#
Since 0.4, every function that moved has a new home in braintools, and the old names still work as deprecated aliases. Braintools 1.0.0 removes all of them, together with the deprecated arguments listed below. This page lists every deprecation and its replacement, so code can be updated before the upgrade.
Finding deprecated calls in your code#
A deprecated name warns when it is called (or a deprecated class is
instantiated), never when it is imported. The warning category is
braintools._deprecation.BraintoolsDeprecationWarning, and every message has
the same form:
`braintools.metric.firing_rate` is deprecated since 0.4.0 and will be removed in 1.0.0. Use `braintools.analysis.spike.firing_rate` instead.
Since 0.4, BraintoolsDeprecationWarning is a subclass of FutureWarning
(it used to subclass DeprecationWarning). Python shows FutureWarning by
default, so the warnings now appear even when the deprecated call is made from
library code rather than from your script. Filters written for
DeprecationWarning no longer match them.
To turn every braintools deprecation into an error, so that each remaining call site fails loudly:
python -W error::FutureWarning my_script.py
or, from Python (for example in a test suite’s conftest.py):
import warnings
from braintools._deprecation import BraintoolsDeprecationWarning
warnings.simplefilter('error', BraintoolsDeprecationWarning)
With pytest, add a filter to pyproject.toml:
[tool.pytest.ini_options]
filterwarnings = [
'error:`braintools\.[^`]*` is deprecated since:FutureWarning',
]
To silence them instead (for example in a downstream package that has not
migrated yet), use
warnings.filterwarnings('ignore', category=BraintoolsDeprecationWarning).
Every deprecation#
The table lists every deprecation registered in braintools. A function or
class entry is an alias of the replacement. An argument entry is a
deprecated argument or argument value of a function that stays. A feature
entry is an object that is deprecated without a direct replacement.
Deprecated |
Replacement |
Kind |
Since |
Removed in |
|---|---|---|---|---|
|
|
class |
0.4.0 |
1.0.0 |
|
|
function |
0.4.0 |
1.0.0 |
|
|
argument |
0.4.0 |
1.0.0 |
|
|
class |
0.4.0 |
1.0.0 |
|
|
argument |
0.2.0 |
1.0.0 |
|
|
argument |
0.1.0 |
1.0.0 |
|
|
argument |
0.1.0 |
1.0.0 |
|
|
argument |
0.1.0 |
1.0.0 |
|
|
argument |
0.1.0 |
1.0.0 |
|
|
argument |
0.1.0 |
1.0.0 |
|
|
argument |
0.1.0 |
1.0.0 |
|
|
argument |
0.1.0 |
1.0.0 |
|
|
argument |
0.1.0 |
1.0.0 |
|
|
argument |
0.1.0 |
1.0.0 |
|
|
argument |
0.1.0 |
1.0.0 |
|
|
argument |
0.1.0 |
1.0.0 |
|
|
class |
0.4.0 |
1.0.0 |
|
|
function |
0.4.0 |
1.0.0 |
|
|
function |
0.4.0 |
1.0.0 |
|
|
function |
0.4.0 |
1.0.0 |
|
|
function |
0.4.0 |
1.0.0 |
|
|
function |
0.4.0 |
1.0.0 |
|
|
function |
0.4.0 |
1.0.0 |
|
|
function |
0.4.0 |
1.0.0 |
|
|
function |
0.4.0 |
1.0.0 |
|
|
function |
0.4.0 |
1.0.0 |
|
|
function |
0.4.0 |
1.0.0 |
|
|
function |
0.4.0 |
1.0.0 |
|
|
function |
0.4.0 |
1.0.0 |
|
|
function |
0.4.0 |
1.0.0 |
|
|
function |
0.4.0 |
1.0.0 |
|
|
function |
0.4.0 |
1.0.0 |
|
|
function |
0.4.0 |
1.0.0 |
|
|
function |
0.4.0 |
1.0.0 |
|
|
function |
0.4.0 |
1.0.0 |
|
|
function |
0.4.0 |
1.0.0 |
|
|
function |
0.4.0 |
1.0.0 |
|
|
function |
0.4.0 |
1.0.0 |
|
|
function |
0.4.0 |
1.0.0 |
|
|
function |
0.4.0 |
1.0.0 |
|
|
argument |
0.1.0 |
1.0.0 |
|
|
argument |
0.1.0 |
1.0.0 |
|
|
class |
0.4.0 |
1.0.0 |
|
|
class |
0.4.0 |
1.0.0 |
|
|
class |
0.4.0 |
1.0.0 |
|
|
class |
0.4.0 |
1.0.0 |
|
|
argument |
0.4.0 |
1.0.0 |
|
|
class |
0.4.0 |
1.0.0 |
|
|
class |
0.4.0 |
1.0.0 |
|
|
class |
0.4.0 |
1.0.0 |
|
|
feature |
0.4.0 |
1.0.0 |
|
|
argument |
0.4.0 |
1.0.0 |
|
|
argument |
0.4.0 |
1.0.0 |
|
|
argument |
0.4.0 |
1.0.0 |
|
|
argument |
0.4.0 |
1.0.0 |
The top-level braintools.spike_bitwise* names are also kept as aliases of
braintools.spike.bitwise*. They do not warn yet, because other packages in
the ecosystem bind them at import time, but new code should use
braintools.spike.bitwise_or and the other braintools.spike.bitwise* names.
braintools.metric → braintools.analysis#
The measures for analysing neural activity moved out of braintools.metric
into the subpackages of braintools.analysis. The functions themselves are
unchanged: same arguments, same results. Only the import path changes.
Old ( |
New |
|---|---|
|
|
|
|
|
|
|
|
|
|
# Before
rate = braintools.metric.firing_rate(spikes, width=5.0)
# After
rate = braintools.analysis.spike.firing_rate(spikes, width=5.0)
braintools.metric.raster_plot(sp_matrix, times) has no one-to-one
replacement. Use braintools.spike.SpikeTrains.from_dense to hold the spikes,
or compute the same arrays directly:
t, i = numpy.nonzero(sp_matrix > 0)
neuron_indices, spike_times = i, times[t] # == metric.raster_plot(sp_matrix, times)
Plotting a raster is braintools.visualize.raster_plot, which is not
deprecated.
The training losses and metrics (cross-entropy, regression losses, ranking
losses, cosine_similarity and the rest) stay in braintools.metric.
Top-level encoders → braintools.spike#
The ten spike encoders moved from the top level to braintools.spike:
LatencyEncoder, RateEncoder, PoissonEncoder, PopulationEncoder,
BernoulliEncoder, DeltaEncoder, StepCurrentEncoder, SpikeCountEncoder,
TemporalEncoder and RankOrderEncoder.
# Before
encoder = braintools.PoissonEncoder()
# After
encoder = braintools.spike.PoissonEncoder()
Instances built either way pass isinstance checks against both names. The
time_window argument of PoissonEncoder never had an effect and is
deprecated; drop it.
braintools.trainer is frozen#
Since 0.4, braintools.trainer gets maintenance fixes only, with no new
features. Features that never did anything are deprecated:
GradientClipCallbacknever clipped gradients. UseTrainer(gradient_clip_val=...).Trainer(precision=...)other than 32: cast the model and data to the dtype you want instead.Trainer(deterministic=...): passTrainer(seed=...).Trainer(benchmark=...): drop it; XLA autotunes automatically.Trainer(strategy=...)other than'auto': drop it.
conn.MorphologyDistance(decay_function=str) → distance profiles#
MorphologyDistance took the decay function as a string. Pass a
braintools.init distance profile instead; it carries its own length scale,
so sigma is omitted.
Old |
New |
|---|---|
|
|
|
|
|
|
cogtask.utils.firing_rate → rate_to_prob#
braintools.cogtask.utils.firing_rate(base, dt) converts a rate in Hz to a
spike probability per time step (base * dt / 1000), not a firing rate. It is
renamed braintools.cogtask.utils.rate_to_prob, with the same arguments and
result, so it is no longer confused with braintools.analysis.spike.firing_rate.
Deprecated unit= arguments and load_matfile(header_info=...)#
The
unit=argument ofConstant,Uniform,Normal,LogNormal,Gamma,Exponential,TruncatedNormal,BetaandWeibullinbraintools.initis deprecated: attach the unit to the values instead, for exampleNormal(0.0 * u.mV, 1.0 * u.mV)rather thanNormal(0.0, 1.0, unit=u.mV).ZeroInit(unit=...)is not deprecated.Orthogonal(unit=...)andDeltaOrthogonal(unit=...)are deprecated: multiply the generated weights by the unit.braintools.file.load_matfile(header_info=...)meant the inverse of its name. Useinclude_header=not header_info.
Before 0.4 these warned with a plain DeprecationWarning. They now use
BraintoolsDeprecationWarning like every other deprecation.