rhayes777 / PyAutoFit

PyAutoFit: Classy Probabilistic Programming
https://pyautofit.readthedocs.io/
MIT License
60 stars 11 forks source link

Notes on hacking a fix for the GridSearch Optimizer #96

Closed Jammy2211 closed 3 years ago

Jammy2211 commented 4 years ago

Firstly, the Result class in AutoLens includes positions, which are not found when results are passed to a phase after a grid search phase. We probably need to update the GridSearch's getattr method:

Traceback (most recent call last):
  File "/home/jammy/PycharmProjects/PyAuto/autolens_workspace/runners/advanced/no_lens_light/lens_power_law__subhalo_nfw__source_sersic.py", line 168, in <module>
    pipeline.run(dataset=imaging, mask=mask)
  File "/home/jammy/PycharmProjects/PyAuto/PyAutoLens/autolens/pipeline/pipeline.py", line 15, in run
    return self.run_function(runner)
  File "/home/jammy/PycharmProjects/PyAuto/PyAutoFit/autofit/tools/pipeline.py", line 198, in run_function
    results.add(name, func(phase, results))
  File "/home/jammy/PycharmProjects/PyAuto/PyAutoLens/autolens/pipeline/pipeline.py", line 12, in runner
    info=info,
  File "/home/jammy/PycharmProjects/PyAuto/PyAutoLens/autolens/pipeline/phase/dataset/phase.py", line 71, in run
    dataset=dataset, mask=mask, results=results, positions=positions
  File "/home/jammy/PycharmProjects/PyAuto/PyAutoLens/autolens/pipeline/phase/imaging/phase.py", line 128, in make_analysis
    results=results,
  File "/home/jammy/PycharmProjects/PyAuto/PyAutoLens/autolens/pipeline/phase/imaging/analysis.py", line 11, in __init__
    super(Analysis, self).__init__(cosmology=cosmology, results=results)
  File "/home/jammy/PycharmProjects/PyAuto/PyAutoLens/autolens/pipeline/phase/dataset/analysis.py", line 19, in __init__
    result = last_result_with_use_as_hyper_dataset(results=results)
  File "/home/jammy/PycharmProjects/PyAuto/PyAutoLens/autolens/pipeline/phase/dataset/analysis.py", line 10, in last_result_with_use_as_hyper_dataset
    if result.use_as_hyper_dataset:
  File "/home/jammy/PycharmProjects/PyAuto/PyAutoFit/autofit/optimize/grid_search.py", line 41, in __getattr__
    return getattr(self.best_result, item)
AttributeError: 'Result' object has no attribute 'use_as_hyper_dataset'

The next issue is, when for the phase after a GridSearch you attempt to pass a result, you get the follwing error:

Traceback (most recent call last):
  File "/home/jammy/PycharmProjects/PyAuto/autolens_workspace/runners/advanced/no_lens_light/lens_power_law__subhalo_nfw__source_sersic.py", line 168, in <module>
    pipeline.run(dataset=imaging, mask=mask)
  File "/home/jammy/PycharmProjects/PyAuto/PyAutoLens/autolens/pipeline/pipeline.py", line 15, in run
    return self.run_function(runner)
  File "/home/jammy/PycharmProjects/PyAuto/PyAutoFit/autofit/tools/pipeline.py", line 198, in run_function
    results.add(name, func(phase, results))
  File "/home/jammy/PycharmProjects/PyAuto/PyAutoLens/autolens/pipeline/pipeline.py", line 12, in runner
    info=info,
  File "/home/jammy/PycharmProjects/PyAuto/PyAutoLens/autolens/pipeline/phase/dataset/phase.py", line 63, in run
    self.save_meta_dataset(meta_dataset=self.meta_dataset)
  File "/home/jammy/PycharmProjects/PyAuto/PyAutoFit/autofit/tools/phase.py", line 109, in save_meta_dataset
    meta_dataset, f
AttributeError: Can't pickle local object 'make_pipeline.<locals>.GridPhase'
Jammy2211 commented 3 years ago

Sorted.