Skip to content

Commit e754ba6

Browse files
authored
Merge pull request #269 from nstarman/units_proposal
Phase 3 Funding | Starkman & Foreman-Mackey | Units
2 parents f0ea0f8 + e01981f commit e754ba6

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
### Title
2+
3+
### Project Team
4+
5+
Nathaniel Starkman (NS) and Dan Foreman-Mackey (DFM)
6+
7+
8+
### Project Description
9+
10+
[`Quantity`][Quantity] is a backbone of Astropy, leveraging the power of [NumPy]
11+
[NumPy] and adding units. However, the computing landscape is changing. Many
12+
numpy-like libraries exist for different use cases: [Dask][Dask] for
13+
distributed computing, [CuPy][CuPy] for GPU, [xarray][xarray] for labeled
14+
data, [JAX][JAX] for autograd and GPU acceleration, [zarr][zarr] for compressed
15+
arrays, etc. Though these libraries offer a numpy-like API and interoperability
16+
protocols, `Quantity` is incompatible with them, which prevents users from
17+
choosing the most suitable library while also having units. In other words,
18+
users working on larger-than memory data or doing machine learning, among other
19+
use cases, struggle to use Astropy.
20+
21+
Therefore, we propose to determine how best to extend `Quantity` to support
22+
numpy-like libraries and all the use cases they confer. This entails creating a
23+
plugin architecture and a reference implementation, starting with JAX
24+
(crucial for machine learning).
25+
26+
27+
### Project / Work
28+
29+
There are two components to this project:
30+
31+
1. Extension to the Quantity framework to allow [`Quantity`][Quantity] to be
32+
abstracted from subclassing [`numpy.ndarray`][NumPy] and to instead use a
33+
broader range of base classes. NS is currently developing this approach in
34+
https://github.com/astropy/astropy/pull/12921. This framework will support the
35+
use of, for example, a JAX array as the storage back end for a `Quantity` when
36+
appropriate. This will be a plugin architecture with 3rd party library support
37+
housed in a to-be-proposed affiliate (preferably coordinated) package.
38+
39+
2. Connect JAX with the new Quantity framework. There are two options to make
40+
this work:
41+
- Issue / PR to JAX to support custom tracer objects, which are conceptually
42+
similar to function overrides offered by NumPy. DFM is already discussing
43+
this with some members of the JAX development team.
44+
45+
- If (a) is not possible, wrap JAX’s numpy. DFM already has a package `jpu`
46+
with a reference implementation that will serve as the basis of this
47+
work.
48+
49+
50+
### Deliverables
51+
52+
Given how deeply numpy is embedded in Quantity, e.g. the use of in-memory
53+
``.view()``, extending Quantity to other libraries will introduce changes.
54+
Therefore, our work will be to:
55+
56+
1. Create a reference implementation for both the Astropy changes and the
57+
affiliate package, detailed in the previous section.
58+
59+
2. Write a report of our findings.
60+
61+
These two results will serve either as the basis for a future PR / APE, if the
62+
approach succeeds; or as an explanation why the options explored are not
63+
suitable for Astropy, along with recommendations for other approaches.
64+
65+
66+
### Future Work
67+
68+
This project is to determine a path forward for Astropy to support the next
69+
generation of array libraries. With a reference implementation and detailed
70+
report the community will be able to provide input on next steps. We suggest
71+
the following as possible future works:
72+
73+
1. An Astropy Proposal for Enhancement to complete and roll out the reference
74+
implementation. This would presumably include the affiliate/coordinated package
75+
for 3rd party library integrations.
76+
77+
2. An Astropy Proposal for Enhancement for the alternative implementation
78+
suggested in the report.
79+
80+
3. A grant proposal (e.g. for phase 4) to fund this future work and ensure a
81+
smooth transition and long-term support for the current Quantity framework.
82+
83+
84+
### Approximate Budget
85+
86+
For NS:
87+
Target budget: $8,400 for 70 hours of work at $120/hour (rate negotiable).
88+
Minimum budget: $5,950 for 70 hours of work at $85/hour.
89+
90+
For DFM:
91+
Dan Foreman-Mackey is graciously donating his time and expertise.
92+
93+
94+
[Quantity]: https://docs.astropy.org/en/stable/units/quantity.html
95+
[NumPy]: https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html
96+
[Dask]: https://www.dask.org
97+
[CuPy]: https://cupy.dev
98+
[xarray]: https://docs.xarray.dev/en/stable/index.html
99+
[JAX]: https://jax.readthedocs.io/en/latest/notebooks/quickstart.html
100+
[zarr]: https://zarr.readthedocs.io/en/stable/
101+
102+
### Approved Budget
103+
$8,400

0 commit comments

Comments
 (0)