Skip to content

Serialize

pyggdrasil.serialize.serialize_tree_to_dict(tree_root, *, serialize_data, naming=None)

Serializes a tree with data into a nested dictionary.

Parameters:

Name Type Description Default
tree_root TreeNode[NameType, DataType]

node representing the root of the tree to be serialized

required
serialize_data Callable[[DataType], Any]

function serializing a DataType object

required
naming Optional[_NamingConvention]

serialization naming conventions, non-default values are discouraged

None

Returns:

Type Description
DictSeralizedFormat

dictionary storing the tree in the format:

DictSeralizedFormat

{ "name": "Root name", "data": [serialized root.data], "children": [ { "name": "Child name", "data": [serialized child.data], "children": [ ... ] } ... ]

DictSeralizedFormat

}

pyggdrasil.serialize.deserialize_tree_from_dict(dct, *, deserialize_data, naming=None)

Creates tree from dictionary in the DictSerializedFormat.

Parameters:

Name Type Description Default
dct DictSeralizedFormat

dictionary to be read

required
deserialize_data Callable[[Any], DataType]

factory method creating DataType objects from dictionaries

required
naming Optional[_NamingConvention]

serialization naming conventions, non-default values are discouraged

None

Returns:

Type Description
TreeNode

root node to the generated tree

pyggdrasil.serialize.read_mcmc_samples(fullpath)

Reads in all MCMC samples from JSON file for a given run.

Parameters:

Name Type Description Default
fullpath Path

path to JSON file

required

Returns:

Type Description
list[MCMCSample]

MCMC sample

pyggdrasil.serialize.save_mcmc_sample(sample, out_fp)

Appends MCMC sample to JSON file.

Parameters:

Name Type Description Default
sample MCMCSample

MCMC sample to be saved

required
out_fp Path

path to JSON file

required

Returns:

Type Description
None

None

pyggdrasil.serialize.read_tree_node(fp)

Reads Json file to Tree object from disk.

Parameters:

Name Type Description Default
fp Path

directory to save tree to

required

pyggdrasil.serialize.save_tree_node(tree, output_fp)

Saves Tree object as dict /json to disk.

Parameters:

Name Type Description Default
tree TreeNode

Tree object to be saved

required
output_fp Path

directory to save tree to

required

Returns: None

pyggdrasil.serialize.save_metric_result(axis, result, out_fp, axis_name='iteration')

Appends metric result to JSON file.

pyggdrasil.serialize.read_metric_result(fullpath)

Reads in all metric results from JSON file for a given run.