示例#1
0
def test_einsum_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_einsum(gate=m, wf=t, wf_target_inds=[0, 1]), m, atol=1e-8)

    np.testing.assert_allclose(
        targeted_einsum(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,
    )
示例#2
0
def test_einsum_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_einsum(gate=m, wf=t.reshape((2, 2, 2)), wf_target_inds=[0]),
        np.dot(kron(m, i, i), t).reshape((2, 2, 2)),
        atol=1e-8,
    )

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

    np.testing.assert_allclose(
        targeted_einsum(gate=m, wf=t.reshape((2, 2, 2)), wf_target_inds=[2]),
        np.dot(kron(i, i, m), t).reshape((2, 2, 2)),
        atol=1e-8,
    )
示例#3
0
def test_wfn_ordering_einsum():
    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_einsum(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))
示例#4
0
def test_H_einsum():
    h_mat = GATES["H"]
    one_q_wfn = np.zeros((2, ), dtype=np.complex128)
    one_q_wfn[0] = 1 + 0.0j
    one_q_wfn = targeted_einsum(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))