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

Fix Aggregator setter #216

Merged
merged 8 commits into from
Feb 7, 2025
Merged

Fix Aggregator setter #216

merged 8 commits into from
Feb 7, 2025

Conversation

schmoelder
Copy link
Contributor

@schmoelder schmoelder commented Jan 27, 2025

Fixes #215

Added methods to indicate whether the internal data should be transposed (i.e., have shape (n_containers, *parameter_shape)). While this resolves the immediate issue, I had to overwrite the __set__ method of the Aggregator base class, which feels less than ideal. I'll revisit this implementation to explore alternative approaches, but it should work for now.

Additionally, I noticed there are currently no tests for any aggregated parameters. This is unexpected, as I was fairly certain I had written some. Maybe they got lost somewhere...

ToDos:

  • Stoich coeffs in reactions should be sized
  • Check if the wrong code snippet is commented out in SizedAggregator.__set__
  • Check length of container vs value in Aggregator.__set__
  • Check consistency of transpose=True vs False in SizedAggregator
  • Add tests

@schmoelder schmoelder added this to the v0.11.0 milestone Jan 27, 2025
@schmoelder schmoelder force-pushed the fix/aggregator_setter branch 4 times, most recently from f9a5108 to 482f188 Compare January 28, 2025 16:20
@schmoelder schmoelder marked this pull request as ready for review January 28, 2025 16:20
@schmoelder schmoelder force-pushed the fix/aggregator_setter branch 2 times, most recently from 8644605 to aedce9f Compare January 29, 2025 05:49
@schmoelder
Copy link
Contributor Author

I refactored the transport functionality and now only the __get__ and __set__ methods are extended in the subclass (instead of being overwritten) which I find much more elegant.

I also added tests for the aggregator, so once tests pass, I'd appreciate another thorough review. 🤓

@schmoelder schmoelder force-pushed the fix/aggregator_setter branch from aedce9f to 7b70fc7 Compare January 29, 2025 06:14
@ronald-jaepel
Copy link
Collaborator

Usage in optimizationProblems works nicely. 👍

Setting slices of aggregators didn't work. It didn't raise an Error or Warning and also didn't change the values. I've extended the tests for that. If that is a use-case you don't see users using, feel free to remove the tests again.

@schmoelder
Copy link
Contributor Author

Setting slices of aggregators didn't work. It didn't raise an Error or Warning and also didn't change the values. I've extended the tests for that. If that is a use-case you don't see users using, feel free to remove the tests again.

Damn, that's a tricky one, since we're always returning a new value that is being constructed by iterating over the internal instances. So there is no internal reference that points back to the underlying container elements. I'm honestly not completely sure how to handle this but I'll think a bit further about it.

@schmoelder schmoelder force-pushed the fix/aggregator_setter branch 4 times, most recently from 764464c to 3c5ffc7 Compare January 29, 2025 15:57
@schmoelder
Copy link
Contributor Author

Puh, this was a "difficult birth". In the end I did decide to provide proxy objects to the aggregated parameters which now seems to work properly. I had to adapt one more test but I think it's fine now...

self.aggregator = getattr(obj, 'aggregator', None)
self.instance = getattr(obj, 'instance', None)

def __array_function__(self, func, types, *args, **kwargs):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one here caused a lot of trouble... 😅

@schmoelder schmoelder force-pushed the fix/aggregator_setter branch from 3c5ffc7 to cce4e92 Compare February 7, 2025 11:07
@schmoelder schmoelder merged commit a624ca9 into dev Feb 7, 2025
4 checks passed
@schmoelder schmoelder deleted the fix/aggregator_setter branch February 7, 2025 11:23
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.

Setting of stochiometric matrix in optimization Problem confusing or broken
2 participants