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

TotalInvTracker to be an inventory check on whole agents #1646

Merged
merged 21 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Since last release
* Add random number generator (Mersenne Twister 19937, from boost) and the ability to set the seed in the simulation control block (#1599, #1639)
* Allow randomness in request frequency and size through buy policy (#1634)
* Adds support for Cython3 (#1636)
* Adds TotalInvTracker, which allows an inventory cap to be set for multiple resource buffers, and is now required for material buy policy (#1646)

**Changed:**

Expand Down
10 changes: 9 additions & 1 deletion cli/cycpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,14 @@
('{0}::toolkit::ResBuf'.format(CYCNS), CYCNS + '::Product'),
('{0}::toolkit::ResBuf'.format(CYCNS), CYCNS + '::Material'),
'{0}::toolkit::ResMap'.format(CYCNS),
'{0}::toolkit::TotalInvTracker'.format(CYCNS),
gonuke marked this conversation as resolved.
Show resolved Hide resolved
('{0}::toolkit::TotalInvTracker'.format(CYCNS), '{0}::toolkit::ResBuf'.format(CYCNS), CYCNS + '::Material'),
}

TEMPLATES = {'std::vector', 'std::set', 'std::list', 'std::pair',
'std::map', '{0}::toolkit::ResBuf'.format(CYCNS),
CYCNS + '::toolkit::ResMap',}
CYCNS + '::toolkit::ResMap',
CYCNS + '::toolkit::TotalInvTracker',}

WRANGLERS = {
'{0}::Agent'.format(CYCNS),
Expand Down Expand Up @@ -1079,6 +1082,7 @@ def impl(self, ind=" "):
"m->{var}.capacity());\n"),
CYCNS + '::toolkit::ResBuf': "{var}.capacity(m->{var}.capacity());\n",
CYCNS + '::toolkit::ResMap': '{var}.obj_ids(m->obj_ids());\n',
CYCNS + '::toolkit::TotalInvTracker': "{var}.capacity();\n",
}

class InitFromDbFilter(CodeGeneratorFilter):
Expand Down Expand Up @@ -1145,6 +1149,7 @@ def impl(self, ind=" "):
CYCNS + '::toolkit::ResBuf': '{var}.capacity({capacity});\n',
CYCNS + '::toolkit::ResMap': (
'{var}.obj_ids(qr.GetVal<{tstr}>("{var}"))\n;'),
CYCNS + '::toolkit::TotalInvTracker': '{var}.capacity();\n',
}


Expand Down Expand Up @@ -1893,6 +1898,7 @@ def impl(self, ind=" "):
CYCNS + '::toolkit::ResourceBuff': None,
CYCNS + '::toolkit::ResBuf': None,
CYCNS + '::toolkit::ResMap': '{var}.obj_ids()',
CYCNS + '::toolkit::TotalInvTracker': None,
}


Expand Down Expand Up @@ -1947,6 +1953,7 @@ def impl(self, ind=" "):
'invs[\"{var}\"] = {var}.PopNRes({var}.count());\n'
'{var}.Push(invs["{var}"]);\n'),
CYCNS + '::toolkit::ResMap': "invs[\"{var}\"] = {var}.ResValues();\n",
CYCNS + '::toolkit::TotalInvTracker': ';\n',
}


Expand Down Expand Up @@ -1995,6 +2002,7 @@ def impl(self, ind=" "):
CYCNS + '::toolkit::ResourceBuff': "{var}.PushAll(inv[\"{var}\"]);\n",
CYCNS + '::toolkit::ResBuf': "{var}.Push(inv[\"{var}\"]);\n",
CYCNS + '::toolkit::ResMap': "{var}.ResValues(inv[\"{var}\"]);\n",
CYCNS + '::toolkit::TotalInvTracker': ";\n",
}


Expand Down
15 changes: 14 additions & 1 deletion cyclus/gentypesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,15 @@ def convert_to_cpp(self, x, t):
'std::list': 'std_list',
'std::vector': 'std_vector',
'cyclus::toolkit::ResBuf': 'cpp_cyclus.ResBuf',
'cyclus::toolkit::TotalInvTracker': 'cpp_cyclus.TotalInvTracker',
'cyclus::toolkit::ResMap': 'cpp_cyclus.ResMap',
}

# Don't include the base resource class here since it is pure virtual.
RESOURCES = ['MATERIAL', 'PRODUCT']

INVENTORIES = ['cyclus::toolkit::ResourceBuff', 'cyclus::toolkit::ResBuf',
'cyclus::toolkit::ResMap']
'cyclus::toolkit::TotalInvTracker', 'cyclus::toolkit::ResMap']

USE_SHARED_PTR = ('MATERIAL', 'PRODUCT', 'cyclus::Material', 'cyclus::Product')

Expand Down Expand Up @@ -419,6 +420,7 @@ def convert_to_cpp(self, x, t):
'std::list': 'std_list',
'std::vector': 'std_vector',
'cyclus::toolkit::ResBuf': 'res_buf',
'cyclus::toolkit::TotalInvTracker': 'total_inv_tracker',
'cyclus::toolkit::ResMap': 'res_map',
}

Expand Down Expand Up @@ -453,6 +455,7 @@ def convert_to_cpp(self, x, t):
'std::list': 'List',
'std::vector': 'Vector',
'cyclus::toolkit::ResBuf': 'ResBuf',
'cyclus::toolkit::TotalInvTracker': 'total_inv_tracker',
'cyclus::toolkit::ResMap': 'ResMap',
}

Expand Down Expand Up @@ -489,6 +492,7 @@ def convert_to_cpp(self, x, t):
'std::list': ('val',),
'std::vector': ('val',),
'cyclus::toolkit::ResBuf': ('val',),
'cyclus::toolkit::TotalInvTracker': ('val',),
'cyclus::toolkit::ResMap': ('key', 'val'),
}

Expand All @@ -509,6 +513,7 @@ def convert_to_cpp(self, x, t):
'std::list': 'np.NPY_OBJECT',
'std::vector': 'np.NPY_OBJECT',
'cyclus::toolkit::ResBuf': 'np.NPY_OBJECT',
'cyclus::toolkit::TotalInvTracker': 'np.NPY_OBJECT',
'cyclus::toolkit::ResMap': 'np.NPY_OBJECT',
}

Expand All @@ -529,6 +534,7 @@ def convert_to_cpp(self, x, t):
'std::list': '[]',
'std::vector': '[]',
'cyclus::toolkit::ResBuf': 'None',
'cyclus::toolkit::TotalInvTracker': 'None',
'cyclus::toolkit::ResMap': 'None',
}

Expand Down Expand Up @@ -646,6 +652,7 @@ def convert_to_cpp(self, x, t):
' py{var}[i] = {var}_i\n',
'py{var}'),
'cyclus::toolkit::ResBuf': ('', '', 'None'),
'cyclus::toolkit::TotalInvTracker': ('', '', 'None'),
'cyclus::toolkit::ResMap': ('', '', 'None'),
}

Expand Down Expand Up @@ -758,6 +765,12 @@ def convert_to_cpp(self, x, t):
'py{var} = <_{classname}> {var}\n'
'cpp{var} = deref(py{var}.ptx)\n',
'cpp{var}'),
'cyclus::toolkit::TotalInvTracker': (
'cdef _{classname} py{var}\n'
'cdef cpp_cyclus.TotalInvTracker[{valtype}] cpp{var}\n',
'py{var} = <_{classname}> {var}\n'
'cpp{var} = deref(py{var}.ptx)\n',
'cpp{var}'),
'cyclus::toolkit::ResMap': (
'cdef _{classname} py{var}\n'
'cdef cpp_cyclus.ResMap[{keytype}, {valtype}] cpp{var}\n',
Expand Down