hydra-zen
hydra-zen copied to clipboard
Allow dictionary for overrides in `launch`
Currently launch
requires overrides to be a list of strings of type param=value
.
This PR allows the user to provide a dictionary as an override: {param: val, ...}
. Where param
is a string and val
can be one of int
, float
, str
, and bool
along with with two special types:
-
hydra_list
: A list type supported by Hydra, e.g.,hydra_list([1,2,3]) -> "[1,2,3]"
-
multirun
: A list that will be converted into a Hydra multirun value, e.g.,multirun([1,2,3]) -> "1,2,3"
Override Types
override_primitive_examples = {
"str": "\(1,2\)", # --> "\(1,2\)" (no change)
"NULL": None, # --> "null"
"int": 10, # --> "10"
"float" 3.14, # --> "3.14"
"bool": True, # --> "True"
"list": hydra_list([1, 2, 3]), # --> "[1, 2, 3]"
"multirun_list": multirun([1, 2, 3]) # --> "1,2,3"
}
Example of multirun
The use of the multirun
type is what really makes this PR special. With the current overrides
structure a user must create the string that contains the list of values to multirun overview.
import random
from hydra_zen import launch, instantiate, make_config
values_for_experiment = [random.uniform(0, 1) for i in range(10)]
ov = []
jobs = launch(
make_config(),
instantiate,
overrides=[
"+param=" + ",".join([str(i) for i in values_for_experiment])
],
multirun=True
)
This PR allows the user to provide the multirun value without having to create the string:
import random
from hydra_zen import launch, instantiate, make_config, multirun
values_for_experiment = [random.uniform(0, 1) for i in range(10)]
jobs = launch(
make_config(),
instantiate,
overrides={
"+param": multirun(values_for_experiment)
},
multirun=True
)
TODO:
- [ ] Update this PR description
- [ ] Add
null
support in supported types - [ ] Test configs are the same for list of strings and dictionary
- [ ] Update docstrings
- [ ] Update docs