Skip to content

Commit 730c41c

Browse files
authored
Merge pull request #477 from scopatz/coinop
Works for me!
2 parents 0e21439 + bef6a32 commit 730c41c

File tree

9 files changed

+85
-19
lines changed

9 files changed

+85
-19
lines changed

CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,11 @@ IF(NOT CYCLUS_DOC_ONLY)
172172
MESSAGE("-- HDF5 High Level Libraries: ${HDF5_C_HL_LIBRARIES}")
173173

174174
# find coin and link to it
175-
FIND_PACKAGE(COIN REQUIRED)
176-
SET(CYCAMORE_INCLUDE_DIRS ${CYCAMORE_INCLUDE_DIRS} ${COIN_INCLUDE_DIRS})
177-
set(LIBS ${LIBS} ${COIN_LIBRARIES})
175+
FIND_PACKAGE(COIN)
176+
if(COIN_FOUND)
177+
SET(CYCAMORE_INCLUDE_DIRS ${CYCAMORE_INCLUDE_DIRS} ${COIN_INCLUDE_DIRS})
178+
SET(LIBS ${LIBS} ${COIN_LIBRARIES})
179+
endif()
178180
MESSAGE("-- COIN Root: ${COIN_ROOT}")
179181
MESSAGE("-- COIN Include directories: ${COIN_INCLUDE_DIRS}")
180182
MESSAGE("-- COIN Libraries: ${COIN_LIBRARIES}")

src/cycamore.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
#ifndef CYCAMORE_SRC_CYCAMORE_H_
22
#define CYCAMORE_SRC_CYCAMORE_H_
33

4+
// These includes must come before others.
5+
#include "cyclus.h"
46
#include "cycamore_version.h"
57

68
#include "batch_reactor.h"
79
#include "batch_reactor_tests.h"
810
#include "deploy_inst.h"
911
#include "enrichment.h"
1012
#include "enrichment_tests.h"
13+
#if CYCLUS_HAS_COIN
1114
#include "growth_region.h"
1215
#include "growth_region_tests.h"
16+
#endif
1317
#include "inpro_reactor.h"
1418
#include "inpro_reactor_tests.h"
1519
#include "manager_inst.h"

src/growth_region.cc

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@
33

