Skip to content

Applying FermionOperator to wavefunction gives memory error #136

@kevinsung

Description

@kevinsung

This example has 4 electrons in 8 orbitals. Why is it trying to allocate a 64 GB array?

import fqe
from 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions