Too Few Degrees of Freedom

681 views
Skip to first unread message

Mayowa Oladele

unread,
Mar 17, 2022, 10:23:50 PM3/17/22
to Pyomo Forum
Hello All,

I keep getting an error message "Too Few Degrees of Freedom" when I try to solve my ODEs and I don't know why. I have 35 Constraints and I have also listed all the parameters and variables.

Here is a snippet of the code: 

# Speicfy the initial conditions

def _init(m):
    # for soluble liquid phase
    yield m.S_su_out[m.t.first()] == 1
    yield m.S_aa_out[m.t.first()] == 1
    yield m.S_fa_out[m.t.first()] == 1
    yield m.S_va_out[m.t.first()] == 1
    yield m.S_bu_out[m.t.first()] == 1
    yield m.S_pro_out[m.t.first()] == 1
    yield m.S_ac_out[m.t.first()] == 1
    yield m.S_h2_out[m.t.first()] == 1
    yield m.S_ch4_out[m.t.first()] == 1
    yield m.S_IC_out[m.t.first()] == 1
    yield m.S_IN_out[m.t.first()] == 1
    yield m.S_I_out[m.t.first()] == 1
    # for particulate liquid phase
    yield m.X_c_out[m.t.first()] == 1
    yield m.X_ch_out[m.t.first()] == 1
    yield m.X_pr_out[m.t.first()] == 1
    yield m.X_li_out[m.t.first()] == 1
    yield m.X_su_out[m.t.first()] == 1
    yield m.X_aa_out[m.t.first()] == 1
    yield m.X_fa_out[m.t.first()] == 1
    yield m.X_c4_out[m.t.first()] == 1
    yield m.X_pro_out[m.t.first()] == 1
    yield m.X_ac_out[m.t.first()] == 1
    yield m.X_h2_out[m.t.first()] == 1
    yield m.X_I_out[m.t.first()] == 1
    # for gas phase
    yield m.S_gas_h2_out[m.t.first()] == 1
    yield m.S_gas_ch4_out[m.t.first()] == 1
    yield m.S_gas_co2_out[m.t.first()] == 1
    # for cation and anion
    yield m.S_cat_out[m.t.first()] == 1
    yield m.S_an_out[m.t.first()] == 1
    # for ions
    yield m.S_va_minus[m.t.first()] == 1
    yield m.S_bu_minus[m.t.first()] == 1
    yield m.S_pro_minus[m.t.first()] == 1
    yield m.S_ac_minus[m.t.first()] == 1
    yield m.S_hco3_minus[m.t.first()] == 1
    yield m.S_nh3[m.t.first()] == 1
m.init_conditions = ConstraintList(rule=_init)

# Discretize model using radau collocation
discretizer = TransformationFactory('dae.collocation')
discretizer.apply_to(m,nfe=35,ncp=6,scheme='LAGRANGE-RADAU')

# solve the model
opt = SolverFactory('ipopt')
results = opt.solve(m, tee=True)


The error message below:

NOTE: You are using Ipopt by default with the MUMPS linear solver. Other linear solvers might be more efficient (see Ipopt documentation). This is Ipopt version 3.11.1, running with linear solver mumps. Number of nonzeros in equality constraint Jacobian...: 229273 Number of nonzeros in inequality constraint Jacobian.: 0 Number of nonzeros in Lagrangian Hessian.............: 9620 Error in an AMPL evaluation. Run with "halt_on_ampl_error yes" to see details. Error evaluating Jacobian of equality constraints at user provided starting point. No scaling factors for equality constraints computed! Exception of type: TOO_FEW_DOF in file "../../../../Ipopt/src/Interfaces/IpIpoptApplication.cpp" at line 860: Exception message: status != TOO_FEW_DEGREES_OF_FREEDOM evaluated false: Too few degrees of freedom (rethrown)! EXIT: Problem has too few degrees of freedom. WARNING: Loading a SolverResults object with a warning status into model.name="unknown"; - termination condition: other - message from solver: Too few degrees of freedom (rethrown)!

Thank you.

Nicholson, Bethany L.

unread,
Mar 21, 2022, 4:29:46 PM3/21/22
to pyomo...@googlegroups.com

Are all 35 of your constraints differential equations? You only need to specify initial conditions for the differential variables (i.e. the state variables that you are differentiating in your differential equations). You can try using the model size report utility in Pyomo to see how many degrees of freedom you are off by. Add the following lines after discretizing the model:

 

from pyomo.util.model_size import build_model_size_report

report = build_model_size_report(m)

