Skip to content

Commit 04f3765

Browse files
committed
change hydra yaml syntax to better support overrides for node_definitions
1 parent 5f34658 commit 04f3765

3 files changed

Lines changed: 15 additions & 8 deletions

File tree

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,18 @@ dataflow:
6767
6868
# everything else is used to instantiate and spin the nodes with hydra
6969
node_definitions:
70-
- _target_: dora_utils.examples.chatter.talker.Talker
70+
talker: # <--- this name doesn't matter
71+
_target_: dora_utils.examples.chatter.talker.Talker
7172
node_id: talker
7273
max_workers: null
73-
- _target_: dora_utils.examples.chatter.listener.Listener
74+
listener: # <--- this name doesn't matter
75+
_target_: dora_utils.examples.chatter.listener.Listener
7476
node_id: listener
7577
max_workers: null
7678
override_msg: null
79+
7780
```
78-
Everything under the `dataflow` section is the "standard" `dora` dataflow, which defines the nodes, their IDs, their inputs/outputs, etc. Under `node_definitions` is a list of `hydra` targets, so you can instantiate arbitrarily complicated nodes using `hydra`'s composition API.
81+
Everything under the `dataflow` section is the "standard" `dora` dataflow, which defines the nodes, their IDs, their inputs/outputs, etc. Under `node_definitions` is a list of `hydra` targets, so you can instantiate arbitrarily complicated nodes using `hydra`'s composition API. Above, you'll see that there are comments saying "this name doesn't matter." We use this yaml syntax because we want to be able to use `hydra`'s configuration override syntax to preserve default values. Because lists are atomic in `hydra`, we can't override single list elements, so in any file that specifies another configuration file as a default, we would have to copy and paste the entire `node_definitions` section. When we instead structure things like a dictionary, overrides work!
7982

8083
If we run
8184
```bash
@@ -91,10 +94,12 @@ I heard Hello World from speech
9194
Now, if we modify `chatter.yaml` to instead show
9295
```
9396
node_definitions:
94-
- _target_: dora_utils.examples.chatter.talker.Talker
97+
talker:
98+
_target_: dora_utils.examples.chatter.talker.Talker
9599
node_id: talker
96100
max_workers: null
97-
- _target_: dora_utils.examples.chatter.listener.Listener
101+
listener:
102+
_target_: dora_utils.examples.chatter.listener.Listener
98103
node_id: listener
99104
max_workers: null
100105
override_msg: "override" # change this field for this example!

dora_utils/launch/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def run(cfg: DictConfig) -> None:
2828
process = subprocess.Popen(f"dora up && dora start {dataflow_path}", shell=True)
2929

3030
yaml_paths = []
31-
for node_cfg in cfg.node_definitions:
31+
for node_cfg in cfg.node_definitions.values():
3232
node_name = f"tmp_{node_cfg.node_id}"
3333
yaml_path = write_tmp(node_cfg, tmp_dir, node_name)
3434
subprocess.Popen(f"python {Path(__file__).parent}/_launch_node.py -cp {tmp_dir} -cn {node_name}", shell=True)

scripts/configs/chatter.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ dataflow:
1414

1515
# everything else is used to instantiate and spin the nodes with hydra
1616
node_definitions:
17-
- _target_: dora_utils.examples.chatter.talker.Talker
17+
talker:
18+
_target_: dora_utils.examples.chatter.talker.Talker
1819
node_id: talker
1920
max_workers: null
20-
- _target_: dora_utils.examples.chatter.listener.Listener
21+
listener:
22+
_target_: dora_utils.examples.chatter.listener.Listener
2123
node_id: listener
2224
max_workers: null
2325
override_msg: null

0 commit comments

Comments
 (0)