def test_compute_hR_vs_expect(backend, dtype, chi, d): _, _, A_R, H = random_hermitian_system(backend, dtype, chi, d) I = tn.eye(chi, backend=backend, dtype=dtype) hR = ct.compute_hR(A_R, H) result = tn.abs(tn.trace(hR)) compare = ct.twositeexpect([A_R, I, A_R], H) rtol = (2*A_R.size + I.size + H.size) * np.finfo(dtype).eps np.testing.assert_allclose(result.array, compare.array, rtol=rtol)
def test_trace(backend, dtype): """ Checks that Tensor.trace() works. """ shape = (2, 3, 3) A, _ = testing_utils.safe_randn(shape, backend, dtype) if A is not None: np.testing.assert_allclose( tensornetwork.trace(A).array, A.backend.trace(A.array))
def mpsnorm(mps: ThreeTensors) -> tn.Tensor: """ Norm of the MPS. Args: mps: The MPS. Returns: norm: Its norm. """ A_L, C, A_R = mps A_CR = leftmult(C, A_R) rho = rholoc(A_L, A_CR) the_norm = tn.abs(tn.trace(rho)) return the_norm
def vumps_approximate_tm_eigs(C) -> TwoTensors: """ Returns the approximate transfer matrix dominant eigenvectors, rL ~ C^dag C, and lR ~ C Cdag = rLdag, both trace-normalized. Args: C: From the MPS. Returns: rL, lR: right fixed point of L, left fixed point of R. """ rL = C.H @ C rL /= tn.trace(rL) lR = rL.H return rL, lR