def test_remove_duplicate_ops_not_affect_others():
    """
    Test remove duplicated ops doesn't affect other ops. We add another `add` op here, but keep
    the input to remove_ops only restricted to the first `add` op. This test is for checking that
    the second add op doesn't get removed.
    """

    @mb.program(input_specs=[mb.TensorSpec(shape=(2, 4))])
    def prog(x0):
        x1 = mb.add(x=x0, y=x0)
        x2 = mb.add(x=x0, y=x0)
        return x1, x2

    block = prog.functions["main"]
    x0 = block.inputs["x0"]
    ops = [block.find_ops(op_type="add")[0]]
    block.set_outputs([x0])
    block.remove_ops(ops)
    # Deleting one add operation should not affect the other one.
    assert len(block.operations) == 1
    assert len(block.inputs) == 1
    assert len(block.outputs) == 1

    Test remove duplicated ops doesn't affect other ops. We add another `add` op here, but keep
    the input to remove_ops only restricted to the first `add` op. This test is for checking that
    the second add op doesn't get removed.
    
coremltools/converters/mil/mil/tests/test_block.py