Skip to content
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

Constant for large values in Cyclus/Cycamore #606

Merged
merged 13 commits into from
Jul 28, 2024

Conversation

bennibbelink
Copy link
Contributor

cyclus/cyclus#1757 updates some archetypes to use a new constant instead of 1e299. This updates cycamore to use the same constants. CI will only pass when this PR and cyclus 1757 are tested together, so please refer to the cyclus PR for test status.

Copy link

github-actions bot commented May 18, 2024

Build Status Report - aa67f87 - 2024-07-21 21:20:28 +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 ⚠️

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

A question related to how this all fits together in the cyclus ecosystem

src/enrichment.h Outdated
"range": [0.0, 1e299], \
"range": [0.0, "cyclus::cy_large_double"], \
Copy link
Member

Choose a reason for hiding this comment

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

So this has me thinking about where else this metadata is used... If you have an installed build with this branch, can you run cyclus -m and see what it reports as the range? Has the substitution happened at that point?

Other tools may read/parse this metadata without access to cyclus::cy_large_double

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The substitution has not happened at that point
image
Do we want those values to be expanded to their numeric equivalents? I'll see if it can be done given the build process in place

Copy link
Member

Choose a reason for hiding this comment

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

There are two issues here...

  1. on one hand it would be good to have expanded so that other users of this metadata know what it is
  2. if we want modules to be plug-an-play with different installs of Cyclus, maybe we want this to be substituted later??

It's possible we could do both, but performing the substitution before we publish the metadata? That might be a bigger project though!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What if we substitute later and have a section of metadata (or a different cli flag perhaps) that shows users the values for constants in this install of cyclus? That way we don't need to modify the preprocessor, modules are plug-and-play, and users have a way to see what the constants are (as long as we put them in an intuitive place)

Copy link
Member

Choose a reason for hiding this comment

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

Related - how is the substitution made under your current paradigm - when is it substituted and what can it be used for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now cyclus::cy_large_double is a static const double so it is evaluated at runtime and exists in the cyclus C++ namespace (and in the cyclus.lib python library via cython wrapper). It is not evaluated before/by cycpp.py. We could probably #define the value instead so it is substituted by cpp (though I'm still not sure there's a way to substitute it into the #pragma cyclus statement to be evaluated before cycpp.py is run). Does that answer your question?

Copy link
Member

Choose a reason for hiding this comment

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

I'm trying to recall if there is any code on the Cyclus side that uses those values and were the substitution happens to use those values. For example, if the range of a variable is set in these pragmas, I think it results in an XML grammar entry that requires the value to be within that range. Is the substitution done before generating the snippet of grammar so that XML only knows about the numerical value? Or is the substitution happening later?

It's also possible that the value is not actually used anywhere by Cyclus and only exists for other tools that use the metadata.

Copy link
Contributor Author

@bennibbelink bennibbelink May 23, 2024

Choose a reason for hiding this comment

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

KFacility, Sink, and Source in cyclus use this value. When calling cyclus -m the variable name is still included in metadata instead of the value. However, when viewing an agent's xml schema I don't see any reference at all. For example - capacity in Source is defined as so:

  #pragma cyclus var { \
    "doc": "amount of commodity that can be supplied at each time step", \
    "uilabel": "Maximum Throughput", \
    "uitype": "range", \
    "range": [0.0, "cy_large_double"], \
    "tooltip": "source capacity" \
  }
  double capacity;

But this is what I see when printing the agent schema via the cyclus cli (is this incomplete?):

root@a52714cb3b92:/cyclus# cyclus --agent-schema :agents:Source
<interleave>
    <element name="commod">
        <data type="token"/>
    </element>
    <optional>
        <element name="recipe_name">
            <data type="token"/>
        </element>
    </optional>
    <element name="capacity">
        <data type="double"/>
    </element>
</interleave>

