Example #1
0
def test_tensordot_reorders_matrices():
    t = np.eye(4).reshape((2, 2, 2, 2))
    m = np.array([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0]).reshape((2, 2, 2, 2))

    np.testing.assert_allclose(targeted_tensordot(gate=m, wf=t, wf_target_inds=[0, 1]), m, atol=1e-8)

    np.testing.assert_allclose(
        targeted_tensordot(gate=m, wf=t, wf_target_inds=[1, 0]),
        np.array([1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0]).reshape((2, 2, 2, 2)),
        atol=1e-8,
    )
Example #2
0
def test_wfn_ordering_tensordot():
    h_mat = GATES["H"]
    two_q_wfn = np.zeros((2, 2), dtype=np.complex128)
    two_q_wfn[0, 0] = 1 + 0.0j
    two_q_wfn = targeted_tensordot(gate=h_mat,
                                   wf=two_q_wfn,
                                   wf_target_inds=[0])
    np.testing.assert_allclose(two_q_wfn[:, 0], 1 / np.sqrt(2) * np.ones(2))
Example #3
0
def test_H_tensordot():
    h_mat = GATES["H"]
    one_q_wfn = np.zeros((2, ), dtype=np.complex128)
    one_q_wfn[0] = 1 + 0.0j
    one_q_wfn = targeted_tensordot(gate=h_mat,
                                   wf=one_q_wfn,
                                   wf_target_inds=[0])
    np.testing.assert_allclose(one_q_wfn, 1 / np.sqrt(2) * np.ones(2))
Example #4
0
def test_tensordot_matches_kron_then_dot():
    t = np.array([1, 2, 3, 4, 5, 6, 7, 8])
    m = np.array([[2, 3], [5, 7]])
    i = np.eye(2)

    np.testing.assert_allclose(
        targeted_tensordot(m, t.reshape((2, 2, 2)), [0]),
        np.dot(kron(m, i, i), t).reshape((2, 2, 2)),
        atol=1e-8,
    )

    np.testing.assert_allclose(
        targeted_tensordot(m, t.reshape((2, 2, 2)), [1]),
        np.dot(kron(i, m, i), t).reshape((2, 2, 2)),
        atol=1e-8,
    )

    np.testing.assert_allclose(
        targeted_tensordot(m, t.reshape((2, 2, 2)), [2]),
        np.dot(kron(i, i, m), t).reshape((2, 2, 2)),
        atol=1e-8,
    )