Fix Tests for new Decay on Absorb behavior#2
Conversation
|
@gonuke Doesn't look like I have permission to add you as a reviewer, so pinging you like this so it (hopefully) shows up in your inbox |
|
Thanks for the fixes here @dean-krueger All the other decay tests work without a context. I think we may want to have some tests that just decay these different materials directly (ie. without a context) and then some that rely on the context. |
|
I'm not totally clear on what you mean by your comment, but I'll do my best to respond to what I think you mean? The context is important for this specific test where it may not be for others because the new decay on absorb functionality is fundamentally linked to the time at which the materials are said to have been decayed. Since time lives in the context, we need to have it for this particular test. Since this test is specific to the behavior of materials decay when they are combined with the |
|
A couple of related things:
|
A few questions about this:
Is it possible (or more importantly "indented under normal operation") for Cyclus' context to go backwards in time? I didn't think it was, in which case I agree that this would be a bug, and would then argue that a material absorb test is probably not the place to make sure this isn't happening. As always happy to do whatever, just wanted to make sure we were on the same page! |
|
Regarding the context:
|
|
Regarding backward decay:
|
|
Gotcha. I'm going to advocate for moving this conversation/issue to the main PR and separating it from this PR, which simply aims to fix those two failing tests. I will make a comment in the main PR about adding additional tests and reference your explanations. |
|
Refactor these such that we use the REAL context (not the fake context). @gonuke and I talked about one or two other things maybe but I forget what they were. Perhaps I will remember while I'm fixing the first thing, or maybe he'll leave a comment if he remembers. |
|
@gonuke I added the stuff we were talking about (a check to make sure that both materials have a context if we're going to be setting their common decay time to the context time, and a block on backwards decay). This should be ready for another look, and then hopefully we can get this merged so that the other PR (cyclus#1918) can go forward. |
|
I think we need to figure out some rebasing of something somewhere. It's likely that my original PR is now way behind the main branch because this PR into my PR seems to bring a lot of unrelated updates. |
|
oh, yeah. It seems so. Does it work if you just sync your branch with main through GitHub? If not I can go through and try to figure out which commits are extra and pull those out. |
|
This may need a rebase against my rebased branch to isolate the differences for the PR |
…ntext before setting common_decay_time to the context time
9d75ffb to
fd6c654
Compare
|
Rebased and ready for review (I quickly checked that it only has stuff I changed in it now, and I'm PRETTY sure it worked)! @gonuke |
Downstream Build Status Report - fd6c654 - 2026-05-19 12:19:16 -0500Build
|
|
Wanted to ping this again @gonuke because this is currently my highest-priority task in the v1.7 release project and I think it should be pretty close to ready. |
gonuke
left a comment
There was a problem hiding this comment.
It seems we should maybe document/discuss the different states of things for this
| @@ -106,8 +106,8 @@ void Material::Absorb(Material::Ptr mat) { | |||
|
|
|||
| // force both mateiral objects to advance to the same decay time | |||
There was a problem hiding this comment.
| // force both mateiral objects to advance to the same decay time | |
| // force both material objects to advance to the same decay time |
| int common_decay_time = std::max(this->prev_decay_time_, mat->prev_decay_time_); | ||
| if (ctx_ != NULL && ctx_->sim_info().decay != "never") { | ||
| common_decay_time = ctx_->time(); | ||
| if (HasContext() && mat->HasContext() && ctx_->sim_info().decay != "never") { |
There was a problem hiding this comment.
I'm trying to understand why we care if the material has a context here?
There was a problem hiding this comment.
Maybe I misinterpreted something, but didn't we have a whole conversation about these needing a context above?
| // Block backwards decay with std::max | ||
| int dt = std::max(curr_time - prev_decay_time_, 0); |
There was a problem hiding this comment.
Is this change necessary to fix the problems we're experiencing?
Is it possible for this to occur? and might there be cases where we want to see where a material came from?
There was a problem hiding this comment.
Again, I think you suggested we do this?
Regarding backward decay:
I don't think it's every been considered a normal behavior
if we always want to force decay to move forward we need to not just use the context time, but take the max of >the previous decay times and the context time to determine the new time
we can also fail/warn if the previous decay times are ever beyond the current context time
if we leave it as is, it's possible that we cause decay to go backwards
whatever we choose, we need to test it appropriately
| if (HasContext() && mat->HasContext() && ctx_->sim_info().decay != "never") { | ||
| common_decay_time = std::max(ctx_->time(), common_decay_time); | ||
| } |
There was a problem hiding this comment.
I'm not sure I agree with this choice. I guess we haven't thought through all the possible permutations of the state of each material and what we should do in those states...
| m1->Absorb(m3); | ||
| EXPECT_EQ(10, m1->prev_decay_time()); | ||
| EXPECT_EQ(11, m1->prev_decay_time()); | ||
| m1->Absorb(m2); | ||
| EXPECT_EQ(10, m1->prev_decay_time()); | ||
| EXPECT_EQ(11, m1->prev_decay_time()); |
There was a problem hiding this comment.
I wonder if we should test that decay actually occurs? Or do we consider it covered by other tests?
There was a problem hiding this comment.
We test the actual decay behavior in a few places, typically by calling decay and then checking that it's done something (using the EXPECT_NE test) but specifically in DecayCustomTimeStep we check that 1/2 of Cs-137 decays in one halflife of Cs-137, so I'd consider that "tested"
|
Let me put some thoughts here on relative decay times of materials. To begin with, let's assume that the context for the two materials is the same. If that's not true, we're in a very different space...
In practice, it's not clear how we get into a state that is in rows 2-4 here? Do we need to allow for them? Do we throw an error? |
|
Apologies - I did not go back and read the full chain of discussion and will need to do that and update my comments/questions! |
|
No worries! I just wanted to make sure we were on the same page! |
|
(We'll probably want to capture this discussione somewhere else, eventually!!) I looked at all the ways that
It's thus probably useful to understand the range of outcomes from
I think it makes sense for untracked materials (i.e. those without a context) to be allowed to decay forward or backward in time. A key discussion point: Is there a use case for allowing a material that is part of a context to decay backwards in time or beyond the current context time? My first instinct is to say that all materials with a context should always decay to the current context time and only the current context time. The consequences of this:
What should the behavior be for absorbing two materials outside any context? We can choose an arbitrary decay time for these after the absorption is complete. Since we have no context, it needs to be based on the |
This PR fixes the (/at least) two tests that seemed to be failing in the Cyclus build. The two failing tests were:
MaterialTest.AbsorbPrevDecayandResourceTest.MaterialUnitValueMaterialTest.AbsorbPrevDecaywas fixed by adding a fake context to the simulation and then stepping through fakectx->time and checking that absorb records the correct timestamp (should be 11)ResourceTest.MaterialUnitValuewas failing because when you made the change in thematerial.ccAbsorbfunction you accidentally deleted the part that averages the unit value of combined materials. I added that bit back and this test started passing! I guess this just goes to show why tests are so valuable! 😁Either way, this PR should fix at least those two tests, and they were the ones I saw that were failing in your Cyclus PR, so hopefully this fixes that and then we're good to go!