Пример #1
0
def test_iswap_matrix():
    cirq.testing.assert_allclose_up_to_global_phase(cirq.ISwapGate().matrix(),
                                                    np.array([[1, 0, 0, 0],
                                                              [0, 0, 1j, 0],
                                                              [0, 1j, 0, 0],
                                                              [0, 0, 0, 1]]),
                                                    atol=1e-8)
Пример #2
0
def test_iswap_decompose():
    a = cirq.NamedQubit('a')
    b = cirq.NamedQubit('b')

    original = cirq.ISwapGate(exponent=0.5)
    decomposed = cirq.Circuit.from_ops(original.default_decompose([a, b]))

    cirq.testing.assert_allclose_up_to_global_phase(
        original.matrix(), decomposed.to_unitary_matrix(), atol=1e-8)

    assert decomposed.to_text_diagram() == """
a: ───@───H───X───T───X───T^-1───H───@───
      │       │       │              │
b: ───X───────@───────@──────────────X───
    """.strip()
Пример #3
0
def fermi_fourier_trans_2(p: cirq.QubitId, q: cirq.QubitId) -> cirq.OP_TREE:
    """The 2-mode fermionic Fourier transformation can be implemented
    straightforwardly by the √iSWAP gate. The √iSWAP gate can be readily
    implemented with the gmon qubits using the XX + YY Hamiltonian. The matrix
    representation of the 2-qubit fermionic Fourier transformation is:
    [1  0      0      0],
    [0  1/√2   1/√2   0],
    [0  1/√2  -1/√2   0],
    [0  0      0     -1]
    The square root of the iSWAP gate is:
    [1, 0, 0, 0],
    [0, 0.5 + 0.5j, 0.5 - 0.5j, 0],
    [0, 0.5 - 0.5j, 0.5 + 0.5j, 0],
    [0, 0, 0, 1]

    Args:
        p: the id of the first qubit
        q: the id of the second qubit
    """

    yield cirq.Z(p)**1.5
    yield cirq.ISwapGate(exponent=0.5).on(q, p)
    yield cirq.Z(p)**1.5
Пример #4
0
def bogoliubov_trans(p, q, theta):
    """The 2-mode Bogoliubov transformation is mapped to two-qubit operations.
     We use the identity X S^\dag X S X = Y X S^\dag Y S X = X to transform
     the Hamiltonian XY+YX to XX+YY type. The time evolution of the XX + YY
     Hamiltonian can be expressed as a power of the iSWAP gate.

    Args:
        p: the first qubit
        q: the second qubit
        theta: The rotational angle that specifies the Bogoliubov
        transformation, which is a function of the kinetic energy and
        the superconducting gap.
    """

    # The iSWAP gate corresponds to evolve under the Hamiltonian XX+YY for
    # time -pi/4.
    expo = -4 * theta / np.pi

    yield cirq.X(p)
    yield cirq.S(p)
    yield cirq.ISwapGate(exponent=expo).on(p, q)
    yield cirq.S(p)**1.5
    yield cirq.X(p)