-
Notifications
You must be signed in to change notification settings - Fork 62
Better interface for setParameters
#326
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
base: master
Are you sure you want to change the base?
Conversation
@syntron I think PR #314 is an improvement with respect to the current interface, but the interface from this PR is superior and I would suggest to implement it like this in all the set methods. It is the most natural way. For quick comparison: model.setParameters(['Name1=Value1', 'Name2=Value2', ...]) # Current interface (cumbersome, error prone, have to deal with conversion to strings, etc).
model.SetParameters(dict(Name1=Value1, Name2=Value2, ...)) # PR #314 (boilerplate `dict()`, other than that it is acceptable).
model.SetParameters(Name1=Value1, Name2=Value2, ...) # This PR (as good as it gets). I would also only keep the current interface with strings for backwards compatibility, and add a warning that it will be deprecated in the future. |
I see the dict based interface as preferable if lots of options are handled which are defined before as dictionary. My idea is to add an additional function which just translates the argument key based variant to the dict based version.
This is done in PR #314; I also prepared a commit which would remove the depreciated / old way of setting the options. |
The "normal Python interface" from this PR can naturally do that (if I understood correctly what you mean): parameters = {f'Name{i}': i**2 for i in range(999)} # 999 different parameters.
model.setParameters(**parameters) My advice is to keep it simple and to offer the user an interface he would expect in Python. Less maintenance and more user friendly. This is also the way it is done in many other packages, e.g. plot_settings = dict(color='green', marker='o', linestyle='dashed', linewidth=2, markersize=12)
plot(x, y, **plot_settings) |
@SengerM I learned something and will check this out - thanks for the explanation! |
Purpose
are more clean and natural than
It should be backwards compatible, meaning that it still accepts the strings.