Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider generalizing backends of array APIs #98

Open
diegoferigo opened this issue Sep 17, 2024 · 2 comments
Open

Consider generalizing backends of array APIs #98

diegoferigo opened this issue Sep 17, 2024 · 2 comments

Comments

@diegoferigo
Copy link
Member

diegoferigo commented Sep 17, 2024

I remember a f2f discussion a while ago with @Giulero about how to generalize algorithms to work on NumPy / JAX / PyTorch etc. At that time, there was no concrete solution excluding what today became Farama-Foundation/Jumpy that was only supporting NumPy and JAX.

After a couple of years, it seems that the community is trying to address this use case with the Python array API standard. It seems that this solution is the one that got major traction and attracted most of the interest towards this unification.

ADAM, today, generalizes the underlying array APIs used by the RBDAs by introducing a custom abstraction layer based on adam.core.spatial_math.{ArrayLike|ArrayLikeFactory|SpatialMath}, which has implementations in CasADi, JAX, NumPy, and PyTorch.

I think that CasADi --at least in the short term and at least officially-- won't be compatible with these Array APIs. However, providing in ADAM a new backend based on these new APIs could ease the maintenance of the other backends (or, possibly remove them), and could bring with no additional effort also support for all other array providers that are adhere with the API standard.

A good starting point could be the data-apis/array-api-compat wrapper1, its usage seems pretty straightforward.

Footnotes

  1. https://data-apis.org/array-api-compat/

@diegoferigo diegoferigo changed the title Consider generalizing all backends of array APIs Consider generalizing backends of array APIs Sep 17, 2024
@Giulero
Copy link
Collaborator

Giulero commented Sep 18, 2024

Thanks a lot @diegoferigo! <3
This would be lovely indeed. I agree that finally exploiting these new Array APIs will make the library more maintainable.
Regarding CasADi, we could maybe maintain the actual abstraction layer and implement a new backend for what we can unify. A sort of hybrid structure, eventually converging to a cleaner solution when we find a solution for the CasADi backend.
As soon as possible I can try to draft a PR and ask you other suggestions ;)

@diegoferigo
Copy link
Member Author

Regarding CasADi, we could maybe maintain the actual abstraction layer and implement a new backend for what we can unify. A sort of hybrid structure, eventually converging to a cleaner solution when we find a solution for the CasADi backend.

Yep I agree! If there is interest in merging at least the remaining ones by exploiting array-api-compact, then ADAM could probably provide a custom CasADi implementation based on their array APIs. There is no need for a full implementation, likely only a subset of array operations (those that are currently abstracted) are necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants