def test_already_converted():
    q0 = cirq.LineQubit(0)
    circuit = cirq.Circuit(cirq.PauliStringPhasor(cirq.X.on(q0)))
    c_orig = cirq.Circuit(circuit)
    ConvertToPauliStringPhasors().optimize_circuit(circuit)

    assert circuit == c_orig
Пример #2
0
def test_fail_unsupported_gate():
    class UnsupportedDummy(cirq.Gate):
        pass

    q0, q1 = cirq.LineQubit.range(2)
    circuit = cirq.Circuit.from_ops(UnsupportedDummy()(q0, q1), )
    with pytest.raises(TypeError):
        ConvertToPauliStringPhasors().optimize_circuit(circuit)
Пример #3
0
def test_already_converted():
    q0 = cirq.LineQubit(0)
    circuit = cirq.Circuit.from_ops(
        PauliStringPhasor(cirq.PauliString.from_single(q0, cirq.Pauli.X)), )
    c_orig = cirq.Circuit(circuit)
    ConvertToPauliStringPhasors().optimize_circuit(circuit)

    assert circuit == c_orig
Пример #4
0
def test_ignore_unsupported_gate():
    class UnsupportedDummy(cirq.Gate):
        pass

    q0, q1 = cirq.LineQubit.range(2)
    circuit = cirq.Circuit.from_ops(UnsupportedDummy()(q0, q1), )
    c_orig = cirq.Circuit(circuit)
    ConvertToPauliStringPhasors(ignore_failures=True).optimize_circuit(circuit)

    assert circuit == c_orig
def test_convert():
    q0, q1 = cirq.LineQubit.range(2)
    circuit = cirq.Circuit(cirq.X(q0), cirq.Y(q1) ** 0.25, cirq.Z(q0) ** 0.125, cirq.H(q1))
    c_orig = cirq.Circuit(circuit)
    ConvertToPauliStringPhasors().optimize_circuit(circuit)

    cirq.testing.assert_allclose_up_to_global_phase(circuit.unitary(), c_orig.unitary(), atol=1e-7)
    cirq.testing.assert_has_diagram(
        circuit,
        """
0: ───[X]────────[Z]^(1/8)─────────

1: ───[Y]^0.25───[Y]^-0.5────[Z]───
""",
    )
Пример #6
0
def test_convert():
    q0, q1 = cirq.LineQubit.range(2)
    circuit = cirq.Circuit.from_ops(
        cirq.X(q0),
        cirq.Y(q1)**0.25,
        cirq.Z(q0)**0.125,
        cirq.H(q1),
    )
    c_orig = cirq.Circuit(circuit)
    ConvertToPauliStringPhasors().optimize_circuit(circuit)

    cirq.testing.assert_allclose_up_to_global_phase(
        circuit.to_unitary_matrix(), c_orig.to_unitary_matrix(), atol=1e-7)
    assert circuit.to_text_diagram() == """
0: ───[X]────────[Z]^0.125─────────

1: ───[Y]^0.25───[Y]^-0.5────[Z]───
""".strip()
def test_convert_keep_clifford():
    q0, q1 = cirq.LineQubit.range(2)
    circuit = cirq.Circuit(
        cirq.X(q0),
        cirq.Y(q1)**0.25,
        cirq.Z(q0)**0.125,
        cirq.SingleQubitCliffordGate.H(q1),
    )
    c_orig = cirq.Circuit(circuit)
    ConvertToPauliStringPhasors(keep_clifford=True).optimize_circuit(circuit)

    cirq.testing.assert_allclose_up_to_global_phase(circuit.unitary(),
                                                    c_orig.unitary(),
                                                    atol=1e-7)
    cirq.testing.assert_has_diagram(circuit, """
0: ───X──────────[Z]^(1/8)───

1: ───[Y]^0.25───H───────────
""")