-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Odometer tester #55
Odometer tester #55
Conversation
It's because you are using a # Select determinants
while True:
if new[-1] < wfn.nbasis and (np.sum(cost[new]) + t * cost[new[-1]]) < qmax:
# Accept determinant and go back to last particle
wfn.add_occs(np.vstack((new, new)))
j = wfn.nocc_up - 1
else:
# Reject determinant and cycle j
new[:] = old
j -= 1
... and it works: [1+]-[*36-cost-tester]-[michelle@t14s-g4]-[~/Git/pyci]-% pytest -sv pyci/test/test_odometer.py
================================================= test session starts =================================================
platform linux -- Python 3.11.8, pytest-7.4.4, pluggy-1.3.0 -- /home/michelle/Git/venv/bin/python
cachedir: .pytest_cache
rootdir: /home/michelle/Git/pyci
plugins: anyio-4.2.0
collecting ... converged SCF energy = -1.06610864931794
converged SCF energy = -1.06610864931794
converged SCF energy = -2.09854593699772
collected 3 items
pyci/test/test_odometer.py::test_odometer_one_spin[wfn0-cost0-0-0.7] PASSED
pyci/test/test_odometer.py::test_odometer_one_spin[wfn1-cost1-0-1.0] PASSED
pyci/test/test_odometer.py::test_odometer_one_spin[wfn2-cost2-0-1.2] PASSED
================================================== 3 passed in 0.72s ================================================== You should check if the wfn instance is a one-spin (doci or genci) or two-spin (fullci) and if it's two-spin, do as I showed here. |
Actually an easier solution is just, start with a wfn = pyci.doci_wfn(nbasis, n_up, n_dn)
# fill `wfn`
# ...
wfn = pyci.fullci_wfn(wfn) You can upcast |
@msricher Is there a simple way of checking if the wfn instance is one-spin or two-spin? I've updated the Odometer algorithm to check the type of the wfn object using My concern with doing it this way is that we have to list out every possible type of wfn object and check if the instance of wfn is of the one-spin or two-spin type, and I'm not sure if there would be more types of wfn objects that would be implemented later and not be included in the types I have currently listed. if isinstance(wfn, pyci.fullci_wfn):
two_spin = True
elif isinstance(wfn, (pyci.doci_wfn, pyci.genci_wfn)):
two_spin = False
else:
raise TypeError
while True:
if new[-1] < wfn.nbasis and (np.sum(cost[new]) + t * cost[new[-1]]) < qmax:
# Accept determinant and go back to last particle
if two_spin:
wfn.add_occs(np.vstack((new, new)))
else:
wfn.add_occs(new) |
This is fine, there's only three classes, so you can check this way. There won't be more added. |
You can also just use the abstract superclasses |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks ok to me. If the tests run, you can merge it, although I'm not as familiar with this work being done, so I'd wait for Rik to approve it.
Can you rename the h{2,4}.fcidump files to specify the basis set? E.g. h2_sto3g.fcidump.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job! There are few things that needs to be fixed:
- I don't think there is a need to check a way function type in the odometer_one_spin algorithm. It is used only for the one_spin wavefunction and this can be checked directly in the test function when
odometer_one_spin
orodometer_two_spin
is called. - Test if the expected orbitals are selected when custom cost is provided
- Fix the test that throws the error on GH action. There is something wrong with a missing file
All finished, ready to merge. |
OK, yes this is ready to be merged. Can you just rebase it on master? Then I'll merge it. |
1a6c705
to
42d2af1
Compare
@msricher All done. |
@msricher Made a test for odometer one spin for H2 system in the minimal basis, I would expect that when we pass cost of the orbitals as energies: [0.74587179 1.10115033], if q_max is bigger than 0.75 it would select only the first determinant. If it is bigger than 1.2, it would select all determinants.
Currently, selecting a value lower than 0.74, doesn't select any determinant as expected. However, if it is bigger than 1.2 currently then we get an index error (or a segmentation fault error when we tried with the H4 system). Can you help to figure out what's going on?