openmod-initiative / toolchest

A common repository for tools used in energy modeling.
BSD 3-Clause "New" or "Revised" License
5 stars 4 forks source link

add pyomoio.py #7

Closed ojdo closed 4 years ago

ojdo commented 8 years ago

This is my first attempt to add the promised Pyomo to Pandas functionality as mentioned in #6. Please review liberally, as this is my first attempt at non-trivial unit testing. I am quite unsure how to structure and use the transp_setup function within the tests (c.f. @with_setup decorator). Or should I use TestCase inheriting classes and assign the setup function as the setUp method? It did not get any clue as to what is preferable from the docs.

Not included (yet): testing of functions with a solved model state. I first want to check whether the CI files need some help to figure out how to get pyomo, first.

gidden commented 8 years ago

Thanks @ojdo! I'll try to get to look at this today. You beat me to the first code PR =)

gidden commented 8 years ago

Hey @ojdo, I took this for a spin with one of the models I use and got the following error:

In [29]: pyomoio.list_entities(m, 'var')
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-29-5594168abb50> in <module>()
----> 1 pyomoio.list_entities(m, 'var')

/home/gidden/.local/lib/python2.7/site-packages/toolchest-0.0.1-py2.7.egg/toolchest/pyomoio.pyc in list_entities(instance, entity_type)
    146     entities = sorted(
    147         (name, entity.doc, _get_onset_names(entity))
--> 148         for (name, entity) in iter_entities
    149         if filter_by_type(entity, entity_type))
    150 

/home/gidden/.local/lib/python2.7/site-packages/toolchest-0.0.1-py2.7.egg/toolchest/pyomoio.pyc in <genexpr>((name, entity))
    147         (name, entity.doc, _get_onset_names(entity))
    148         for (name, entity) in iter_entities
--> 149         if filter_by_type(entity, entity_type))
    150 
    151     # if something was found, wrap tuples in DataFrame, otherwise return empty

/home/gidden/.local/lib/python2.7/site-packages/toolchest-0.0.1-py2.7.egg/toolchest/pyomoio.pyc in _get_onset_names(entity)
    206                     pyomo.Objective)):
    207         if entity.dim() > 0 and entity._index:
--> 208             labels = _get_onset_names(entity._index)
    209         else:
    210             # zero dimensions, so no onset labels

/home/gidden/.local/lib/python2.7/site-packages/toolchest-0.0.1-py2.7.egg/toolchest/pyomoio.pyc in _get_onset_names(entity)
    187                 domains = entity.domain.set_tuple
    188             else:
--> 189                 domains = entity.set_tuple
    190 
    191             for domain_set in domains:

AttributeError: 'SimpleSet' object has no attribute 'set_tuple'
gidden commented 8 years ago

Ok, went through it once. Thanks @ojdo!

ojdo commented 8 years ago

Better late than never... Thanks @gidden for the thorough review! I followed your main suggestion to change the return type of get_entity to Series. I opted to preserve the get_entities function, because in 'practice' I often use it to read out multiple timeseries to a single data structure.

ojdo commented 7 years ago

@gidden Would you mind having a look at the amended PR for pyomoio? I hope I addressed all the minor and major points.