def test_projected_entropy(self): Y = 13 N = 21 L = aux.lfy(N) k = L number_of_qubits = k + L proj_state = construct_modular_state(k, L, aux.nonzeros_decimal( k, Y, N)).toarray().flatten() state = np.zeros(2**(3 * L)) state[:2**(k + L)] = proj_state.flatten() tries = 100 for i in range(tries): chosen_qubits = random_bipartition(range(number_of_qubits), number_of_qubits // 2) proj_entr = entanglement_entropy_from_state(proj_state, chosen_qubits, sparse=False, gpu=False) entr = entanglement_entropy_from_state(state, chosen_qubits, sparse=False, gpu=False) np.testing.assert_almost_equal(proj_entr, entr)
def test_svd_eigvals(self): Y = 13 numb = [21, 33, 66] tries = 50 for N in numb: eigval_entr = [] svd_entr = [] L = aux.lfy(N) k = 2 * L number_of_qubits = k + L state = construct_modular_state(k, L, aux.nonzeros_decimal( k, Y, N)).toarray().flatten() chosens = [ random_bipartition(range(number_of_qubits), number_of_qubits // 2) for i in range(tries) ] for i in range(tries): chosen = chosens[i] notchosen = bip.notchosen(chosen, k + L) W = W_from_state_numba(state, chosen, notchosen) sv = numpysvd(W, compute_uv=False) sv2 = sv**2 sv2[sv2 < 1e-15] = 1 svd_entr.append(np.sum(sv2 * np.log2(sv2))) l = np.linalg.eigvalsh(W.dot(W.T)) l[l < 1e-15] = 1 eigval_entr.append(np.sum(l * np.log2(l))) np.testing.assert_array_almost_equal(eigval_entr, svd_entr, decimal=12)
def test_sparse_entropy_equal_qiskit(self): N = 33 Y = aux.coprime(N) L = aux.lfy(N) k = 2 * L number_of_qubits = k + L nonzeros_decimal = aux.nonzeros_decimal(k, N, Y) state = construct_modular_state(k, L, nonzeros_decimal) tries = 200 for i in range(tries): chosen = random_bipartition(range(number_of_qubits), number_of_qubits // 2) notchosen = bip.notchosen(chosen, number_of_qubits) state_entropy = entanglement_entropy_from_state(state, chosen, sparse=True) qentropy = entropy( partial_trace(Statevector(state.toarray().flatten()), [k + L - 1 - i for i in notchosen])) self.assertTrue(np.abs(qentropy - state_entropy) < 1e-12)
def test_IQFT_entropy_equals_qiskit(self): Y = 13 N = 28 L = aux.lfy(N) k = 2 * L number_of_qubits = k + L state = construct_modular_state(k, L, aux.nonzeros_decimal(k, Y, N)) state = apply_IQFT(L, state.toarray()) tries = 30 for i in range(tries): chosen_qubits = random_bipartition(range(number_of_qubits), number_of_qubits // 2) notchosen_qubits = notchosen(chosen_qubits, number_of_qubits) myentropy = entanglement_entropy_from_state(state, chosen_qubits, sparse=False, gpu=False) qentropy = entropy( partial_trace(Statevector(state), notchosen_qubits)) self.assertTrue(np.abs(myentropy - qentropy) < 1e-5)
numb = [21, 33] #, 66, 129] L_list = [] tries = 20 percentages = [5, 10, 15, 20, 25, 30, 100] L_times = np.zeros((tries, len(percentages))) means = np.zeros((len(numb), len(percentages))) with open("jax_eigh_time_scaling.txt", "a+") as file: for idx, N in enumerate(numb): L = aux.lfy(N) L_list.append(L) k = 2 * L number_of_qubits = k + L state = construct_modular_state(k, L, aux.nonzeros_decimal(k, Y, N)) chosens = [ bip.random_bipartition(range(number_of_qubits), number_of_qubits // 2) for i in range(tries) ] for i, perc in enumerate(percentages): number_total_eigvals = 2**(number_of_qubits // 2) number_eigvals_computed = int( ceil(perc * number_total_eigvals / 100)) for j in range(tries): chosen = chosens[i] notchosen = bip.notchosen(chosen, k + L) W = matrix_from_sparse_modular_state(state, chosen, notchosen, False) start = time() sl = jseigh(W.dot(W.T), eigvals_only=True, turbo=False,