Skip to content

Add value setter for simple logged quantities.#69

Closed
MTCam wants to merge 11 commits into
illinois-ceesd:mainfrom
MTCam:user-quantities
Closed

Add value setter for simple logged quantities.#69
MTCam wants to merge 11 commits into
illinois-ceesd:mainfrom
MTCam:user-quantities

Conversation

@MTCam

@MTCam MTCam commented Jun 18, 2021

Copy link
Copy Markdown
Member

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

Comment thread examples/log-mpi.py
@inducer

inducer commented Jun 20, 2021

Copy link
Copy Markdown
Collaborator

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

@inducer inducer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A few more, sorry.

Comment thread examples/log-mpi.py Outdated
Comment thread examples/log-mpi.py Outdated
Comment thread examples/log-mpi.py Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍

Copy link
Copy Markdown
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

thomasgibson commented Aug 4, 2021

Copy link
Copy Markdown

@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

MTCam commented Aug 4, 2021

Copy link
Copy Markdown
Member Author

@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.

@inducer inducer left a comment

Copy link
Copy Markdown
Collaborator

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 thread logpyle/__init__.py
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
Copy Markdown
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.

Comment thread examples/log-mpi.py
from mpi4py import MPI


class PushLogQuantity(LogQuantity):

Copy link
Copy Markdown
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.

Comment thread examples/log-mpi.py
self._quantity_value = None
return val

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

Copy link
Copy Markdown
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.

Comment thread logpyle/__init__.py
:param name: the name of the logged quantity.
:param value: the value of the logged quantity.
"""
if name in self.quantity_data:

Copy link
Copy Markdown
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.

Comment thread logpyle/__init__.py
value_setter(value)
else:
from warnings import warn
warn(f"No value_setter defined for log quantity (name={name}).")

Copy link
Copy Markdown
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

inducer commented Aug 11, 2021

Copy link
Copy Markdown
Collaborator

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

@inducer

inducer commented Sep 23, 2021

Copy link
Copy Markdown
Collaborator

@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