def test_duplicate_outputs_substituion():
    """Replaces var that appears more than once in outputs."""
    @mb.program(input_specs=[mb.TensorSpec(shape=(2, 4)), mb.TensorSpec(shape=(2, 4))])
    def prog(x0, y0):
        x1 = mb.add(x=x0, y=y0)
        z = mb.log(x=x1)
        return x1, x1, z

    block = prog.functions["main"]
    add = block.find_ops(op_type="add")[0]
    x0 = add.inputs["x"]
    y0 = add.inputs["y"]
    x1 = add.outputs[0]

    with block:
        x2 = mb.mul(x=x0, y=y0, before_op=add, name="new_output")

    block.replace_uses_of_var_after_op(anchor_op=x2.op, old_var=x1, new_var=x2)
    block.remove_ops([add])
    assert block.outputs[0].op.name == "new_output"
    assert block.outputs[1].op.name == "new_output"
    assert len(block.outputs[0].consuming_blocks) == 1
Replaces var that appears more than once in outputs.
coremltools/converters/mil/mil/tests/test_block.py