Using LHS Value to Debug An Infeasible Problem#

This notebook aims to show how to use the left-hand side (LHS) value (Constraint.e) to debug an infeasible problem.

The LHS value is the value of the left-hand side of the equation. It is useful to check which constraints are violated.

[1]:
import ams
[2]:
ams.config_logger(stream_level=20)

First, let’s solve a DCOPF.

[3]:
sp = ams.load(ams.get_case('matpower/case14.m'),
              no_output=True)
Parsing input file "/Users/jinningwang/work/ams/ams/cases/matpower/case14.m"...
Input file parsed in 0.0070 seconds.
Zero line rates detacted in rate_a, rate_b, rate_c, adjusted to 999.
System set up in 0.0034 seconds.
[4]:
sp.DCOPF.run(solver='CLARABEL')
Building system matrices
Parsing OModel for <DCOPF>
Evaluating OModel for <DCOPF>
Finalizing OModel for <DCOPF>
<DCOPF> initialized in 0.0144 seconds.
<DCOPF> solved as optimal in 0.0160 seconds, converged in 11 iterations with CLARABEL.
[4]:
True
[5]:
sp.DCOPF.pg.v.round(2)
[5]:
array([2.21, 0.38, 0.  , 0.  , 0.  ])

Then, we can lower down the generator maximum output to create an infeasible problem.

[6]:
sp.StaticGen.set(src='pmax', attr='v', idx=[1, 2, 3, 4, 5], value=0.5)
[6]:
True

Remember to update the corresponding parameters in the routine.

[7]:
sp.DCOPF.update('pmax')
[7]:
True

Now, we can see that the problem is infeasible.

[8]:
sp.DCOPF.run(solver='CLARABEL')
DCOPF failed as infeasible in 9 iterations with CLARABEL!
[8]:
False

Then, we can turn off some constraints and sovle it again.

[9]:
sp.DCOPF.disable(['pglb', 'pgub'])
Turn off constraints: pglb, pgub
[9]:
True

Note that since there are some constraints touched, the OModel will be updated automatically.

[10]:
sp.DCOPF.run(solver='CLARABEL')
Disabled constraints: pglb, pgub
Finalizing OModel for <DCOPF>
<DCOPF> initialized in 0.0019 seconds.
<DCOPF> solved as optimal in 0.0167 seconds, converged in 9 iterations with CLARABEL.
[10]:
True
[11]:
sp.DCOPF.pg.v
[11]:
array([ 2.31448356,  0.39836206, -0.04094854, -0.04094854, -0.04094854])

Since all the inequality constraints are written in the form of \(Ax -b \leq 0\), we can check the violated constraints by finding the those with positive Constraint.e.

[12]:
sp.DCOPF.pgub.e
[12]:
array([ 1.81448356, -0.10163794, -0.54094854, -0.54094854, -0.54094854])
[13]:
sp.DCOPF.pglb.e
[13]:
array([-2.31448356, -0.39836206,  0.04094854,  0.04094854,  0.04094854])