-
Notifications
You must be signed in to change notification settings - Fork 25
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
Applying FermionOperator to wavefunction gives memory error #136
Comments
It looks like it is building a Hamiltonian with a general 8 fermion
interaction (but here defined only with one non zero element).
Sent from Gmail Mobile
…On Sun, Nov 17, 2024 at 12:54 PM Kevin J. Sung ***@***.***> wrote:
This example has 4 electrons in 8 orbitals. Why is it trying to allocate a
64 GB array?
import fqefrom openfermion import FermionOperator, hermitian_conjugated
op = FermionOperator("5^ 3 2 12^") + FermionOperator("2 4^ 11^ 15 12 14^ 4 8^")op += hermitian_conjugated(op)wfn = fqe.get_wavefunction(4, 0, 8)wfn.set_wfn(strategy="hartree-fock")new_wfn = wfn.apply(op)
Traceback (most recent call last):
File "/home/kjs/projects/scratch/fqe-repro.py", line 8, in <module>
new_wfn = wfn.apply(op)
^^^^^^^^^^^^^
File "/home/kjs/.pyenv/versions/scratch/lib/python3.12/site-packages/fqe/fqe_decorators.py", line 365, in convert
hamil = build_hamiltonian(ops,
^^^^^^^^^^^^^^^^^^^^^^
File "/home/kjs/.pyenv/versions/scratch/lib/python3.12/site-packages/fqe/fqe_decorators.py", line 104, in build_hamiltonian
ops_mat[index] = fermionops_tomatrix(term, norb)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/kjs/.pyenv/versions/scratch/lib/python3.12/site-packages/fqe/fqe_decorators.py", line 225, in fermionops_tomatrix
tensor = numpy.zeros(tensor_dim, dtype=numpy.complex128)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
numpy.core._exceptions._ArrayMemoryError: Unable to allocate 64.0 GiB for an array with shape (16, 16, 16, 16, 16, 16, 16, 16) and data type complex128
—
Reply to this email directly, view it on GitHub
<#136>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN5NRF5PWYICGXYVETGMLT2BD7B3AVCNFSM6AAAAABR6KAV5WVHI2DSMVQWIX3LMV43ASLTON2WKOZSGY3DMNBZHA2TQMQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
If I remember correctly if you pass FermonOperator directly to apply, it would create a dense operator, because FQE does not know if your operator is better handled as a sparse operator or not. Can you first create a SparseHamiltonian object explicitly and pass that to apply? https://github.com/quantumlib/OpenFermion-FQE/blob/master/src/fqe/hamiltonians/sparse_hamiltonian.py @awhite862 please follow up when you get a chance. |
Ah okay this works: new_wfn = wfn.apply(fqe.get_sparse_hamiltonian(op)) In this case it would be nice to automatically choose to use sparse instead of dense. I'll leave this issue open in case you want to track that, otherwise feel free to close. |
We could potentially add some more sophisticated logic to try to guess the most efficient representation of the operator when it is passed as a |
This example has 4 electrons in 8 orbitals. Why is it trying to allocate a 64 GB array?
The text was updated successfully, but these errors were encountered: