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
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
8fc752c
new files and small name changes to create deploymanagerinst
abachma2 Mar 26, 2021
31839c4
fixed typo
abachma2 Mar 26, 2021
2c69856
missed instance, fixed typo
abachma2 Mar 26, 2021
7653f29
Merge branch 'master' of github.com:cyclus/cycamore into deploy-manag…
abachma2 Mar 26, 2021
3a53159
added test file
abachma2 Mar 26, 2021
1a1483d
missed a few instances near the end
abachma2 Mar 26, 2021
064b850
inherit from managerinst, installs, tests fail
abachma2 Apr 2, 2021
3e2d6b8
makes explicit calls to functions in cyclus::Institution actually cal…
katyhuff Apr 22, 2021
8ce30e9
pulled in BuildNotify from ManagerInst, tests still fail
abachma2 Apr 26, 2021
dc1e951
copied functions from ManagerInst, tests pass, works with toy problem
abachma2 Apr 29, 2021
d574667
added tests from ManagerInst, new tests don't pass
abachma2 May 3, 2021
2e93d6e
changed to TEST_F and all tests pass now
abachma2 May 3, 2021
6078305
cleaned up extra lines, added functionality to comments
abachma2 May 7, 2021
882b853
added sample test for corner case test
abachma2 Jan 21, 2022
ca24a31
filled in test with cyclus mock sim
abachma2 Jan 21, 2022
8fe92de
changed mocksim definition
abachma2 Jan 21, 2022
bb8e75f
added definition for prototypes in mocksim
abachma2 Jan 21, 2022
bc52e9c
removed config for growthregion
abachma2 Jan 21, 2022
797e8fe
changed config name ack
abachma2 Jan 21, 2022
416ba1f
added additional MockSims, all separate sims, need to combine
abachma2 Jan 24, 2022
031ab59
added commodity and capacity to dummyprotos
abachma2 Jan 25, 2022
63ac68a
Removed DeployManagerInst, added feature to DeployInst
abachma2 Jan 26, 2022
a001062
added input for integration tests
abachma2 Jan 26, 2022
43ac611
moved functions around to make unit tests build and pass
abachma2 Jan 26, 2022
ad57d01
Merge branch 'master' into deploy-manager-inst
abachma2 Jan 26, 2022
3a98763
changes suggested from @opotowsky
abachma2 Jan 27, 2022
b8a2925
Revert "changes suggested from @opotowsky"
abachma2 Jan 27, 2022
1fca401
Revert "Merge branch 'master' into deploy-manager-inst"
abachma2 Jan 27, 2022
7fa2a09
changes requested from @opotowsky
abachma2 Jan 27, 2022
ed47d55
added commodity recipe, needed for tests
abachma2 Jan 27, 2022
df920e1
added new test for integration of deploy and manager insts
abachma2 Jan 27, 2022
41383f8
Revert "Revert "Merge branch 'master' into deploy-manager-inst""
abachma2 Jan 27, 2022
34c0517
Merge branch 'master-changes' into deploy-manager-inst
abachma2 Jan 27, 2022
f327056
modified doc sting of TestGrowth2
abachma2 Jan 27, 2022
3262056
removed extra includes, moved the one non-duplicate
abachma2 Jan 27, 2022
50d1f66
added new test for deployinst + nullregion
abachma2 Feb 7, 2022
6384312
input file for new test
abachma2 Feb 7, 2022
f8e3f6e
made register and unregister private
abachma2 Feb 9, 2022
43137a2
put TestProducer back into manager_inst_tests.cc
abachma2 Feb 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions input/growth/deploy_and_manager_insts.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
<simulation>
<control>
<duration>10</duration>
<startmonth>1</startmonth>
<startyear>2018</startyear>
<decay>never</decay>
</control>

<archetypes>
<spec> <lib>cycamore</lib><name>GrowthRegion</name> </spec>
<spec> <lib>cycamore</lib><name>DeployInst</name> </spec>
<spec> <lib>cycamore</lib><name>ManagerInst</name> </spec>
<spec> <lib>cycamore</lib><name>Source</name> </spec>
<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.

<name>commodity1</name>
<solution_priority>1.0</solution_priority>
</commodity>

<facility>
<name>Source1</name>
<config>
<Source>
<outcommod>commodity1</outcommod>
<outrecipe>commod_recipe</outrecipe>
<throughput>1</throughput>
</Source>
</config>
</facility>

<facility>
<name>Source2</name>
<config>
<Source>
<outcommod>commodity1</outcommod>
<outrecipe>commod_recipe</outrecipe>
<throughput>1</throughput>
</Source>
</config>
</facility>

<facility>
<name>Sink</name>
<config>
<Sink>
<in_commods>
<val>commodity1</val>
</in_commods>
</Sink>
</config>
</facility>

