ebachelet / pyLIMA

GNU General Public License v3.0
31 stars 8 forks source link

pickle issue #47

Closed ytsapras closed 1 year ago

ytsapras commented 2 years ago

code complains if once a single model has been fit and .produce_output called, a second model is attempted with multiprocessing.

Traceback (most recent call last):
  File "blah.py", line 100, in <module>
    current_event.fit(Model_2, 'DE', DE_population_size = 20, computational_pool = pool)
  File "/home/ytsapras/Installed_Programs/anaconda3/lib/python3.7/site-packages/pyLIMA/event.py", line 107, in fit
    grid_resolution=grid_resolution, computational_pool=computational_pool, binary_regime=binary_regime)
  File "/home/ytsapras/Installed_Programs/anaconda3/lib/python3.7/site-packages/pyLIMA/microlfits.py", line 186, in mlfit
    self.fit_results, self.fit_covariance, self.fit_time = self.differential_evolution(pool)
  File "/home/ytsapras/Installed_Programs/anaconda3/lib/python3.7/site-packages/pyLIMA/microlfits.py", line 527, in differential_evolution
    disp=True,workers = worker,
  File "/home/ytsapras/Installed_Programs/anaconda3/lib/python3.7/site-packages/scipy/optimize/_differentialevolution.py", line 308, in differential_evolution
    ret = solver.solve()
  File "/home/ytsapras/Installed_Programs/anaconda3/lib/python3.7/site-packages/scipy/optimize/_differentialevolution.py", line 751, in solve
    self.population[self.feasible]))
  File "/home/ytsapras/Installed_Programs/anaconda3/lib/python3.7/site-packages/scipy/optimize/_differentialevolution.py", line 874, in _calculate_population_energies
    parameters_pop[0:nfevs]))
  File "/home/ytsapras/Installed_Programs/anaconda3/lib/python3.7/site-packages/scipy/_lib/_util.py", line 414, in __call__
    return self._mapfunc(func, iterable)
  File "/home/ytsapras/Installed_Programs/anaconda3/lib/python3.7/multiprocessing/pool.py", line 268, in map
    return self._map_async(func, iterable, mapstar, chunksize).get()
  File "/home/ytsapras/Installed_Programs/anaconda3/lib/python3.7/multiprocessing/pool.py", line 657, in get
    raise self._value
  File "/home/ytsapras/Installed_Programs/anaconda3/lib/python3.7/multiprocessing/pool.py", line 431, in _handle_tasks
    put(task)
  File "/home/ytsapras/Installed_Programs/anaconda3/lib/python3.7/multiprocessing/connection.py", line 206, in send
    self._send_bytes(_ForkingPickler.dumps(obj))
  File "/home/ytsapras/Installed_Programs/anaconda3/lib/python3.7/multiprocessing/reduction.py", line 51, in dumps
    cls(buf, protocol).dump(obj)
_pickle.PicklingError: Can't pickle <class 'pyLIMA.microloutputs.Fit_outputs'>: attribute lookup Fit_outputs on pyLIMA.microloutputs failed
blackmanjw commented 1 year ago

Hi Yiannis,

Did you ever find a solution to this? I'm simply trying to pickle a your_event.fits[0] object so I can replot it later and I get the same error:

PicklingError                             Traceback (most recent call last)
<ipython-input-33-381a5798d73f> in <module>
      2 import pickle
      3 with open('pylima_usbl.pkl', 'wb') as file:
----> 4           pickle.dump(your_event.fits[0], file)
      5 file.close()

PicklingError: Can't pickle <class 'pyLIMA.microloutputs.Fit_outputs'>: attribute lookup Fit_outputs on pyLIMA.microloutputs failed
ytsapras commented 1 year ago

Hi Josh, I haven't encountered this problem again but maybe Etienne can comment on this. In any case, I have switched to using the new version of pyLIMA (ReBranding branch), which comes with easier plotting options. I think there are no plans to support the first release once the new version is official so if you want to test things out, I suggest checking out the ReBranding branch and playing with it to identify any potential bugs there.

Note that some of the commands have changed in the new release, but you can look at the examples/_new files to see how it handles things.

blackmanjw commented 1 year ago

Hi Yiannis, Thx...I didn't realise there was a newer branch, so I'll give that a go. I spent a bunch of time writing some code to output some pngs/pdfs with geometry/zooms etc the way I want but I'll see what's in the new release..