当前位置: 首页>>代码示例>>Python>>正文


Python hamiltonians.MolecularData方法代码示例

本文整理汇总了Python中openfermion.hamiltonians.MolecularData方法的典型用法代码示例。如果您正苦于以下问题:Python hamiltonians.MolecularData方法的具体用法?Python hamiltonians.MolecularData怎么用?Python hamiltonians.MolecularData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在openfermion.hamiltonians的用法示例。


在下文中一共展示了hamiltonians.MolecularData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: h_n_linear_molecule

# 需要导入模块: from openfermion import hamiltonians [as 别名]
# 或者: from openfermion.hamiltonians import MolecularData [as 别名]
def h_n_linear_molecule(bond_distance: float, n_hydrogens: int,
                        basis: str = 'sto-3g'):
    # coverage: ignore
    if n_hydrogens < 1 or n_hydrogens % 2 != 0:
        raise ValueError('Must specify a positive, even number of hydrogens.')
    molecule = MolecularData(
        geometry=_h_n_linear_geometry(bond_distance, n_hydrogens),
        charge=0,
        basis=basis,
        multiplicity=1,
        description=f"linear_r-{bond_distance}",
    )
    if NO_OFPSI4:
        raise NOOFPsi4Error("openfermion-psi4 is not installed")

    molecule = run_psi4(molecule, run_fci=False, run_mp2=False, run_cisd=False,
                        run_ccsd=False, delete_input=False, delete_output=False)

    return molecule 
开发者ID:quantumlib,项目名称:OpenFermion-Cirq,代码行数:21,代码来源:molecular_data_construction.py

示例2: test_consistency

# 需要导入模块: from openfermion import hamiltonians [as 别名]
# 或者: from openfermion.hamiltonians import MolecularData [as 别名]
def test_consistency(self):
        """Test consistency with JW for FermionOperators."""
        # Random interaction operator
        n_qubits = 5
        iop = random_interaction_operator(n_qubits, real=False)
        op1 = jordan_wigner(iop)
        op2 = jordan_wigner(get_fermion_operator(iop))

        self.assertEqual(op1, op2)

        # Interaction operator from molecule
        geometry = [('Li', (0., 0., 0.)), ('H', (0., 0., 1.45))]
        basis = 'sto-3g'
        multiplicity = 1

        filename = os.path.join(DATA_DIRECTORY, 'H1-Li1_sto-3g_singlet_1.45')
        molecule = MolecularData(geometry, basis, multiplicity,
                                 filename=filename)
        molecule.load()

        iop = molecule.get_molecular_hamiltonian()
        op1 = jordan_wigner(iop)
        op2 = jordan_wigner(get_fermion_operator(iop))

        self.assertEqual(op1, op2) 
开发者ID:quantumlib,项目名称:OpenFermion,代码行数:27,代码来源:_jordan_wigner_test.py

示例3: test_tqdm_conversions_h2_631g

# 需要导入模块: from openfermion import hamiltonians [as 别名]
# 或者: from openfermion.hamiltonians import MolecularData [as 别名]
def test_tqdm_conversions_h2_631g(self):
        # construct the 2-hole-RDM for LiH the slow way
        # TODO: speed up this calculation by directly contracting from the wf.
        filename = "H2_6-31g_singlet_0.75.hdf5"
        molecule = MolecularData(
            filename=os.path.join(DATA_DIRECTORY, filename))
        true_tqdm = self.tqdm_h2_6_31g

        test_tqdm = map_two_pdm_to_two_hole_dm(molecule.fci_two_rdm,
                                               molecule.fci_one_rdm)
        assert numpy.allclose(true_tqdm, test_tqdm)

        true_oqdm = numpy.eye(molecule.n_qubits) - molecule.fci_one_rdm
        test_oqdm = map_two_hole_dm_to_one_hole_dm(
            true_tqdm, molecule.n_qubits - molecule.n_electrons)
        assert numpy.allclose(true_oqdm, test_oqdm)

        test_tpdm = map_two_hole_dm_to_two_pdm(true_tqdm, molecule.fci_one_rdm)
        assert numpy.allclose(test_tpdm, molecule.fci_two_rdm) 
