quantumlib / OpenFermion-Cirq

Quantum circuits for simulations of quantum chemistry and materials.
Apache License 2.0
276 stars 87 forks source link

Error on running the H6 simulation using LowRankTrotterAnsatz (raises the ValueError 'one_body_matrix is not Hermitian.') #323

Open unpilbaek opened 5 years ago

unpilbaek commented 5 years ago

I have set up the H6 molecule as below and used the LowRankTrotterAnsatz in the ./configs/sample_config.py:

molecule_settings = MoleculeSettings(
    geometry=[('H', (0., 0., -2.5)),
              ('H', (0., 0., -1.5)),
              ('H', (0., 0., -0.5)),
              ('H', (0., 0., 0.5)),
              ('H', (0., 0., 1.5)),
              ('H', (0., 0., 2.5))
              ],
    basis='sto-3g',
    multiplicity=1,
    charge=0,
    description = 'H6-sto-3g-1.0')

molecule = molecule_maker.get_molecule(molecule_settings)

ansatz=LowRankTrotterAnsatz(molecule.get_molecular_hamiltonian())

and ran my vqe_ensemble.py for the analysis purposes. However, I get the following error message:

Traceback (most recent call last):
  File "vqe_ensemble.py", line 9, in <module>
    import determinant_ansatz as determinant_ansatz
  File "/Users/user/git-repo/offdiagonal/determinant_ansatz.py", line 5, in <module>
    from settings import CONFIG
  File "/Users/user/git-repo/offdiagonal/settings.py", line 26, in <module>
    spec.loader.exec_module(CONFIG)
  File "./configs/sample_config.py", line 41, in <module>
    ansatz=LowRankTrotterAnsatz(molecule.get_molecular_hamiltonian())
  File "/Users/user/git-repo/OpenFermion-Cirq/openfermioncirq/variational/ansatzes/low_rank.py", line 158, in __init__
    one_body_squares[j]))
  File "/Users/user/anaconda3/envs/vqe/lib/python3.6/site-packages/openfermion/utils/_low_rank.py", line 209, in prepare_one_body_squared_evolution
    raise ValueError('one_body_matrix is not Hermitian.')
ValueError: one_body_matrix is not Hermitian.

I was able to run the same code for the linear H2 and H4 molecules without getting the ValueError at the end. It seems like there may be some numerical error that makes the one_body_matrix non-Hermitian.

kevinsung commented 5 years ago

@babbush @jarrodmcc thoughts?

babbush commented 5 years ago

I agree with @unpilbaek that its quite possibly due to some sort of numerical round-off error. I won't have time to get to the bottom of this right now though. The low rank factorization stuff is very prone to numerical instabilities.