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: Adding non-default loggables explicitly. #1331
Changes from 7 commits
2ea3b05
6047864
8538562
020a5bc
e1c05be
642583f
3aa807c
35311f7
3d8b208
05a3429
292e382
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -568,9 +568,9 @@ class they come from. For instance, the `hoomd.md.pair.LJ` class has a | |
``categories`` determines what if any types of loggable quantities (see | ||
`LoggerCategories`) are appropriate for a given `Logger` object. This helps | ||
logging backends determine if a `Logger` object is compatible. The | ||
``only_default`` flag is mainly a convenience by allowing quantities not | ||
commonly logged (but available) to be passed over unless explicitly asked | ||
for. You can override the ``only_default`` flag by explicitly listing the | ||
``only_default`` flag affects performance by controlling whether available | ||
quantities not commonly logged are skipped (the default) or logged. | ||
You can override the ``only_default`` flag by explicitly listing the | ||
quantities you want in `add`, but the same is not true with regards | ||
to ``categories``. | ||
|
||
|
@@ -595,9 +595,8 @@ class they come from. For instance, the `hoomd.md.pair.LJ` class has a | |
the only types of loggable quantities that can be logged by this | ||
logger. Defaults to allowing every type. | ||
only_default (`bool`, optional): Whether to log only quantities that are | ||
logged by "default", defaults to ``True``. This mostly means that | ||
performance centric loggable quantities will be passed over when | ||
logging when false. | ||
logged by "default". Defaults to ``True``. If ``False``, loggable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the quotes on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is specified by the specific loggable. We could use italic. I was just trying to emphasize the word. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think emphasizing it is confusing because the parameter also contains "default". Would we lose much by omitting this bit? |
||
quantities that would slow performance are not be logged. | ||
""" | ||
|
||
def __init__(self, categories=None, only_default=True): | ||
|
@@ -624,11 +623,12 @@ def only_default(self): | |
quantities.""" | ||
return self._only_default | ||
|
||
def _filter_quantities(self, quantities): | ||
def _filter_quantities(self, quantities, force_quantities=False): | ||
for quantity in quantities: | ||
if self._only_default and not quantity.default: | ||
if quantity.category not in self._categories: | ||
continue | ||
elif quantity.category in self._categories: | ||
# Must be before default check to overwrite _only_default | ||
if not self._only_default or quantity.default or force_quantities: | ||
yield quantity | ||
|
||
def _get_loggables_by_name(self, obj, quantities): | ||
|
@@ -643,7 +643,7 @@ def _get_loggables_by_name(self, obj, quantities): | |
"object {} has not loggable quantities {}.".format( | ||
obj, bad_keys)) | ||
yield from self._filter_quantities( | ||
map(lambda q: obj._export_dict[q], quantities)) | ||
map(lambda q: obj._export_dict[q], quantities), True) | ||
|
||
def add(self, obj, quantities=None, user_name=None): | ||
"""Add loggables from obj to logger. | ||
|
@@ -727,10 +727,12 @@ def __setitem__(self, namespace, value): | |
name and category. If using a method it should not take | ||
arguments or have defaults for all arguments. | ||
""" | ||
if isinstance(value, _LoggerEntry): | ||
super().__setitem__(namespace, value) | ||
else: | ||
super().__setitem__(namespace, _LoggerEntry.from_tuple(value)) | ||
if not isinstance(value, _LoggerEntry): | ||
value = _LoggerEntry.from_tuple(value) | ||
if value.category not in self.categories: | ||
raise ValueError( | ||
"User specified loggable is not of an accepted category.") | ||
super().__setitem__(namespace, value) | ||
|
||
def __iadd__(self, obj): | ||
"""Add quantities from object or list of objects to logger. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cbkerr
only_default
doesn't really effect performance. It is just to prevent quantities that may not be commonly desired from automatically being added onLogger.__iadd__
andLogger.add
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see the documentation was completely misleading here... I think I meant show not slow...