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

Update tutorial 06 #103

Closed mcleantom closed 10 months ago

mcleantom commented 10 months ago

At the end of the tutorial, it talks about a bug in the np.where function if the false condition returns NaN. I have done a fresh install of ASB and run the code and I no longer get this issue, so I assume this bug has been fixed:

opti = asb.Opti()
x = opti.variable(init_guess=1)
f = np.where(
    x >= 0,
    x ** 1.5,
    (-x) ** 1.5
)
opti.minimize(f)
sol = opti.solve()

This is Ipopt version 3.14.11, running with linear solver MUMPS 5.4.1.

...

EXIT: Optimal Solution Found.
      solver  :   t_proc      (avg)   t_wall      (avg)    n_eval
       nlp_f  |  12.00us (  1.71us)   8.59us (  1.23us)         7
  nlp_grad_f  |  11.00us (  3.67us)  10.50us (  3.50us)         3
  nlp_hess_l  |   2.00us (  2.00us)   1.84us (  1.84us)         1
       total  | 867.00us (867.00us) 822.41us (822.41us)         1

I am running ASB version 4.1.1.

peterdsharpe commented 10 months ago

Hey Tom!

Nice catch! You're right that this has been fixed, thanks to a bugfix in the underlying CasADi function that the aerosandbox.numpy backend links to.

Fixing commit that updates the tutorial is here on develop, and will go live with the next release: https://github.com/peterdsharpe/AeroSandbox/commit/1f1badf3246deca448c8effce622a7f59962ba95

Thank you! :)