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

Require dill #940

Merged
merged 7 commits into from
Feb 21, 2024
Merged

Require dill #940

merged 7 commits into from
Feb 21, 2024

Conversation

newville
Copy link
Member

Description

This requires the dill package to be installed for lmfit. That simplifies several tests for dill in the code.

This also includes a change (with back-compatible checks) to the format for a saved Model, with __setstate__/__getstate__.

Also included here are tests of loading models across Python versions -- in general this does not work and model functions need to be re-provided for successfully loading a model saved from a different version. The added tests add appropriate messages and successfully load models when the objective function is provided.

Type of Changes
  • Bug fix
  • New feature
  • Refactoring / maintenance
  • Documentation / examples
Tested on

Python: 3.11.5 | packaged by conda-forge | (main, Aug 27 2023, 03:35:23) [Clang 15.0.7 ]

lmfit: 1.2.2.post37+g3e05019, scipy: 1.11.4, numpy: 1.26.2, asteval: 0.9.31, uncertainties: 3.1.7

Verification

Have you

  • [?] included docstrings that follow PEP 257?
  • referenced existing Issue and/or provided relevant link to mailing list?
  • verified that existing tests pass locally?
  • verified that the documentation builds locally?
  • squashed/minimized your commits and written descriptive commit messages?
  • added or updated existing tests to cover the changes?
  • updated the documentation and/or added an entry to the release notes (doc/whatsnew.rst)?
  • added an example?

Copy link

codecov bot commented Feb 18, 2024

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (6096c3a) 93.10% compared to head (a9269bd) 93.11%.

Files Patch % Lines
lmfit/jsonutils.py 80.00% 2 Missing ⚠️
lmfit/model.py 92.30% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #940      +/-   ##
==========================================
+ Coverage   93.10%   93.11%   +0.01%     
==========================================
  Files          10       10              
  Lines        3711     3720       +9     
==========================================
+ Hits         3455     3464       +9     
  Misses        256      256              

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

@newville
Copy link
Member Author

I would like to build changes to address "independent variables vs opts" (discussed in #925 and #926) on top of this. So, I would like to merge this (I think "internal only" and with testing) within a couple of days to push a small but significant push on top of this.

OK to merge?

Copy link
Contributor

@reneeotten reneeotten left a comment

Choose a reason for hiding this comment

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

@newville I am fine with always requiring dill that does make life easier indeed. The change should be documented in doc/installation.rst as well.

One comment on the proposed change for you to consider, other than that I am fine with merging it.

lmfit/model.py Outdated
now supports versions of 'state'.

State Versions:
'1': state is a tuple of length 9:
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a bit confusing to me as there is actually no version "state 1", at least not explicitly. I assume this state is how things are saved before this PR - correct? I think the description could be a bit more clear on this.

In fact, I am not really sure the additional complication is needed. To me it appears that the "previous" way of doing things would always result in a tuple, the "new" method will save things as a dict. That distinction in itself should be sufficient to distinguish what to do with the input (and ideally after a while, we can just deprecate and eventually remove reading of the tuple state.
The version key seems not really necessary, I would hope that we don't need to change this anymore and we ideally don't want to have to deal with writing/reading of different versions. Are you not sure yet about the structure of this yet; it would be good to make sure to have that all settled before implementing this change.

Copy link
Member Author

Choose a reason for hiding this comment

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

@reneeotten Thanks -- will fix

lmfit/model.py Outdated
(fname, func, name, prefix, ivars, pnames,
phints, nan_policy, opts) = left
elif isinstance(left, dict) and 'version' in left:
if left['version'] == '2':
Copy link
Contributor

Choose a reason for hiding this comment

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

this is always "True"

Copy link
Member Author

Choose a reason for hiding this comment

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

@reneeotten Thanks - I'll look at this. I think the idea was to attempt to be future-proof.

@reneeotten
Copy link
Contributor

thanks @newville - looks food to me. Perhaps update the "dill" requirement in "doc/installation.rst" and then it should be good to (squash) merge.

@newville newville merged commit c9c2b2d into master Feb 21, 2024
14 checks passed
@newville newville deleted the require_dill branch April 4, 2024 18:24
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.

2 participants