def setUp(self): #TODO: Test rectangular x as well self.d = [2, 3] self.D = [2, 4, 3] self.l0 = sp.rand(self.D[0], self.D[0]) + 1.j * sp.rand(self.D[0], self.D[0]) self.r1 = sp.rand(self.D[1], self.D[1]) + 1.j * sp.rand(self.D[1], self.D[1]) self.r2 = sp.rand(self.D[2], self.D[2]) + 1.j * sp.rand(self.D[2], self.D[2]) self.ld0 = mm.simple_diag_matrix( sp.rand(self.D[0]) + 1.j * sp.rand(self.D[0])) self.rd1 = mm.simple_diag_matrix( sp.rand(self.D[1]) + 1.j * sp.rand(self.D[1])) self.rd2 = mm.simple_diag_matrix( sp.rand(self.D[2]) + 1.j * sp.rand(self.D[2])) self.eye0 = mm.eyemat(self.D[0], dtype=sp.complex128) self.eye1 = mm.eyemat(self.D[1], dtype=sp.complex128) self.eye2 = mm.eyemat(self.D[2], dtype=sp.complex128) self.A0 = sp.rand(self.d[0], self.D[0], self.D[0]) + 1.j * sp.rand( self.d[0], self.D[0], self.D[0]) self.A1 = sp.rand(self.d[0], self.D[0], self.D[1]) + 1.j * sp.rand( self.d[0], self.D[0], self.D[1]) self.A2 = sp.rand(self.d[1], self.D[1], self.D[2]) + 1.j * sp.rand( self.d[1], self.D[1], self.D[2]) self.A3 = sp.rand(self.d[1], self.D[2], self.D[2]) + 1.j * sp.rand( self.d[1], self.D[2], self.D[2]) self.B1 = sp.rand(self.d[0], self.D[0], self.D[1]) + 1.j * sp.rand( self.d[0], self.D[0], self.D[1]) self.B2 = sp.rand(self.d[1], self.D[1], self.D[2]) + 1.j * sp.rand( self.d[1], self.D[1], self.D[2]) self.E1_AB = make_E_noop(self.A1, self.B1) self.E2_AB = make_E_noop(self.A2, self.B2) self.op1s_1 = sp.rand(self.d[0], self.d[0]) + 1.j * sp.rand(self.d[0], self.d[0]) self.E1_op_AB = make_E_1s(self.A1, self.B1, self.op1s_1) self.op2s = sp.rand(self.d[0], self.d[1], self.d[0], self.d[1]) + 1.j * sp.rand( self.d[0], self.d[1], self.d[0], self.d[1]) self.E12_op = make_E_2s(self.A1, self.A2, self.B1, self.B2, self.op2s) self.AA12 = tc.calc_AA(self.A1, self.A2) self.BB12 = tc.calc_AA(self.B1, self.B2) self.C_A12 = tc.calc_C_mat_op_AA(self.op2s, self.AA12) self.C_conj_B12 = tc.calc_C_conj_mat_op_AA(self.op2s, self.BB12) self.C01 = sp.rand(self.d[0], self.d[0], self.D[0], self.D[1]) + 1.j * sp.rand( self.d[0], self.d[0], self.D[0], self.D[1])
def restore_LCF_l(A, lm1, Gm1, sanity_checks=False, zero_tol=1E-15): if Gm1 is None: GhGm1 = lm1 else: GhGm1 = Gm1.conj().T.dot(lm1.dot(Gm1)) M = eps_l_noop(GhGm1, A, A) G, Gi, new_D = herm_fac_with_inv(M, zero_tol=zero_tol, return_rank=True, sanity_checks=sanity_checks) if Gm1 is None: Gm1 = G if sanity_checks: if new_D == A.shape[2]: eye = sp.eye(A.shape[2]) else: eye = mm.simple_diag_matrix(np.append(np.zeros(A.shape[2] - new_D), np.ones(new_D)), dtype=A.dtype) if not sp.allclose(G.dot(Gi), eye, atol=1E-13, rtol=1E-13): log.warning("Sanity Fail in restore_LCF_l!: Bad GT!") for s in xrange(A.shape[0]): A[s] = Gm1.dot(A[s]).dot(Gi) if new_D == A.shape[2]: l = mm.eyemat(A.shape[2], A.dtype) else: l = mm.simple_diag_matrix(np.append(np.zeros(A.shape[2] - new_D), np.ones(new_D)), dtype=A.dtype) if sanity_checks: lm1_ = mm.eyemat(A.shape[1], A.dtype) l_ = eps_l_noop(lm1_, A, A) if not sp.allclose(l_, l.A, atol=1E-13, rtol=1E-13): log.warning("Sanity Fail in restore_LCF_l!: l is bad") log.warning(la.norm(l_ - l)) return l, G, Gi
def setUp(self): #TODO: Test rectangular x as well self.d = [2, 3] self.D = [2, 4, 3] self.l0 = sp.rand(self.D[0], self.D[0]) + 1.j * sp.rand(self.D[0], self.D[0]) self.r1 = sp.rand(self.D[1], self.D[1]) + 1.j * sp.rand(self.D[1], self.D[1]) self.r2 = sp.rand(self.D[2], self.D[2]) + 1.j * sp.rand(self.D[2], self.D[2]) self.ld0 = mm.simple_diag_matrix(sp.rand(self.D[0]) + 1.j * sp.rand(self.D[0])) self.rd1 = mm.simple_diag_matrix(sp.rand(self.D[1]) + 1.j * sp.rand(self.D[1])) self.rd2 = mm.simple_diag_matrix(sp.rand(self.D[2]) + 1.j * sp.rand(self.D[2])) self.eye0 = mm.eyemat(self.D[0], dtype=sp.complex128) self.eye1 = mm.eyemat(self.D[1], dtype=sp.complex128) self.eye2 = mm.eyemat(self.D[2], dtype=sp.complex128) self.A0 = sp.rand(self.d[0], self.D[0], self.D[0]) + 1.j * sp.rand(self.d[0], self.D[0], self.D[0]) self.A1 = sp.rand(self.d[0], self.D[0], self.D[1]) + 1.j * sp.rand(self.d[0], self.D[0], self.D[1]) self.A2 = sp.rand(self.d[1], self.D[1], self.D[2]) + 1.j * sp.rand(self.d[1], self.D[1], self.D[2]) self.A3 = sp.rand(self.d[1], self.D[2], self.D[2]) + 1.j * sp.rand(self.d[1], self.D[2], self.D[2]) self.B1 = sp.rand(self.d[0], self.D[0], self.D[1]) + 1.j * sp.rand(self.d[0], self.D[0], self.D[1]) self.B2 = sp.rand(self.d[1], self.D[1], self.D[2]) + 1.j * sp.rand(self.d[1], self.D[1], self.D[2]) self.E1_AB = make_E_noop(self.A1, self.B1) self.E2_AB = make_E_noop(self.A2, self.B2) self.op1s_1 = sp.rand(self.d[0], self.d[0]) + 1.j * sp.rand(self.d[0], self.d[0]) self.E1_op_AB = make_E_1s(self.A1, self.B1, self.op1s_1) self.op2s = sp.rand(self.d[0], self.d[1], self.d[0], self.d[1]) + 1.j * sp.rand(self.d[0], self.d[1], self.d[0], self.d[1]) self.E12_op = make_E_2s(self.A1, self.A2, self.B1, self.B2, self.op2s) self.AA12 = tc.calc_AA(self.A1, self.A2) self.BB12 = tc.calc_AA(self.B1, self.B2) self.C_A12 = tc.calc_C_mat_op_AA(self.op2s, self.AA12) self.C_conj_B12 = tc.calc_C_conj_mat_op_AA(self.op2s, self.BB12) self.C01 = sp.rand(self.d[0], self.d[0], self.D[0], self.D[1]) + 1.j * sp.rand(self.d[0], self.d[0], self.D[0], self.D[1])
def restore_RCF_r(A, r, G_n_i, zero_tol=1E-15, sanity_checks=False, sc_data=''): """Transforms a single A[n] to obtain r[n - 1] = eye(D). Implements the condition for right-orthonormalization from sub-section 3.1, theorem 1 of arXiv:quant-ph/0608197v2. This function must be called for each n in turn, starting at N + 1, passing the gauge transformation matrix from the previous step as an argument. Finds a G[n-1] such that orthonormalization is fulfilled for n. If rank-deficiency is encountered, the result fulfills the orthonormality condition in the occupied subspace with the zeros at the top-left (for example r = diag([0, 0, 1, 1, 1, 1, 1])). Parameters ---------- A : ndarray The parameter tensor for the nth site A[n]. r : ndarray or object with array interface The matrix r[n]. G_n_i : ndarray The inverse gauge transform matrix for site n obtained in the previous step (for n + 1). sanity_checks : bool (False) Whether to perform additional sanity checks. zero_tol : float Tolerance for detecting zeros. Returns ------- r_nm1 : ndarray or simple_diag_matrix or eyemat The new matrix r[n - 1]. G_nm1 : ndarray The gauge transformation matrix for the site n - 1. G_n_m1_i : ndarray The inverse gauge transformation matrix for the site n - 1. """ if G_n_i is None: GGh_n_i = r else: GGh_n_i = G_n_i.dot(r.dot(G_n_i.conj().T)) M = eps_r_noop(GGh_n_i, A, A) X, Xi, new_D = herm_fac_with_inv(M, zero_tol=zero_tol, return_rank=True, sanity_checks=sanity_checks) G_nm1 = Xi.conj().T G_nm1_i = X.conj().T if G_n_i is None: G_n_i = G_nm1_i if sanity_checks: #GiG may not be equal to eye in the case of rank-deficiency, #but the rest should lie in the null space of A. GiG = G_nm1_i.dot(G_nm1) As = np.sum(A, axis=0) if not sp.allclose( GiG.dot(As).dot(G_n_i), As.dot(G_n_i), atol=1E-13, rtol=1E-13): log.warning("Sanity Fail in restore_RCF_r!: Bad GT! %s %s", la.norm(GiG.dot(As).dot(G_n_i) - As.dot(G_n_i)), sc_data) for s in xrange(A.shape[0]): A[s] = G_nm1.dot(A[s]).dot(G_n_i) if new_D == A.shape[1]: r_nm1 = mm.eyemat(A.shape[1], A.dtype) else: r_nm1 = sp.zeros((A.shape[1]), dtype=A.dtype) r_nm1[-new_D:] = 1 r_nm1 = mm.simple_diag_matrix(r_nm1, dtype=A.dtype) if sanity_checks: r_nm1_ = G_nm1.dot(M).dot(G_nm1.conj().T) if not sp.allclose(r_nm1_, r_nm1.A, atol=1E-13, rtol=1E-13): log.warning( "Sanity Fail in restore_RCF_r!: r != g old_r gH! %s %s", la.norm(r_nm1_ - r_nm1), sc_data) r_nm1_ = eps_r_noop(r, A, A) if not sp.allclose(r_nm1_, r_nm1.A, atol=1E-13, rtol=1E-13): log.warning("Sanity Fail in restore_RCF_r!: r is bad! %s %s", la.norm(r_nm1_ - r_nm1), sc_data) return r_nm1, G_nm1, G_nm1_i
def restore_RCF_r(A, r, G_n_i, zero_tol=1E-15, sanity_checks=False, sc_data=''): """Transforms a single A[n] to obtain r[n - 1] = eye(D). Implements the condition for right-orthonormalization from sub-section 3.1, theorem 1 of arXiv:quant-ph/0608197v2. This function must be called for each n in turn, starting at N + 1, passing the gauge transformation matrix from the previous step as an argument. Finds a G[n-1] such that orthonormalization is fulfilled for n. If rank-deficiency is encountered, the result fulfills the orthonormality condition in the occupied subspace with the zeros at the top-left (for example r = diag([0, 0, 1, 1, 1, 1, 1])). Parameters ---------- A : ndarray The parameter tensor for the nth site A[n]. r : ndarray or object with array interface The matrix r[n]. G_n_i : ndarray The inverse gauge transform matrix for site n obtained in the previous step (for n + 1). sanity_checks : bool (False) Whether to perform additional sanity checks. zero_tol : float Tolerance for detecting zeros. Returns ------- r_nm1 : ndarray or simple_diag_matrix or eyemat The new matrix r[n - 1]. G_nm1 : ndarray The gauge transformation matrix for the site n - 1. G_n_m1_i : ndarray The inverse gauge transformation matrix for the site n - 1. """ if G_n_i is None: GGh_n_i = r else: GGh_n_i = G_n_i.dot(r.dot(G_n_i.conj().T)) M = eps_r_noop(GGh_n_i, A, A) X, Xi, new_D = herm_fac_with_inv(M, zero_tol=zero_tol, return_rank=True, sanity_checks=sanity_checks) G_nm1 = Xi.conj().T G_nm1_i = X.conj().T if G_n_i is None: G_n_i = G_nm1_i if sanity_checks: #GiG may not be equal to eye in the case of rank-deficiency, #but the rest should lie in the null space of A. GiG = G_nm1_i.dot(G_nm1) As = np.sum(A, axis=0) if not sp.allclose(GiG.dot(As).dot(G_n_i), As.dot(G_n_i), atol=1E-13, rtol=1E-13): log.warning("Sanity Fail in restore_RCF_r!: Bad GT! %s %s", la.norm(GiG.dot(As).dot(G_n_i) - As.dot(G_n_i)), sc_data) for s in xrange(A.shape[0]): A[s] = G_nm1.dot(A[s]).dot(G_n_i) if new_D == A.shape[1]: r_nm1 = mm.eyemat(A.shape[1], A.dtype) else: r_nm1 = sp.zeros((A.shape[1]), dtype=A.dtype) r_nm1[-new_D:] = 1 r_nm1 = mm.simple_diag_matrix(r_nm1, dtype=A.dtype) if sanity_checks: r_nm1_ = G_nm1.dot(M).dot(G_nm1.conj().T) if not sp.allclose(r_nm1_, r_nm1.A, atol=1E-13, rtol=1E-13): log.warning("Sanity Fail in restore_RCF_r!: r != g old_r gH! %s %s", la.norm(r_nm1_ - r_nm1), sc_data) r_nm1_ = eps_r_noop(r, A, A) if not sp.allclose(r_nm1_, r_nm1.A, atol=1E-13, rtol=1E-13): log.warning("Sanity Fail in restore_RCF_r!: r is bad! %s %s", la.norm(r_nm1_ - r_nm1), sc_data) return r_nm1, G_nm1, G_nm1_i