-
Notifications
You must be signed in to change notification settings - Fork 111
[Minor] Add kwargs to Plotting methods
#195
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
Conversation
matteobettini
left a comment
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.
Thanbks! Definitely useful.
I don't think the name difference is too much of a problem but worst case we can create a performance_profiles function that just calls performance_profile_figure
benchmarl/eval_results.py
Outdated
| **{ | ||
| "metric_name": Plotting.METRIC_TO_PLOT, | ||
| "metrics_to_normalize": Plotting.METRICS_TO_NORMALIZE, | ||
| "save_tabular_as_latex": True, | ||
| **kwargs, | ||
| } |
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.
I don't think we need to create a dict here, you can just add the kwargs
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.
It allows for overriding the parameters like metric_name or save_tabular_as_latex on a per-call basis.
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.
mmh then it would be better to have them as explicit args with defaults
def aggregate_scores(environment_comparison_matrix, metric_name=Plotting.METRIC_TO_PLOT, metrics_to_normalize=Plotting.METRICS_TO_NORMALIZE,save_tabular_as_latex=True, **kwargs):
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.
Yes sure. Since they are class attributes the above syntax won't work but something like that should do
@staticmethod
def aggregate_scores(environment_comparison_matrix, metric_name=None, metrics_to_normalize=None, **kwargs):
return aggregate_scores(
dictionary=environment_comparison_matrix,
metric_name=metric_name or Plotting.METRIC_TO_PLOT,
metrics_to_normalize=metrics_to_normalize or Plotting.METRICS_TO_NORMALIZE,
**kwargs,
)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.
class Ciao:
CIAO = "test"
@staticmethod
def test(stuff=CIAO):
print(stuff)
Ciao.test()testit is working for me, am I missing smth?
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.
Yes I was thinking about inheritance. But in fact what I did doesn't work either because we need classmethods.
The idea would be to do:
class CustomPlotting(Plotting):
METRICS_TO_NORMALIZE = ["custom_metric"]
METRIC_TO_PLOT = "custom_metric"I updated the PR. Maybe the PR name should also be updated to reflect this. Let me know what you think.
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.
Sorry I am not understanding. did you see the snippet in my previous comment? does it work for you?
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.
Sorry for not being clear. Yes I saw it and answered based on it.
If you have:
class Ciao:
CIAO = "test"
@staticmethod
def test(stuff=CIAO):
print(stuff)
class CusomCiao(Ciao):
CIAO = "custom"
Ciao.test()then the result will be test instead of custom. But it works with the following:
class Ciao:
CIAO = "test"
@classmethod
def test(cls):
print(cls.CIAO)
class CusomCiao(Ciao):
CIAO = "custom"
Ciao.test()|
Check the PR now, and let me know if it runs. I think this is the simplest way to have defaults |
Well, not really... It does answer the kwargs issue (so I'm happy with it), but inheritance of defaults won't work this way, as I mentioned here: #195 (comment). I am not sure to see the point of making a class if we can't use inheritance, but your call. Thanks anyway! |
|
Ah now I understand, you were planning in case someone were to extend the class. I don't think we need that kind of flexibility. This class is just a hook point to call the plotting library and only has static methods. if users want to change the class attributes (which should not be needed in benchmarl) they can edit them directly without any need to subclass. |
|
Gotcha, thanks! |
What does this PR do?
It simply adds a
kwargsargument to thePlottingmethods.Additionally
performance_profile_figureshould be renamedperformance_profiles> impact docs & static assetsLet me know if this is of interest.