<region>
<name>Single Region</name>
<config>
<GrowthRegion>
<growth>
<item>
<commod>commodity1</commod>
<piecewise_function>
<piece>
<start>5</start>
<function>
<type>linear</type>
<params>0 5</params>
</function>
</piece>
</piecewise_function>
</item>
</growth>
</GrowthRegion>
</config>

<institution>
<name>First Institution</name>
<initialfacilitylist>
<entry>
<prototype>Sink</prototype>
<number>1</number>
</entry>
</initialfacilitylist>
<config>
<ManagerInst>
<prototypes>
<val>Source2</val>
</prototypes>
</ManagerInst>
</config>
</institution>

<institution>
<name>Second Institution</name>
<config>
<DeployInst>
<prototypes>
<val>Source1</val>
</prototypes>
<build_times>
<val>1</val>
</build_times>
<n_build>
<val>1</val>
</n_build>
</DeployInst>
</config>
</institution>
</region>

<recipe>
<name>commod_recipe</name>
<basis>mass</basis>
<nuclide> <id>922350000</id> <comp>0.711</comp> </nuclide>
<nuclide> <id>922380000</id> <comp>99.289</comp> </nuclide>
</recipe>

</simulation>
1 change: 1 addition & 0 deletions src/cycamore.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "batch_reactor.h"
#include "batch_reactor_tests.h"
#include "deploy_inst.h"
#include "deploy_inst_tests.h"
#include "enrichment.h"
#include "enrichment_tests.h"
#if CYCLUS_HAS_COIN
Expand Down
51 changes: 51 additions & 0 deletions src/deploy_inst.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,57 @@ void DeployInst::EnterNotify() {
RecordPosition();
}

void DeployInst::BuildNotify(Agent* a) {
Register_(a);
}

void DeployInst::DecomNotify(Agent* a) {
Unregister_(a);
}

void DeployInst::Register_(Agent* a) {
using cyclus::toolkit::CommodityProducer;
using cyclus::toolkit::CommodityProducerManager;

CommodityProducer* cp_cast = dynamic_cast<CommodityProducer*>(a);
if (cp_cast != NULL) {
LOG(cyclus::LEV_INFO3, "mani") << "Registering agent "
<< a->prototype() << a->id()
<< " as a commodity producer.";
CommodityProducerManager::Register(cp_cast);
}
}

