minaskar / pocomc

pocoMC: A Python implementation of Preconditioned Monte Carlo for accelerated Bayesian Computation
https://pocomc.readthedocs.io
GNU General Public License v3.0
80 stars 9 forks source link

Sigma calculation error: AttributeError: 'float' object has no attribute 'item' #22

Closed augeorge closed 3 months ago

augeorge commented 1 year ago

Hello I have been using the pococmc package to sample parameters of an ODE-based system. Occasionally, an error arises in my runs: AttributeError: 'float' object has no attribute 'item'. This happens at different times depending on which seed I use, and sometimes doesn't happen at all. It seems like sigma is a Tensor object but is somehow incorrectly being typed as a float? Any ideas how to fix this?

Error trace example:

  sampler.run(p_0, ess, gamma, int(n_dim), int(1000*n_dim), progress=True)
  File "/opt/miniconda3/envs/pyPoco/lib/python3.10/site-packages/pocomc/sampler.py", line 405, in run
    self.u, self.x, self.J, self.L, self.P = self._mutate(
  File "/opt/miniconda3/envs/pyPoco/lib/python3.10/site-packages/pocomc/sampler.py", line 532, in _mutate
    results = preconditioned_metropolis(
  File "/opt/miniconda3/envs/pyPoco/lib/python3.10/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "/opt/miniconda3/envs/pyPoco/lib/python3.10/site-packages/pocomc/mcmc.py", line 167, in preconditioned_metropolis
    scale=sigma.item() / (2.38 / np.sqrt(n_dim)),
AttributeError: 'float' object has no attribute 'item'
DouglasRWalker commented 1 year ago

I am getting the same error, but for me this error raises every time I run pocomc on a particular model system. However, it never once raised that error when I was running on a simpler system. I would be interested in knowing if there has been any work toward addressing this issue in the code?

minaskar commented 3 months ago

This is resolved in the latest release. Feel free to reopen this if the problem re-appears.