Skip to content

Support params as a dictionary. #68

@pavelkomarov

Description

@pavelkomarov

Right now parameters to the various methods are bubbled together into tuples, fed to each method as an argument, and unpacked there. This is for the purposes of iteration in the parameter optimization code, but packaging this way can be mildly confusing, because parameters are unlabeled and sensitive to ordering.

A neat feature of the python language is that you can give functions arguments and keyword arguments and then feed them with a tuple and a dictionary:

def method_of_choice(x, y, param1=1, param2=2, param3=3):
    print(x)
    print(y)
    print(param1)
    print(param2)
    print(param3)

>>>method_of_choice(*(10, 11))
10
11
1
2
3
>>>method_of_choice(*(1, 2, 3, 4, 5))
1
2
3
4
5
>>>method_of_choice(*(1, 2),**{'param1':5,'param2':6,'param3':8})
1
2
5
6
8

The * unpacks a list, and the ** unpacks a dictionary. So there is a ton of flexibility when calling methods. I propose exploiting this in the optimization code and elsewhere to call methods using labeled keyword arguments where possible. Backwards compatibility can be kept via the params list for now, with its presence overriding any default values set in kwargs, but I propose throwing a warning in that case to let users know they should prefer the kwargs in the future. Kwargs also allow us to set reasonable default parameter values, so users don't have to do as much thinking.

Metadata

Metadata

Assignees

Labels

simplificationunifying, shortening, and cleaning tasks that make the modules and user interface more cohesive

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions