Skip to content

Commit

Permalink
Merge pull request cyclus#1757 from bennibbelink/cyclus_large
Browse files Browse the repository at this point in the history
  • Loading branch information
gonuke authored Jul 27, 2024
2 parents 1ce434e + 7f34985 commit bf43602
Show file tree
Hide file tree
Showing 19 changed files with 73 additions and 40 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ platform.h
src/Core/Utility/Env.cpp
src/cyclus_nuc_data.h5
stubs/stub_version.h
src/cyc_limits.h
src/env.cc
src/version.cc
src/version.h
Expand All @@ -42,6 +43,7 @@ tests/db.h5
cyclus/cpp_typesystem.pxd
cyclus/typesystem.pxd
cyclus/typesystem.pyx
cyclus/system.py
tests/libcyclus-orig.h5
tests/libcyclus-orig.sqlite
tests/libcyclus-test.h5
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Since last release
* Consistently use hyphens in ``install.py`` flags (#1748)
* Material sell policy can package materials (#1749, #1774)
* Use miniforge for conda CI builds instead of miniconda (#1763)
* Define constants ``CY_LARGE_DOUBLE``, ``CY_LARGE_INT``, and ``CY_NEAR_ZERO`` (#1757)
* Warning and limits on number of packages that can be created from a resource at once (#1771)

**Removed:**
Expand Down
18 changes: 15 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ ENDIF()
# This project name is cyclus.
PROJECT(CYCLUS VERSION 1.6.0)

INCLUDE(CheckTypeSize)
CHECK_TYPE_SIZE("int" INT_SIZE_IN_BYTES LANGUAGE CXX)
MATH(EXPR INT_MAX "(1 << (${INT_SIZE_IN_BYTES} * 8 - 1)) - 1")

SET(CY_LARGE_INT "${INT_MAX}")
SET(CY_LARGE_DOUBLE "1e299")
SET(CY_NEAR_ZERO "1e-08")

MESSAGE("CY_LARGE_INT: ${CY_LARGE_INT}")
MESSAGE("CY_LARGE_DOUBLE: ${CY_LARGE_DOUBLE}")
MESSAGE("CY_NEAR_ZERO: ${CY_NEAR_ZERO}")

# check for and enable c++17 support (required for cyclus)
INCLUDE(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++17" COMPILER_SUPPORTS_CXX17)
Expand Down Expand Up @@ -396,12 +408,12 @@ IF(NOT CYCLUS_DOC_ONLY)
ADD_SUBDIRECTORY("${CYCLUS_SHARE_DIR}")
ADD_SUBDIRECTORY("${CYCLUS_SOURCE_DIR}")
ADD_SUBDIRECTORY("${CYCLUS_TEST_DIR}")
ADD_SUBDIRECTORY("${CYCLUS_AGENTS_DIR}")
ADD_SUBDIRECTORY("${CYCLUS_CLI_DIR}")
ADD_SUBDIRECTORY("${CYCLUS_CMAKE_DIR}")
if(Cython_FOUND)
ADD_SUBDIRECTORY("${CYCLUS_PYSOURCE_DIR}")
endif(Cython_FOUND)
ADD_SUBDIRECTORY("${CYCLUS_AGENTS_DIR}")
ADD_SUBDIRECTORY("${CYCLUS_CLI_DIR}")
ADD_SUBDIRECTORY("${CYCLUS_CMAKE_DIR}")

##############################################################################################
####################################### end includes #########################################
Expand Down
4 changes: 3 additions & 1 deletion agents/k_facility.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include "cyclus.h"

#pragma cyclus exec from sidecar import CY_LARGE_DOUBLE, CY_LARGE_INT, CY_NEAR_ZERO

namespace cyclus {

class Context;
Expand Down Expand Up @@ -200,7 +202,7 @@ class KFacility : public cyclus::Facility {
double current_capacity;

#pragma cyclus var { \
"default": 1e299, \
"default": CY_LARGE_DOUBLE, \
"tooltip": "k-facility maximum inventory size", \
"doc": "total maximum inventory size of the k-facility", \
"uilabel": "Maximum Inventory" \
Expand Down
6 changes: 4 additions & 2 deletions agents/sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include "cyclus.h"

#pragma cyclus exec from sidecar import CY_LARGE_DOUBLE, CY_LARGE_INT, CY_NEAR_ZERO

namespace cyclus {

/// @class Sink
Expand Down Expand Up @@ -93,7 +95,7 @@ class Sink : public cyclus::Facility {
std::string recipe_name;

#pragma cyclus var {\
"default": 1e299, \
"default": CY_LARGE_DOUBLE, \
"doc": "total maximum inventory size of " \
"sink facility", \
"uilabel": "Maximum Inventory", \
Expand All @@ -106,7 +108,7 @@ class Sink : public cyclus::Facility {
"accept at each time step", \
"uilabel": "Maximum Throughput", \
"uitype": "range", \
"range": [0.0, 1e299], \
"range": [0.0, CY_LARGE_DOUBLE], \
"tooltip": "sink capacity" \
}
double capacity;
Expand Down
4 changes: 3 additions & 1 deletion agents/source.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#include "cyclus.h"

#pragma cyclus exec from sidecar import CY_LARGE_DOUBLE, CY_LARGE_INT, CY_NEAR_ZERO

namespace cyclus {

class Context;
Expand Down Expand Up @@ -115,7 +117,7 @@ class Source : public cyclus::Facility {
"doc": "amount of commodity that can be supplied at each time step", \
"uilabel": "Maximum Throughput", \
"uitype": "range", \
"range": [0.0, 1e299], \
"range": [0.0, CY_LARGE_DOUBLE], \
"tooltip": "source capacity" \
}
double capacity;
Expand Down
9 changes: 9 additions & 0 deletions cli/sidecar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import sys, importlib.util as iu
spec = iu.spec_from_file_location("cyclus.system", "../cyclus/system.py")
mod = iu.module_from_spec(spec)
sys.modules["cyclus.system"] = mod
spec.loader.exec_module(mod)

CY_LARGE_DOUBLE = mod.CY_LARGE_DOUBLE
CY_LARGE_INT = mod.CY_LARGE_INT
CY_NEAR_ZERO = mod.CY_NEAR_ZERO
1 change: 1 addition & 0 deletions cyclus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ INCLUDE_DIRECTORIES(${CYCLUS_CORE_INCLUDE_DIRS})
#
# First things first, code-generation
#
CONFIGURE_FILE(system.py.in "${CMAKE_CURRENT_SOURCE_DIR}/system.py" @ONLY)
message(STATUS "Generating Type System API for Python")
EXECUTE_PROCESS(COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/gentypesystem.py
"--src-dir=${CMAKE_CURRENT_SOURCE_DIR}"
Expand Down
3 changes: 2 additions & 1 deletion cyclus/pyagents.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from cyclus.agents import Region, Institution, Facility
from cyclus import typesystem as ts
from cyclus.system import CY_LARGE_DOUBLE

class NullRegion(Region):
"""A simple do nothing region."""
Expand Down Expand Up @@ -31,7 +32,7 @@ class Sink(Facility):
uitype="recipe",
)
max_inv_size = ts.Double(
default=1e299,
default=CY_LARGE_DOUBLE,
doc="total maximum inventory size of sink facility",
uilabel= "Maximum Inventory",
tooltip="sink maximum inventory size",
Expand Down
5 changes: 3 additions & 2 deletions cyclus/system.py → cyclus/system.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from concurrent import futures as concurrent_futures
except ImportError:
concurrent_futures = None



CY_LARGE_INT = @CY_LARGE_INT@
CY_LARGE_DOUBLE = @CY_LARGE_DOUBLE@
CY_NEAR_ZERO = @CY_NEAR_ZERO@
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ else()
set(cyclus_has_coin 0)
endif()
CONFIGURE_FILE(platform.h.in "${CMAKE_CURRENT_SOURCE_DIR}/platform.h" @ONLY)

CONFIGURE_FILE(version.cc.in "${CMAKE_CURRENT_SOURCE_DIR}/version.cc" @ONLY)
CONFIGURE_FILE(version.h.in "${CMAKE_CURRENT_SOURCE_DIR}/version.h" @ONLY)
CONFIGURE_FILE(cyc_limits.h.in "${CMAKE_CURRENT_SOURCE_DIR}/cyc_limits.h" @ONLY)

SET(cyclus_install_dir "${CMAKE_INSTALL_PREFIX}")
SET(cyclus_build_dir "${CYCLUS_BINARY_DIR}")
Expand Down
12 changes: 6 additions & 6 deletions src/cyc_limits.h → src/cyc_limits.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ static const double float_ulp_eq = 2;
/// maximum value for a function modifier (i.e., a_i for variable x_i)
static const double kModifierLimit = pow(10, 10);

/// maximum (+ or -) value for an integer variable
static const int kIntBoundLimit = std::numeric_limits<int>::max();
/// maximum (+) value for an integer variable
static const int CY_LARGE_INT = @CY_LARGE_INT@;

/// maximum (+ or -) value for a linear variable
static const double kLinBoundLimit = std::numeric_limits<double>::max();
/// maximum (+) value for a linear variable
static const double CY_LARGE_DOUBLE = @CY_LARGE_DOUBLE@;

/// epsilon value to turn determine difference between constraint values
static const double kConstraintEps = 1e-08;
/// constant near-zero value
static const double CY_NEAR_ZERO = @CY_NEAR_ZERO@;

} // namespace cyclus

Expand Down
2 changes: 1 addition & 1 deletion src/mock_sim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ MockAgent::MockAgent(Context* ctx, Recorder* rec, SqliteBack* b, bool is_source)
rec_(rec),
back_(b),
source_(is_source),
cap_(1e299),
cap_(cyclus::CY_LARGE_DOUBLE),
lifetime_(-1),
start_(0) {
std::stringstream ss;
Expand Down
2 changes: 1 addition & 1 deletion src/toolkit/mat_query.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ double MatQuery::Amount(Composition::Ptr c) {
compmath::Normalize(&m_other);

Nuc limiter;
double min_ratio = 1e300;
double min_ratio = cyclus::CY_LARGE_DOUBLE;
CompMap::iterator it;
for (it = m_other.begin(); it != m_other.end(); ++it) {
Nuc nuc = it->first;
Expand Down
4 changes: 2 additions & 2 deletions tests/material_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ TEST_F(MaterialTest, DecayShortcut) {
Material::Ptr m = Material::CreateUntracked(1.0, c);

std::string u235 ("u235");
ASSERT_NEAR(3.11996e-17, pyne::decay_const(u235), 1e-20);
ASSERT_NEAR(3.11996e-17, pyne::decay_const(u235), cyclus::CY_NEAR_ZERO);

double sec_per_month = 2629152;
double u235_lambda = pyne::decay_const(u235) * sec_per_month; // per month
Expand Down Expand Up @@ -345,7 +345,7 @@ TEST_F(MaterialTest, DecayCustomTimeStep) {
cyclus::compmath::Normalize(&newv);

// one half of atoms should have decayed away
double eps = 1e-6;
double eps = cyclus::CY_NEAR_ZERO;
EXPECT_NEAR(0.5, newv[id("Cs137")], eps) << "one Cs137 half-life duration time step did not decay half of Cs atoms";
}

Expand Down
6 changes: 3 additions & 3 deletions tests/resource_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ResourceTest : public ::testing::Test {
double mmax_qty = static_cast<double>(0.95*std::numeric_limits<int>::max());
mmax = Material::Create(dummy, mmax_qty, c);
// overflow limit
pmax = Product::Create(dummy, 1e299, "bananas");
pmax = Product::Create(dummy, cyclus::CY_LARGE_DOUBLE, "bananas");
}

virtual void TearDown() {
Expand Down Expand Up @@ -163,7 +163,7 @@ TEST_F(ResourceTest, PackageResource) {
EXPECT_EQ(p2_pkgd[1]->quantity(), 2);
EXPECT_EQ(p2_pkgd[0]->package_name(), pkg_name);
EXPECT_EQ(p2_pkgd[1]->package_name(), pkg_name);

Material::Ptr m3 = m2->ExtractQty(5.5);
std::vector<Material::Ptr> m3_pkgd = m3->Package<Material>(pkg);
EXPECT_EQ(m3->package_name(), Package::unpackaged_name());
Expand All @@ -184,4 +184,4 @@ TEST_F(ResourceTest, RepackageLimit) {
// over limit, throw
EXPECT_THROW(mmax->Package<Material>(pkg), cyclus::ValueError);
EXPECT_THROW(pmax->Package<Product>(pkg), cyclus::ValueError);
}
}
2 changes: 1 addition & 1 deletion tests/toolkit/enrichment_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ TEST_F(EnrichmentTests, enrichmentcalcs) {
double product_qty = UraniumQty(mat_by_mass_);
EXPECT_DOUBLE_EQ(feed_qty_, FeedQty(product_qty, assays));
EXPECT_DOUBLE_EQ(tails_qty_, TailsQty(product_qty, assays));
EXPECT_NEAR(swu_, SwuRequired(product_qty, assays), 1e-8);
EXPECT_NEAR(swu_, SwuRequired(product_qty, assays), cyclus::CY_NEAR_ZERO);
}

} // namespace toolkit
Expand Down
2 changes: 1 addition & 1 deletion tests/toolkit/matl_buy_policy_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ TEST_F(MatlBuyPolicyTests, NormalActiveDormant) {
TEST_F(MatlBuyPolicyTests, MixedActiveDormant) {
using cyclus::QueryResult;

boost::shared_ptr<NormalIntDist> a_dist = boost::shared_ptr<NormalIntDist>(new NormalIntDist(5, 1, 0, 1e299));
boost::shared_ptr<NormalIntDist> a_dist = boost::shared_ptr<NormalIntDist>(new NormalIntDist(5, 1, 0, cyclus::CY_LARGE_INT));
boost::shared_ptr<UniformIntDist> d_dist = boost::shared_ptr<UniformIntDist>(new UniformIntDist(1, 3));

int dur = 12;
Expand Down
28 changes: 14 additions & 14 deletions tests/toolkit/matl_sell_policy_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MatlSellPolicyTests: public ::testing::Test {
ResBuf<Material> buff;
Composition::Ptr comp, comp1;
Material::Ptr mat, mat1;

virtual void SetUp() {
fac1 = new TestFacility(tc.get());
cap = 5;
Expand Down Expand Up @@ -78,7 +78,7 @@ TEST_F(MatlSellPolicyTests, StartStop) {

TEST_F(MatlSellPolicyTests, Bids) {
MatlSellPolicy p;
std::string commod("commod");
std::string commod("commod");
CommodMap<Material>::type reqs;
reqs[commod] = std::vector<Request<Material>*>();
Request<Material>* req = Request<Material>::Create(mat1, fac1, commod);
Expand Down Expand Up @@ -113,7 +113,7 @@ TEST_F(MatlSellPolicyTests, Bids) {
ASSERT_FLOAT_EQ((*(*obs.begin())->bids().begin())->offer()->quantity(),
2);
ASSERT_EQ((*(*obs.begin())->bids().begin())->offer()->comp(), comp1);


// quantize bigger than the quantity in storage
// Qty = 3, Throughput = 3, Quanta = 6 -> No transaction
Expand All @@ -125,21 +125,21 @@ TEST_F(MatlSellPolicyTests, Bids) {

TEST_F(MatlSellPolicyTests, Trades) {
MatlSellPolicy p;
std::string commod("commod");
std::string commod("commod");
std::vector<Trade<Material> > trades;
std::vector<std::pair<Trade<Material>, Material::Ptr> > obs;

Request<Material>* req = Request<Material>::Create(mat1, fac1, commod);
Bid<Material>* bid = Bid<Material>::Create(req, mat, fac1);
Trade<Material> trade(req, bid, 1);
trades.push_back(trade);

// basic
p.Init(NULL, &buff, "").Set(commod);
p.GetMatlTrades(trades, obs);
ASSERT_EQ(obs.size(), 1);
ASSERT_EQ(obs.begin()->second->comp(), comp);

// ignore comp
obs.clear();
p.Init(NULL, &buff, "", qty, true).Set(commod);
Expand All @@ -159,7 +159,7 @@ TEST_F(MatlSellPolicyTests, Package) {

cyclus::MockSim sim(dur);
cyclus::Agent* a = new TestFacility(sim.context());

sim.context()->AddPrototype(a->prototype(), a);
sim.agent = sim.context()->CreateAgent<cyclus::Agent>(a->prototype());
sim.AddSink("commod").capacity(2).Finalize();
Expand Down Expand Up @@ -192,7 +192,7 @@ TEST_F(MatlSellPolicyTests, Package) {
EXPECT_EQ(1, qr_trans.GetVal<int>("Time", 1));
EXPECT_EQ(2, qr_trans.GetVal<int>("Time", 2));

// Resource 0 is the material of 5 that we first created.
// Resource 0 is the material of 5 that we first created.
QueryResult qr_all_res = sim.db().Query("Resources", NULL);
EXPECT_EQ(5, qr_all_res.GetVal<double>("Quantity", 0));

Expand Down Expand Up @@ -223,7 +223,7 @@ TEST_F(MatlSellPolicyTests, TransportUnit) {

cyclus::MockSim sim(dur);
cyclus::Agent* a = new TestFacility(sim.context());

sim.context()->AddPrototype(a->prototype(), a);
sim.agent = sim.context()->CreateAgent<cyclus::Agent>(a->prototype());
sim.AddSink("commod").Finalize();
Expand Down Expand Up @@ -283,15 +283,15 @@ TEST_F(MatlSellPolicyTests, PackageLimit) {

cyclus::MockSim sim(dur);
cyclus::Agent* a = new TestFacility(sim.context());

sim.context()->AddPrototype(a->prototype(), a);
sim.agent = sim.context()->CreateAgent<cyclus::Agent>(a->prototype());
sim.AddSink("commod").Finalize();
TestFacility* fac = dynamic_cast<TestFacility*>(sim.agent);

cyclus::toolkit::ResBuf<cyclus::Material> buf;

double qty = 1e299;
double qty = cyclus::CY_LARGE_DOUBLE;
CompMap cm;
cm[922380000] = 1;
Composition::Ptr comp = Composition::CreateFromMass(cm);
Expand All @@ -303,11 +303,11 @@ TEST_F(MatlSellPolicyTests, PackageLimit) {
Package::Ptr p = sim.context()->GetPackage("foo");

cyclus::toolkit::MatlSellPolicy sellpol;
sellpol.Init(fac, &buf, "buf", 1e299, false, 0, p->name())
sellpol.Init(fac, &buf, "buf", cyclus::CY_LARGE_DOUBLE, false, 0, p->name())
.Set("commod").Start();

ASSERT_THROW(sim.Run(), cyclus::ValueError);
}

}
}
}

0 comments on commit bf43602

Please sign in to comment.