Comments (4)
Sorry for the delay, but I just confirmed this works. Thanks for the help!
from openfermion-pyscf.
Does the ground state wavefunction have the correct number of electrons in the case that fails?
from openfermion-pyscf.
No, when I use a number operator on the ground-state wavefunction of the frozen core Hamiltonian, I get 6 electrons instead of 4.
from openfermion-pyscf.
There seem to be two problems in your code.
The first is how you specify the geometry.
PySCF accepts both "string" and "list" as the geometry specification. (here)
However, In "MolecularData" class of OpenFermion, the geometry is assumed to be a list.
If you provide a string, MolecularData's "n_electrons" will be set to 0. (here)
The function "generate_molecular_hamiltonian" in OpenFermion-PySCF uses this "n_electrons" to generate occupied_indices and active_indices (here), and calls the OpenFermion function "get_molecular_hamiltonian", resulting in the improper active space.
In the case of your code, active_indices=[-2, -1, 0, 1, 2], occupied_indices=[].
Note that if you did not set the active space in the "generate_molecular_hamiltonian" function, the "get_molecular_hamiltonian" function seems to work correctly. (here)
The second problem is that the "refstr" (Hartree-Fock state basis) is incorrect.
In the case of your code, the "refstr" is "0000001111", but the correct "refstr" is "1111000000".
The correct code and output are shown below.
from pyscf import gto, scf, mcscf
from openfermionpyscf import generate_molecular_hamiltonian
from openfermion.linalg import get_sparse_operator
import numpy as np
import scipy
# geom = "H 0 0 0; H 0 0 1; H 0 0 2; H 0 0 3; H 0 0 4; H 0 0 5"
geom = [["H", (0., 0., 0.)],
["H", (0., 0., 1.)],
["H", (0., 0., 2.)],
["H", (0., 0., 3.)],
["H", (0., 0., 4.)],
["H", (0., 0., 5.)]]
basis = "sto-3g"
reference = "rhf"
N_e = 4
N_qubits = 10
multiplicity = 1
# PySCF SCF and CASCI Calculations
mol = gto.M(atom=geom, basis=basis, verbose=False)
mol.build()
mf = scf.RHF(mol)
mf.conv_tol_grad = 1e-8
mf.max_cycle = 10000
mf.init_guess = "atom"
print("PySCF HF Energy:")
print(mf.kernel())
mycas = mcscf.CASCI(mf, int(N_qubits/2), N_e)
casci = mycas.kernel(verbose=False)
print("PYSCF CASCI:")
print(casci[0])
H = generate_molecular_hamiltonian(geom,
basis,
multiplicity,
n_active_electrons=N_e,
n_active_orbitals=int(N_qubits/2))
H = get_sparse_operator(H).real
refstr = ""
# for i in range(N_e, N_qubits):
# refstr += "0"
# for i in range(0, N_e):
# refstr += "1"
for i in range(0, N_e):
refstr += "1"
for i in range(N_e, N_qubits):
refstr += "0"
ref = np.zeros(2**N_qubits)
ref[int(refstr, 2)] = 1
ref = scipy.sparse.csc_matrix(ref).T
print("OpenFermion-PySCF HF Energy:")
print((ref.T@H@ref)[0,0])
print("OpenFermion-PySCF CASCI Energy:")
w, v = scipy.sparse.linalg.eigsh(H, which = "SA")
print(w[0])
exit()
Output:
PySCF HF Energy:
-3.135532213966319
PYSCF CASCI:
-3.1981030445646605
OpenFermion-PySCF HF Energy:
-3.1355322139663198
OpenFermion-PySCF CASCI Energy:
-3.1981030446364223
It should be noted that the lowest eigenvalue obtained by Hamiltonian diagonalization does not necessarily correspond to the CASCI energy. This is because Hamiltonian diagonalization is performed by linear combinations of all electron configurations, so the obtained eigenstate do not necessarily preserve the number of electrons, Sz, etc.
from openfermion-pyscf.
Related Issues (20)
- PyPI installation of PySCF unreliable
- ImportError: No module named 'pyscf' but OpenFermion-PySCF is installed HOT 2
- Continuous integration testing HOT 1
- more tests!
- run_pyscf does not work on PyscfMolecularData HOT 1
- Example notebook raises warnings HOT 1
- run_pyscf is broken HOT 2
- CC double excitation pre-factor convention HOT 1
- RDM calculation not stored correctly in MolecularData HOT 2
- Set parse_arg option of pyscf.gto.mole.Mole.build to False
- Return none spin summed rdms
- Testing with github actions HOT 1
- Optional disable file saving when `run_pyscf` HOT 1
- Package breaks with latest h5py HOT 1
- Unable to install using pip within Python 3.7.9 environment HOT 4
- 'PyscfMolecularData' object has no attribute 'general_calculations'
- Permission denied: '08fd403b-e30d-4e78-97d5-dcb570445762.hdf5' -> '/usr/local/lib/python3.9/site-packages/openfermion/testing/data/H2_sto-3g_singlet_0.7414.hdf5'
- 2 tests fail
- Inconsistency in get_molecular_hamiltonian()
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openfermion-pyscf.