Beispiel #1
0
def test_remove_redundant_acquaintance_opportunities():
    a, b, c, d, e = cirq.LineQubit.range(5)
    swap = cca.SwapPermutationGate()

    ops = [cca.acquaint(a, b), cca.acquaint(a, b)]
    strategy = cirq.Circuit(ops)
    diagram_before = """
0: ───█───█───
      │   │
1: ───█───█───
    """
    ct.assert_has_diagram(strategy, diagram_before)
    cca.remove_redundant_acquaintance_opportunities(strategy)
    diagram_after = """
0: ───█───────
      │
1: ───█───────
    """
    ct.assert_has_diagram(strategy, diagram_after)

    ops = [
        cca.acquaint(a, b),
        cca.acquaint(c, d),
        swap(d, e),
        swap(c, d),
        cca.acquaint(d, e)
    ]
    strategy = cirq.Circuit(ops)
    diagram_before = """
0: ───█───────────────────
      │
1: ───█───────────────────

2: ───█─────────0↦1───────
      │         │
3: ───█───0↦1───1↦0───█───
          │           │
4: ───────1↦0─────────█───
    """
    ct.assert_has_diagram(strategy, diagram_before)
    cca.remove_redundant_acquaintance_opportunities(strategy)
    diagram_after = """
0: ───█───────────────────
      │
1: ───█───────────────────

2: ───█─────────0↦1───────
      │         │
3: ───█───0↦1───1↦0───────
          │
4: ───────1↦0─────────────
    """
    ct.assert_has_diagram(strategy, diagram_after)
Beispiel #2
0
def test_remove_redundant_acquaintance_opportunities():
    device = cca.UnconstrainedAcquaintanceDevice
    a, b, c, d, e = cirq.LineQubit.range(5)
    swap = cca.SwapPermutationGate()

    with pytest.raises(TypeError):
        ops = [cca.acquaint(a, b)]
        strategy = cirq.Circuit.from_ops(ops)
        cca.remove_redundant_acquaintance_opportunities(strategy)

    ops = [cca.acquaint(a, b), cca.acquaint(a, b)]
    strategy = cirq.Circuit.from_ops(ops, device=device)
    diagram_before = """
0: ───█───█───
      │   │
1: ───█───█───
    """
    ct.assert_has_diagram(strategy, diagram_before)
    cca.remove_redundant_acquaintance_opportunities(strategy)
    cca.remove_redundant_acquaintance_opportunities(strategy)
    diagram_after = """
0: ───█───────
      │
1: ───█───────
    """
    ct.assert_has_diagram(strategy, diagram_after)

    ops = [
        cca.acquaint(a, b),
        cca.acquaint(c, d),
        swap(d, e),
        swap(c, d),
        cca.acquaint(d, e)
    ]
    strategy = cirq.Circuit.from_ops(ops, device=device)
    diagram_before = """
0: ───█───────────────────
      │
1: ───█───────────────────

2: ───█─────────0↦1───────
      │         │
3: ───█───0↦1───1↦0───█───
          │           │
4: ───────1↦0─────────█───
    """
    ct.assert_has_diagram(strategy, diagram_before)
    cca.remove_redundant_acquaintance_opportunities(strategy)
    diagram_after = """
0: ───█───────────────────
      │
1: ───█───────────────────

2: ───█─────────0↦1───────
      │         │
3: ───█───0↦1───1↦0───────
          │
4: ───────1↦0─────────────
    """
    ct.assert_has_diagram(strategy, diagram_after)