Пример #1
0
def test_init_from_double_map_vs_kwargs(trans1, trans2, from1):
    from2 = from1 + 1
    from1_str, from2_str = (str(frm).lower() + '_to' for frm in (from1, from2))
    gate_kw = CliffordGate.from_double_map(**{
        from1_str: trans1,
        from2_str: trans2
    })
    gate_map = CliffordGate.from_double_map({from1: trans1, from2: trans2})
    # Test initializes the same gate
    assert gate_kw == gate_map
Пример #2
0
def test_init_invalid():
    with pytest.raises(ValueError):
        CliffordGate.from_single_map()
    with pytest.raises(ValueError):
        CliffordGate.from_single_map({})
    with pytest.raises(ValueError):
        CliffordGate.from_single_map({Pauli.X: (Pauli.X, False)},
                                     y_to=(Pauli.Y, False))
    with pytest.raises(ValueError):
        CliffordGate.from_single_map({
            Pauli.X: (Pauli.X, False),
            Pauli.Y: (Pauli.Y, False)
        })
    with pytest.raises(ValueError):
        CliffordGate.from_double_map()
    with pytest.raises(ValueError):
        CliffordGate.from_double_map({})
    with pytest.raises(ValueError):
        CliffordGate.from_double_map({Pauli.X: (Pauli.X, False)})
    with pytest.raises(ValueError):
        CliffordGate.from_double_map(x_to=(Pauli.X, False))
    with pytest.raises(ValueError):
        CliffordGate.from_single_map({
            Pauli.X: (Pauli.Y, False),
            Pauli.Y: (Pauli.Z, False),
            Pauli.Z: (Pauli.X, False)
        })
    with pytest.raises(ValueError):
        CliffordGate.from_single_map({
            Pauli.X: (Pauli.X, False),
            Pauli.Y: (Pauli.X, False)
        })
Пример #3
0
def test_pass_operations_over_single(shift, t_or_f):
    q0, q1 = _make_qubits(2)
    X, Y, Z = (pauli + shift for pauli in Pauli.XYZ)

    op0 = CliffordGate.from_pauli(Y)(q1)
    ps_before = PauliString({q0: X}, t_or_f)
    ps_after = ps_before
    _assert_pass_over([op0], ps_before, ps_after)

    op0 = CliffordGate.from_pauli(X)(q0)
    op1 = CliffordGate.from_pauli(Y)(q1)
    ps_before = PauliString({q0: X, q1: Y}, t_or_f)
    ps_after = ps_before
    _assert_pass_over([op0, op1], ps_before, ps_after)

    op0 = CliffordGate.from_double_map({Z: (X, False), X: (Z, False)})(q0)
    ps_before = PauliString({q0: X, q1: Y}, t_or_f)
    ps_after = PauliString({q0: Z, q1: Y}, t_or_f)
    _assert_pass_over([op0], ps_before, ps_after)

    op1 = CliffordGate.from_pauli(X)(q1)
    ps_before = PauliString({q0: X, q1: Y}, t_or_f)
    ps_after = ps_before.negate()
    _assert_pass_over([op1], ps_before, ps_after)

    ps_after = PauliString({q0: Z, q1: Y}, not t_or_f)
    _assert_pass_over([op0, op1], ps_before, ps_after)
Пример #4
0
def test_init_from_double(trans1, trans2, from1):
    from2 = from1 + 1
    gate = CliffordGate.from_double_map({from1: trans1, from2: trans2})
    # Test initializes what was expected
    assert gate.transform(from1) == trans1
    assert gate.transform(from2) == trans2
    _assert_not_mirror(gate)
    _assert_no_collision(gate)
Пример #5
0
def test_init_from_double_invalid(trans1, trans2, from1):
    from2 = from1 + 1
    # Test throws on invalid arguments
    with pytest.raises(ValueError):
        CliffordGate.from_double_map({from1: trans1, from2: trans2})