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

Tutorial 01 - Vortex Lattice Method is not working #77

Closed jannav84 closed 2 years ago

jannav84 commented 2 years ago

Hello, there is some issue with tutorial on VLM (AeroSandbox/tutorial/06 - Aerodynamics/01 - AeroSandbox 3D Aerodynamics Tools/01 - Vortex Lattice Method.ipynb)

If I run it, I've got error: TypeError: VortexLatticeMethod.init() missing 1 required positional argument: 'opti' In case I provide argument opti=asb.Opti() I obtain other error: TypeError: AeroSandboxObject.init() takes 1 positional argument but 3 were given

Could you please help me with solving this issue?

Thank you, Jan

peterdsharpe commented 2 years ago

Hi Jan!

I'm surprised to see this error - that almost seems like it's coming from AeroSandbox v2.x.x syntax (current version is 3.5.2). Could you please confirm the Python version and AeroSandbox version you're using, as well as your OS? To obtain your ASB version:

print(asb.__version__)

If not on the latest version, please try updating (pip install --upgrade aerosandbox[full]) and, if the issue persists, copy-paste the traceback.

Thanks! -Peter

jannav84 commented 2 years ago

Hello Peter, upgrade to the latest version did a trick. I had v3.1.0 (even though I installed the ASB two days ago via pip). But now, it is working well!

Nevertheless, there is one issue, maybe. If I use "aerosandbox.numpy" in the my old code what is working well using "numpy" I receive error:

"ind = np.where(yi == ysFi)
TypeError: where() missing 2 required positional arguments: 'value_if_true' and 'value_if_false'"

Is it your intention, or some bug? I read your comments on your implementation of numpy in aerosandbox, that sometimes it might not work properly.

Also I have problems with debug mode in PyCharm. I'm not sure, if you will be able to help me. But I try it :-) Debug mode gave me error listed bellow. It seems that it is problem of classic numpy. On your test case on VLM I can run debug mode as usuall.

Traceback (most recent call last):
  File "C:\Users\navratil\AppData\Local\Programs\Python\Python310\lib\site-packages\numpy\core\getlimits.py", line 459, in __new__
    dtype = numeric.dtype(dtype)
TypeError: 'NoneType' object is not callable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "D:\Work\TAG\Flexwing_py\InterfaceAVLNastran.py", line 5, in <module>
    import h5py
  File "C:\Users\navratil\AppData\Local\Programs\Python\Python310\lib\site-packages\h5py\__init__.py", line 45, in <module>
    from ._conv import register_converters as _register_converters, \
  File "h5py\_conv.pyx", line 1, in init h5py._conv
  File "h5py\h5t.pyx", line 278, in init h5py.h5t
  File "h5py\h5t.pyx", line 273, in h5py.h5t._get_available_ftypes
  File "C:\Users\navratil\AppData\Local\Programs\Python\Python310\lib\site-packages\numpy\core\getlimits.py", line 462, in __new__
    dtype = numeric.dtype(type(dtype))
TypeError: 'NoneType' object is not callable

Thank you! Jan

peterdsharpe commented 2 years ago

upgrade to the latest version did a trick

Yay, glad to hear!


Regarding aerosandbox.numpy.where - this is (sort of) intended. aerosandbox.numpy.where is intended to support a masking conditional syntax of np.where(condition, value_if_true, value_if_false), which is patterned after the syntax of NumPy's where function, docs here.

That's a 3-argument where function: basically, a conditional ternary operator, but vectorized.

What you're looking for is the 1-argument version of NumPy's where function, which is a little different. As described in the NumPy docs, try using the more idiomatic syntax of np.asarray(condition).nonzero() for this operation. Note for use with AeroSandbox: this operation is (generally) not differentiable, for AD/optimization purposes - you can't differentiate a boolean.

In the future, we might go through and add support for the 1-argument version, but in practice, this syntax is often not used (as described in NumPy docs).


Re: PyCharm Debugging

Hm! It's a bit tough to debug this without a minimum reproducable example. But it looks like the line that triggers this is import h5py, so I might try asking around in the h5py issue board? Before doing so, I'd try updating your NumPy and h5py versions to see if that fixes it.