开发者ID:quantumlib,项目名称:OpenFermion,代码行数:21,代码来源:_rdm_mapping_functions_test.py

示例4: test_tqdm_conversions_h2_sto3g

# 需要导入模块: from openfermion import hamiltonians [as 别名]
# 或者: from openfermion.hamiltonians import MolecularData [as 别名]
def test_tqdm_conversions_h2_sto3g(self):
        filename = "H2_sto-3g_singlet_1.4.hdf5"
        molecule = MolecularData(
            filename=os.path.join(DATA_DIRECTORY, filename))
        true_tqdm = self.tqdm_h2_sto3g

        test_tqdm = map_two_pdm_to_two_hole_dm(molecule.fci_two_rdm,
                                               molecule.fci_one_rdm)
        assert numpy.allclose(true_tqdm, test_tqdm)

        true_oqdm = numpy.eye(molecule.n_qubits) - molecule.fci_one_rdm
        test_oqdm = map_two_hole_dm_to_one_hole_dm(
            true_tqdm, molecule.n_qubits - molecule.n_electrons)
        assert numpy.allclose(true_oqdm, test_oqdm)

        test_tpdm = map_two_hole_dm_to_two_pdm(true_tqdm, molecule.fci_one_rdm)
        assert numpy.allclose(test_tpdm, molecule.fci_two_rdm) 
开发者ID:quantumlib,项目名称:OpenFermion,代码行数:19,代码来源:_rdm_mapping_functions_test.py

示例5: test_tqdm_conversions_lih_sto3g

# 需要导入模块: from openfermion import hamiltonians [as 别名]
# 或者: from openfermion.hamiltonians import MolecularData [as 别名]
def test_tqdm_conversions_lih_sto3g(self):
        filename = "H1-Li1_sto-3g_singlet_1.45.hdf5"
        molecule = MolecularData(
            filename=os.path.join(DATA_DIRECTORY, filename))
        true_tqdm = self.tqdm_lih_sto3g

        test_tqdm = map_two_pdm_to_two_hole_dm(molecule.fci_two_rdm,
                                               molecule.fci_one_rdm)
        assert numpy.allclose(true_tqdm, test_tqdm)

        true_oqdm = numpy.eye(molecule.n_qubits) - molecule.fci_one_rdm
        test_oqdm = map_two_hole_dm_to_one_hole_dm(
            true_tqdm, molecule.n_qubits - molecule.n_electrons)
        assert numpy.allclose(true_oqdm, test_oqdm)

        test_tpdm = map_two_hole_dm_to_two_pdm(true_tqdm, molecule.fci_one_rdm)
        assert numpy.allclose(test_tpdm, molecule.fci_two_rdm) 
开发者ID:quantumlib,项目名称:OpenFermion,代码行数:19,代码来源:_rdm_mapping_functions_test.py

示例6: test_phdm_conversions_h2_631g

# 需要导入模块: from openfermion import hamiltonians [as 别名]
# 或者: from openfermion.hamiltonians import MolecularData [as 别名]
def test_phdm_conversions_h2_631g(self):
        filename = "H2_6-31g_singlet_0.75.hdf5"
        molecule = MolecularData(
            filename=os.path.join(DATA_DIRECTORY, filename))
        true_phdm = self.phdm_h2_6_31g

        test_phdm = map_two_pdm_to_particle_hole_dm(molecule.fci_two_rdm,
                                                    molecule.fci_one_rdm)
        assert numpy.allclose(test_phdm, true_phdm)

        test_opdm = map_particle_hole_dm_to_one_pdm(true_phdm,
                                                    molecule.n_electrons,
                                                    molecule.n_qubits)
        assert numpy.allclose(test_opdm, molecule.fci_one_rdm)

        test_tpdm = map_particle_hole_dm_to_two_pdm(true_phdm,
                                                    molecule.fci_one_rdm)
        assert numpy.allclose(test_tpdm, molecule.fci_two_rdm) 
