-
Notifications
You must be signed in to change notification settings - Fork 194
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
Report usage using a richer configuration traversing protocol #3229
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d6378b5
Traverse configuration heirarchy to report more usage information
benclifford 8beeba1
move site count away from being a hard-coded parameter to being usage…
benclifford f21d88e
abstract away from requiring a DFK to support non-DFK users of parsl
benclifford 7253fc7
Merge branch 'master' into benc-usage-protocol
benclifford 3f9559e
Merge branch 'master' into benc-usage-protocol
benclifford a2fd7cd
fix typo
benclifford 831ffc7
Remove explicit utf-8 encoding selection in favour of default
benclifford b0f5b79
import inspect module in normal place
benclifford 9dbbca8
add return type annotations onto get_parsl_usage dispatched methods
benclifford File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import inspect | ||
|
||
from parsl.utils import RepresentationMixin | ||
|
||
from abc import abstractmethod | ||
from functools import singledispatch | ||
from typing import Any, List, Sequence | ||
|
||
|
||
# Traverse the configuration hierarchy, returning a JSON component | ||
# for each one. Configuration components which implement | ||
# RepresentationMixin will be in the right form for inspecting | ||
# object attributes. Configuration components which are lists or tuples | ||
# are traversed in sequence. Other types default to reporting no | ||
# usage information. | ||
|
||
@singledispatch | ||
def get_parsl_usage(obj) -> List[Any]: | ||
return [] | ||
|
||
|
||
@get_parsl_usage.register | ||
def get_parsl_usage_representation_mixin(obj: RepresentationMixin) -> List[Any]: | ||
t = type(obj) | ||
qualified_name = t.__module__ + "." + t.__name__ | ||
|
||
# me can contain anything that can be rendered as JSON | ||
me: List[Any] = [] | ||
|
||
if isinstance(obj, UsageInformation): | ||
# report rich usage information for this component | ||
attrs = {'c': qualified_name} | ||
attrs.update(obj.get_usage_information()) | ||
me = [attrs] | ||
else: | ||
# report the class name of this component | ||
me = [qualified_name] | ||
|
||
# unwrap typeguard-style unwrapping | ||
init: Any = type(obj).__init__ | ||
if hasattr(init, '__wrapped__'): | ||
init = init.__wrapped__ | ||
|
||
argspec = inspect.getfullargspec(init) | ||
|
||
for arg in argspec.args[1:]: # skip first arg, self | ||
arg_value = getattr(obj, arg) | ||
d = get_parsl_usage(arg_value) | ||
me += d | ||
|
||
return me | ||
|
||
|
||
@get_parsl_usage.register(list) | ||
@get_parsl_usage.register(tuple) | ||
def get_parsl_usage_sequence(obj: Sequence) -> List[Any]: | ||
result = [] | ||
for v in obj: | ||
result += get_parsl_usage(v) | ||
return result | ||
benclifford marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
class UsageInformation: | ||
@abstractmethod | ||
def get_usage_information(self) -> dict: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Stylistic alternative (but by no means a blocker):