def update_children_parents()

in src/lic/ppl/world/world.py [0:0]


    def update_children_parents(self, node: RVIdentifier):
        """
        Update the parents that the child no longer depends on.

        :param node: the node whose parents are being evaluated.
        """
        for child in self.diff_stack_.get_node_raise_error(node).children.copy():
            if not self.variables_.contains_node(child):
                continue

            new_child_var = self.diff_stack_.get_node(child)
            old_child_var = self.get_node_earlier_version(child)
            if not new_child_var or not old_child_var:
                continue
            new_parents = new_child_var.parent
            old_parents = old_child_var.parent if old_child_var is not None else set()

            dropped_parents = old_parents - new_parents
            for parent in dropped_parents:
                # parent node variable may need to be added to the latest
                # diff, so we may need to call get_node_in_world with
                # to_create_new_diff = True.
                parent_var = self.get_node_in_world(
                    parent, to_create_new_diff=not self.diff_.contains_node(parent)
                )
                # pyre-fixme
                if not parent_var and child not in parent_var.children:
                    continue
                parent_var.children.remove(child)
                if len(parent_var.children) != 0 or parent in self.observations_:
                    continue

                self.diff_stack_.mark_for_delete(parent)
                self.diff_stack_.update_log_prob(
                    -1 * self.variables_.get_node_raise_error(parent).log_prob
                )

                # pyre-fixme[16]: `Optional` has no attribute `parent`.
                ancestors = [(parent, x) for x in parent_var.parent]
                while len(ancestors) > 0:
                    ancestor_child, ancestor = ancestors.pop(0)
                    # ancestor node variable may need to be added to the latest
                    # diff, so we may need to call get_node_in_world with
                    # to_create_new_diff = True.
                    ancestor_var = self.get_node_in_world(
                        ancestor,
                        to_create_new_diff=not self.diff_.contains_node(ancestor),
                    )
                    if ancestor_var is None:
                        continue
                    ancestor_var.children.remove(ancestor_child)
                    if (
                        len(ancestor_var.children) == 0
                        and ancestor not in self.observations_
                    ):
                        self.diff_stack_.mark_for_delete(ancestor)
                        self.diff_stack_.update_log_prob(
                            -1 * self.variables_.get_node_raise_error(ancestor).log_prob
                        )
                        ancestors.extend([(ancestor, x) for x in ancestor_var.parent])