print(‘Num constraints: ‘, report.activated.constraints)

print(‘Num variables: ‘, report.activated.variables)

 

If you are trying to solve a forward simulation of a system of ODEs then the number of variables should be equal to the number of constraints.

 

Bethany

--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyomo-forum/c7cebb04-6177-4eb5-9a23-03b6ba913b34n%40googlegroups.com.

Mayowa Oladele

unread,
Mar 22, 2022, 11:39:26 AM3/22/22
to Pyomo Forum
Hi Bethany,

I now have equal number of variables and constraints.

I solved it and got this:   ValueError: Cannot load a SolverResults object with bad status: error

The error message below:


Ipopt 3.11.1: ****************************************************************************** This program contains Ipopt, a library for large-scale nonlinear optimization. Ipopt is released as open source code under the Eclipse Public License (EPL). For more information visit http://projects.coin-or.org/Ipopt ****************************************************************************** NOTE: You are using Ipopt by default with the MUMPS linear solver. Other linear solvers might be more efficient (see Ipopt documentation). This is Ipopt version 3.11.1, running with linear solver mumps. Number of nonzeros in equality constraint Jacobian...: 48933 Number of nonzeros in inequality constraint Jacobian.: 0 Number of nonzeros in Lagrangian Hessian.............: 2564 Error in an AMPL evaluation. Run with "halt_on_ampl_error yes" to see details. Error evaluating Jacobian of equality constraints at user provided starting point. No scaling factors for equality constraints computed! Total number of variables............................: 3096 variables with only lower bounds: 0 variables with lower and upper bounds: 0 variables with only upper bounds: 0 Total number of equality constraints.................: 3096 Total number of inequality constraints...............: 0 inequality constraints with only lower bounds: 0 inequality constraints with lower and upper bounds: 0 inequality constraints with only upper bounds: 0 Error in an AMPL evaluation. Run with "halt_on_ampl_error yes" to see details. Number of Iterations....: 0 Number of objective function evaluations = 0 Number of objective gradient evaluations = 0 Number of equality constraint evaluations = 1 Number of inequality constraint evaluations = 0 Number of equality constraint Jacobian evaluations = 0 Number of inequality constraint Jacobian evaluations = 0 Number of Lagrangian Hessian evaluations = 0 Total CPU secs in IPOPT (w/o function evaluations) = 0.019 Total CPU secs in NLP function evaluations = 0.000 EXIT: Invalid number in NLP function or derivative detected.
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) ~\AppData\Local\Temp/ipykernel_14760/3114321947.py in <module> 3 #opt.options['linear_solver'] = 'MA86' 4 #opt.options['max_iter']= 10000 ----> 5 results = opt.solve(m, tee=True) 6 m.pprint() ~\Anaconda5\lib\site-packages\pyomo\opt\base\solvers.py in solve(self, *args, **kwds) 624 else: 625 if self._load_solutions: --> 626 _model.solutions.load_from( 627 result, 628 select=self._select_index, ~\Anaconda5\lib\site-packages\pyomo\core\base\PyomoModel.py in load_from(self, results, allow_consistent_values_for_fixed_vars, comparison_tolerance_for_fixed_vars, ignore_invalid_labels, id, delete_symbol_map, clear, default_variable_value, select, ignore_fixed_vars) 222 "an 'aborted' status, but containing a solution") 223 else: --> 224 raise ValueError("Cannot load a SolverResults object " 225 "with bad status: %s" 226 % str(results.solver.status)) ValueError: Cannot load a SolverResults object with bad status: error


Nicholson, Bethany L.

unread,
Mar 22, 2022, 12:04:22 PM3/22/22
to pyomo...@googlegroups.com

The problem is noted in the IPOPT status message: “EXIT: Invalid number in NLP function or derivative detected.”

 

Try adding the following options to your call to the solver to help debug the problem:

 

solver_options = {‘halt_on_ampl_error’:’yes’}

opt = SolverFactory('ipopt')

results = opt.solve(m, tee=True, symbolic_solver_labels=True, options=solver_options)

Message has been deleted

Jace

unread,
Apr 5, 2022, 9:02:20 AM4/5/22
to Pyomo Forum
Hi Bethany,

I have a similar question:

I tried to simulate a dynamic model for chromatography using the Simulator function but I got an error saying that it does not work for equations with more than 2 DerivativeVar. 

For simulation of systems of PDAEs, we should be using the forward difference method with initial/boundary conditions specified and solve the forward finite difference optimization problem without an objective function?

Thank you,
Jacey
Reply all
Reply to author
Forward
0 new messages