MomentsLD / moments

MIT License
10 stars 3 forks source link

Godambe not working when running IM parsing example #192

Open jiseonmin opened 2 months ago

jiseonmin commented 2 months ago

Hello! I was running into some issues while running examples/LD/parsing-and-inference-example.py. FYI, I forked the main repository and made a new environment to test it. Is there a bug in LD/Inference.py, or is it something specific to this example script? This is the error message I got:

Traceback (most recent call last):
  File "/gpfs/home/jiseonm/moments/examples/LD/parsing-and-inference-example.py", line 205, in <module>
    uncerts = moments.LD.Godambe.GIM_uncert(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/gpfs/home/jiseonm/micromamba/envs/moments_env/lib/python3.12/site-packages/moments/LD/Godambe.py", line 398, in GIM_uncert
    GIM, H, J, cU = _get_godambe(
                    ^^^^^^^^^^^^^
  File "/gpfs/home/jiseonm/micromamba/envs/moments_env/lib/python3.12/site-packages/moments/LD/Godambe.py", line 248, in _get_godambe
    grad_temp = _get_grad(func, p0, eps, args=[bs_ms, vcs])
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/gpfs/home/jiseonm/micromamba/envs/moments_env/lib/python3.12/site-packages/moments/LD/Godambe.py", line 179, in _get_grad
    fp = func(pwork, *args)
         ^^^^^^^^^^^^^^^^^^
  File "/gpfs/home/jiseonm/micromamba/envs/moments_env/lib/python3.12/site-packages/moments/LD/Godambe.py", line 226, in func
    ll = Inference.ll_over_bins(y, m, v)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/gpfs/home/jiseonm/micromamba/envs/moments_env/lib/python3.12/site-packages/moments/LD/Inference.py", line 252, in ll_over_bins
    ll_vals.append(_ll(xs[ii], mus[ii], Sigma_inv))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/gpfs/home/jiseonm/micromamba/envs/moments_env/lib/python3.12/site-packages/moments/LD/Inference.py", line 211, in _ll
    return -1.0 / 2 * np.dot(np.dot((x - mu).transpose(), Sigma_inv), x - mu)
                                     ~~^~~~
ValueError: operands could not be broadcast together with shapes (14,) (13,) 

There were two small changes I had to make to go through the lines before the Godambe step. I don't think it's relevant for my question, but I will report them here just in case. First, numpy.2 doesn't seem to be compatible with scikit.allel, so I had to downgrade it. Next, I changed line 57 to ts.write_vcf(fout, allow_position_zero=True) from ts.write_vcf(fout). Thanks!

apragsdale commented 2 months ago

Hi @jiseonmin - thanks for opening in this issue. I'm busy at this very moment with the first week of teaching here, but I'll try to look into this as soon as possible. It may be that there is just an issue with that example script.

Your point about numpy 2 is right, and it could cause incompatibilities with other dependencies of moments, and possibly with moments itself. For that reason, we've pinned the numpy requirement to <2.0.