From afee0f8d7eeaa6e630935a6b4f440729e2cd761a Mon Sep 17 00:00:00 2001 From: abachmann Date: Tue, 23 Jan 2024 08:41:03 -0600 Subject: [PATCH] correct dictionary format for normalizing These changes allow an archetype to pass a dictionary as simple as {'commodity_name1':Resource1} as the request portfolio, and it can be normalized as needed to interact with the DRE properly --- cyclus/lib.pyx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/cyclus/lib.pyx b/cyclus/lib.pyx index 055d866590..1e9ddd30c5 100644 --- a/cyclus/lib.pyx +++ b/cyclus/lib.pyx @@ -1837,7 +1837,7 @@ cpdef dict normalize_request_portfolio(object inp): constrs = inp.get('constraints', []) else: commods = [] - for name, reqs in inp: + for name, reqs in inp.items(): if name == 'preference' or name == 'exclusive': continue commods.append({name:reqs}) @@ -1855,10 +1855,11 @@ cpdef dict normalize_request_portfolio(object inp): if isinstance(val, ts.Resource): req = default_req.copy() req['target'] = val - if 'preference' in inp['commodities'][index]: - req['preference'] = inp['commodities'][index]['preference'] - if 'exclusive' in inp['commodities'][index]: - req['exclusive'] = inp['commodities'][index]['exclusive'] + if 'commodities' in inp: + if 'preference' in inp['commodities'][index]: + req['preference'] = inp['commodities'][index]['preference'] + if 'exclusive' in inp['commodities'][index]: + req['exclusive'] = inp['commodities'][index]['exclusive'] commods[index][key] = [req] elif isinstance(val, Mapping):