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

New feature for DeployInst #529

Merged
merged 39 commits into from
Feb 10, 2022
Merged

Conversation

abachma2
Copy link
Member

This PR adds a feature to the DeployInst: The facilities deployed by this institution are now registered with a GrowthRegion and how these facilities contribute to meeting any specified demand in the region.

I have added new tests to the DeployInst unit tests and a new input file to the regression tests to test how the DeployInst, GrowthRegion, and ManagerInst all interact with each other. Changes in the unit tests include some changes to the ManagerInst tests to prevent duplicate function definitions that threw errors when building.

All unit tests for DeployInst, GrowthRegion, and ManagerInst pass (although there were other errors in the unit tests, see #528), and the integration test passes.

Copy link
Member

@opotowsky opotowsky left a comment

Choose a reason for hiding this comment

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

GREAT WORK! This is a valuable contribution on its own (likely for you and other users), but is also shockingly timely with my personal needs.

I left a few comments about, maybe some require discussion so I'll keep an eye out for replies.

There is one not-small change we need to discuss: the integration tests. I'd like some input from you, @gonuke, @nuclearkatie, and/or anyone else on if this should be tested in test_regression.py or if we should make a new test file, test_integration.py. Because this is upgrading DeployInst behavior, I could see an argument for regression, but the original intention was an integration test ensuring DeployInst and ManagerInst play correctly together within GrowthRegion.

Thanks so much for your hard work on this!

P.S. This was edited to delete some confusion over where the regression test input files live. There is a dir (tests/input/) that has input files that aren't used for these tests (maybe they were once upon a time). The input files for the tests actually come from input/.

src/deploy_inst.h Outdated Show resolved Hide resolved
src/deploy_inst.h Outdated Show resolved Hide resolved
@@ -1,10 +1,10 @@
#include "manager_inst_tests.h"

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TestProducer::TestProducer(cyclus::Context* ctx) : cyclus::Facility(ctx) {}
//TestProducer::TestProducer(cyclus::Context* ctx) : cyclus::Facility(ctx) {}
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason this line and line 7 are commented out?

Copy link
Member

Choose a reason for hiding this comment

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

I ran cycamore_unit_tests with and without these commented out and both times it ran 195 tests... I didn't do a clean build in between so maybe that's why?

Copy link
Member Author

Choose a reason for hiding this comment

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

When these lines are included (not commented out) I got errors when building cycamore because of duplicate definitions. Removing this and line 7 removes the duplication. You most likely didn't run into this issue because it was happening on the build and not with the unit tests. I will remove the commented out lines.

Copy link
Member

Choose a reason for hiding this comment

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

I see they were added in deploy_inst_tests.cc (along with the corresponding class definition in deploy_inst_tests.h) so that is where the TestProducer class duplication is coming from, since it was also defined in manager_inst_tests.h.

I'm not sure what these lines do/don't do. I'm guessing it needs to test DeployInst as a commodity producer, which is needed, and further, it is likely needed for both ManagerInst and DeployInst.

I tried deleting the duplicated definition from deploy_inst_tests.h, and including manager_inst_tests.h in deploy_inst_tests.cc. Not sure that's good practice, though, but it didn't work either way. I'll play around a little more.

Copy link
Member Author

Choose a reason for hiding this comment

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

All of the tests in manager_insts_tests.cc are being run without these lines. My guess is that the initialization of the function in deploy_insts_tests.cc is still valid for this one.

input/growth/deploy_and_manager_insts.xml Outdated Show resolved Hide resolved
input/growth/deploy_and_manager_insts.xml Outdated Show resolved Hide resolved
input/growth/deploy_and_manager_insts.xml Outdated Show resolved Hide resolved
<spec> <lib>cycamore</lib><name>Sink</name> </spec>
</archetypes>

<commodity>
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 not sure this block is even needed for this simple simulation. At least, upon skimming the resulting DBs with and without it, I didn't see a difference. We can get someone more knowledgable to weigh in.

Copy link
Member Author

Choose a reason for hiding this comment

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

I felt like it was good practice to include a sink in the simulation. Also, this way it matches more with the source_sink_linear.xml file also in that directory.

Copy link
Member

Choose a reason for hiding this comment

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

Oh I meant the commodity block with the priority, not the sink. I should have done a better job w that comment :-)

Copy link
Member

Choose a reason for hiding this comment

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

(this is a comment of the lowest priority, btw)

Copy link
Member Author

Choose a reason for hiding this comment

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

That was just a force of habit. If you really think it needs to be removed I can do that.

Copy link
Member

Choose a reason for hiding this comment

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

It depends if we prefer the input file to be a good example or to be bare bones. I was reviewing from the bare bone perspective, which given the remaining questions in Issue #530 may or may not be valid.

Copy link
Member

Choose a reason for hiding this comment

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

This is definitely not a necessary block, but I would NOT require its remove for this to merge.

@abachma2 abachma2 marked this pull request as draft January 27, 2022 14:22
@abachma2 abachma2 marked this pull request as ready for review January 27, 2022 16:22
src/deploy_inst_tests.cc Outdated Show resolved Hide resolved
Copy link
Member

@opotowsky opotowsky left a comment

Choose a reason for hiding this comment

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

Changes are looking good! I still have questions about the TestProducer class duplication issue and what exactly is happening, which hopefully @gonuke or @nuclearkatie can help with.

In my initial review I had raised a question about whether the "integration test" belongs in test_regression.py or not....I'm fine with it there but would like others to also weigh in.

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.

