Esempio n. 1
0
def test_weights_and_exponent(weights):
    exponents = numpy.linspace(-1, 1, 8)
    gates = tuple(
        ofc.CombinedDoubleExcitationGate(weights / exponent, exponent=exponent)
        for exponent in exponents)

    for g1 in gates:
        for g2 in gates:
            assert cirq.approx_eq(g1, g2, atol=1e-100)

    for i, (gate, exponent) in enumerate(zip(gates, exponents)):
        assert gate.exponent == 1
        new_exponent = exponents[-i]
        new_gate = gate._with_exponent(new_exponent)
        assert new_gate.exponent == new_exponent
Esempio n. 2
0
def test_combined_double_excitation_gate_text_diagram():
    gate = ofc.CombinedDoubleExcitationGate((1, 1, 1))
    qubits = cirq.LineQubit.range(6)
    circuit = cirq.Circuit.from_ops([gate(*qubits[:4]), gate(*qubits[-4:])])

    actual_text_diagram = circuit.to_text_diagram()
    expected_text_diagram = """
0: ───⇊⇈────────
      │
1: ───⇊⇈────────
      │
2: ───⇊⇈───⇊⇈───
      │    │
3: ───⇊⇈───⇊⇈───
           │
4: ────────⇊⇈───
           │
5: ────────⇊⇈───
    """.strip()
    assert actual_text_diagram == expected_text_diagram

    actual_text_diagram = circuit.to_text_diagram(use_unicode_characters=False)
    expected_text_diagram = """
0: ---a*a*aa------------
      |
1: ---a*a*aa------------
      |
2: ---a*a*aa---a*a*aa---
      |        |
3: ---a*a*aa---a*a*aa---
               |
4: ------------a*a*aa---
               |
5: ------------a*a*aa---
    """.strip()
    assert actual_text_diagram == expected_text_diagram
Esempio n. 3
0
def test_combined_double_excitation_consistency():
    ofc.testing.assert_implements_consistent_protocols(
        ofc.CombinedDoubleExcitationGate())
Esempio n. 4
0
def test_combined_double_excitation_decompose(weights):
    cirq.testing.assert_decompose_is_consistent_with_unitary(
        ofc.CombinedDoubleExcitationGate(weights))
Esempio n. 5
0
def test_combined_double_excitation_eq():
    eq = cirq.testing.EqualsTester()

    eq.add_equality_group(
        ofc.CombinedDoubleExcitationGate((1.2, 0.4, -0.4), exponent=0.5),
        ofc.CombinedDoubleExcitationGate((0.3, 0.1, -0.1), exponent=2),
        ofc.CombinedDoubleExcitationGate((-0.6, -0.2, 0.2), exponent=-1),
        ofc.CombinedDoubleExcitationGate((0.6, 0.2, 3.8)),
        ofc.CombinedDoubleExcitationGate((1.2, 0.4, -0.4),
                                         rads=0.5 * numpy.pi),
        ofc.CombinedDoubleExcitationGate((1.2, 0.4, -0.4), degs=90),
        ofc.CombinedDoubleExcitationGate((1.2, 0.4, -0.4),
                                         duration=0.5 * numpy.pi / 2))

    eq.add_equality_group(
        ofc.CombinedDoubleExcitationGate((-0.6, 0.0, 0.3), exponent=0.5),
        ofc.CombinedDoubleExcitationGate((-0.6, 0.0, 0.3),
                                         rads=0.5 * numpy.pi),
        ofc.CombinedDoubleExcitationGate((-0.6, 0.0, 0.3), degs=90))

    eq.make_equality_group(lambda: ofc.CombinedDoubleExcitationGate(
        (0.1, -0.3, 0.0), exponent=0.0))
    eq.make_equality_group(lambda: ofc.CombinedDoubleExcitationGate(
        (1., -1., 0.5), exponent=0.75))
Esempio n. 6
0
def test_combined_double_excitation_init_with_multiple_args_fails():
    with pytest.raises(ValueError):
        _ = ofc.CombinedDoubleExcitationGate((1, 1, 1),
                                             exponent=1.0,
                                             duration=numpy.pi / 2)
Esempio n. 7
0
         -1, 0.5 + 1j * numpy.sqrt(3), 1j, -1j, -1
     ]) / 4., 5e-6),
    (ofc.DoubleExcitation, 0,
     numpy.array([1, -1, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) / 4.,
     numpy.array([1, -1, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) / 4.,
     5e-6),
    (ofc.DoubleExcitation, 0.25,
     numpy.array([1, 0, 0, -2, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 1]) /
     numpy.sqrt(15),
     numpy.array([
         1, 0, 0, +3j / numpy.sqrt(2) - numpy.sqrt(2), 0, 0, 0, 0, 0, 0, 0, 0,
         3 / numpy.sqrt(2) - 1j * numpy.sqrt(2), 0, 0, 1
     ]) / numpy.sqrt(15), 5e-6)
]
combined_double_excitation_simulator_test_cases = [
    (ofc.CombinedDoubleExcitationGate(
        (0, 0, 0)), 1., numpy.ones(16) / 4., numpy.ones(16) / 4., 5e-6),
    (ofc.CombinedDoubleExcitationGate((0.2, -0.1, 0.7)), 0.,
     numpy.array([1, -1, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) / 4.,
     numpy.array([1, -1, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) / 4.,
     5e-6),
    (ofc.CombinedDoubleExcitationGate((0.2, -0.1, 0.7)), 0.3,
     numpy.array([1, -1, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) / 4.,
     numpy.array([
         1, -1, -1, -numpy.exp(-numpy.pi * 0.105j), -1,
         -numpy.exp(-numpy.pi * 0.585j),
         numpy.exp(numpy.pi * 0.03j), 1, 1,
         numpy.exp(numpy.pi * 0.03j),
         numpy.exp(-numpy.pi * 0.585j), 1,
         numpy.exp(-numpy.pi * 0.105j), 1, 1, 1
     ]) / 4., 5e-6),
    (ofc.CombinedDoubleExcitationGate((1. / 3, 0, 0)), 1.,