开发者ID:quantumlib,项目名称:OpenFermion,代码行数:20,代码来源:_rdm_mapping_functions_test.py

示例7: test_phdm_conversions_h2_sto3g

# 需要导入模块: from openfermion import hamiltonians [as 别名]
# 或者: from openfermion.hamiltonians import MolecularData [as 别名]
def test_phdm_conversions_h2_sto3g(self):
        filename = "H2_sto-3g_singlet_1.4.hdf5"
        molecule = MolecularData(
            filename=os.path.join(DATA_DIRECTORY, filename))
        true_phdm = self.phdm_h2_sto3g

        test_phdm = map_two_pdm_to_particle_hole_dm(molecule.fci_two_rdm,
                                                    molecule.fci_one_rdm)
        assert numpy.allclose(test_phdm, true_phdm)

        test_opdm = map_particle_hole_dm_to_one_pdm(true_phdm,
                                                    molecule.n_electrons,
                                                    molecule.n_qubits)
        assert numpy.allclose(test_opdm, molecule.fci_one_rdm)

        test_tpdm = map_particle_hole_dm_to_two_pdm(true_phdm,
                                                    molecule.fci_one_rdm)
        assert numpy.allclose(test_tpdm, molecule.fci_two_rdm) 
开发者ID:quantumlib,项目名称:OpenFermion,代码行数:20,代码来源:_rdm_mapping_functions_test.py

示例8: setUp

# 需要导入模块: from openfermion import hamiltonians [as 别名]
# 或者: from openfermion.hamiltonians import MolecularData [as 别名]
def setUp(self):

        # Setup.
        geometry = [('H', (0., 0., 0.)), ('H', (0., 0., 0.7414))]
        basis = 'sto-3g'
        multiplicity = 1
        filename = os.path.join(THIS_DIRECTORY, 'data',
                                'H2_sto-3g_singlet_0.7414')
        molecule = MolecularData(
            geometry, basis, multiplicity, filename=filename)
        molecule.load()
        self.n_fermions = molecule.n_electrons
        self.n_orbitals = molecule.n_qubits

        # Get molecular Hamiltonian.
        self.molecular_hamiltonian = molecule.get_molecular_hamiltonian()
        self.fci_rdm = molecule.get_molecular_rdm(use_fci=1) 
开发者ID:quantumlib,项目名称:OpenFermion,代码行数:19,代码来源:_rdm_equality_constraints_test.py

示例9: setUp

# 需要导入模块: from openfermion import hamiltonians [as 别名]
# 或者: from openfermion.hamiltonians import MolecularData [as 别名]
def setUp(self):

        # Set up molecule.
        geometry = [('H', (0., 0., 0.)), ('H', (0., 0., 0.7414))]
        basis = 'sto-3g'
        multiplicity = 1
        filename = os.path.join(THIS_DIRECTORY, 'data',
                                'H2_sto-3g_singlet_0.7414')
        molecule = MolecularData(
            geometry, basis, multiplicity, filename=filename)
        molecule.load()
        self.n_fermions = molecule.n_electrons
        self.n_orbitals = molecule.n_qubits

        # Get molecular Hamiltonian.
        molecular_hamiltonian = molecule.get_molecular_hamiltonian()
        self.fermion_hamiltonian = get_fermion_operator(molecular_hamiltonian) 
开发者ID:quantumlib,项目名称:OpenFermion,代码行数:19,代码来源:_equality_constraint_projection_test.py

示例10: test_spin_adapt_h2

# 需要导入模块: from openfermion import hamiltonians [as 别名]
# 或者: from openfermion.hamiltonians import MolecularData [as 别名]
def test_spin_adapt_h2():
    """
    Test if we accurately generate the fci spin-adapted d2-matrices
    """
    h2_file = os.path.join(DATA_DIRECTORY, "H2_sto-3g_singlet_0.7.hdf5")
    molecule = MolecularData(filename=h2_file)
    d2aa, d2bb, d2ab = get_sz_spin_adapted(molecule.fci_two_rdm)
    assert np.allclose(d2aa, np.zeros((1, 1)))
    assert np.allclose(d2bb, np.zeros((1, 1)))

    true_d2ab = np.array([[0.98904311, 0., 0., -0.10410015],
                          [0., 0., 0., 0.],
                          [0., 0., 0., 0.],
                          [-0.10410015, 0., 0., 0.01095689]])
    assert np.allclose(d2ab, true_d2ab)

    test_tpdm = unspin_adapt(d2aa, d2bb, d2ab)
    assert np.allclose(molecule.fci_two_rdm, test_tpdm) 
