You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Support List/Tuple/Dict of dataclasses via CLI, config files, and encode/decode
Add support for container-of-dataclass fields (List[DC], Tuple[DC, ...],
Dict[str, DC]) as first-class citizens. These can now be set from the
command line as YAML/JSON strings (e.g. --points '[{x: 1.0, y: 2.0}]'),
from config files, and via encode/decode. Deeply nested structures are
also supported.
- Add is_dict_of_dataclasses utility and wire it into DataclassWrapper
- Replace NotImplementedError with working FieldWrapper registration
- Add 78 tests covering encode/decode, config file, CLI, and deep nesting
- Document the feature in README, docs/step_by_step, and docs/api
- Bump version to 0.3.2
- Drop Python 3.6 support (bump to >=3.7, remove dataclasses backport)
- Update CI to Python 3.7-3.12, actions v4/v5
- Fix mutable default warnings in test fixtures
Copy file name to clipboardExpand all lines: README.md
+59Lines changed: 59 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -243,6 +243,65 @@ Training my_third_exp...
243
243
Saving to /share/experiments/my_third_exp
244
244
```
245
245
246
+
#### Lists and Dicts of Dataclasses 🐲
247
+
`pyrallis` also supports `List[Dataclass]`, `Tuple[Dataclass, ...]`, and `Dict[str, Dataclass]` fields. These can be set from a config file in the natural YAML structure, **or directly from the command line as a YAML/JSON string**:
The equivalent YAML config file uses the standard nested structure:
286
+
```yaml
287
+
datasets:
288
+
- path: /data/imagenet
289
+
split: train
290
+
- path: /data/coco
291
+
split: train
292
+
eval_sets:
293
+
imagenet_val:
294
+
path: /data/imagenet
295
+
split: val
296
+
coco_val:
297
+
path: /data/coco
298
+
split: val
299
+
```
300
+
301
+
This also works with deeply nested structures -- for example a `List[Dataclass]` where each dataclass itself contains a `Dict[str, Dataclass]` field, and so on.
302
+
303
+
> CLI args always take priority over the config file, so you can mix and match: load a base config from a file and override specific container fields on the command line.
304
+
246
305
### 🐲 5/5 Easy Serialization with `pyrallis.dump` 🐲
247
306
As your config get longer you will probably want to start working with configuration files. Pyrallis supports encoding a dataclass configuration into a `yaml` file 💾
Collections can also contain dataclass types. `#!python typing.List[SomeDataclass]`, `#!python typing.Tuple[SomeDataclass, ...]`, and `#!python typing.Dict[str, SomeDataclass]` are all supported. From the command line these are passed as YAML/JSON strings:
Copy file name to clipboardExpand all lines: docs/step_by_step.md
+59Lines changed: 59 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -172,6 +172,65 @@ Training my_third_exp...
172
172
Saving to /share/experiments/my_third_exp
173
173
```
174
174
175
+
## Lists and Dicts of Dataclasses
176
+
`pyrallis` also supports `List[Dataclass]`, `Tuple[Dataclass, ...]`, and `Dict[str, Dataclass]` fields. These can be set from a config file in the natural YAML structure, **or directly from the command line as a YAML/JSON string**:
The equivalent YAML config file uses the standard nested structure:
215
+
```yaml
216
+
datasets:
217
+
- path: /data/imagenet
218
+
split: train
219
+
- path: /data/coco
220
+
split: train
221
+
eval_sets:
222
+
imagenet_val:
223
+
path: /data/imagenet
224
+
split: val
225
+
coco_val:
226
+
path: /data/coco
227
+
split: val
228
+
```
229
+
230
+
This also works with deeply nested structures -- for example a `List[Dataclass]` where each dataclass itself contains a `Dict[str, Dataclass]` field, and so on.
231
+
232
+
> CLI args always take priority over the config file, so you can mix and match: load a base config from a file and override specific container fields on the command line.
233
+
175
234
## Easy Serialization
176
235
As your config get longer you will probably want to start working with configuration files. Pyrallis supports encoding a dataclass configuration into a `yaml` file 💾
0 commit comments