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

Add value setter for simple logged quantities. #69

Closed
wants to merge 11 commits into from

Conversation

MTCam
Copy link
Member

@MTCam MTCam commented Jun 18, 2021

This helps illinois-ceesd/mirgecom#391, and adds a basic value-setting capability for users' logged quantities. The user would be responsible for implementing the capability user-side and making sure it does something useful. The local logpyle changes just fix it up so that such that a setter function can be registered.

fixes: #68

@inducer
Copy link
Collaborator

inducer commented Jun 20, 2021

Unsubscribing... @-mention or request review once it's ready for a look or needs attention.

@MTCam MTCam requested a review from inducer June 21, 2021 11:32
Copy link
Collaborator

@inducer inducer left a comment

Choose a reason for hiding this comment

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

A few more, sorry.

examples/log-mpi.py Outdated Show resolved Hide resolved
examples/log-mpi.py Outdated Show resolved Hide resolved
Comment on lines 14 to 29
class UserLogQuantity(LogQuantity):
"""Logging support for arbitrary user quantities."""

def __init__(self, name, value=None, unit=None,
description=None) -> None:
LogQuantity.__init__(self, name=name, unit=unit,
description=description)
self._quantity_value = value

def __call__(self) -> float:
"""Return the actual logged quantity."""
return self._quantity_value

def set_quantity_value(self, value: Any) -> None:
"""Set the value of the logged quantity."""
self._quantity_value = value
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it make sense to move this to a place where it's importable?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, somehow this fell off my radar. I am not accustomed to having logpyle PRs that I'm watching.

Yes, we could definitely move this and make it "a thing" offered by logpyle - but before we commit to doing that, I just want to point out that this is just an example of how to use the capability added by this change set - which was just the part that allows a setter function to be passed into, and then invoked from inside logging.

It would be my preference to add a class similar to this to the logging_quantities.py of MIRGE-Com, instead of a canned one offered by logpyle, but I defer to @inducer and @matthiasdiener about whether to offer this or similar as a logpyle construct.

Copy link
Collaborator

Choose a reason for hiding this comment

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

My vote would be to offer it here... the duplication between the two examples is already a bit much for me to bear. OTOH, if you'd like to demonstrate how (not very) hard it is to make your own LogQuantity, then maybe I could be convinced.

Copy link
Member Author

Choose a reason for hiding this comment

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

I see the value in offering a base one. How about we offer a base one, and demonstrate how to make one's own one?

Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

Copy link
Collaborator

Choose a reason for hiding this comment

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

(There could be a comment on the demo one that this specific thing already exists and can just be imported.)

@thomasgibson
Copy link

thomasgibson commented Aug 4, 2021

@MTCam @inducer Can we revive this PR? My UG student (@sipieta2) and I have been using this functionality for logging. Would really like to get this into the main branch of logpyle.

@MTCam
Copy link
Member Author

MTCam commented Aug 4, 2021

@MTCam @inducer Can we revive this PR? My UG student (@sipieta2) and I have been using this functionality for logging. Would really like to get this into the main branch of logpyle.

👍

Go for it from my perspective. There is an associated logpyle PR for this work too. I am assuming you found that.

Copy link
Collaborator

@inducer inducer left a comment

Choose a reason for hiding this comment

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

LGTM after these are addressed.

Comment on lines +751 to +764
def set_quantity_value(self, name: str, value: Any) -> None:
"""Set a the value of a named LogQuantity.

:param name: the name of the logged quantity.
:param value: the value of the logged quantity.
"""
if name in self.quantity_data:
value_setter = self.quantity_data[name].value_setter
if value_setter:
value_setter(value)
else:
from warnings import warn
warn(f"No value_setter defined for log quantity (name={name}).")

Copy link
Collaborator

Choose a reason for hiding this comment

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

Make this a function instead.

@@ -10,6 +11,26 @@
from mpi4py import MPI


class PushLogQuantity(LogQuantity):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rather than duplicating it, please move this somewhere and import from there.

self._quantity_value = None
return val

def set_quantity_value(self, value: Any) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Naming? I think set_value would suffice.

:param name: the name of the logged quantity.
:param value: the value of the logged quantity.
"""
if name in self.quantity_data:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just access it and handle the KeyError.

value_setter(value)
else:
from warnings import warn
warn(f"No value_setter defined for log quantity (name={name}).")
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should probably be an error.

@inducer
Copy link
Collaborator

inducer commented Aug 11, 2021

Unsubscribing... @-mention or request review once it's ready for a look or needs attention.

@inducer
Copy link
Collaborator

inducer commented Sep 23, 2021

@MTCam Do you agree that this should be closed in favor of #74?

@MTCam MTCam closed this Sep 23, 2021
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.

allow updating quantities through LogManager class, not LogQuantity
3 participants