Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dynesty: new method to save only the raw dynesty sample results #1331

Merged
merged 14 commits into from
Mar 21, 2024

Conversation

dilpath
Copy link
Member

@dilpath dilpath commented Mar 20, 2024

With this change, things like AMICI models that exist in the dynesty loglikelihood, are not saved in the dynesty internal result.

Dummy pyPESTO objects (e.g. for analysis or plotting) can be created by supplying the raw_results to get_original_dynesty_samples or get_mcmc_like_dynesty_samples.

@dilpath dilpath requested a review from arrjon March 20, 2024 14:03
@dilpath dilpath requested a review from vwiela as a code owner March 20, 2024 14:03
@dilpath dilpath changed the title dynesty: manually restore pyPESTO information dynesty: new method to save only the raw dynesty sample results Mar 20, 2024
@codecov-commenter
Copy link

codecov-commenter commented Mar 20, 2024

Codecov Report

Attention: Patch coverage is 70.83333% with 14 lines in your changes are missing coverage. Please review.

Project coverage is 82.38%. Comparing base (81ff7ff) to head (29a5069).

Files Patch % Lines
pypesto/sample/dynesty.py 70.83% 14 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1331      +/-   ##
===========================================
- Coverage    84.29%   82.38%   -1.91%     
===========================================
  Files          152      152              
  Lines        12432    12452      +20     
===========================================
- Hits         10479    10259     -220     
- Misses        1953     2193     +240     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@arrjon
Copy link
Contributor

arrjon commented Mar 21, 2024

Thanks Dilan! I check your branch and something seems not quite right yet

  • some results seem to be discared: sampler.results.logz does not have the same size before and after loading it
  • Moreover, if I call restore_internal_sampler I get AttributeError: 'DynestySampler' object has no attribute 'results'. However, using directly dynesty.utils.restore_sampler works fine. (this issue was already there before your updates)

@dilpath
Copy link
Member Author

dilpath commented Mar 21, 2024

  • some results seem to be discared: sampler.results.logz does not have the same size before and after loading it

Works fine for me, logz is the same shape before and after using save_raw_results and load_raw_results. However, these methods do not save the dynesty DynestySampler.sampler object. Could you try e.g.

print(pypesto_sampler.sampler.results.logz.shape)
pypesto.sample.dynesty.save_raw_results(pypesto_sampler, "dynesty.raw")
raw_results = pypesto.sample.dynesty.load_raw_results("dynesty.raw")
print(raw_results.logz.shape)
  • Moreover, if I call restore_internal_sampler I get AttributeError: 'DynestySampler' object has no attribute 'results'. However, using directly dynesty.utils.restore_sampler works fine. (this issue was already there before your updates)

Also cannot reproduce, e.g. with

print(pypesto_sampler_original.sampler.results.logz.shape)
pypesto_sampler_original.save_internal_sampler("dynesty.dill")
pypesto_sampler = pypesto.sample.DynestySampler(objective_type="negloglike")
pypesto_sampler.restore_internal_sampler("dynesty.dill")
print(pypesto_sampler.sampler.results.logz.shape)

AttributeError: 'DynestySampler' object has no attribute 'results'

Maybe you are trying to access the pyPESTO sampler object, instead of the dynesty sampler object?

# pyPESTO sampler object is `DynestySampler`
pypesto_sampler = pypesto.sample.DynestySampler()
# dynesty sampler object is at `DynestySampler.sampler`
pypesto_sampler.sampler

pypesto_sampler.sampler will have pypesto_sampler.sampler.results.

@arrjon
Copy link
Contributor

arrjon commented Mar 21, 2024

to reproduce the attribute error use in the sampler notebook

sampler = sample.DynestySampler(objective_type="negloglike")
result = sample.sample(
    problem=problem,
    n_samples=None,
    sampler=sampler,
    filename=None,
)
print(sampler.results.logz)

sampler.save_internal_sampler("dynesty.dill")

dummy_sampler = sample.DynestySampler()
dummy_sampler.restore_internal_sampler("dynesty.dill")

print(dummy_sampler.results.logz)

Copy link
Contributor

@arrjon arrjon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now this is fixed, thanks!

Copy link
Contributor

@vwiela vwiela left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Nice to circumvent the confusion if one does not need to deal with sampler.results and sampler.sampler.results anymore, but can access the raw results more easily now.
Thanks.

@dilpath dilpath merged commit 9bde856 into develop Mar 21, 2024
18 checks passed
@dilpath dilpath deleted the cleaner_dynesty_internal_save branch March 21, 2024 16:12
@PaulJonasJost PaulJonasJost mentioned this pull request Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants