Skip to content

Backend API

Every nonlinear fit tries its model from a grid of starting values, and the grid is fitted as one batch of array operations before the best few results are polished on the CPU. set_backend chooses the array library for that batch. See Speed and the GPU for when the GPU is worth it.

set_backend

sars.set_backend

set_backend(name: str) -> None

Choose the array library that screens each model's start grid.

Every fit tries each model from a grid of starting values. They're run as one batch, on numpy (the default) or, for large datasets or many fits, on an NVIDIA GPU through CuPy (pip install 'sars[gpu]'). The final solve (at tight tolerances, or the defaults for a full bootstrap's resamples) always runs on the CPU, so results agree between backends to the solver's tolerance wherever that solve converges.

Parameters:

Name Type Description Default
name ('numpy', 'cupy')

The backend for every fit that follows, in this process and in the worker processes that n_jobs starts.

"numpy"

Raises:

Type Description
ValueError

If name isn't one of the backends.

ImportError

If name is "cupy" and CuPy isn't installed or finds no GPU.

get_backend

sars.get_backend

get_backend() -> str

The array library screening start grids: "numpy" or "cupy".