peterdsharpe / AeroSandbox

Aircraft design optimization made fast through modern automatic differentiation. Composable analysis tools for aerodynamics, propulsion, structures, trajectory design, and much more.
https://peterdsharpe.github.io/AeroSandbox/
MIT License
687 stars 111 forks source link

Any list of the numpy supported functions? #119

Closed mrrezaie closed 5 months ago

mrrezaie commented 5 months ago

Hi, I'm looking for a list of numpy supported functions to see how I can formulate my problem. Is there any available? Thank you.

peterdsharpe commented 5 months ago

Hey @mrrezaie ,

Good news and bad news:

Bad news is that the only formal list, in this thesis (pg. 72), is somewhat out of date.

Good news is that the reason it's out of date is that many new functions have been added since then!

The most up-to-date place to look would be directly in the aerosandbox.numpy source code: https://github.com/peterdsharpe/AeroSandbox/tree/master/aerosandbox/numpy

NumPy functions here are categorized into different modules; if you have a question about a specific function, let me know and I'll try to point you in the right direction.

Best, Peter

mrrezaie commented 5 months ago

Thanks for your response. I was looking for something like this: https://numba.pydata.org/numba-doc/dev/reference/numpysupported.html

Does this error mean that numpy.gradient has not been supported yet? Or I'm doing something wrong here?

import casadi
import aerosandbox.numpy as np

opti = casadi.Opti()
A = opti.variable(10)
np.gradient(A, 0.01, edge_order=2)

AttributeError: 'MX' object has no attribute 'full'

Exception: Implicit conversion of symbolic CasADi type to numeric matrix not supported. This may occur when you pass a CasADi object to a numpy function. Use an equivalent CasADi function instead of that numpy function.

cdhainaut commented 5 months ago

numpy.gradient is not present in AeroSandbox master branch, but @peterdsharpe added it in the develop branch recently: https://github.com/peterdsharpe/AeroSandbox/blob/develop/aerosandbox/numpy/calculus.py.

The error you get: Exception: Implicit conversion of symbolic CasADi type to numeric matrix not supported. This may occur when you pass a CasADi object to a numpy function. Use an equivalent CasADi function instead of that numpy function.

Tells you quite explicitly that you try to use a non-casadi-supported numpy function

mrrezaie commented 5 months ago

I see; thanks for your help. Great to see you are improving numpy support. I hope casadi will do the same in near future. https://github.com/casadi/casadi/issues/2626

cdhainaut commented 5 months ago

I had some thoughts about this numpy/casadi interactions lately, actually. I'd be happy to have your opinions on that: https://github.com/peterdsharpe/AeroSandbox/discussions/120

peterdsharpe commented 5 months ago

@mrrezaie , AeroSandbox v4.2.0 was just released a few minutes ago which makes the newly-added numpy.gradient() public! pip install --upgrade aerosandbox[full] should pull in the changes.

mrrezaie commented 5 months ago

@peterdsharpe It is working very well, thanks a lot for your help.

@cdhainaut This is indeed a very good proposal. Actually, I know nothing about aerodynamics and aircraft, and casadi-numpy interaction was the only reason I'm using AeroSandbox. So, as a user and a beginner, I like this idea. However, it seems that casadi has already some plans to improve its numpy support. Perhaps you developers could collaborate with each other on this and make something fabulous.

Thanks again.