WagnerGroup / pyqmc

Python library for real space quantum Monte Carlo
MIT License
82 stars 33 forks source link

Fix a key error in compute_tmoves() in eval_ecp.py #427

Closed cychow2 closed 9 months ago

cychow2 commented 9 months ago

Fix the following key error

  File "/projects/wagner/cychow2/.conda/envs/cco-new/lib/python3.11/concurrent/futures/process.py", line 256, in _process_worker
    r = call_item.fn(*call_item.args, **call_item.kwargs)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/projects/wagner/cychow2/.conda/envs/cco-new/lib/python3.11/site-packages/pyqmc/dmc.py", line 171, in dmc_propagate
    newepos, mask, probability, ecp_totweight = propose_tmoves(
                                                ^^^^^^^^^^^^^^^
  File "/projects/wagner/cychow2/.conda/envs/cco-new/lib/python3.11/site-packages/pyqmc/dmc.py", line 83, in propose_tmoves
    moves = energy_accumulator.nonlocal_tmoves(configs, wf, e, tstep)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/projects/wagner/cychow2/.conda/envs/cco-new/lib/python3.11/site-packages/pyqmc/accumulators.py", line 61, in nonlocal_tmoves
    return eval_ecp.compute_tmoves(self.mol, configs, wf, e, self.threshold, tau)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/projects/wagner/cychow2/.conda/envs/cco-new/lib/python3.11/site-packages/pyqmc/eval_ecp.py", line 60, in compute_tmoves
    npts = d["ratio"].shape[1]
           ~^^^^^^^^^
KeyError: 'ratio'

that results from a DMC run. This occurs when the ecp mask of an atom is all False.

willwheelera commented 9 months ago

I looked back for the reason why I added if not np.any(mask): return {"total": ecp_val}. It had to do with wf.testvalue not handling zero configs, and I thought it was better to avoid calling it in that case. Another way to address that is to replace ratio = wf.testvalue(e, epos, mask)[0] with

    if np.any(mask):
        ratio = wf.testvalue(e, epos, mask)[0]
    else:
        ratio = np.zeros(P_l.shape[:2])

That might be a simpler fix than generating empty arrays for all the variables or adding an if statement to compute_tmoves.