a2rl.save_metadata#
- a2rl.save_metadata(metadata, yaml_file, compact=False)[source]#
Save an in-memory metadata object into a YAML file.
- Parameters:
metadata (
Metadata
|MetadataDict
) – Metadata object.compact (
bool
) – When set to True, do not outputNone
entries.
- Return type:
See also
Examples
Save an in-memory metadata object.
>>> import a2rl as wi >>> m = wi.Metadata( ... states=["s", "t"], ... actions=["a"], ... rewards=["r"], ... tags={"k": "v"} ... ) >>> wi.save_metadata(m, "/tmp/metadata.yaml") >>> with open("/tmp/metadata.yaml") as f: ... print(''.join(f.readlines())) states: - s - t actions: - a rewards: - r forced_categories: null frequency: null tags: k: v
Save metadata in compact mode to exclude null items in the YAML output.
>>> wi.save_metadata(m, "/tmp/metadata.yaml", compact=True) >>> with open("/tmp/metadata.yaml") as f: ... print(''.join(f.readlines())) states: - s - t actions: - a rewards: - r tags: k: v
Save a dictionary. Be aware that the dictionary must specifies all the
Metadata
fields, including the default ones. If you prefer the flexibility to not re-declare the default fields, please useMetadata
instead.>>> d: wi.MetadataDict = { ... "states": ["s", "t"], ... "actions": ["a"], ... "rewards": ["r"], ... "forced_categories": ["a"], ... "frequency": None, ... "tags": {}, ... } >>> wi.save_metadata(d, "/tmp/metadata.yaml", compact=True) >>> with open("/tmp/metadata.yaml") as f: ... print(''.join(f.readlines())) states: - s - t actions: - a rewards: - r forced_categories: - a tags: {}