Wow @abachma2 - this is a great deep dive into the dusty corners of Cyclus! Because you've done that dive, I think you can better answer any questions that arise. I'd be happy to jump on a call to discuss anything.

  1. Is testing exhaustive enough?
  2. Can a deploy inst still be used without a growth region? I guess that it can since there exist tests that do this. I'm just not sure how that is handled...

" list of prototypes for" \
" decommissioned at the end of their lifetime. Deployed and" \
" decommissioned agents are registered and unregistered with a" \
" region. The user specifies a list of prototypes for" \
Copy link
Member

Choose a reason for hiding this comment

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

do we need to specify that it's a Manager region?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure what you mean by Manager region.

Copy link
Member

Choose a reason for hiding this comment

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

Just that it's important to document what kind of region these agents are registered with. I think that's important to note in the documentation, but maybe it's more generic??

Copy link
Member

Choose a reason for hiding this comment

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

I think this is where she previously had "growth region" and I asked that "growth" be removed because in theory it could work within another region?

Copy link
Member

Choose a reason for hiding this comment

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

That's fair - it probably shouldn't be limited to a growth region, specifically, but - on the other hand - GrowthRegion is the only region that implements the toolkit to be useful for registration....

Copy link
Member Author

Choose a reason for hiding this comment

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

@opotowsky is correct, I removed the word growth to try and make it as region agnostic as possible. I thought that the growth region was the only one currently implemented that uses registration, but this wording would be flexible for if a new one was developed.

Comment on lines 47 to 53
private:
/// register a child
void Register_(cyclus::Agent* agent);

/// unregister a child
void Unregister_(cyclus::Agent* agent);


protected:
Copy link
Member

Choose a reason for hiding this comment

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

Why this change? I don't see anything that requires it in the other changes

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't remember why I did that. I can undo that change. Would you also recommend making these functions private in src/deploy_inst.h as well?

Copy link
Member

Choose a reason for hiding this comment

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

its good practice for them to be private unless we need them to be otherwise

@@ -1,11 +1,5 @@
#include "manager_inst_tests.h"

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TestProducer::TestProducer(cyclus::Context* ctx) : cyclus::Facility(ctx) {}
Copy link
Member

Choose a reason for hiding this comment

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

This line is probably necessary, but we may need to discuss some of the code structure because it is not potentially shared between two institutions.

In can probably be defined inline in the single place where the TestProducer is declared.

Comment on lines +15 to +39
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
class TestProducer
: public cyclus::Facility,
public cyclus::toolkit::CommodityProducer {
public:
TestProducer(cyclus::Context* ctx);
~TestProducer();

cyclus::Agent* Clone() {
TestProducer* m = new TestProducer(context());
m->InitFrom(this);
return m;
}

void InitFrom(TestProducer* m) {
cyclus::Facility::InitFrom(m);
}

void InitInv(cyclus::Inventories& inv) {}

cyclus::Inventories SnapshotInv() { return cyclus::Inventories(); }

void Tock() {}
void Tick() {}
};
Copy link
Member

Choose a reason for hiding this comment

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

This might need to go into a separate header file to be included in both the manager_inst and the deploy_inst tests.

Comment on lines 10 to 14
TestProducer::TestProducer(cyclus::Context* ctx) : cyclus::Facility(ctx) {}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TestProducer::~TestProducer() {}

Copy link
Member

Choose a reason for hiding this comment

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

It looks like these were moved from the manager_inst - this is probably not the best place for them.

Copy link
Member Author

Choose a reason for hiding this comment

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

I did move these lines from src/manager_inst_tests.cc. As far as I can tell having these defined in both places breaks the linking to the unit tests when building. I understand the desire to define them somewhere else that does not feel that they are exclusive to just the one set of tests. Any recommendations on that?

Copy link
Member

Choose a reason for hiding this comment

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

They definitely need to be only defined in one place. If they are in two places, they get compiled twice and then the linker finds two copies when it tries to combine them.

Copy link
Member

Choose a reason for hiding this comment

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

I think you can create a file test_producer.h that contains the definition of TestProducer from deploy_inst_test.h and defines these two functions inline in that header/class definition. That header can then be included in both of the institution header files.

<spec> <lib>cycamore</lib><name>Sink</name> </spec>
</archetypes>

<commodity>
Copy link
Member

Choose a reason for hiding this comment

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

This is definitely not a necessary block, but I would NOT require its remove for this to merge.

@abachma2
Copy link
Member Author

abachma2 commented Feb 7, 2022

To answer both of your questions @gonuke, I have added a new integration test to test the function of the DeployInst with a NullRegion. This does pass. The DeployInst does work with other regions. I think the test suite is exhaustive, unless there is another region I am not aware of that should have its integration with the DeployInst tested.

@abachma2
Copy link
Member Author

abachma2 commented Feb 9, 2022

@gonuke suggested moving some of the duplicate definitions between src/deploy_inst_test.h and src/manager_inst_tests.h into a separate header that could be read in by both, but that was not possible without creating a dummy prototype within cycamore that was blank. So the duplications remain, until a better solution is found.

Also, with the use of TestProducer by both src/deploy_insts_tests.cc and src/manager_insts_tests/cc, it seems that all of the information from the unit tests are stored while the tests are being run so this is not a major issue for now, since all of the unit tests and regression tests are running and passing. We should revisit this in the future though.

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.

4 participants