def test_pauli_dim3(self): for dir in (1, 'x', 'X', 2, 'y', 'Y', 3, 'z', 'Z'): x = pauli(dir, dim=3) assert_allclose(eigvals(x), [-1, 0, 1], atol=1e-15)
def test_approx_spectral_function_ptr_ppt_lin_op(self, fn_approx_rtol, psi_abc, psi_ab, bsz): fn, approx, rtol = fn_approx_rtol rho_ab_ppt = partial_transpose(psi_abc.ptr(DIMS, [0, 1]), DIMS[:-1], 0) actual_x = sum(fn(eigvals(rho_ab_ppt))) lo = LazyPtrPptOperator(psi_abc, DIMS, sysa=0, sysb=1) approx_x = approx_spectral_function(lo, fn, K=20, R=20, bsz=bsz) assert_allclose(actual_x, approx_x, rtol=rtol)
def test_approx_spectral_function(self, fn_matrix_rtol, bsz, mpi): fn, matrix, rtol = fn_matrix_rtol a = matrix(2**7) pos = fn == np.sqrt actual_x = sum(fn(eigvals(a))) approx_x = approx_spectral_function(a, fn, K=20, R=20, mpi=mpi, pos=pos, bsz=bsz) assert_allclose(actual_x, approx_x, rtol=rtol)
def test_approx_spectral_function_ptr_lin_op(self, fn_approx_rtol, psi_abc, psi_ab, bsz): fn, approx, rtol = fn_approx_rtol sysa = [0, 1] rho_ab = psi_abc.ptr(DIMS, sysa) actual_x = sum(fn(eigvals(rho_ab))) lo = LazyPtrOperator(psi_abc, DIMS, sysa) approx_x = approx(lo, R=50, bsz=bsz) assert_allclose(actual_x, approx_x, rtol=rtol)
def test_approx_spectral_function_with_v0(self, fn_matrix_rtol, bsz): fn, matrix, rtol = fn_matrix_rtol a = matrix(2**7) actual_x = sum(fn(eigvals(a))) # check un-normalized state work properly v0 = (neel_state(7) + neel_state(7, down_first=True)) v0 = v0.A.reshape(-1) pos = fn == np.sqrt approx_x = approx_spectral_function(a, fn, K=20, v0=v0, pos=pos, bsz=bsz) assert_allclose(actual_x, approx_x, rtol=rtol)
def test_entanglement(self): rho = rand_seperable([2, 3, 2], 10) assert_almost_equal(tr(rho), 1.0) assert isherm(rho) assert logneg(rho, [2, 6]) < 1e-12 assert logneg(rho, [6, 2]) < 1e-12 rho_a = ptr(rho, [2, 3, 2], 1) el = eigvals(rho_a) assert np.all(el < 1 - 1e-12) assert np.all(el > 1e-12)
def test_approx_spectral_subspaces_with_heis_partition(self, bsz): h = ham_heis(10, sparse=True) beta = 0.01 actual_Z = sum(np.exp(-beta * eigvals(h.A))) approx_Z = tr_exp_approx(-beta * h, bsz=bsz) assert_allclose(actual_Z, approx_Z, rtol=3e-2)
def test_eigvals(self, mat_herm_dense, bkd): _, a = mat_herm_dense evals = eigvals(a, backend=bkd) assert_allclose(evals, [-3, -1, 2, 4])
def test_rank(self, bond_dim, cyclic): psi = rand_matrix_product_state(2, 10, bond_dim, cyclic=cyclic) rhoa = ptr(psi, [2] * 10, [0, 1, 2, 3]) el = eigvals(rhoa) # bond_dim squared as cyclic mps is generated assert sum(el > 1e-12) == bond_dim**(2 if cyclic else 1)
def test_ham_heis_bz(self): h = ham_heis(2, cyclic=False, b=1) evals = eigvals(h) assert_allclose(evals, [-3 / 4, -3 / 4, 1 / 4, 5 / 4])
def test_ham_heis_2(self): h = ham_heis(2, cyclic=False) evals = eigvals(h) assert_allclose(evals, [-0.75, 0.25, 0.25, 0.25]) gs = groundstate(h) assert_allclose(expec(gs, singlet()), 1.)
def test_pauli_dim2(self): for dir in (1, 'x', 'X', 2, 'y', 'Y', 3, 'z', 'Z'): x = pauli(dir) assert_allclose(eigvals(x), [-1, 1])
def test_spin_high(self, label, S): D = int(2 * S + 1) op = spin_operator(label, S) assert_allclose(eigvals(op), np.linspace(-S, S, D), atol=1e-13)