Skip to content

Remove Manual Definition of Position from Cycamore#641

Merged
gonuke merged 8 commits intocyclus:mainfrom
dean-krueger:pos-implementation
Jul 15, 2025
Merged

Remove Manual Definition of Position from Cycamore#641
gonuke merged 8 commits intocyclus:mainfrom
dean-krueger:pos-implementation

Conversation

@dean-krueger
Copy link
Copy Markdown
Contributor

@dean-krueger dean-krueger commented Jun 25, 2025

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 var system, it is impossible to inject something like double latitude = 0.0 (it throws an error). I was able to remove the coordinates(0, 0) bit, and to condense the initialization into an injected function, however.

TODO:

  • Update the changelog (oops)

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

  • Read the Contributing to Cyclus guide.
  • Compile and run locally.
  • Add or update tests.
  • Document if needed.
  • Follow style guidelines.
  • Update the changelog.
  • Address all review comments.
    Reviewers, please refer to the Cyclus Guide for Reviewers.

@dean-krueger dean-krueger self-assigned this Jun 25, 2025
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jun 25, 2025

Build Status Report - 2e23bd1 - 2025-07-14 16:00:18 +0000

Build FROM cyclus_20.04_apt/cyclus:latest
  • Cycamore: Success
  • Cymetric: Success
Build FROM cyclus_20.04_apt/cyclus:stable
  • Cycamore: Failure
  • Cymetric: Skipped due to upstream failure ⚠️
Build FROM cyclus_20.04_conda/cyclus:latest
  • Cycamore: Success
  • Cymetric: Success
Build FROM cyclus_20.04_conda/cyclus:stable
  • Cycamore: Failure
  • Cymetric: Skipped due to upstream failure ⚠️
Build FROM cyclus_22.04_apt/cyclus:latest
  • Cycamore: Success
  • Cymetric: Success
Build FROM cyclus_22.04_apt/cyclus:stable
  • Cycamore: Failure
  • Cymetric: Skipped due to upstream failure ⚠️
Build FROM cyclus_22.04_conda/cyclus:latest
  • Cycamore: Success
  • Cymetric: Success
Build FROM cyclus_22.04_conda/cyclus:stable
  • Cycamore: Failure
  • Cymetric: Skipped due to upstream failure ⚠️
Build FROM cyclus_24.04_apt/cyclus:latest
  • Cycamore: Success
  • Cymetric: Success
Build FROM cyclus_24.04_apt/cyclus:stable
  • Cycamore: Failure
  • Cymetric: Skipped due to upstream failure ⚠️
Build FROM cyclus_24.04_conda/cyclus:latest
  • Cycamore: Success
  • Cymetric: Success
Build FROM cyclus_24.04_conda/cyclus:stable
  • Cycamore: Failure
  • Cymetric: Skipped due to upstream failure ⚠️

Copy link
Copy Markdown
Member

@gonuke gonuke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely looking a lot cleaner. There are a 2 or 3 big design decisions we can discuss in person.

Comment on lines +8 to +9
latitude(0.0),
longitude(0.0) {}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's see if we can safely change the regex at cycpp:L488 to make this work

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another alternative: modify tests to NOT expect these values to be initialized until after the input parameters (XML, DB load) is read/parsed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be clear: did NOT have to change cycpp to do this, so we're safe there 😎

<< " entering the simuluation: ";
LOG(cyclus::LEV_DEBUG2, "EnrFac") << str();
RecordPosition();
coordinates.RecordPosition(this);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't we record this in EnterNotify? Which raises a tangential question - is there good documentation on the difference between EnterNotify and Build?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll look into this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)`." \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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..

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yikes - good catch - this should/would probably fail

Comment on lines +254 to +256
// Code Injection:
#include "toolkit/position.cycpp.h"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@dean-krueger dean-krueger requested a review from gonuke June 27, 2025 17:26
@dean-krueger
Copy link
Copy Markdown
Contributor Author

I think this should be "fixed" now, but let me know if either of you see anything else you think should be changed before it's good to go! Thanks a ton for all the review @gonuke @bam241

Copy link
Copy Markdown
Member

@gonuke gonuke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM - thanks @dean-krueger

@gonuke
Copy link
Copy Markdown
Member

gonuke commented Jul 2, 2025

This needs a rebase because of the merge of the buy/sell stuff - that should also retrigger tests with the new cyclus code

@dean-krueger
Copy link
Copy Markdown
Contributor Author

Rebase should have worked, I'll ping you when the tests all pass for a merge

@dean-krueger
Copy link
Copy Markdown
Contributor Author

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

@dean-krueger
Copy link
Copy Markdown
Contributor Author

It looks like the latest branches are all passing now. I think it makes sense that the stable ones are failing, but I'll let you be the judge of that @gonuke

Copy link
Copy Markdown
Member

@gonuke gonuke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks right and passes the expected tests. Thanks @dean-krueger

@gonuke gonuke merged commit e4ec85c into cyclus:main Jul 15, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Task] Clean Manual Position Definitions out of Cycamore Agents

3 participants