In regular python scripts, you can pass command line parameters to python scripts with the sys.argv
. For example, a python script named parameter_pass.py
that contains:
# simple python example
import sys
val = sys.argv[1]
print(val)
Called with python parameter_pass.py hi
prints 'hi' to the console. But the same does not work for a pyomo solve
command line call as far as I can tell. Is there a way to pass command line parameters beyond solver options to a pyomo model?
I don't know of an easy way to do this with the pyomo solve
command line interface but you can easily do this by using the scripting interface to Pyomo. Just write a Python script that builds a concrete Pyomo model and calls a solver and you can run it using python mymodel.py
. Then you can add anything else you want to the Python script including passing in command line values.