Search code examples
documentationpyomo

How to get information / help for pyomo functions, methods etc


First of all I am new to python and pyomo (but got some basic knowlege in Matlab, C, R, and some hardware orientated languages). I am looking for some kind of documentation for pyomo, something like the help function in other languages but i didn´t find it yet. For eg. I want to know what type and structure the arguments passed to into param() or .create-instance should have. There are various examples but I am not able to interpret and adapt them to my case.

help(pyomo.create_instance())

AttributeError: module 'pyomo' has no attribute 'create_instance'

My concrete problem I will present in a different post, but in general I am struggeling finding informations.


Solution

  • First of all, some useful resources:

    Finally, from inside your IDE/notebook, you can still use help and dir, but you have to make sure you are using them on functions/methods that actually exist, and that you call it on the method, not its result.

    As per the message you receive, pyomo.create_instance does not exist. create_instance is a method of pyomo.environ.AbstractModel, so you should use help(pyomo.environ.AbstractModel) (notice that there is not parenthesis since we are not calling the function/method). To clarify this, in Matlab there is no distinction between writing some_function_name and some_function_name(): the function is called (executed) anyway. In Python, some_function_name gives you the function as an object, whereas some_function_name() actually calls the function. As you can imagine, help works on the function object, not on its results.

    As a final comment, 99% of the things you actually want to use from pyomo are located inside pyomo.environ (unless you want to use the newer but less stable kernel library). What I usually do is start with from pyomo import environ as pe so that I have all I need available without typing pyomo.environ a million times.