def test_deserialize_node(generate_root, simple_actions, mock_policy, default_config): serializer = MoleculeSerializer() root = generate_root("CCCCOc1ccc(CC(=O)N(C)O)cc1") action_list, prior_list = mock_policy(root.state.mols[0]) root.expand() child = root.promising_child() node_serialized = root.serialize(serializer) deserializer = MoleculeDeserializer(serializer.store) root_new = Node.from_dict(node_serialized, None, default_config, deserializer) assert len(root_new.children()) == 1 new_child = root_new.children()[0] assert root_new.children_view()["values"] == root.children_view()["values"] assert root_new.children_view()["priors"] == root.children_view()["priors"] assert ( root_new.children_view()["visitations"] == root.children_view()["visitations"] ) assert root_new.is_expanded assert new_child.children_view()["values"] == child.children_view()["values"] assert new_child.children_view()["priors"] == child.children_view()["priors"] assert ( new_child.children_view()["visitations"] == child.children_view()["visitations"] ) assert not new_child.is_expanded assert str(root_new.state) == str(root.state) assert str(new_child.state) == str(child.state)
def from_json(cls, filename: str, config: Configuration) -> "SearchTree": """ Create a new search tree by deserialization from a JSON file :param filename: the path to the JSON node :param config: the configuration of the search :return: a deserialized tree """ tree = SearchTree(config) with open(filename, "r") as fileobj: dict_ = json.load(fileobj) mol_deser = MoleculeDeserializer(dict_["molecules"]) tree.root = Node.from_dict(dict_["tree"], tree, config, mol_deser) return tree