Remove Manual Definition of Position from Cycamore#641
Conversation
…on and remove the duplucate code
Build Status Report - 2e23bd1 - 2025-07-14 16:00:18 +0000Build
|
gonuke
left a comment
There was a problem hiding this comment.
This is definitely looking a lot cleaner. There are a 2 or 3 big design decisions we can discuss in person.
src/deploy_inst.cc
Outdated
| latitude(0.0), | ||
| longitude(0.0) {} |
There was a problem hiding this comment.
Putting these in the initialization list means that it's a required change for developers to use this toolkit (in addition to the code injection and changes in EnterNotify, for example).
Is there a way to avoid it? The injected code declares a default value of 0 for these. I confess, I can't remember how those defaults are imposed (other than like this), but it would be useful if we could think of a way to avoid changing constructors of agents when we inject code. Maybe that's not realistic. If not, we might want to inject a function that we can call from the constructor rather than messing with initialization lists, so that the developer only has to call the function and doesn't have to know all the details of initialization "under the hood".
There was a problem hiding this comment.
I'm not saying there ISN'T, but I will say that I tried a few different things to get rid of this entirely, and ultimately I came back around to having to do it this way. I'm not sure about whether this can be functionalized or not, but your fear from our last FC/S meeting was right on the money. If you don't initialize these variables, you get garbage in them before you call EnterNotify() and initialize them with InitializePosition(). Because of that, if you do something like src_inst = new cycamore::DeployInst(ctx_); (which happens in the tests in the SetUp() function) you get that those variables are full of garbage and specifically the tests fail. Happy to talk more about this in person, and also to try other things, this is just what I settled on last night when I was giving this a first pass.
There was a problem hiding this comment.
Let's see if we can safely change the regex at cycpp:L488 to make this work
There was a problem hiding this comment.
Another alternative: modify tests to NOT expect these values to be initialized until after the input parameters (XML, DB load) is read/parsed
There was a problem hiding this comment.
I went in an changed the throws in the CheckLat and CheckLon functions to cyclus::Warn warnings through cerr so that they don't "throw" but users are still (loudly) notified that they've done something illegal. I had to change a few tests to correctly capture that behavior for testing, but that all happened on the CYCLUS side of things (in case you see something weird and new in there, that's what it's for). This makes it so that all the tests pass, and we can remove the latitude(0.0) longitude(0.0) bits from the initializer lists like we wanted. Felt like a good compromise.
There was a problem hiding this comment.
Just to be clear: did NOT have to change cycpp to do this, so we're safe there 😎
src/enrichment.cc
Outdated
| << " entering the simuluation: "; | ||
| LOG(cyclus::LEV_DEBUG2, "EnrFac") << str(); | ||
| RecordPosition(); | ||
| coordinates.RecordPosition(this); |
There was a problem hiding this comment.
Didn't we record this in EnterNotify? Which raises a tangential question - is there good documentation on the difference between EnterNotify and Build?
There was a problem hiding this comment.
It seems like someone put this in Build before because Enrichment didn't implement its own EnterNotify. It should probably only be in one place, and I wonder if this feature is reason enough to implement EnterNotify or can Build be a substitute?
There was a problem hiding this comment.
Admittedly, I was making these changes pretty late at night and so I wasn't "thinking" so much as "doing", but you're totally right. Good catch!
|
|
||
| private: | ||
| // Code Injection: | ||
| #include "toolkit/position.cycpp.h" |
There was a problem hiding this comment.
This code injection ends with a protected: block which makes everything after it protected. We should be careful where the code injection happens if it might mess with the protection of member variables and functions
There was a problem hiding this comment.
I'll look into this
There was a problem hiding this comment.
Should be fixed now
| "\n\n" \ | ||
| " * Start times are inclusive. For a start time :math:`t_0`, the demand "\ | ||
| "function is evaluated on :math:`[t_0, \infty)`." \ | ||
| "function is evaluated on :math:`[t_0, infinity)`." \ |
There was a problem hiding this comment.
Interesting... I'm pretty sure the previous was chosen to enable LaTeX based rendering.... since this documentation is used in various places, that may be true in the minority of circumstances. Interesting to think this through, though..
There was a problem hiding this comment.
I made this change because the compiler was giving a warning about the \i bit, and I was mostly just curious whether this was the thing that was causing that. I forgot that this was used in documentation elsewhere, though. I figured "warning bad", but maybe that's not necessarily true.
| longitude(0.0) { | ||
| cyclus::Warn<cyclus::EXPERIMENTAL_WARNING>( | ||
| "the Mixer archetype is experimental"); | ||
| RecordPosition(); |
There was a problem hiding this comment.
Yikes - good catch - this should/would probably fail
| // Code Injection: | ||
| #include "toolkit/position.cycpp.h" | ||
|
|
There was a problem hiding this comment.
I think an injection there, would have a hidden effect.
As in the injection the last section is protected my guess is that AddMat_() and RecordEnrichment_ will be protected and not private as it was intended.
One need to be careful that injection might change what appear in the parasited file.
There was a problem hiding this comment.
Good catch, I've never really understood how the whole protected/public/private thing truly worked, so this flew under my radar. I'll go back and check this all more carefully!
… change I just made in cyclus/cyclus/src/toolkit/position.cycpp.h to remove redundancy in the InitializePosition() function
gonuke
left a comment
There was a problem hiding this comment.
This LGTM - thanks @dean-krueger
|
This needs a rebase because of the merge of the buy/sell stuff - that should also retrigger tests with the new cyclus code |
|
Rebase should have worked, I'll ping you when the tests all pass for a merge |
|
Looks like the tests didn't re-trigger? Not totally sure how to get that to happen, but all the checks passed, so I'll lob this back over the wall and hopefully everything is good... @gonuke |
|
It looks like the |
gonuke
left a comment
There was a problem hiding this comment.
This looks right and passes the expected tests. Thanks @dean-krueger
Summary of Changes
This PR removes all the manual definition of position in Cycamore Agents.
Related CEPs and Issues
This PR is related to:
Associated Developers
@bam241
@gonuke
Design Notes
I attempted to remove all initialization from the constructor (the
latitude(0.0), longitude(0.0), coordinates(0, 0)bit), but because of limitations with the#pragma cyclus varsystem, it is impossible to inject something likedouble latitude = 0.0(it throws an error). I was able to remove thecoordinates(0, 0)bit, and to condense the initialization into an injected function, however.TODO:
Testing and Validation
The code was built locally on my machine. No additional tests were added, but all existing tests passed on my machine.
Checklist
Reviewers, please refer to the Cyclus Guide for Reviewers.