Skip to content

Commit

Permalink
Merge pull request cyclus#1755 from bennibbelink/resource-buff
Browse files Browse the repository at this point in the history
  • Loading branch information
gonuke authored May 18, 2024
2 parents 4894eb4 + 8220843 commit e3df773
Show file tree
Hide file tree
Showing 16 changed files with 25 additions and 922 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Since last release

**Removed:**

* Removed the ResourceBuff class and replaced its instances with ResBuf (#1755)

**Fixed:**


Expand Down
2 changes: 1 addition & 1 deletion agents/k_facility.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class KFacility : public cyclus::Facility {
double max_inv_size;

#pragma cyclus var {'capacity': 'max_inv_size'}
cyclus::toolkit::ResourceBuff inventory;
cyclus::toolkit::ResBuf<cyclus::Resource> inventory;

/// Conversion factors for input and output amounts.
#pragma cyclus var { \
Expand Down
2 changes: 1 addition & 1 deletion agents/sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class Sink : public cyclus::Facility {
double capacity;

#pragma cyclus var {'capacity': 'max_inv_size'}
cyclus::toolkit::ResourceBuff inventory;
cyclus::toolkit::ResBuf<cyclus::Resource> inventory;
};

} // namespace cyclus
Expand Down
11 changes: 1 addition & 10 deletions cli/cycpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@
PRIMITIVES = {'bool', 'int', 'float', 'double', 'std::string', 'cyclus::Blob',
'boost::uuids::uuid', }

BUFFERS = {'{0}::toolkit::ResourceBuff'.format(CYCNS),
'{0}::toolkit::ResBuf'.format(CYCNS),
BUFFERS = {'{0}::toolkit::ResBuf'.format(CYCNS),
('{0}::toolkit::ResBuf'.format(CYCNS), CYCNS + '::Resource'),
('{0}::toolkit::ResBuf'.format(CYCNS), CYCNS + '::Product'),
('{0}::toolkit::ResBuf'.format(CYCNS), CYCNS + '::Material'),
Expand Down Expand Up @@ -1078,8 +1077,6 @@ def impl(self, ind=" "):
return impl

res_impl = {
CYCNS + '::toolkit::ResourceBuff': ("{var}.set_capacity("
"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",
Expand Down Expand Up @@ -1145,7 +1142,6 @@ def impl(self, ind=" "):
return impl

res_impl = {
CYCNS + '::toolkit::ResourceBuff': '{var}.set_capacity({capacity});\n',
CYCNS + '::toolkit::ResBuf': '{var}.capacity({capacity});\n',
CYCNS + '::toolkit::ResMap': (
'{var}.obj_ids(qr.GetVal<{tstr}>("{var}"))\n;'),
Expand Down Expand Up @@ -1895,7 +1891,6 @@ def impl(self, ind=" "):
return impl

res_exprs = {
CYCNS + '::toolkit::ResourceBuff': None,
CYCNS + '::toolkit::ResBuf': None,
CYCNS + '::toolkit::ResMap': '{var}.obj_ids()',
CYCNS + '::toolkit::TotalInvTracker': None,
Expand Down Expand Up @@ -1946,9 +1941,6 @@ def impl(self, ind=" "):
return impl

res_impl = {
CYCNS + '::toolkit::ResourceBuff': (
'invs[\"{var}\"] = {var}.PopN({var}.count());\n'
'{var}.PushAll(invs["{var}"]);\n'),
CYCNS + '::toolkit::ResBuf': (
'invs[\"{var}\"] = {var}.PopNRes({var}.count());\n'
'{var}.Push(invs["{var}"]);\n'),
Expand Down Expand Up @@ -1999,7 +1991,6 @@ def impl(self, ind=" "):
return impl

res_impl = {
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
29 changes: 0 additions & 29 deletions cyclus/cpp_cyclus.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -834,35 +834,6 @@ cdef extern from "toolkit/position.h" namespace "cyclus::toolkit":
# Inventories and Resource Buffers
#

cdef extern from "toolkit/resource_buff.h" namespace "cyclus::toolkit":

ctypedef vector[Resource.Ptr] Manifest

cdef cppclass ResourceBuff:
enum AccessDir:
FRONT
BACK
ResourceBuff()
double capacity()
void set_capacity(double)
int count()
double quantity()
double space()
cpp_bool empty()
Manifest PopQty(double)
Manifest PopQty(double, double)
Manifest PopN(int)
Resource.Ptr Pop(AccessDir)
shared_ptr[T] Pop[T]()
void Push(shared_ptr[Resource])
void PushAll[B](vector[B])

cdef extern from "toolkit/resource_buff.h" namespace "cyclus::toolkit::ResourceBuff":

enum AccessDir:
FRONT
BACK

cdef extern from "toolkit/res_buf.h" namespace "cyclus::toolkit":

ctypedef vector[Resource.Ptr] ResVec
Expand Down
124 changes: 4 additions & 120 deletions cyclus/gentypesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ def convert_to_cpp(self, x, t):
'UUID': 'cpp_cyclus.uuid',
'MATERIAL': 'cpp_cyclus.Material',
'PRODUCT': 'cpp_cyclus.Product',
'RESOURCE_BUFF': 'cpp_cyclus.ResourceBuff',
# C++ normal types
'bool': 'cpp_bool',
'int': 'int',
Expand All @@ -369,7 +368,6 @@ def convert_to_cpp(self, x, t):
'boost::uuids::uuid': 'cpp_cyclus.uuid',
'cyclus::Material': 'cpp_cyclus.Material',
'cyclus::Product': 'cpp_cyclus.Product',
'cyclus::toolkit::ResourceBuff': 'cpp_cyclus.ResourceBuff',
# Template Types
'std::set': 'std_set',
'std::map': 'std_map',
Expand All @@ -384,10 +382,11 @@ def convert_to_cpp(self, x, t):
# Don't include the base resource class here since it is pure virtual.
RESOURCES = ['MATERIAL', 'PRODUCT']

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

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

FUNCNAMES = {
# type system types
Expand All @@ -401,7 +400,6 @@ def convert_to_cpp(self, x, t):
'UUID': 'uuid',
'MATERIAL': 'material',
'PRODUCT': 'product',
'RESOURCE_BUFF': 'resource_buff',
# C++ normal types
'bool': 'bool',
'int': 'int',
Expand All @@ -412,7 +410,6 @@ def convert_to_cpp(self, x, t):
'boost::uuids::uuid': 'uuid',
'cyclus::Material': 'material',
'cyclus::Product': 'product',
'cyclus::toolkit::ResourceBuff': 'resource_buff',
# Template Types
'std::set': 'std_set',
'std::map': 'std_map',
Expand All @@ -436,7 +433,6 @@ def convert_to_cpp(self, x, t):
'UUID': 'Uuid',
'MATERIAL': 'Material',
'PRODUCT': 'Product',
'RESOURCE_BUFF': 'ResourceBuff',
# C++ normal types
'bool': 'Bool',
'int': 'Int',
Expand All @@ -447,7 +443,6 @@ def convert_to_cpp(self, x, t):
'boost::uuids::uuid': 'Uuid',
'cyclus::Material': 'Material',
'cyclus::Product': 'Product',
'cyclus::toolkit::ResourceBuff': 'ResourceBuff',
# Template Types
'std::set': 'Set',
'std::map': 'Map',
Expand All @@ -470,7 +465,6 @@ def convert_to_cpp(self, x, t):
'std::string': 'bytes({var}).decode()',
'cyclus::Blob': 'blob_to_bytes({var})',
'boost::uuids::uuid': 'uuid_cpp_to_py({var})',
'cyclus::toolkit::ResourceBuff': 'None',
}

# note that this maps normal forms to python
Expand All @@ -482,7 +476,6 @@ def convert_to_cpp(self, x, t):
'std::string': 'str_py_to_cpp({var})',
'cyclus::Blob': 'cpp_cyclus.Blob(std_string(<const char*> {var}))',
'boost::uuids::uuid': 'uuid_py_to_cpp({var})',
'cyclus::toolkit::ResourceBuff': 'resource_buff_to_cpp({var})',
}

TEMPLATE_ARGS = {
Expand All @@ -506,7 +499,6 @@ def convert_to_cpp(self, x, t):
'boost::uuids::uuid': 'np.NPY_OBJECT',
'cyclus::Material': 'np.NPY_OBJECT',
'cyclus::Product': 'np.NPY_OBJECT',
'cyclus::toolkit::ResourceBuff': 'None',
'std::set': 'np.NPY_OBJECT',
'std::map': 'np.NPY_OBJECT',
'std::pair': 'np.NPY_OBJECT',
Expand All @@ -527,7 +519,6 @@ def convert_to_cpp(self, x, t):
'boost::uuids::uuid': 'uuid.UUID(int=0)',
'cyclus::Material': 'None',
'cyclus::Product': 'None',
'cyclus::toolkit::ResourceBuff': 'None',
'std::set': 'set()',
'std::map': '{}',
'std::pair': '(None, None)',
Expand Down Expand Up @@ -563,7 +554,6 @@ def convert_to_cpp(self, x, t):
'cpp_cyclus.Product]({var})\n'
'py_{var} = pyx_{var}\n',
'py_{var}'),
'cyclus::toolkit::ResourceBuff': ('', '', 'None'),
# templates
'std::set': (
'{valdecl}\n'
Expand Down Expand Up @@ -686,12 +676,6 @@ def convert_to_cpp(self, x, t):
'cpp{var} = reinterpret_pointer_cast[cpp_cyclus.Product, '
'cpp_cyclus.Resource](py{var}.ptx)\n',
'cpp{var}'),
'cyclus::toolkit::ResourceBuff': (
'cdef _{classname} py{var}\n'
'cdef cpp_cyclus.ResourceBuff cpp{var}\n',
'py{var} = <_{classname}> {var}\n'
'cpp{var} = deref(py{var}.ptx)\n',
'cpp{var}'),
# templates
'std::set': (
'{valdecl}\n'
Expand Down Expand Up @@ -1277,18 +1261,6 @@ class interface in a simple way usable for things such as: bananas,
"""
cdef object manifest_to_py(cpp_cyclus.Manifest manifest):
"""Turns a manifest into a list of Resources."""
cdef list m = []
cdef _Resource r
for ptr in manifest:
r = Resource()
r.ptx = ptr
m.append(r)
rtn = m
return rtn
#
# Inventories block
#
Expand Down Expand Up @@ -1316,93 +1288,7 @@ def empty(self):
"""Returns true if nothing is stored."""
return self.ptx.empty()
{% if t == 'RESOURCE_BUFF' %}
@property
def capacity(self):
"""The maximum resource quantity this store can hold."""
return self.ptx.capacity()
@capacity.setter
def capacity(self, double val):
self.ptx.set_capacity(val)
@property
def count(self):
"""the total number of constituent resource objects in the store."""
return self.ptx.count()
def __len__(self):
return self.ptx.count()
@property
def space(self):
"""The quantity of space remaining in this store."""
return self.ptx.space()
def pop_qty(self, double quantity, double eps=-1.0):
"""Pops the specified quantity of resources from the buffer.
Negative eps values are ignored (default).
"""
cdef cpp_cyclus.Manifest manifest
if eps < 0.0:
manifest = self.ptx.PopQty(quantity)
else:
manifest = self.ptx.PopQty(quantity, eps)
rtn = manifest_to_py(manifest)
return rtn
def pop_n(self, int num):
"""Pops the specified number of resources from the buffer."""
rtn = manifest_to_py(self.ptx.PopN(num))
return rtn
def pop(self, bint back=False):
"""Pops one resource object from the store."""
cdef _Resource r = Resource()
if back:
r.ptx = self.ptx.Pop(cpp_cyclus.BACK)
else:
r.ptx = self.ptx.Pop(cpp_cyclus.FRONT)
rtn = r
return rtn
def push(self, _Resource r):
"""Pushes a single resource object to the buffer."""
self.ptx.Push(r.ptx)
def push_all(self, rs):
"""Pushes one or more resource objects to the store."""
cdef std_vector[shared_ptr[cpp_cyclus.Resource]] v
cdef _Resource cpp_r
for r in rs:
cpp_r = <_Resource> r
v.push_back(cpp_r.ptx)
self.ptx.PushAll[shared_ptr[cpp_cyclus.Resource]](v)
def pop_all_res(self):
"""A consistent interface for popping all of the resources from the buffer.
For ResourceBuff, this is equivalent to self.pop_n(len(self))
"""
rtn = manifest_to_py(self.ptx.PopN(self.ptx.count()))
return rtn
def push_many(self, rs):
"""A consistent interface for pushing many resources into the buffer.
For ResourceBuff, this simply calls push_all().
"""
self.push_all(rs)
{% for r in ts.resources %}{% set rfname = ts.funcname(r) %}{% set rcname = ts.classname(r) %}
def pop_{{rfname}}(self):
"""Pops one resource object from the store as a {{rfname}}."""
cdef _{{rcname}} r = {{rcname}}()
r.ptx = self.ptx.Pop(cpp_cyclus.FRONT) # don't bother casting back and forth
rtn = r
return rtn
{% endfor %}
{% elif ts.norms[t][0] == 'cyclus::toolkit::ResBuf' %}
{% if ts.norms[t][0] == 'cyclus::toolkit::ResBuf' %}
{% set r = ts.norms[t][1] %}
{% set rcname = ts.classname(r) %}
@property
Expand Down Expand Up @@ -2580,8 +2466,6 @@ def typesystem_pyx(ts, ns):
cdef class _Product(_Resource):
pass
cdef object manifest_to_py(cpp_cyclus.Manifest)
{% for t in ts.inventory_types %}
{% set tclassname = ts.classname(t)%}
cdef class _{{tclassname}}:
Expand Down
2 changes: 1 addition & 1 deletion cyclus/pyagents.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Sink(Facility):
tooltip="sink capacity",
default=100.0,
)
inventory = ts.ResourceBuffInv(capacity='max_inv_size')
inventory = ts.ResBufProduct()

def get_material_requests(self):
if len(self.recipe) == 0:
Expand Down
1 change: 0 additions & 1 deletion src/cyclus.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ extern "C" {
#include "toolkit/infile_converters.h"
#include "toolkit/mat_query.h"
#include "toolkit/position.h"
#include "toolkit/resource_buff.h"
#include "toolkit/res_buf.h"
#include "toolkit/res_manip.h"
#include "toolkit/res_map.h"
Expand Down
1 change: 0 additions & 1 deletion src/query_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ enum DbTypes {
// Resource Tools
MATERIAL, // ["cyclus::Material", 0, [], "MATERIAL", false]
PRODUCT, // ["cyclus::Product", 0, [], "PRODUCT", false]
RESOURCE_BUFF, // ["cyclus::toolkit::ResourceBuff", 0, [], "RESOURCE_BUFF", false]
RES_BUF_MATERIAL, // ["cyclus::toolkit::ResBuf<cyclus::Material>", 1, [], ["RES_BUF", "MATERIAL"], false]
RES_BUF_PRODUCT, // ["cyclus::toolkit::ResBuf<cyclus::Product>", 1, [], ["RES_BUF", "PRODUCT"], false]
RES_MAP_INT_MATERIAL, // ["cyclus::toolkit::ResMap<int, cyclus::Material>", 2, [], ["RES_MAP", "INT", "MATERIAL"], false]
Expand Down
Loading

0 comments on commit e3df773

Please sign in to comment.