不可追踪的对象属性

Untrackable object attribute

我正在尝试在此处调整此代码:https://github.com/nachonavarro/gabes/blob/master/gabes/circuit.py(第 136 行) 但是我遇到了一个问题,因为属性 .chosen_label 被多次使用,但我在代码中的任何地方都找不到它。对象 left_gateright_gategate 是门对象 (https://github.com/nachonavarro/gabes/blob/master/gabes/gate.py)

def reconstruct(self, labels):
    levels = [[node for node in children]
              for children in anytree.LevelOrderGroupIter(self.tree)][::-1]
    for level in levels:
        for node in level:
            gate = node.name
            if node.is_leaf:
                garblers_label = labels.pop(0)
                evaluators_label = labels.pop(0)
            else:
                left_gate = node.children[0].name
                right_gate = node.children[1].name
                garblers_label = left_gate.chosen_label
                evaluators_label = right_gate.chosen_label
            output_label = gate.ungarble(garblers_label, evaluators_label)
            gate.chosen_label = output_label
    return self.tree.name.chosen_label

代码运行没有错误,.chosen_label 是一个 Label 对象 (https://github.com/nachonavarro/gabes/blob/master/gabes/label.py)

如有任何帮助,我们将不胜感激

属性设置同样的方法:

for level in levels:
    for node in level:
        gate = node.name
        if node.is_leaf:
            # set `garblers_label` and `evaluators_label` from 
            # the next two elements of the `labels` argument 
        else:
            # use the child nodes of this node to use their gates, and
            # set `garblers_label` and `evaluators_label` to the  left and
            # right `chosen_label` values, respectively.
        # generate the `Label()` instance based on `garblers_label` and `evaluators_label`
        output_label = gate.ungarble(garblers_label, evaluators_label)
        gate.chosen_label = output_label

我不熟悉 anytree 库,所以我不得不查找文档:anytree.LevelOrderGroupIter(...) function 将树中的节点从根到叶排序,按级别分组。这里的树看起来是一棵平衡二叉树(每个节点有 0 个或 2 个子节点),所以你得到一个 [(rootnode,), (level1_left, level1_right), (level2_left_left, level2_left_right, level2_right_left, level2_right_right), ...] 的列表。该函数以相反的顺序循环遍历这些级别。这意味着 叶被处理 首先 .

一旦所有 node.is_leaf 节点都设置了 chosen_label,其他非叶节点可以引用在它们之前已处理的级别上的叶节点上的 chosen_label 值。

因此,假设 labels 是一个列表,其叶节点数至少是树中叶节点数的两倍,您最终会通过 gate.ungarble() 函数在每个级别聚合这些标签值,最终值通过 self.tree.name.chosen_label.

在根节点找到