def test_d2_spin_rep_hubbard(): n_density, rdm_generator = system_hubbard() density = AntiSymmOrbitalDensity(n_density, 8) tpdm_aa, tpdm_bb, tpdm_ab, _ = density.construct_tpdm() bas_aa, bas_ab = geminal_spin_basis(4) tpdm_ab = Tensor(tpdm_ab, name='cckk_ab', basis=bas_ab) rdms = MultiTensor([tpdm_ab]) dim = int(np.sqrt(tpdm_ab.data.shape[0])) s_rep_dual_constant = 0 for i, j in product(range(dim), repeat=2): s_rep_dual_constant += tpdm_ab.data[bas_ab.rev((i, j)), bas_ab.rev((j, i))] N = 4 M = 0 S = 0 db = DualBasis() db += s_representability_d2ab(dim, N, M, S) rdms.dual_basis = db xvec = rdms.vectorize_tensors() A, _, b = rdms.synthesize_dual_basis() assert np.allclose(A.dot(xvec) - b, 0.0) assert np.allclose(A.dot(xvec), s_rep_dual_constant)
def test_d2_spin_sz_rep(): n_density, rdm_generator, transform, molecule = system() assert np.isclose(molecule.fci_energy, -2.84383506834) density = AntiSymmOrbitalDensity(n_density, molecule.n_qubits) tpdm_aa, tpdm_bb, tpdm_ab, _ = density.construct_tpdm() opdm_a, opdm_b = density.construct_opdm() bas_aa, bas_ab = geminal_spin_basis(molecule.n_orbitals) tpdm_ab = Tensor(tpdm_ab, name='cckk_ab', basis=bas_ab) opdm_a = Tensor(opdm_a, name='ck_a') opdm_b = Tensor(opdm_b, name='ck_b') rdms = MultiTensor([opdm_a, opdm_b, tpdm_ab]) dim = int(np.sqrt(tpdm_ab.data.shape[0])) sz_rep_value = 0 for i in range(dim): sz_rep_value += 0.5 * (opdm_a.data[i, i] - opdm_b.data[i, i]) N = molecule.n_electrons M = 0 S = 0 db = DualBasis() db += s_representability_d2ab(dim, N, M, S) db += sz_representability(dim, M) rdms.dual_basis = db xvec = rdms.vectorize_tensors() A, _, b = rdms.synthesize_dual_basis() assert np.allclose(A.dot(xvec) - b, 0.0)
def test_d2_spin_rep(): n_density, rdm_generator, transform, molecule = system() assert np.isclose(molecule.fci_energy, -2.84383506834) density = AntiSymmOrbitalDensity(n_density, molecule.n_qubits) tpdm_aa, tpdm_bb, tpdm_ab, _ = density.construct_tpdm() bas_aa, bas_ab = geminal_spin_basis(molecule.n_orbitals) tpdm_ab = Tensor(tpdm_ab, name='cckk_ab', basis=bas_ab) rdms = MultiTensor([tpdm_ab]) dim = int(np.sqrt(tpdm_ab.data.shape[0])) s_rep_dual_constant = 0 for i, j in product(range(dim), repeat=2): s_rep_dual_constant += tpdm_ab.data[bas_ab.rev((i, j)), bas_ab.rev((j, i))] N = molecule.n_electrons M = 0 S = 0 db = DualBasis() db += s_representability_d2ab(dim, N, M, S) rdms.dual_basis = db xvec = rdms.vectorize_tensors() A, _, b = rdms.synthesize_dual_basis() assert np.allclose(A.dot(xvec) - b, 0.0) assert np.allclose(A.dot(xvec), s_rep_dual_constant)