Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with numpy type handling in writers #2927

Closed
AndreGismo opened this issue Jul 29, 2023 · 2 comments · Fixed by #2953
Closed

Error with numpy type handling in writers #2927

AndreGismo opened this issue Jul 29, 2023 · 2 comments · Fixed by #2953
Labels

Comments

@AndreGismo
Copy link

AndreGismo commented Jul 29, 2023

Summary

I have updated from pyomo 6.3.0 to pyomo 6.6.1 and now I get an error when I try to run code. But the same code ran under pyomo 6.3.0 without errors. I use glpk 5.0 as solver. I use conda for creating virtual environments. I got the new pyomo version from conda forge using conda install -c conda-forge pyomo.

The error tells me something about a missing right-hand side. But I build my constraints as always, and under pyomo 6.3.0 everything was fine.

Steps to reproduce the issue

I could not find a way to reproduce the error in a short minimal working example, sorry! :(
But here is the link to my respository with the code.

The executable script is test_optimization.py.
One will also need the files

  • battery_electric_vehicle.py,
  • household.py,
  • optimization.py
  • and EMO.py

to run the file test_optimization.py

Other dependencies are mainly:

  • pandas
  • numpy
  • matplotlib
  • pandapower
  • scipy

Basically, a ConcreteModel is built and than the solver ('glpk') is called to solve the problem.

Error Message

GLPSOL--GLPK LP/MIP Solver 5.0
Parameter(s) specified in the command line:
 --write C:\Users\andre\AppData\Local\Temp\tmptt02uba8.glpk.raw --wglp C:\Users\andre\AppData\Local\Temp\tmpcdek_rm3.glpk.glp
 --cpxlp C:\Users\andre\AppData\Local\Temp\tmpve2nmu93.pyomo.lp
Reading problem data from 'C:\Users\andre\AppData\Local\Temp\tmpve2nmu93.pyomo.lp'...
C:\Users\andre\AppData\Local\Temp\tmpve2nmu93.pyomo.lp:201: missing right-hand side
CPLEX LP file processing error
ERROR: Solver (glpk) returned non-zero return code (1)
ERROR: See the solver log above for diagnostic information.
Traceback (most recent call last):
  File "C:\Users\andre\Desktop\Studium TH Köln\Studium TH Köln (Ma)\Module\MA\MA Waffenschmidt\ARBEIT\CODE\Code\test_optimization.py", line 139, in <module>
    test.run_optimization_fixed_horizon(tee=True)
  File "C:\Users\andre\Desktop\Studium TH Köln\Studium TH Köln (Ma)\Module\MA\MA Waffenschmidt\ARBEIT\CODE\Code\optimization.py", line 998, in run_optimization_fixed_horizon
    self.solver_factory.solve(self.optimization_model, tee=kwargs['tee'])
  File "C:\Users\andre\anaconda3\envs\testEnv\lib\site-packages\pyomo\opt\base\solvers.py", line 627, in solve
    raise ApplicationError("Solver (%s) did not exit normally" % self.name)
pyomo.common.errors.ApplicationError: Solver (glpk) did not exit normally

Process finished with exit code 1

Information on your system

Pyomo version: 6.6.1
Python version: 3.9.17
Operating system: Microsoft Windows 10 Pro (10.0.19045 Build 19045)
How Pyomo was installed (PyPI, conda, source): conda
Solver (if applicable): glpk

Additional information

The optimization model is built in the file optimization.py, in the class GridLineOptimizer in the method _setup_model, starts in line 474.

@AndreGismo AndreGismo added the bug label Jul 29, 2023
@blnicho
Copy link
Member

blnicho commented Aug 1, 2023

@AndreGismo could you try adding the option symbolic_solver_labels=True to your call to solve? I'm hoping this will get GLPK to print the name of the constraint causing the problem. You could also try adding the option keepfiles=True to the call to solve and manually look through the lp file for the problematic constraint. If you can identify which constraint is causing the error, you should be able to put together a small Pyomo model that reproduces the issue.

It's going to be really hard for us to debug this without a minimal stand-alone example that reproduces the error you're seeing.

@AndreGismo
Copy link
Author

AndreGismo commented Aug 7, 2023

@blnicho thank you for the tip! I have added the option symbolic_solver_labels=True, however the output didn't change.

To be honest, I haven't ever seen before these lp files. But I managed to spot a difference between two lp files:

  • one from a run with pyomo 6.3.0 where everything went well
  • one from a run with pyomo 6.6.1 where it says: missing right hand side

The main difference: the working lp file from the run with pyomo 6.3.0 directly specifies right hand side as float. However, the lp file from the run with pyomo 6.6.1 specifies right hand side as an array with only one entry.

Can it be possible, that this causes the error?

I couldn't find a way to attach the files, so I will just paste the contents (not everything, only till the first contraint causing the error occurs)

The not working lp file:
* Source Pyomo model name=GridLineOptimization *\

max
max_power:
+23 I(0_0)
+22 I(1_0)
+21 I(2_0)
+20 I(3_0)
+19 I(4_0)
+18 I(5_0)
+17 I(6_0)
+16 I(7_0)
+15 I(8_0)
+14 I(9_0)
+13 I(10_0)
+12 I(11_0)
+11 I(12_0)
+10 I(13_0)
+9 I(14_0)
+8 I(15_0)
+7 I(16_0)
+6 I(17_0)
+5 I(18_0)
+4 I(19_0)
+3 I(20_0)
+2 I(21_0)
+1 I(22_0)
+23 I(0_3)
+22 I(1_3)
+21 I(2_3)
+20 I(3_3)
+19 I(4_3)
+18 I(5_3)
+17 I(6_3)
+16 I(7_3)
+15 I(8_3)
+14 I(9_3)
+13 I(10_3)
+12 I(11_3)
+11 I(12_3)
+10 I(13_3)
+9 I(14_3)
+8 I(15_3)
+7 I(16_3)
+6 I(17_3)
+5 I(18_3)
+4 I(19_3)
+3 I(20_3)
+2 I(21_3)
+1 I(22_3)

s.t.

c_l_min_voltage(0)_:
-0.004 I(0_0)
-0.016 I(0_3)

= array([-21.96752416])

c_l_min_voltage(1)_:
-0.004 I(1_0)
-0.016 I(1_3)

= array([-21.97414019])

the working lp file:
* Source Pyomo model name=GridLineOptimization *\

max
max_power:
+23 I(0_0)
+23 I(0_3)
+13 I(10_0)
+13 I(10_3)
+12 I(11_0)
+12 I(11_3)
+11 I(12_0)
+11 I(12_3)
+10 I(13_0)
+10 I(13_3)
+9 I(14_0)
+9 I(14_3)
+8 I(15_0)
+8 I(15_3)
+7 I(16_0)
+7 I(16_3)
+6 I(17_0)
+6 I(17_3)
+5 I(18_0)
+5 I(18_3)
+4 I(19_0)
+4 I(19_3)
+22 I(1_0)
+22 I(1_3)
+3 I(20_0)
+3 I(20_3)
+2 I(21_0)
+2 I(21_3)
+1 I(22_0)
+1 I(22_3)
+21 I(2_0)
+21 I(2_3)
+20 I(3_0)
+20 I(3_3)
+19 I(4_0)
+19 I(4_3)
+18 I(5_0)
+18 I(5_3)
+17 I(6_0)
+17 I(6_3)
+16 I(7_0)
+16 I(7_3)
+15 I(8_0)
+15 I(8_3)
+14 I(9_0)
+14 I(9_3)

s.t.

c_l_min_voltage(0)_:
-0.0040000000000000001 I(0_0)
-0.016 I(0_3)

= -21.967524164721453

c_l_min_voltage(1)_:
-0.0040000000000000001 I(1_0)
-0.016 I(1_3)

= -21.974140185166789

However, I still couldn't find a way to reproduce the error. As I understand the error, it stems from the constraint min_voltage. Now when I build a minimal example, just including the objective and the mentioned constraint, everything works. I don't understand this.

@blnicho blnicho changed the title Error with pyomo 6.6.1 Error with numpy type handling in writers Aug 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants