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

Bug: Numpy type represented as "np.float64(1.234)" instead of "1.234" #121

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

ZackTully
Copy link
Collaborator

@ZackTully ZackTully commented Nov 14, 2024

There is a bug in the amr_wind_standin to emulator' communication. amr_wind_standincreates a list of numbers (some are python native floats and some are numpy floats) calledmessage_from_client_array, which is cast as a string before being passed to emulator' via helics. In emulator this message is read using ast.literal_eval(), which parses the string into a list of only native python types.

Casting a python list to string calls the __repr__() (meaning representation, I think) method on each element in the list. At some point numpy changed this behavior so that instead of returning "1.234" the __repr__ method returns "np.float64(1.234)". This is what was causing the error in the ast.literal_eval call in emulator. The error message was:

error: malformed node or string on line 1: <ast.Call object at 0x2971aafb0>

Originally, I was going to replace the ast.literal_eval call with eval but then I learned this might be dangerous ( https://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html ).

I fixed the bug by casting the amr_wind_standin message to native python floats before sending through helics but a similar issue may pop up again elsewhere.

https://numpy.org/neps/nep-0051-scalar-representation.html#alternatives

@ZackTully ZackTully added the bug Something isn't working label Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants