-
Notifications
You must be signed in to change notification settings - Fork 270
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
enabled use of different independent_vars... #788
Conversation
@Julian-Hochhaus @reneeotten I'm not certain why this is failing... Anyone have any idea? |
@newville @Julian-Hochhaus Part of it is an old failure that I haven't been able to figure out. In a few tests the number of func evaluation doesn't appear to be correct for "certain Python versions with latest dependencies, bit only on Linux". New failures since this PR are due yo Sphinx version 5. Some stuff has changed there and now throws a warning (which we deliberately treat as an error). Nothing too problematic I'm sure - just haven't found the time yet to look. We should really fix the new issues and find a way around the "old" ones so we can actually use the test-suite again to check new code. I'll try to do that this weekend, things have been a bit hectic after just changing jobs. |
lmfit/model.py
Outdated
if 'independent_vars' not in kws: | ||
kws['independent_vars'] = self.left.independent_vars | ||
kws['independent_vars'] = list(dict.fromkeys([*self.left.independent_vars, *self.right.independent_vars])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The functional change looks fine I think. But first making a dictionary and then converting it to a list seems a bit awkward to me. Is this the easiest/cleanest way of doing it (I haven't checked myself yet)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps
ivar1, ivar2 = self.left.independent_vars, self.right.independent_vars
kws['independent_vars'] = ivar1 + [x for x in ivar2 if x not in ivar1]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have reviewed my solution and the alternative suggestions by @newville. Performance-wise the solution of making a dictionary and later converting it back to a list is generally faster. If the lengths of lists of independent_vars are in the range of n=100 by a factor of 30, for shorter and more reasonable lengths of n=10 it is only a factor of 2.
Obviously, in typical cases, the execution speed will never play a role because we will probably never have large numbers of independent variables. I will therefore use a version similar to @newville 's one, for better readability.
@Julian-Hochhaus also please add a test (e.g., based on the code you used to show the issue) that failed before and is now fixed with this PR. |
@reneeotten OK, thanks. It looks like some of the failures might be due to high expected precisions and highly precise expected number of function evaluations. I think some of those tolerances could probably be relaxed... |
@Julian-Hochhaus can you please |
@reneeotten @newville I was on vacation for the last two weeks, I will review the proposed optimization of the code and will rebase and trigger the tests again as soon as possible. |
I surely will asap and will clean my commit history too, so that the pull request, later on, gets nice and tidy |
@reneeotten I have created an example that shows that the code now works with two models with different independant_vars. |
@Julian-Hochhaus I'll admit to being hesitant about any analysis involving Azure, but it looks like maybe you need to remove the As an aside (or maybe a rant ;) )
and it's probably fine for, you know, all the simple cases. We're as guilty as the next person - it is in many of our examples.
In any production library or testing code, it is certain to cause failures. Basically, Thanks for allowing the rant... ;) |
@newville Thanks for the rant :). I have removed the plotting because it was not necessary to show the improvement of the code via plotting. I think the pull request is therefore finally ready to be published. |
I’ll take a look during the holiday weekend |
Thanks, Looks good to me! +1 on merging. |
@Julian-Hochhaus @newville I still see a few issues with this PR.
In short, I would recommend to add a test in |
lmfit/model.py
Outdated
if 'independent_vars' not in kws: | ||
kws['independent_vars'] = self.left.independent_vars | ||
ivar_left, ivar_right = self.left.independent_vars, self.right.independent_vars | ||
kws['independent_vars'] = ivar_left + [ivar for ivar in ivar_right if ivar not in ivar_left] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about
kws['independent_vars'] = np.unique(self.left.independent_vars + self.right.independent_vars)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, this was my bad... it should return a list
not an array
so that conversion is required here
Sorry to annoy you again, but I may need your help again @reneeotten. I am not sure why it is failing right now, assume it has to do with the testing in test_model.py |
The components to create a CompositeModel can now have different independent variables.
@Julian-Hochhaus okay, I think I've fixed up the things that needed changes... For future reference: (1) it's easier to make changes in a separate branch than Some of these things, amongst others are covered in our CONTRIBUTING guidelines. |
@Julian-Hochhaus @reneeotten Thanks to both of you for seeing this through! |
@reneeotten Thanks a lot for your help, I learned so much on the way. It was my first public pull request :). Thanks for your remarks, they will help me a lot in the future while contributing to public projects! |
... in Composite Model
The independent_vars in the CompositeModel are now no longer only the independent_vars of the left model.
Now, the independent_vars of the left model and right model are both passed to the independent_vars of the CompositeModel.
To reach that, I simply changed l.1120 in
model.py
from:to :
This fix solves the problem described in detail here.
Type of Changes
Tested on
Python: 3.8.3 (default, Jul 2 2020, 16:21:59)
[GCC 7.3.0]
lmfit: 1.0.3.post31+gb930dde.d20220613, scipy: 1.5.0, numpy: 1.18.5, asteval: 0.9.26, uncertainties: 3.1.6
Verification
Have you