lecture-python-advanced.myst
lecture-python-advanced.myst copied to clipboard
[amss] remove interpolation and replace np.interp
The interpolation package is used in the amss lecture as it provided numba jit compatible functions.
The np.interp function is now compatible with numba so we can update this lecture and remove a dependency.
Currently this lecture uses
from interpolation.splines import eval_linear, UCGrid, nodes
hopefully we can find alternatives in numpy as a quick short term fix.
In the medium term we will update this lecture to use jax
@HumphreyYang are you familiar with these lectures?
We need to replace these interpolation functions with numpy alternatives (for now). Are there any easy replacements?
Hi @mmcky, as far as I know there is no simple alternative for UCGrid for multi-dimensional interpolation in numpy.
There is one in scipy:
https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.RegularGridInterpolator.html
Would you like pure numpy implementation?
Thanks @HumphreyYang
Also just FYI I am doing some testing of Copilot.
I assigned it to fix this issue and here is what it is coming up with so far
https://github.com/QuantEcon/lecture-python-advanced.myst/pull/228
Hi @mmcky, as far as I know there is no simple alternative for UCGrid for multi-dimensional interpolation in
numpy.There is one in
scipy: https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.RegularGridInterpolator.htmlWould you like pure
numpyimplementation?
I would just need to check if this sits in numba jit or not.
Hi @mmcky, I just had a try, no, RegularGridInterpolator is not in numba.
I think we might need to implement our own interpolator in numpy like what copilot is doing.
Let's see how it goes.
Just noting that this is also in JAX: https://docs.jax.dev/en/latest/_autosummary/jax.scipy.interpolate.RegularGridInterpolator.html
Maybe someone could bite the bullet and just convert this whole lecture over to JAX...?
Maybe someone could bite the bullet and just convert this whole lecture over to JAX...?
Many thanks @jstac, I can do that!
I think it would probably easier than writing a numba compatible function that replicates the figure as I did this afternoon : )
I think it would probably easier than writing a numba compatible function that replicates the figure as I did this afternoon
Thanks for doing that @HumphreyYang ! I really appreciate the effort nontheless. What you did was natural and we could pause at that and open a separate issue if you like. I'll leave it up to you.
Many thanks, @jstac. I think this issue and PR make a really nice case study on Copilot and AI that we can share with the team.
It’s my fault for getting a bit too involved in trying to beat the AI by replicating the graph : )
I’ll leave this issue to @mmcky and start rewriting!
Just noting that this is also in JAX: https://docs.jax.dev/en/latest/_autosummary/jax.scipy.interpolate.RegularGridInterpolator.html
Maybe someone could bite the bullet and just convert this whole lecture over to JAX...?
thanks @jstac I will start cross checking some of these functions with jax docs
I agree with the comments above on trying the JAX APIs. Also, the lectures here are in the advanced series so we can prefer JAX over numba even if some of the code looks complex with JAX.