The section of JSON dedicated to Source when calling cyclus -m is:

 ":agents:Source": {
   "all_parents": [
    "cyclus::Agent", 
    "cyclus::Facility", 
    "cyclus::Ider", 
    "cyclus::StateWrangler", 
    "cyclus::TimeListener", 
    "cyclus::Trader"
   ], 
   "doc": "A minimum implementation source facility that provides a commodity with a given capacity", 
   "entity": "facility", 
   "name": "cyclus::Source", 
   "parents": ["cyclus::Facility"], 
   "vars": {
    "capacity": {
     "alias": "capacity", 
     "doc": "amount of commodity that can be supplied at each time step", 
     "index": 2, 
     "range": [0.0, "cy_large_double"], 
     "shape": [-1], 
     "tooltip": "source capacity", 
     "type": "double", 
     "uilabel": "Maximum Throughput", 
     "uitype": "range"
    }, 
    "commod": {
     "alias": "commod", 
     "doc": "commodity that the source facility supplies", 
     "index": 0, 
     "schematype": "token", 
     "shape": [-1], 
     "tooltip": "source commodity", 
     "type": "std::string", 
     "uilabel": "Commodity", 
     "uitype": "outcommodity"
    }, 
    "recipe_name": {
     "alias": "recipe_name", 
     "default": "", 
     "doc": "Recipe name for source facility's commodity.If empty, source supplies material with requested compositions.", 
     "index": 1, 
     "schematype": "token", 
     "shape": [-1], 
     "tooltip": "commodity recipe name", 
     "type": "std::string", 
     "uilabel": "Recipe", 
     "uitype": "recipe"
    }
   }

@bennibbelink bennibbelink marked this pull request as draft June 1, 2024 00:22
@bennibbelink
Copy link
Contributor Author

bennibbelink commented Jun 1, 2024

With some inspiration from the preprocessor docs, the substitution now takes place during the execution of cycpp.py. There are two sets of variables maintained, one in C++ namespace (in src/cyc_limits.h) and one in Python namespace (in cyclus/system.py). Archetype developers can use #pragma cyclus exec to import the constants into the global python namespace during cycpp.py execution (thus they can be used to define variable metadata). I just got this into a working state, I welcome suggestions for improvement!

CI in this PR will not pass since it is based on the published cyclus docker images - see cyclus/cyclus#1757 for CI status. Still failing on one test but not related to the new constants - need to resolve #611 then we should see CI pass in the cyclus PR

EDIT: CI now passing in cyclus/cyclus#1757

@bennibbelink bennibbelink requested a review from gonuke June 13, 2024 01:29
@bennibbelink bennibbelink marked this pull request as ready for review July 18, 2024 20:42
@gonuke
Copy link
Member

gonuke commented Jul 18, 2024

Can you check whether any new large numbers crept in during recent PRs? A rebase and search, perhaps?

@gonuke
Copy link
Member

gonuke commented Jul 18, 2024

I don't understand how this is passing? What cyclus version is it using to get the right values for the constants?

@bennibbelink
Copy link
Contributor Author

Can you check whether any new large numbers crept in during recent PRs? A rebase and search, perhaps?

I will check and make a comment after.

I don't understand how this is passing? What cyclus version is it using to get the right values for the constants?

I'm seeing failures for all 8 builds... remember there are no "soft" failures in Github actions so we must refer to the bot's comment for the correct build statuses (unless I'm misunderstanding)

@gonuke
Copy link
Member

gonuke commented Jul 20, 2024

I guess I already forgot our standard testing regimen - or perhaps more accurately was confused between cyclus and cycamore.

(For my own benefit...) standard CI testing for cyclus/cyclus has hard failures and soft failures for downstream testing. Standard CI testing for cyclus/cycamore has ONLY soft failures because all testing uses some upstream repo whose state may or may not be consistent.

Given that, in this particular case, what should we be reviewing in cycamore - just the code itself and ignoring the tests?

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

A couple of little things here - they aren't critical, but nice to have.

src/sink.h Outdated
"doc": "When a random distribution is used to determine the " \
"frequency of the request, this is the upper bound. Default 1e299"}
"frequency of the request, this is the upper bound. Default CY_LARGE_INT (1e299)"}
Copy link
Member

Choose a reason for hiding this comment

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

Can we get the actual value of the variable to appear here rather than hardcoding 1e299 in the string? Would this work?

Suggested change
"frequency of the request, this is the upper bound. Default CY_LARGE_INT (1e299)"}
"frequency of the request, this is the upper bound. Default CY_LARGE_INT (" + str(CY_LARGE_INT) + ")"}

I think this is ultimately processed in python, so not sure how the value of this metadata is passed along.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, this is now replaced at build time

src/storage.cc Show resolved Hide resolved
@bennibbelink
Copy link
Contributor Author

(For my own benefit...) standard CI testing for cyclus/cyclus has hard failures and soft failures for downstream testing. Standard CI testing for cyclus/cycamore has ONLY soft failures because all testing uses some upstream repo whose state may or may not be consistent.

Correct.

Given that, in this particular case, what should we be reviewing in cycamore - just the code itself and ignoring the tests?

Yes, except since we have an associated PR in cyclus/cyclus we can use those CI tests as a reference. That's why I have the cyclus PR temporarily referencing this PR - we can see that CI passes when the two branches are in sync with each other

@bennibbelink
Copy link
Contributor Author

Can you check whether any new large numbers crept in during recent PRs? A rebase and search, perhaps?

Just went through and replaced a handful of instances of hardcoded constants. It looks like they were arbitrary small/large values, but someone else should go through and confirm. I also went through cyclus and replaced some hardcoded values.

@gonuke
Copy link
Member

gonuke commented Jul 26, 2024

I'm ready to merge this - let me know if we need to coordinate @bennibbelink - or should I go ahead with this?

@bennibbelink
Copy link
Contributor Author

bennibbelink commented Jul 27, 2024

I've changed the ref in cyclus/cyclus back to cyclus/cycamore, so they are both ready to be merged. I don't think we need to coordinate, regardless of how we do this there will be an intermediate state where the projects are out of sync. With that being said... maybe it makes sense to merge cyclus first then see CI pass on cycamore just since thats the typical workflow (of introducing features to cyclus then catching up downstream)?

That may contradict a comment I made earlier about the appropriate merge procedure but I think this makes sense, what do you think?

@bennibbelink
Copy link
Contributor Author

Re-ran CI and this is passing on the :latest image, should be good to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants