-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
Implement copy!
for noise types
#127
Conversation
Some more thoughts:
But my understanding is that there is something odd about noise types. Typically, there is a clear distinction between a problem, its arguments, and its solution. For instance, an |
Yes, I've thought about that too, but it seemed like a really big lift and it's hard to know what the tangible advantage in the end ends up being. |
Yeah, I understand that. It is not clear the advantages are worth the trouble. But I will keep this in mind to maybe try implementing this at some point, in a nonbreaking way, adding fields and types instead of replacing them, for testing purposes. |
Ok, I am opening this PR so we can discuss whether this approach and the implementation are ok or not and, hopefully, get it approved. I've been scratching my head over this for the past few days.
There is this issue to connect
prob.noise
withsol.W
when solving an SDE, RODE, etc.. We need, somehow, to letprob
know that we are solving the problem again, so a newreseed!
and a newreinit!
can be triggered and a different sample path can be used.Originally, we had
prob.noise = sol.W
, which had the problem of affecting all the previous solves because they all aliassol.W
. My first fix was todeepcopy
theprob.noise
when solving it and thendeepcopy
thesol.W
back toprob.noise
(SciML/StochasticDiffEq.jl#496). This week, however, I found a side effect of that, which is that of dealiasingsol.W.u
fromsol.W.W
. And this also has the problem of abusing deepcopy. So, there is this idea of adding a propercopy
for noise types, to avoid usingdeepcopy
. This is an attempt of that.copy
by recursively going down the fields and eitherassigning
or usingcopy
orrecursivecopy
or, at the last resort,deepcopy
. Everything seems fine, but I can't say I am 100% sure it won't break at some point. But that is how it usually is. In all tests, here and over at StochasticDiffEq, it seems to be deep copying only thesource
fields of very specific noise types such asNoiseWrapper
andNoiseApproximation
, some of which actually use deepcopy themselves, upon creation of an instance. So I guess that is okay. My only concern is that some types are subtypes ofAbstractArray
and could get down torecursivecopy
and end up not being copied properly or failing. But I haven't found any case of that so far. (if one tries torecursivecopy
aVirtualBrownianTree
, it breaks, but my implementation of copy seems fine).AbstractArray
. Because of that, I used a different symbol, in part not to mess with other tests (extraction_test.jl
comparessol
and_sol
and there are two fields that are different, likesol.curt
, if I remember correctly, and a proper equality would fail.)copy
andcopy!
since it might eventually usedeepcopy
?