Skip to content

Commit

Permalink
Draft JOSS article about SciPy elementwise iterative methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mdhaber committed Jan 3, 2025
1 parent 34a4bbf commit bf93e30
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/draft-pdf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Draft PDF
on: [push]

jobs:
paper:
runs-on: ubuntu-latest
name: Paper Draft
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build draft PDF
uses: openjournals/openjournals-draft-action@master
with:
journal: joss
# This should be the path to the paper within your repo.
paper-path: paper.md
- name: Upload
uses: actions/upload-artifact@v4
with:
name: paper
# This is the output path where Pandoc will write the compiled
# PDF. Note, this should be the same directory as the input
# paper.md
path: paper.pdf
60 changes: 60 additions & 0 deletions paper.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
@misc{numdifftools,
author = {Per A. Brodtkorb},
title = {numdifftools 0.9.41},
year = {2022},
publisher = {GitHub},
url = {https://github.com/pbrod/numdifftools}
}


@misc{quad,
author = {The {S}ci{P}y developers},
title = {`scipy.integrate.quad`},
year = {2024},
url = {https://docs.scipy.org/doc/scipy-1.14.0/reference/generated/scipy.integrate.quad.html}
}

@inproceedings{ansel2024pytorch,
title={Pytorch 2: Faster machine learning through dynamic python bytecode transformation and graph compilation},
author={Ansel, Jason and Yang, Edward and He, Horace and Gimelshein, Natalia and Jain, Animesh and Voznesensky, Michael and Bao, Bin and Bell, Peter and Berard, David and Burovski, Evgeni and others},
booktitle={Proceedings of the 29th ACM International Conference on Architectural Support for Programming Languages and Operating Systems, Volume 2},
pages={929--947},
year={2024}
}

@inproceedings{cupy,
title={Cupy: A numpy-compatible library for nvidia gpu calculations},
author={Okuta, Ryosuke and Unno, Yuya and Nishino, Daisuke and Hido, Shohei and Loomis, Crissman},
journal={Proceedings of Workshop on Machine Learning Systems ({L}earning{S}ys) in The Thirty-first Annual Conference on Neural Information Processing Systems {NIPS}},
year={2017}
}

@manual{mpmath,
key = {mpmath},
author = {The mpmath development team},
title = {mpmath: a {P}ython library for arbitrary-precision floating-point arithmetic (version 1.3.0)},
note = {{\tt http://mpmath.org/}},
year = {2023},
}

@article{numpy,
title={Array programming with NumPy},
author={Harris, Charles R and Millman, K Jarrod and Van Der Walt, St{\'e}fan J and Gommers, Ralf and Virtanen, Pauli and Cournapeau, David and Wieser, Eric and Taylor, Julian and Berg, Sebastian and Smith, Nathaniel J and others},
journal={Nature},
volume={585},
number={7825},
pages={357--362},
year={2020},
publisher={Nature Publishing Group}
}

@article{scipy,
title={{S}ci{P}y 1.0: fundamental algorithms for scientific computing in {P}ython},
author={Virtanen, Pauli and Gommers, Ralf and Oliphant, Travis E and Haberland, Matt and Reddy, Tyler and others},
journal={Nature methods},
volume={17},
number={3},
pages={261--272},
year={2020},
publisher={Nature Publishing Group}
}
61 changes: 61 additions & 0 deletions paper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
title: 'Vectorized, Array API Compatible Functions for Quadrature, Series Summmation, Differentiation, Optimization, and Root Finding in SciPy'
tags:
- Python
- SciPy
- integration
- differentiation
- optimization
- root finding
authors:
- name: Matt Haberland^[Corresponding author]
affiliation: 1
orcid: 0000-0003-4806-3601
authors:
- name: Albert Steppi
affiliation: 2
orcid: 0000-0001-5871-6245
authors:
- name: Pamphile Roy
affiliation: 3
orcid: 0000-0001-9816-1416
affiliations:
- name: California Polytechnic State University, San Luis Obispo, USA
index: 1
- name: Quansight Labs, Austin, USA
index: 2
- name: Consulting Manao GMBH, Vienna, Austria
index: 3
date: 1 March 2025
bibliography: paper.bib

---

# Summary

Numerical integration, series summation, differentiation, optimization, and root finding are fundamental problems with applications in essentially all domains of science and engineering. Frequently, such problems do not arise individually, but rather in batches; e.g., differentiation of a single curve at many points or minimization of a function for many values of a parameter. When the related problems are all independent, embarrassingly parallel calculation is possible However, SciPy – the de facto standard library for such algorithms – did not offer features for vectorized solution of such problems with NumPy [@numpy] arrays, let alone array library agnostic implementations.

This paper discusses several new features that fill this gap, included in SciPy 1.15.0:
- `scipy.differentiate`, a sub-package for numerical differentiation of scalar or vector-valued functions of one or more variables,
- `scipy.integrate.tanhsinh` for quadrature of scalar or vector-valued integrands of one variable,
- `scipy.integrate.nsum` for summation of real-valued finite or infinite series,
- `scipy.optimize.elementwise` for finding roots and minimization of a single-input, single output function.

Although the details of the algorithms are inherently distinct, of these features rely on a common framework for elementwise iterative methods and share similar interfaces. For example, `scipy.optimize.differentiate` accepts the scalar function to be differentiated as a callable, the points at which to evaluate the derivative as an N-dimensional array, and any other parameters of the function as N-dimensional arrays. `differentiate` passes abscissae and parameters to the callable as N-dimensional arrays, adaptively approximating the derivative(s) to achieve specified tolerances. Furthermore, arrays need not be NumPy arrays; the implementation works with any Python Array-API compatible arrays (assuming the user-provided callable does, too). These features will dramatically improve performance of end-user applications, and together, they form the backbone of SciPy's new random variable infrastructure.

# Statement of need

Before the release of SciPy 1.15.0, the need for these capabilities was partially met in the scientific Python ecosystem. As popular examples, [@numdifftools] provides a suite of tools for numerical differentiation, `scipy.integrate` offers several functions for numerical integration, mpmath's [@mpmath] `nsum` function is for series summation, and `scipy.optimize` offers tools for scalar minimization and root finding. However, to the authors' knowledge, the new implementations are unique in that they offer the following advantages.

- Backend-independence: all of these features are "Array API compatible" in the sense that they rely almost entirely on the Python standard libary and calls to Python Array API Standard functions/methods. Consequently, the functions accept objects other than NumPy arrays, such as PyTorch [@pytorch] tensors and CuPy [@cupy] arrays, and the calculations are performed by the underlying library.
- Speed: the features take maximum advantage of vectorized user callables, avoiding slow Python loops and the excessive overhead of repeatedly calling compiled code.
- Prevalence: SciPy is one of the most popular scientific Python packages. If a scientific Python user needs these features, chances are that they already have SciPy installed, eliminating the need to find and learn a new package.
- Easy-of-use: the function API reference are thorough, and the interfaces share common features and operate smoothly with other SciPy functions.
- Dependability: as with all SciPy code, these features were designed and implemented following good software development practices. They have been carefully peer-reviewed, and extensive unit tests protect against backward incompatible changes and regressions.

# Acknowledgements

We gratefully acknowledge the support of Chan Zuckerberg Initiative Essential
Open Source Software for Science Grant CZI EOSS5-0000000176, "SciPy: Fundamental Tools for Biomedical Research". Thanks to all those who have submitted feature requests, bug reports, and review comments related to these features, and especially to SciPy maintainers who reviewed and merged related work.

# References

0 comments on commit bf93e30

Please sign in to comment.