开发者ID:rigetti,项目名称:forest-openfermion,代码行数:20,代码来源:rdm_utilities_test.py

示例11: test_h2_tpdm_build

# 需要导入模块: from openfermion import hamiltonians [as 别名]
# 或者: from openfermion.hamiltonians import MolecularData [as 别名]
def test_h2_tpdm_build():
    """
    Check if constructing the 2-RDM (full) works.  This check uses openfermion
    data and thus requires openfermion to be installed
    """

    h2_file = os.path.join(DATA_DIRECTORY, "H2_sto-3g_singlet_0.7.hdf5")
    molecule = MolecularData(filename=h2_file)
    rdms = molecule.get_molecular_rdm(use_fci=True)
    dim = molecule.n_qubits
    paulis_to_measure = pauli_terms_for_tpdm(dim)
    pauli_to_coeff = {}
    for term in paulis_to_measure:
        # convert back to FermionOperator
        qubit_op = pyquilpauli_to_qubitop(term_with_coeff(term, 1.0))
        pauli_to_coeff[term.id()] = rdms.expectation(qubit_op)

    tpdm = pauli_to_tpdm(dim, pauli_to_coeff)
    assert np.allclose(tpdm, molecule.fci_two_rdm) 
开发者ID:rigetti,项目名称:forest-openfermion,代码行数:21,代码来源:rdm_estimation_test.py

示例12: test_lih_tpdm_aa_build

# 需要导入模块: from openfermion import hamiltonians [as 别名]
# 或者: from openfermion.hamiltonians import MolecularData [as 别名]
def test_lih_tpdm_aa_build():
    """
    Check if 2-RDM construction from pauli terms works for the aa spin adapted
    block
    """
    lih_file = os.path.join(DATA_DIRECTORY, "H1-Li1_sto-3g_singlet_1.45.hdf5")
    molecule = MolecularData(filename=lih_file)
    rdms = molecule.get_molecular_rdm(use_fci=True)
    dim = molecule.n_qubits
    d2aa, d2bb, d2ab = get_sz_spin_adapted(molecule.fci_two_rdm)
    paulis_to_measure = pauli_terms_for_tpdm_aa(dim // 2)
    pauli_to_coeff = {}
    for term in paulis_to_measure:
        # convert back to FermionOperator
        qubit_op = pyquilpauli_to_qubitop(term_with_coeff(term, 1.0))
        pauli_to_coeff[term.id()] = rdms.expectation(qubit_op)

    tpdm_aa = pauli_to_tpdm_aa(dim // 2, pauli_to_coeff)
    assert np.allclose(tpdm_aa, d2aa) 
开发者ID:rigetti,项目名称:forest-openfermion,代码行数:21,代码来源:rdm_estimation_test.py

示例13: test_lih_tpdm_bb_build

# 需要导入模块: from openfermion import hamiltonians [as 别名]
# 或者: from openfermion.hamiltonians import MolecularData [as 别名]
def test_lih_tpdm_bb_build():
    """
    Check if 2-RDM construction from pauli terms works for the bb spin adapted
    block
    """
    lih_file = os.path.join(DATA_DIRECTORY, "H1-Li1_sto-3g_singlet_1.45.hdf5")
    molecule = MolecularData(filename=lih_file)
    rdms = molecule.get_molecular_rdm(use_fci=True)
    dim = molecule.n_qubits
    d2aa, d2bb, d2ab = get_sz_spin_adapted(molecule.fci_two_rdm)
    paulis_to_measure = pauli_terms_for_tpdm_bb(dim // 2)
    pauli_to_coeff = {}
    for term in paulis_to_measure:
        # convert back to FermionOperator
        qubit_op = pyquilpauli_to_qubitop(term_with_coeff(term, 1.0))
        pauli_to_coeff[term.id()] = rdms.expectation(qubit_op)

    tpdm_bb = pauli_to_tpdm_bb(dim // 2, pauli_to_coeff)
    assert np.allclose(tpdm_bb, d2bb) 
开发者ID:rigetti,项目名称:forest-openfermion,代码行数:21,代码来源:rdm_estimation_test.py

示例14: test_h2_spin_adapted_aa

# 需要导入模块: from openfermion import hamiltonians [as 别名]
# 或者: from openfermion.hamiltonians import MolecularData [as 别名]
def test_h2_spin_adapted_aa():
    h2_file = os.path.join(DATA_DIRECTORY, "H2_sto-3g_singlet_0.7.hdf5")
    molecule = MolecularData(filename=h2_file)
    rdms = molecule.get_molecular_rdm(use_fci=True)
    dim = molecule.n_qubits
    paulis_to_measure = pauli_terms_for_tpdm(dim)
    pauli_to_coeff = {}
    for term in paulis_to_measure:
        # convert back to FermionOperator
        qubit_op = pyquilpauli_to_qubitop(term_with_coeff(term, 1.0))
        pauli_to_coeff[term.id()] = rdms.expectation(qubit_op)
    tpdm = pauli_to_tpdm(dim, pauli_to_coeff)
    d2aa, d2bb, d2ab = get_sz_spin_adapted(tpdm)

    paulis_to_measure_aa = pauli_terms_for_tpdm_aa(dim // 2)
    pauli_to_coeff = {}
    for term in paulis_to_measure_aa:
        # convert back to FermionOperator
        qubit_op = pyquilpauli_to_qubitop(term_with_coeff(term, 1.0))
        pauli_to_coeff[term.id()] = rdms.expectation(qubit_op)
    tpdm_aa = pauli_to_tpdm_aa(dim // 2, pauli_to_coeff)

    assert np.allclose(d2aa, tpdm_aa) 
开发者ID:rigetti,项目名称:forest-openfermion,代码行数:25,代码来源:rdm_estimation_test.py

示例15: test_h2_spin_adapted_bb

# 需要导入模块: from openfermion import hamiltonians [as 别名]
# 或者: from openfermion.hamiltonians import MolecularData [as 别名]
def test_h2_spin_adapted_bb():
    h2_file = os.path.join(DATA_DIRECTORY, "H2_sto-3g_singlet_0.7.hdf5")
    molecule = MolecularData(filename=h2_file)
    rdms = molecule.get_molecular_rdm(use_fci=True)
    dim = molecule.n_qubits
    paulis_to_measure = pauli_terms_for_tpdm(dim)
    pauli_to_coeff = {}
    for term in paulis_to_measure:
        # convert back to FermionOperator
        qubit_op = pyquilpauli_to_qubitop(term_with_coeff(term, 1.0))
        pauli_to_coeff[term.id()] = rdms.expectation(qubit_op)
    tpdm = pauli_to_tpdm(dim, pauli_to_coeff)
    d2aa, d2bb, d2ab = get_sz_spin_adapted(tpdm)

    paulis_to_measure_bb = pauli_terms_for_tpdm_bb(dim // 2)
    pauli_to_coeff = {}
    for term in paulis_to_measure_bb:
        # convert back to FermionOperator
        qubit_op = pyquilpauli_to_qubitop(term_with_coeff(term, 1.0))
        pauli_to_coeff[term.id()] = rdms.expectation(qubit_op)
    tpdm_bb = pauli_to_tpdm_bb(dim // 2, pauli_to_coeff)

    assert np.allclose(d2bb, tpdm_bb) 
开发者ID:rigetti,项目名称:forest-openfermion,代码行数:25,代码来源:rdm_estimation_test.py


注:本文中的openfermion.hamiltonians.MolecularData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。