Pyomo / pyomo

An object-oriented algebraic modeling language in Python for structured optimization problems.
https://www.pyomo.org
Other
2.03k stars 518 forks source link

Suppress the outputs of the "pyomo solve" command #2814

Closed ThemisKoutsellis closed 1 year ago

ThemisKoutsellis commented 1 year ago

Summary

I am using the "pyomo solve --solver=glpk osemosys.py *.dat" command. osemosys.py is a AbstractModel() instantiation. You can find the source code here

The results are always printed on the cmd. However, the outputs (it is a python dict) are extremely large yielding a slow OSeMOSYS-model solver execution.

Description

  1. Deploy a command line argument, for the "pyomo solve" command, so that the users are capable to suppress the output.
  2. Deploy a command line argument, for the "pyomo solve" command, which gives the option for the user to save the output dict to a "pickle" python file
jsiirola commented 1 year ago

I believe that you can already do pretty much everything you want with

pyomo solve --solver=glpk --logging=quiet --results=results.json osemosys.py *.dat

That writes the results as a json and not a pickle, but the json is probably more robust and likely faster in this case.

ThemisKoutsellis commented 1 year ago

Unfortunately, the above solution seems to not working. I get the following:

ERROR: Unexpected exception while running model: Unknown results file format: results.json errorcode: 1 retval: None

At least is there a way around to suppress the cmd output? The printed python dict is extremelly large in some models, which causes computational resources issues.

Thank you in advance!

Themis

jsiirola commented 1 year ago

The --logging=quiet option above is the option to turn off the output.

The --results=results.json should be --results json to switch the output format to use JSON instead of YAML (and should be slightly faster).

ThemisKoutsellis commented 1 year ago

Thank you jsiirola for your reply! The --results json option, indeed, works now. However, the--logging=quiet option do not. Because the results are not considered as logs. Perhaps, pyomo considers as logs info such as whether the solution was feasible, the number of solutions etc, which indeed, when passing the--logging=quiet argument, are not displayed. However, the large dict results on cmd are still there.

jsiirola commented 1 year ago

What version of Pyomo are you using? I cannot reproduce the behavior you describe with current release or development branch. I see:

~/ % pyomo solve --solver=glpk  pmedian.py pmedian.test2.dat
[    0.00] Setting up Pyomo environment
[    0.00] Applying Pyomo preprocessing actions
[    0.00] Creating model
[    0.01] Applying solver
[    0.02] Processing results
    Number of solutions: 1
    Solution Information
      Gap: 0.0
      Status: optimal
      Function Value: 13.360120427317106
    Solver results file: results.yml
[    0.03] Applying Pyomo postprocessing actions
[    0.03] Pyomo Finished
~/ %

and

~/ % pyomo solve --solver=glpk  pmedian.py pmedian.test2.dat --results json --logging=quiet
~/ %

Without a complete example, there is little we can do to debug your problem.

ThemisKoutsellis commented 1 year ago

I am using Pyomo==6.5.0 And the python pyomo model (OSeMOSYS model) and the corresponding dat file is here

the command I use is: pyomo solve --solver=glpk --logging=quiet --results json osemosys.py UTOPIA_2015_08_27.dat

ThemisKoutsellis commented 1 year ago

Here are the details of my execution:

  1. the model file is this one
  2. the dat file is this one

    I am using: ply==3.11 Pyomo==6.5.0 which is the latest pyomo version, I guess.

If a execute this cmd command: pyomo solve --solver=glpk osemosys.py UTOPIA_2015_08_27.dat --results json --logging=quiet

I get the following on my terminal: example

, which is an extremely large dictionary: The solution of model's variables (Too many variables in the model). *The cmd terminal only shows a portion of the printed dictionary

jsiirola commented 1 year ago

I cannot reproduce your observed behavior using either 6.5.0 or the main development branch (on Linux or Windows). I see no output to the console with the specified input files and command line. My guess is this is either an issue with running through Visual Studio or a problem with how you have things installed in the Visual Studio environment.

ThemisKoutsellis commented 1 year ago

I tried different OS, different laptops, different set-ups. i.e., MAC. I also tried to execute the command from a cmd or MAC-terminal. Unfortunately, the same issue occurs! It seems, it is not an issue of VS-CODE but an issue of pyomo. I attach the full log files from my MAC. MAC-Terminal-log-file.txt Can we please open an issue for this behavior? Thank you in advance,

Themis

jsiirola commented 1 year ago

OK. This isn't a bug with Pyomo, but with the conda-forge/pyomo-feedstock recipe. Until the next release (due out in ~1 month), you can work around this by installing pyomo using pip and not conda.