void DeployInst::Unregister_(Agent* a) {
using cyclus::toolkit::CommodityProducer;
using cyclus::toolkit::CommodityProducerManager;

CommodityProducer* cp_cast = dynamic_cast<CommodityProducer*>(a);
if (cp_cast != NULL)
CommodityProducerManager::Unregister(cp_cast);
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void DeployInst::WriteProducerInformation(
cyclus::toolkit::CommodityProducer* producer) {
using std::set;
set<cyclus::toolkit::Commodity,
cyclus::toolkit::CommodityCompare> commodities =
producer->ProducedCommodities();
set<cyclus::toolkit::Commodity, cyclus::toolkit::CommodityCompare>::
iterator it;

LOG(cyclus::LEV_DEBUG3, "maninst") << " Clone produces " << commodities.size()
<< " commodities.";
for (it = commodities.begin(); it != commodities.end(); it++) {
LOG(cyclus::LEV_DEBUG3, "maninst") << " Commodity produced: " << it->name();
LOG(cyclus::LEV_DEBUG3, "maninst") << " capacity: " <<
producer->Capacity(*it);
LOG(cyclus::LEV_DEBUG3, "maninst") << " cost: " <<
producer->Cost(*it);
}
}

void DeployInst::RecordPosition() {
std::string specification = this->spec();
context()
Expand Down
22 changes: 19 additions & 3 deletions src/deploy_inst.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ typedef std::map<int, std::vector<std::string> > BuildSched;
// lifetimes. The same prototype can be specified multiple times with any
// combination of the same or different build times, build number, and
// lifetimes.
class DeployInst : public cyclus::Institution,
class DeployInst :
public cyclus::Institution,
public cyclus::toolkit::CommodityProducerManager,
public cyclus::toolkit::Position {
#pragma cyclus note { \
"doc": \
"Builds and manages agents (facilities) according to a manually" \
" specified deployment schedule. Deployed agents are automatically" \
" decommissioned at the end of their lifetime. The user specifies a" \
" 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.

" each and corresponding build times, number to build, and (optionally)" \
" lifetimes. The same prototype can be specified multiple times with" \
" any combination of the same or different build times, build number," \
Expand All @@ -45,6 +48,19 @@ class DeployInst : public cyclus::Institution,

virtual void EnterNotify();

virtual void BuildNotify(Agent* m);
virtual void DecomNotify(Agent* m);
/// write information about a commodity producer to a stream
/// @param producer the producer
void WriteProducerInformation(cyclus::toolkit::CommodityProducer*
producer);

/// register a child
void Register_(cyclus::Agent* agent);

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

protected:
#pragma cyclus var { \
"doc": "Ordered list of prototypes to build.", \
Expand Down
64 changes: 53 additions & 11 deletions src/deploy_inst_tests.cc
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
#include <gtest/gtest.h>

#include "context.h"
#include "deploy_inst.h"
#include "institution_tests.h"
#include "agent_tests.h"
#include "deploy_inst_tests.h"

// make sure that the deployed agent's prototype name is identical to the
// originally specified prototype name - this is important to test because
// DeployInst does some mucking around with registering name-modded prototypes
// in order to deal with lifetime setting.

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

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void DeployInstTests::SetUp() {
ctx_ = new cyclus::Context(&ti_, &rec_);
src_inst = new cycamore::DeployInst(ctx_);
producer = new TestProducer(ctx_);
commodity = cyclus::toolkit::Commodity("commod");
capacity = 5;
producer->cyclus::toolkit::CommodityProducer::Add(commodity);
producer->SetCapacity(commodity, capacity);
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void DeployInstTests::TearDown() {
delete producer;
delete src_inst;
delete ctx_;
}

using cyclus::QueryResult;

TEST(DeployInstTests, ProtoNames) {
TEST_F(DeployInstTests, ProtoNames) {
std::string config =
"<prototypes> <val>foobar</val> </prototypes>"
"<build_times> <val>1</val> </build_times>"
Expand All @@ -32,7 +52,7 @@ TEST(DeployInstTests, ProtoNames) {
EXPECT_EQ(3, stmt->GetInt(0));
}

TEST(DeployInstTests, BuildTimes) {
TEST_F(DeployInstTests, BuildTimes) {
std::string config =
"<prototypes> <val>foobar</val> <val>foobar</val> </prototypes>"
"<build_times> <val>1</val> <val>3</val> </build_times>"
Expand All @@ -59,7 +79,7 @@ TEST(DeployInstTests, BuildTimes) {

// make sure that specified lifetimes are honored both in agent's table record
// and in decommissioning.
TEST(DeployInstTests, FiniteLifetimes) {
TEST_F(DeployInstTests, FiniteLifetimes) {
std::string config =
"<prototypes> <val>foobar</val> <val>foobar</val> <val>foobar</val> </prototypes>"
"<build_times> <val>1</val> <val>1</val> <val>2</val> </build_times>"
Expand Down Expand Up @@ -112,7 +132,7 @@ TEST(DeployInstTests, FiniteLifetimes) {
EXPECT_EQ(8, stmt->GetInt(0));
}

TEST(DeployInstTests, NoDupProtos) {
TEST_F(DeployInstTests, NoDupProtos) {
std::string config =
"<prototypes> <val>foobar</val> <val>foobar</val> <val>foobar</val> </prototypes>"
"<build_times> <val>1</val> <val>1</val> <val>2</val> </build_times>"
Expand Down Expand Up @@ -141,7 +161,7 @@ TEST(DeployInstTests, NoDupProtos) {
EXPECT_EQ(1, stmt->GetInt(0));
}

TEST(DeployInstTests, PositionInitialize) {
TEST_F(DeployInstTests, PositionInitialize) {
std::string config =
"<prototypes> <val>foobar</val> </prototypes>"
"<build_times> <val>1</val> </build_times>"
Expand All @@ -158,7 +178,7 @@ TEST(DeployInstTests, PositionInitialize) {
EXPECT_EQ(qr.GetVal<double>("Longitude"), 0.0);
}

TEST(DeployInstTests, PositionInitialize2) {
TEST_F(DeployInstTests, PositionInitialize2) {
std::string config =
"<prototypes> <val>foobar</val> </prototypes>"
"<longitude> -20.0 </longitude>"
Expand All @@ -177,6 +197,28 @@ TEST(DeployInstTests, PositionInitialize2) {
EXPECT_EQ(qr.GetVal<double>("Longitude"), -20.0);
}

TEST_F(DeployInstTests, producerexists) {
using std::set;
ctx_->AddPrototype("foop", producer);
set<cyclus::toolkit::CommodityProducer*>::iterator it;
for (it = src_inst->cyclus::toolkit::CommodityProducerManager::
producers().begin();
it != src_inst->cyclus::toolkit::CommodityProducerManager::
producers().end();
it++) {
EXPECT_EQ(dynamic_cast<TestProducer*>(*it)->prototype(),
producer->prototype());
}
}

TEST_F(DeployInstTests, productioncapacity) {
EXPECT_EQ(src_inst->TotalCapacity(commodity), 0);
src_inst->BuildNotify(producer);
EXPECT_EQ(src_inst->TotalCapacity(commodity), capacity);
src_inst->DecomNotify(producer);
EXPECT_EQ(src_inst->TotalCapacity(commodity), 0);
}

// required to get functionality in cyclus agent unit tests library
cyclus::Agent* DeployInstitutionConstructor(cyclus::Context* ctx) {
return new cycamore::DeployInst(ctx);
Expand Down
Loading