Skip to content

[Feature] Implement direct getter/setter for Quantity#431

Open
FlorianDeconinck wants to merge 21 commits intoNOAA-GFDL:developfrom
FlorianDeconinck:feat/quantity_direct_getter_setter
Open

[Feature] Implement direct getter/setter for Quantity#431
FlorianDeconinck wants to merge 21 commits intoNOAA-GFDL:developfrom
FlorianDeconinck:feat/quantity_direct_getter_setter

Conversation

@FlorianDeconinck
Copy link
Copy Markdown
Collaborator

@FlorianDeconinck FlorianDeconinck commented Apr 15, 2026

Description

Dear all,

We have reached this moment. Yes, after many hours of debate: I have implemented quantity[:, :, :] = 0 which will behave like quantity.data[:, :, :] = 0.

The main reason for the change is orchestration. TL;DR: when parsing, DaCe maps symbols to their name. If a buffer is used with buffer and buffer.data to access the same memory, it can confuse the parser and lead to difficult to debug numerical error.

This change is also motivated by the fact we have very little to no use for quantity.field during runtime (when we might orchestrate).

Further improvement of the API would require the use of .data and .field to fail during orchestration OR in an "orchestrate" code path. Not implemented here.

How has this been tested?

The quantity unit test has been changed to not use .data and one test has been added.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (e.g. add new modules to docs/docstrings/)
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules
  • New check tests, if applicable, are included

Copy link
Copy Markdown
Collaborator

@romanc romanc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me - just a question about some test asserts.

Comment thread tests/quantity/test_quantity.py Outdated
Copy link
Copy Markdown
Collaborator

@twicki twicki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have direct access without .field should we at least deprecate it here so we can remove it in the release after that?

And for my own edification: I thought we specifically put in the .field and .data functions because that was the only way we could tell orchestration to overwrite the calls for the accesses to work. Why / How did that change? Or do I misremember something here?

@FlorianDeconinck
Copy link
Copy Markdown
Collaborator Author

If we have direct access without .field should we at least deprecate it here so we can remove it in the release after that?

This doesn't really deprecate those access, what it does is make orchestration possible because those access break orchestration. Now - as I said in the PR - what is missing here is a way to forbid those access from being used in orchestrated code path. I tried a few things, it's non-trivial. This alone could warrant a deprecation and removal of the specific accessors.

The counterpoint being that .field is mostly what you want when looking in the data outside of the runtime, making it a very useful shortcut.

And for my own edification: I thought we specifically put in the .field and .data functions because that was the only way we could tell orchestration to overwrite the calls for the accesses to work. Why / How did that change? Or do I misremember something here?

No, we failed to do so. We couldn't make dace.views that worked and we kept having symbol conflicts. Those results are directly motivating this change.

@twicki
Copy link
Copy Markdown
Collaborator

twicki commented Apr 16, 2026

sorry, I mistyped in my comment. I ment deprecating .data as this use-case is now covered by [] access

@FlorianDeconinck
Copy link
Copy Markdown
Collaborator Author

sorry, I mistyped in my comment. I ment deprecating .data as this use-case is now covered by [] access

Yes - that we should. We do need an access, so we'll probably (re)introduce a get_data() or get_buffer() ?

Copy link
Copy Markdown
Collaborator

@oelbert oelbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 minor correction. I do think we should deprecate quantity.data but ideally over multiple releases, and as long as we keep quantity.field.

Comment thread ndsl/quantity/quantity.py Outdated
@FlorianDeconinck
Copy link
Copy Markdown
Collaborator Author

FlorianDeconinck commented Apr 16, 2026

1 minor correction. I do think we should deprecate quantity.data but ideally over multiple releases, and as long as we keep quantity.field.

The problem with keeping quantity.field is that it will not orchestrate in the runtime code. So far, I have no way to warn/cancel it when orchestration. Whereas quantity[halo:-halo-1, halo:-halo-1, -1], the field use case, will work but is ugly.

Unsolved issue.

@romanc
Copy link
Copy Markdown
Collaborator

romanc commented Apr 16, 2026

Regarding deprecating .field: Quantities have a reference to the Backend, which knows if we want to orchestrate or not. Could we add a DeprecationWarning inside the .field acessor of Quantity depending on the backend? I guess that would only trigger upon usage (and not up-front), but better late than never?

Copy link
Copy Markdown
Collaborator

@oelbert oelbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what to say about the field issue beyond just telling people "don't use it at runtime!"

@fmalatino fmalatino added this pull request to the merge queue Apr 16, 2026
@FlorianDeconinck FlorianDeconinck removed this pull request from the merge queue due to a manual request Apr 16, 2026
@FlorianDeconinck
Copy link
Copy Markdown
Collaborator Author

Holding merge to figure out if we can do something clever for field. Like send a picture of Oliver with frown eyebrows with every cloned repository

@FlorianDeconinck FlorianDeconinck marked this pull request as draft April 16, 2026 19:21
@FlorianDeconinck
Copy link
Copy Markdown
Collaborator Author

Drafting: I need to go clean up all the quantity.data inside ndsl itself.

@FlorianDeconinck
Copy link
Copy Markdown
Collaborator Author

Further cleanup:

  • 🧹 removed all use of .data[...] in NDSL
  • 🐞 fixed reduce comm bug that was swapping buffer instead of copying. Though it is not per se a bug, this would absolutely fail orchestration
  • ➕ added a dtype which seems like a fair re-exposure of the underlying memory. Kept strides and itemsize hidden, reachable via _data because those shouldn't be used directly by the user

@FlorianDeconinck
Copy link
Copy Markdown
Collaborator Author

  • ➕ Restored sel API. It is niche but quite useful if you want to slice an array by dimension name without knowing it's indexing
  • ➕ Added a swap_buffer methods that replaced the .data setter
  • 🦾 Made hashing of the State better by actually using the __hash__ of the attributes (which means calling the custom hash of Quantity)
  • 🧹 clean up the .data in the unit tests

@FlorianDeconinck FlorianDeconinck marked this pull request as ready for review April 20, 2026 15:55
@FlorianDeconinck
Copy link
Copy Markdown
Collaborator Author

@romanc / @twicki : lots of clean up. please re-review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants