本文整理匯總了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
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)