pyomo
pyomo copied to clipboard
Model fails with infeasible equality constraints even by changing the Constraints tolerance
Summary
I am trying to create a model in pyomo and using the IPOPT solver. But the model fails with the infeasible constraints even after changing the tolerance values from 1e-02 to 100.
Steps to reproduce the issue
- Steps to be reproduced on Google Colab.
- Install pyomo and IPOPT:
!pip install pyomo
!wget -N -q "https://matematica.unipv.it/gualandi/solvers/ipopt-linux64.zip"
!unzip -o -q ipopt-linux64
- Import Pyomo and other necessary libraries:
from pyomo.environ import *
from pyomo.environ import SolverFactory, TerminationCondition
from pyomo.util.infeasible import log_infeasible_constraints, log_infeasible_bounds
import numpy as np
from pyomo.dae import *
## Define the Pyomo model
import matplotlib.pyplot as plt
- Create model in Pyomo with some equality constraints. For example,
def LD(m,t):
return m.LD[t] == m.VT[t]*(const-m.RR[t])
m.ruleLD = Constraint(m.t,rule=LD)
Complete model cannot be shared due to some restrictions. 5. Call the solver and set the tolerances and various other options and run the solver:
discretizer = TransformationFactory('dae.finite_difference')
discretizer.apply_to(m, nfe=5, wrt=m.t, scheme='BACKWARD')
# m.pprint()
solver = SolverFactory('ipopt')
solver.options['max_iter'] = 10000
# solver.options['output_file'] = 'ipopt_log.txt'
solver.options['acceptable_compl_inf_tol'] = 100
solver.options['acceptable_constr_viol_tol'] = 100
solver.options['acceptable_dual_inf_tol'] = 100
solver_options = {'halt_on_ampl_error':'yes'}#,'honor_original_bounds': 'no'}
#solver_options = {'nlp_scaling_method':'none'}
# m.dual = Suffix(direction=Suffix.IMPORT)
results = solver.solve(m,tee=True, options=solver_options)#symbolic_solver_labels=True, warmstart=False)
print('Solver status:', results.solver.status)
- Log the infeasibility constraints:
log_infeasible_constraints(m)
Error Message
Solver Error Log:
Objective...............: -2.0667437230418777e+03 -2.0667437230418777e+03
Dual infeasibility......: 9.9999736909142856e-01 9.9999736909142856e-01
Constraint violation....: 7.3428239149061570e-04 7.3428239149061570e-04
Complementarity.........: 2.5061213924838309e-09 2.5061213924838309e-09
Overall NLP error.......: 9.9999736909142856e-01 9.9999736909142856e-01
Number of objective function evaluations = 7785
Number of objective gradient evaluations = 874
Number of equality constraint evaluations = 7789
Number of inequality constraint evaluations = 7789
Number of equality constraint Jacobian evaluations = 4633
Number of inequality constraint Jacobian evaluations = 4633
Number of Lagrangian Hessian evaluations = 4595
Total CPU secs in IPOPT (w/o function evaluations) = 656.793
Total CPU secs in NLP function evaluations = 45.965
EXIT: Converged to a point of local infeasibility. Problem may be infeasible.
WARNING:pyomo.core:Loading a SolverResults object with a warning status into model.name="unknown";
- termination condition: infeasible
- message from solver: Ipopt 3.12.13\x3a Converged to a locally infeasible point. Problem may be infeasible.
Solver status: warning
Infeasibility Log
INFO:pyomo.util.infeasible:CONSTR SumYTrule[200.0]: 1.0001426979383388 =/= 1.0
INFO:pyomo.util.infeasible:CONSTR VTrule[400.0]: -2.5151170732592672e-05 =/= 0.0
INFO:pyomo.util.infeasible:CONSTR VT2rule[200.0]: -0.0002786788791127037 =/= 0.0
INFO:pyomo.util.infeasible:CONSTR VT2rule[400.0]: -0.0002759075117577067 =/= 0.0
INFO:pyomo.util.infeasible:CONSTR conXT3[400.0,0]: -0.0001340349043506709 =/= 0.0
INFO:pyomo.util.infeasible:CONSTR conXT3[400.0,1]: -0.0007342883899282032 =/= 0.0
INFO:pyomo.util.infeasible:CONSTR conXT3[800.0,0]: -0.00014118776967880515 =/= 0.0
INFO:pyomo.util.infeasible:CONSTR VT3rule[200.0]: 0.00011070715117966756 =/= 0.0
INFO:pyomo.util.infeasible:CONSTR VT3rule[400.0]: 0.00026325648146689653 =/= 0.0
INFO:pyomo.util.infeasible:CONSTR SumYBrule[200.0]: 0.9996386038256693 =/= 1.0
INFO:pyomo.util.infeasible:CONSTR VBrule[200.0]: -0.00016797172429505736 =/= 0.0
INFO:pyomo.util.infeasible:CONSTR VBrule[400.0]: -0.00015400045193819526 =/= 0.0
INFO:pyomo.util.infeasible:CONSTR VBrule[600.0]: -0.00018539799566497095 =/= 0.0
INFO:pyomo.util.infeasible:CONSTR VBrule[800.0]: -0.00011927730520255864 =/= 0.0
INFO:pyomo.util.infeasible:CONSTR rulehLT3[400.0]: 0.0002562306262916536 =/= 0.0
INFO:pyomo.util.infeasible:CONSTR dXT3_disc_eq[400.0,0]: 0.0001341071217146914 =/= 0.0
INFO:pyomo.util.infeasible:CONSTR dXT3_disc_eq[400.0,1]: 0.000731972531306398 =/= 0.0
INFO:pyomo.util.infeasible:CONSTR dXT3_disc_eq[800.0,0]: 0.00014119302752059953 =/= 0.0
INFO:pyomo.util.infeasible:CONSTR dXB_disc_eq[400.0,0]: -0.00038565575902887387 =/= 0.0
INFO:pyomo.util.infeasible:CONSTR dXB_disc_eq[800.0,0]: -1.1018964831555967e-05 =/= 0.0
INFO:pyomo.util.infeasible:CONSTR dXB_disc_eq[1000,0]: 0.00019732317037527921 =/= 0.0
Information on your system
Platform: Google Colab Pyomo version: 6.8.0 Python version: 3.10.12 Operating system: "Ubuntu 22.04.3 LTS" Jammy How Pyomo was installed (PyPI, conda, source): !pip install pyomo Solver (if applicable): IPOPT (!wget -N -q "https://matematica.unipv.it/gualandi/solvers/ipopt-linux64.zip")