44
namespace cycamore {
55

6-
GrowthRegion::GrowthRegion(cyclus::Context* ctx) : cyclus::Region(ctx) { }
6+
GrowthRegion::GrowthRegion(cyclus::Context* ctx) : cyclus::Region(ctx) {
7+
#if !CYCLUS_HAS_COIN
8+
throw cyclus::Error("Growth Region requires that Cyclus & Cycamore be compiled "
9+
"with COIN support.");
10+
#endif
11+
}
712

813
GrowthRegion::~GrowthRegion() {}
914

1015
void GrowthRegion::AddCommodityDemand_(std::string commod,
1116
Demand& demand) {
12-
13-
17+
18+
1419
cyclus::toolkit::PiecewiseFunctionFactory pff;
1520
cyclus::toolkit::BasicFunctionFactory bff;
1621
bool continuous = false;
@@ -55,7 +60,7 @@ void GrowthRegion::DecomNotify(Agent* a) {
5560
void GrowthRegion::Register_(cyclus::Agent* agent) {
5661
using cyclus::toolkit::CommodityProducerManager;
5762
using cyclus::toolkit::Builder;
58-
63+
#if CYCLUS_HAS_COIN
5964
CommodityProducerManager* cpm_cast =
6065
dynamic_cast<CommodityProducerManager*>(agent);
6166
if (cpm_cast != NULL) {
@@ -72,12 +77,16 @@ void GrowthRegion::Register_(cyclus::Agent* agent) {
7277
<< " as a builder.";
7378
buildmanager_.Register(b_cast);
7479
}
80+
#else
81+
throw cyclus::Error("Growth Region requires that Cyclus & Cycamore be compiled "
82+
"with COIN support.");
83+
#endif
7584
}
7685

7786
void GrowthRegion::Unregister_(cyclus::Agent* agent) {
7887
using cyclus::toolkit::CommodityProducerManager;
7988
using cyclus::toolkit::Builder;
80-
89+
#if CYCLUS_HAS_COIN
8190
CommodityProducerManager* cpm_cast =
8291
dynamic_cast<CommodityProducerManager*>(agent);
8392
if (cpm_cast != NULL)
@@ -86,6 +95,10 @@ void GrowthRegion::Unregister_(cyclus::Agent* agent) {
8695
Builder* b_cast = dynamic_cast<Builder*>(agent);
8796
if (b_cast != NULL)
8897
buildmanager_.Unregister(b_cast);
98+
#else
99+
throw cyclus::Error("Growth Region requires that Cyclus & Cycamore be compiled "
100+
"with COIN support.");
101+
#endif
89102
}
90103

91104
void GrowthRegion::Tick() {
@@ -106,7 +119,7 @@ void GrowthRegion::Tick() {
106119
LOG(cyclus::LEV_INFO3, "greg") << " * demand = " << demand;
107120
LOG(cyclus::LEV_INFO3, "greg") << " * supply = " << supply;
108121
LOG(cyclus::LEV_INFO3, "greg") << " * unmet demand = " << unmetdemand;
109-
122+
110123
if (unmetdemand > 0) {
111124
OrderBuilds(commod, unmetdemand);
112125
}
@@ -116,6 +129,7 @@ void GrowthRegion::Tick() {
116129

117130
void GrowthRegion::OrderBuilds(cyclus::toolkit::Commodity& commodity,
118131
double unmetdemand) {
132+
#if CYCLUS_HAS_COIN
119133
using std::vector;
120134
vector<cyclus::toolkit::BuildOrder> orders =
121135
buildmanager_.MakeBuildDecision(commodity, unmetdemand);
@@ -149,6 +163,10 @@ void GrowthRegion::OrderBuilds(cyclus::toolkit::Commodity& commodity,
149163
context()->SchedBuild(instcast, agentcast->prototype());
150164
}
151165
}
166+
#else
167+
throw cyclus::Error("Growth Region requires that Cyclus & Cycamore be compiled "
168+
"with COIN support.");
169+
#endif
152170
}
153171

154172
extern "C" cyclus::Agent* ConstructGrowthRegion(cyclus::Context* ctx) {

src/growth_region.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ class GrowthRegion : public cyclus::Region {
6767
inline cyclus::toolkit::SupplyDemandManager* sdmanager() {
6868
return &sdmanager_;
6969
}
70-
71-
protected:
70+
71+
protected:
7272
#pragma cyclus var { \
7373
"alias": ["growth", "commod", \
7474
["piecewise_function", \
@@ -102,13 +102,15 @@ class GrowthRegion : public cyclus::Region {
102102
"respective documentation pages.", \
103103
}
104104
std::map<std::string, std::vector<std::pair<int, std::pair<std::string, std::string> > > > commodity_demand; // must match Demand typedef
105-
105+
106+
#if CYCLUS_HAS_COIN
106107
/// manager for building things
107108
cyclus::toolkit::BuildingManager buildmanager_;
109+
#endif
108110

109111
/// manager for Supply and demand
110112
cyclus::toolkit::SupplyDemandManager sdmanager_;
111-
113+
112114
/// register a child
113115
void Register_(cyclus::Agent* agent);
114116

@@ -125,7 +127,6 @@ class GrowthRegion : public cyclus::Region {
125127
/// @param unmetdemand the unmet demand
126128
void OrderBuilds(cyclus::toolkit::Commodity& commodity, double unmetdemand);
127129
};
128-
129130
} // namespace cycamore
130131

131132
#endif // CYCAMORE_SRC_GROWTH_REGION_H_

src/growth_region_tests.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <sstream>
22

33
#include "growth_region_tests.h"
4+
#if CYCLUS_HAS_COIN
45

56
namespace cycamore {
67

@@ -52,3 +53,4 @@ INSTANTIATE_TEST_CASE_P(GrowthRegion, RegionTests,
5253
Values(&GrowthRegionConstructor));
5354
INSTANTIATE_TEST_CASE_P(GrowthRegion, AgentTests,
5455
Values(&GrowthRegionConstructor));
56+
#endif // CYCLUS_HAS_COIN

src/growth_region_tests.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#ifndef CYCAMORE_SRC_GROWTH_REGION_TESTS_H_
22
#define CYCAMORE_SRC_GROWTH_REGION_TESTS_H_
3+
#include "platform.h"
4+
#if CYCLUS_HAS_COIN
35

46
#include <gtest/gtest.h>
57

@@ -30,5 +32,5 @@ class GrowthRegionTests : public ::testing::Test {
3032
};
3133

3234
} // namespace cycamore
33-
35+
#endif // CYCLUS_HAS_COIN
3436
#endif // CYCAMORE_SRC_GROWTH_REGION_TESTS_H_

tests/helper.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
import tables
99
from nose.tools import assert_equal
1010

11+
12+
CYCLUS_HAS_COIN = None
13+
14+
1115
if sys.version_info[0] >= 3:
1216
str_types = (bytes, str)
1317
else:
@@ -57,6 +61,7 @@ def exit_times(agent_id, exit_table):
5761

5862
return exit_times
5963

64+
6065
def run_cyclus(cyclus, cwd, in_path, out_path):
6166
"""Runs cyclus with various inputs and creates output databases
6267
"""
@@ -65,6 +70,7 @@ def run_cyclus(cyclus, cwd, in_path, out_path):
6570
cmd = [cyclus, "-o", out_path, "--input-file", in_path]
6671
check_cmd(cmd, cwd, holdsrtn)
6772

73+
6874
def check_cmd(args, cwd, holdsrtn):
6975
"""Runs a command in a subprocess and verifies that it executed properly.
7076
"""
@@ -80,3 +86,16 @@ def check_cmd(args, cwd, holdsrtn):
8086
print("STDOUT + STDERR:\n\n" + f.read().decode())
8187
holdsrtn[0] = rtn
8288
assert_equal(rtn, 0)
89+
90+
91+
def cyclus_has_coin():
92+
global CYCLUS_HAS_COIN
93+
if CYCLUS_HAS_COIN is not None:
94+
return CYCLUS_HAS_COIN
95+
s = subprocess.check_output(['cyclus', '--version'], universal_newlines=True)
96+
s = s.strip().replace('Dependencies:', '')
97+
m = {k.strip(): v.strip() for k,v in [line.split()[:2] for line in s.splitlines()
98+
if line != '']}
99+
CYCLUS_HAS_COIN = m['Coin-Cbc'] != '-1'
100+
return CYCLUS_HAS_COIN
101+

tests/test_regression.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616

1717
import helper
18-
from helper import check_cmd, run_cyclus, table_exist
18+
from helper import check_cmd, run_cyclus, table_exist, cyclus_has_coin
1919

2020

2121
ALLOW_MILPS = Env().allow_milps
@@ -282,6 +282,8 @@ class TestDynamicCapacitated(TestRegression):
282282
def __init__(self, *args, **kwargs):
283283
super(TestDynamicCapacitated, self).__init__(*args, **kwargs)
284284
self.inf = "./input/dynamic_capacitated.xml"
285+
if not cyclus_has_coin():
286+
raise SkipTest('Cyclus not compiled with COIN')
285287

286288
def setUp(self):
287289
super(TestDynamicCapacitated, self).setUp()
@@ -392,6 +394,8 @@ class TestGrowth(TestRegression):
392394
def __init__(self, *args, **kwargs):
393395
super(TestGrowth, self).__init__(*args, **kwargs)
394396
self.inf = "./input/growth.xml"
397+
if not cyclus_has_coin():
398+
raise SkipTest('Cyclus not compiled with COIN')
395399

396400
def setUp(self):
397401
super(TestGrowth, self).setUp()

tests/test_run_inputs.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,26 @@
22
import subprocess
33

44
from nose.tools import assert_true
5+
from nose.plugins.skip import SkipTest
56

67
import run_inputs as ri
8+
from helper import cyclus_has_coin
9+
10+
11+
def coin_skipper(filename):
12+
raise SkipTest(filename + " cannot be executed since Cyclus was not installed "
13+
"with COIN support")
14+
715

816
def test_inputs():
917
files, _, _ = ri.get_files(ri.input_path)
1018
for f in files:
11-
testf = ri.TestFile(ri.cyclus_path, f, "-v0")
12-
testf.run()
13-
yield assert_true, testf.passed, "Failed running {}".format(f)
19+
absfile = os.path.join(ri.input_path, f)
20+
with open(absfile) as fh:
21+
src = fh.read()
22+
if cyclus_has_coin() or "GrowthRegion" not in src:
23+
testf = ri.TestFile(ri.cyclus_path, f, "-v0")
24+
testf.run()
25+
yield assert_true, testf.passed, "Failed running {}".format(f)
26+
else:
27+
yield coin_skipper, absfile

0 commit comments

Comments
 (0)