rhayes777 / PyAutoFit

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

Fix combined analysis result #1016

Closed Jammy2211 closed 1 month ago

Jammy2211 commented 5 months ago

Running the following script:

https://github.com/Jammy2211/autocti_workspace/blob/main/scripts/dataset_1d/modeling/start_here.py

Gives the following error:

2024-05-03 13:31:49,565 - database_example - INFO - Fit Complete: Updating final results (see output folder).
2024-05-03 13:31:51,888 - autofit.non_linear.samples.samples - INFO - Samples with weight less than 1e-10 removed from samples.csv.
Traceback (most recent call last):
  File "/mnt/c/Users/Jammy/Code/PyAuto/autocti_workspace/scripts/dataset_1d/advanced/database/start_here.py", line 214, in <module>
    search.fit(analysis=analysis, model=model, info=info)
  File "/mnt/c/Users/Jammy/Code/PyAuto/PyAutoFit/autofit/non_linear/search/abstract_search.py", line 589, in fit
    result = self.start_resume_fit(
  File "/mnt/c/Users/Jammy/Code/PyAuto/PyAutoFit/autofit/non_linear/search/abstract_search.py", line 112, in decorated
    return func(self, *args, **kwargs)
  File "/mnt/c/Users/Jammy/Code/PyAuto/PyAutoFit/autofit/non_linear/search/abstract_search.py", line 728, in start_resume_fit
    analysis.save_results_combined(paths=self.paths, result=result)
  File "/mnt/c/Users/Jammy/Code/PyAuto/PyAutoFit/autofit/non_linear/analysis/combined.py", line 208, in save_results_combined
    self.analyses[0].save_results_combined(
  File "/mnt/c/Users/Jammy/Code/PyAuto/PyAutoCTI/autocti/model/analysis.py", line 81, in save_results_combined
    weight_list = []
AttributeError: 'NoneType' object has no attribute 'sample_list'

The problem is that in this code:

https://github.com/rhayes777/PyAutoFit/blob/main/autofit/non_linear/analysis/combined.py

The following part of the code:

    def save_results_combined(self, paths: AbstractPaths, result: Result):
        self.analyses[0].save_results_combined(
            paths=paths,
            result=result,
        )

The input result has result.samples which is None.

This must be due to how for combined analyses the result is being computed and passed around.

NOTE: The code will not raise an error if you run it because I put the following bypass in the autocti source code to get tests passing:

https://github.com/Jammy2211/PyAutoCTI/blob/main/autocti/model/analysis.py

        if result.samples is None:
            return
rhayes777 commented 1 month ago

I think this is resolved although that script now raises an AssertionError when saving the combined result