quantumlib / OpenFermion

The electronic structure package for quantum computers.
Apache License 2.0
1.52k stars 376 forks source link

Lookup dictionary for JW transformation of a FermionOperator #777

Closed alexfleury closed 2 years ago

alexfleury commented 2 years ago

Low-hanging fruit for a simple speedup when working on FermionOperator -> QubitOperator conversions. The problem has been raised in #587. This is not an optimal solution to this issue (neither parallelization nor cython), but there is a significant speed improvement when working with a FermionOperator with redundant terms.

Here is a simple script I used to test:

import time

import openfermion as of
from openfermionpyscf import run_pyscf

mol = of.chem.MolecularData(geometry=[["H", (0., 0., 0.)], ["H", (0., 0., 0.75)]], multiplicity=1, charge=0, basis="ccpvtz")
mol = run_pyscf(mol, verbose=True)
mol_op = mol.get_molecular_hamiltonian()

ferm_op = of.transforms.get_fermion_operator(mol_op)

start_time = time.time()
qubit_op = of.transforms.jordan_wigner(ferm_op)
final_time = time.time() - start_time

print(f"{final_time}s")

On my machine (Arch Linux 5.17.3-arch1-1, python 3.8.5): Before = 10min27s After = 5min14s

Other tests: O2_6-31g_triplet | 81s | 42 s NaCl_sto-3g_singlet | 2min34s | 1min20s

ncrubin commented 2 years ago

@alexfleury , looks like we have a Cirq compatibility issue. I'll take a look and update what's going on here. I am fairly sure this a problem on our side and not yours.

alexfleury commented 2 years ago

All good! I am following this thread to see if there are action items I would have to take care of.