AffineScalarFunction
and related refactoring.
#251
Replies: 10 comments 27 replies
-
@jagerber48 I like this in general. I might have a few small nits: But, also: I think this is really interesting. In
and the setting of (and use of)
to indicate how many positional arguments there were? I think that will always be And also: could "float" be replaced with "float or complex or ndarray"? Where is "float and Python math" required here, and could that be expanded to "available numeric representations"? |
Beta Was this translation helpful? Give feedback.
-
I'm finding it harder than it needs to be to follow since you've used new class and attributes names. It'd be easier to compare current behaviour to this if less has changed. This looks like a good future state. It'd be good to see how you'd handle analytical derivatives. I don't think numerical derivatives should be used when the current behaviour uses analytical for many functions. I found the wrapping to return an AffineScalarType and dealing with nans felt more difficult than it should be. A partial derivative decorator that can handle
I still question the value of delaying the expansion. This doesn't save any time unless the user does not need the std_dev - in which case, why are they using uncertainties? |
Beta Was this translation helpful? Give feedback.
-
Here's a PR on my fork to more easily track the changes. I also made an actual test script to more clearly demonstrate implemented functionality: PR: #256 |
Beta Was this translation helpful? Give feedback.
-
Closed PR on this main repo (that was a mistake) and re-opened a PR on my fork: jagerber/uncertainties/2.
|
Beta Was this translation helpful? Give feedback.
-
refactored into a
Some effort has been made to give slick Some notes/thoughts I've had during this re-implementation process:
There are likely many more detailed features I'm missing. Continuing on this path next steps would be:
|
Beta Was this translation helpful? Give feedback.
-
This code "just works" for pickling and copying. This isn't so surprising since the objects are all immutable and there's not really anything much more complicated then a nested tuple. |
Beta Was this translation helpful? Give feedback.
-
pint uses codspeed
https://github.com/hgrecco/pint/blob/master/.github/workflows/bench.yml
I haven't looked into it myself
…On Fri, Aug 9, 2024 at 2:36 PM Justin Gerber ***@***.***> wrote:
Ah, thank you very much for linking the release with information about the
quadratic -> linear performance optimization. This is extremely helpful. My
understanding is that the performance optimization is to essentially ensure
that linear combinations of uncertainties are evaluated *lazily*. The new
UCombo/UAtom has included this optimization. But with the detail found in
your link I should be able to put together an actual performance test
seeing if performance is impacted.
Note that either the total refactor or the incremental change strategy
dramatically modifies the specific code responsible for this optimization,
it is the main target of this change. So in either case I think it's
important we have some performance testing in the test suite. Before we had
been wondering if this performance optimization was necessary or if it was
somehow a case of premature optimization. Your link makes it very clear
that it is a very important optimization.
I don't know how to properly do performance testing in the test suite (I
have guesses but they feel naive) but I can go ahead and learn how to do
that. Or someone can share if they already know how.
—
Reply to this email directly, view it on GitHub
<#251 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADEMLEHQZEXKTTMFIJAARO3ZQTAV5AVCNFSM6AAAAABK2LBTYKVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTAMRYG4ZDOMY>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Ok, I feel like I'm finally up-to-speed on the whole "situation" we are having with respect to the data models for
One of the centerpieces of the confusion is the fact that a A note on Note that To understand why things are the way they are it is important to understand
So, for each It is central to the current architecture of Some downsides of this approach. The "objects" that we work with are always
As soon as any operation is done on a This dual nature also has a downside involving derivatives. Recall that any
This makes sense. However, we get the sad
The problem is that My feeling on this is that the My proposal is the following:
With respect to the old way of doing things what has happened is that the What happens in this new framework is that when operations are performed with two
But the advantage here is that we also will have
In this new framework correlation can be detected by looking at the intersection of the sets of The big thing that is lost here is that we don't explicitly keep track of the dependency between an
there is no explicit record that
It is basically incidental which exact expression a given The new framework eliminates In the new framework instead of relationships between variables being captured by the
These relationships will of course be more complicated in the multi-variate case where the answer depends on the specific statistical covariances.
A note: above my proposal is to basically remove the For now, I imagine users will construct We could open the possibility for users to create their own Note that So question to the group, @lebigot, @newville , @andrewgsavage , @wshanks what are peoples thoughts on removing (1) the Names and implementation details are of course up for discussion. The only comment I'll make about the implementation here is that the important "lazy linear combination expansion" performance optimization lebigot put in years ago is just as possible in the new framework as it is in the old. |
Beta Was this translation helpful? Give feedback.
-
@jagerber48 +1 on dropping the name But also: I get that I'm OK with keeping "lazy derivatives" but I am also skeptical about potential performance problems for scalar calculations. I would suggest focusing on an implementation we all can understand and maintain. |
Beta Was this translation helpful? Give feedback.
-
Ok, I've been busy for a long time, but now I have some limited time to look at this again. I think we actually left the conversation off in a pretty good spot a few months ago. The conclusion from my perspective was that:
I'll try to move forward on this as I have time. |
Beta Was this translation helpful? Give feedback.
-
There have been many discussions targeting a refactoring of
AffineScalarFunction
and the relatedVariable
,LinearCombination
etc.Here's a bit of code I wrote that re-implements a lot of the core
uncertainties
functionality but in ways which I feel are more clear.Here I laid out some goals for this refactoring
Examples:
I don't know if this code resolves the stated bugs. I need to go back through the discussion to find what those bugs are.
I think this code is much more understandable/readable than the current source code. One way it is greatly helped is by using the newer
inspect.signature
methods for function signature introspection and manipulation. This is usually much easier to work with and understand than the oldargspec
approaches. But I also think some of the other technical details (linear combination expansion, partial derivative calculation, uncertainty propagation) are also more clear.Importantly this code also gets around some of the circularity that seems to be present in the existing source code via the introduction of the simple
UncertaintyAtom
dataclass. There is one point of self-referencing, but that only appears in the type alias forUncertaintyLinearCombination
.I think this code will be easier to make saving/loading work. The only sticking point I see is that it is possible there could be two
UFloat
s that are equal, meaning they have the same value and their uncertainty linear combinations expand to be equal, but the unexpanded forms of their linear combinations differ from each other. The question is, should two suchUFloats
be equal to each other? I think yes. Should they have the same hash? I'm not sure.It's also pretty clear in this code that all the major classes could be made/interpreted to be immutable.
I don't know how this code compares in performance to the current implementation. I tried to follow a similar strategy so I hope it's not too far off. It does look like there was some caching that might be implemented in the current source code which I didn't implement here.
Originally I was considering schemes that looked something like:
So to this end I tried to stick with the "linear combination of uncertainty atoms" approach. I hope this means performance is similar.
Obviously this code doesn't capture the full functionality of
uncertainties
. But I do think it captures a lot of the core functionality in many fewer lines and in a way that is more readable. I'm curious what bits of this implementation might be ported into the main source codeEdit: Updated code so that you can pass either function parameter names that should allow
UFloat
, or parameter numbers. The latter is very useful when dealing with built-in math functions that typically expose positional arguments whose actual names are hard to track down. The latter may be useful for users toUFloat
-ify their own math functions.Edit2: It was necessary to add a
uuid
field toUncertaintyAtom
to ensureUFloat(1, 1) - UFloat(1, 1)
did NOT giveUFloat(0, 0)
. Not that ifx=UFloat(1, 0)
thenx-x
DOES giveUFloat(0, 0)
.Beta Was this translation helpful? Give feedback.
All reactions