🚀 LocalState class: a state-like class for organizing Locals #338
🚀 LocalState class: a state-like class for organizing Locals #338FlorianDeconinck merged 8 commits intoNOAA-GFDL:developfrom
LocalState class: a state-like class for organizing Locals #338Conversation
Add checks for forbidden hybrid `Quantity/Locals` states Add many guardrails to force `LocalState` to fit `Local`s boudaries
|
Adding @fmalatino and @jjuyeonkim for backend visibility on complex NDSL concept that will be reused for optimization ( Adding @oelbert for frontend API visbility. Locals will be the backbone of the merge + cache optimize routine, especially for physics. |
fmalatino
left a comment
There was a problem hiding this comment.
Thanks for looping me in.
| from ndsl.types import Number | ||
|
|
||
|
|
||
| from ndsl.quantity import Quantity, Local # isort:skip |
There was a problem hiding this comment.
Why do they need to be imported last?
There was a problem hiding this comment.
Quantity, Local and State are all intertwined and need a severe clean up because Quantity is used everywhere else.
I am locking them at the bottom so all prior dependency run through before we ask for it - that way we stay clear of the recursion.
| ) | ||
|
|
||
| initial_quantities[_field.name] = quantity_factory_allocator( | ||
| allow_mismatch_float_precision = True |
There was a problem hiding this comment.
I am saving us from a bug where we change the first one but no the second one...
| _field.metadata["units"], | ||
| dtype=_field.metadata["dtype"], | ||
| allow_mismatch_float_precision=True, | ||
| allow_mismatch_float_precision=allow_mismatch_float_precision, |
There was a problem hiding this comment.
| allow_mismatch_float_precision=allow_mismatch_float_precision, | |
| allow_mismatch_float_precision=True, |
| origin=quantity.origin, | ||
| extent=quantity.extent, | ||
| backend=quantity.backend, | ||
| allow_mismatch_float_precision=allow_mismatch_float_precision, |
There was a problem hiding this comment.
| allow_mismatch_float_precision=allow_mismatch_float_precision, | |
| allow_mismatch_float_precision=True, |
| allow_mismatch_float_precision=allow_mismatch_float_precision, | ||
| ) | ||
| initial_quantities[_field.name] = local_ | ||
| else: |
There was a problem hiding this comment.
is the logic here slightly funky? We always create a quantity but only add it if the type is not local? Should we not only create it if it is non-local?
There was a problem hiding this comment.
No we create a Quantity which is the only thing that truly hold memory then if we have been told to make Local, we wrap the quantity into a Local (Local derives from Quantity, but python sucks at OOP).
The allow_locals extra flags is only there because we are giving the capacity to allocate a LocalState as a pure Quantity state for testing and interfacing
There was a problem hiding this comment.
Local derives from Quantity, but python sucks at OOP
😱
There was a problem hiding this comment.
No lies here.
twicki
left a comment
There was a problem hiding this comment.
This all makes sense, thanks for talking me through it!
Description
Introducing
LocalStateaStatecontaining onlyLocals. This allows to organize theLocals in the model in a state-like nested dataclasses structure instead of allocating them directly withmake_local.Also:
Quantity/Localsstates in creatingStateandLocalStateLocalStateto fitLocals boudariesHow has this been tested?
New unit tests covering the basics cases.
Deployed on GEOS's microphysics code during optimization
Checklist