Numba optimised numerical root-finding solvers for multiple data points
Project description
Rapid-Roots
General parallel vectorised root solver using Numba for large data volumes.
Problem
Open source root-finding libraries like Scipy requires users to processes problems sequentially.
# Sequential approach (Slow)
for i in range(1_000_000):
root = scipy.optimize.brentq(func, a[i], b[i], args=(params[i],))
Solution
rapid-roots processes all problems at once using vectorisation and parallelisation.
# Vectorised rapid-roots approach
roots, iters, converged = RootSolvers.get_root(
func, a, b, func_params=func_params, main_solver='brent', use_backup=False
)
Quick Start
pip install rapid-roots
from rapid_roots.solvers import RootSolvers
from numba import njit
import numpy as np
@njit
def f(x, a):
return x**2 - a
@njit
def f_prime(x, a):
return 2*x
# Creates function parameter a in the equation.
params = np.full((10000, 1), 4.0)
# Creates a and b bounds for backup bracketed solvers
a = np.zeros(10000)
b = np.full(10000, 10.0)
# Creates x0 initial guess for main Newton solver
x0 = (a + b) / 2
# Vectorised solver implementation solves 10,000 problems at once.
roots, iters, converged = RootSolvers.get_root(
func=f, a=a, b=b, x0=x0, func_prime=f_prime,
func_params=params, main_solver='newton',
use_backup=True
)
print(f"Solved {converged.sum()} problems") # Solved 10,000 problems
print(f"Mean root: {roots.mean()}") # Mean root: 2.0
API Reference
RootSolvers.get_root()
Main interface for vectorized root finding.
roots, iterations, converged = RootSolvers.get_root(
func=func, # Numba JIT-compiled function
a=None, # Lowerbound brackets for bracketing methods
b=None, # Upperbound brackets for bracketing methods
x0=None, # Initial guess for open methods (Newton)
func_prime=None, # Derivatives for open method (Newton)
func_params=None, # Parameters Array (n_problems, n_params)
main_solver='brent', # 'brent', 'bisection', or 'newton'
tol=1e-12, # Convergence tolerance
max_iter=100, # Maximum iteration
use_backup=True, # Enables automatic fallback
backup_solvers=['newton', 'bisection'] # Fallback methods for unconverged problems
)
Returns:
roots: ndArray - Found roots for each problemiterations: ndArray - Number of iterations usedconverged: ndArray (bool) - Convergence status for each problem
Performance
| Samples | Throughput (Solves/sec) | ||
|---|---|---|---|
| Newton | Brent | Bisection | |
| 10K | 22,951 | 19,632 | 23,219 |
| 100K | 231,065 | 194,212 | 219,248 |
| 1M | 2,187,503 | 1,787,564 | 1,566,471 |
| 10M | 15,404,269 | 9,486,609 | 4,589,518 |
Accuracy
Box plot compares the absolute error distributions against Scipy for Brent, Bisection and Newton implementation across different function categories.
Newton shows the lowest median error with occasional ouliers in challenging categories. Brent is slightly higher in median errors with a wider interquantile range. Meanwhile Bisection displays the largest spread and highest typical error.
Results show errors approach machine precision for all methods against scipy.
Installation
Requirements
- Python ≥ 3.8
- Numpy ≥ 1.20.0
- Numba ≥ 0.56.0
Install from PyPI
pip install rapid-roots
Install from source
git clone https://github.com/CianQuezon/rapid-roots.git
cd rapid-roots
pip install -e .
License
This project is licensed under the MIT License - see the LICENSE file for more details.
Acknowledgements
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rapid_roots-0.1.0.tar.gz.
File metadata
- Download URL: rapid_roots-0.1.0.tar.gz
- Upload date:
- Size: 76.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
439b1462c8e444b76cf5c89bfd2b2c0837437240c6afcf7bddeced516149acbf
|
|
| MD5 |
e0f78b6a57e6decc25e27a0a3476b60a
|
|
| BLAKE2b-256 |
3973e9d5242348b7db1bd9c86e646094c94425446248f81d9ec8a798cbc3497f
|
File details
Details for the file rapid_roots-0.1.0-py3-none-any.whl.
File metadata
- Download URL: rapid_roots-0.1.0-py3-none-any.whl
- Upload date:
- Size: 36.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
80564b4faef367230e71295756739ba7deff91625d938ea645d345b2757dfbb9
|
|
| MD5 |
61bd46819850b8716fd7622aaf1459de
|
|
| BLAKE2b-256 |
ef8bc081af8ae2b92c1a517efac78aaa545a5b400e4b5bff9c2203311a7f2318
|