forked from cvxpy/cvxpy
-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
Describe the bug
ValueError: Variable var1 has no value. This is a bug and should be reported. when adding best_of=5 to a DNLP solve call that's otherwise
To Reproduce
import numpy as np
import cvxpy as cp
N = 91
log_pressure = np.linspace(-4, 2, N)
log_pressure_0 = np.min(log_pressure)
T0 = 100
C1 = 5
rcb_index = 45
log_pressure_rcb = log_pressure[rcb_index]
adiabatic_slope = 2 * C1 * (log_pressure_rcb - log_pressure_0)
temperature = cp.Variable(shape=(N,))
convective_indicators = cp.Variable(shape=(N-1,), bounds=[0,1])
lapse_rate = cp.diff(temperature) / np.diff(log_pressure)
lapse_rate_constraint = lapse_rate <= adiabatic_slope
convective_below_constraint = cp.diff(convective_indicators) >= 0
flux = (temperature - T0 - C1 * (log_pressure - log_pressure_0) ** 2) ** 2
dflux_dT = cp.diff(flux) / cp.diff(temperature)
flux_balance_constraint = cp.square(cp.multiply((1 - convective_indicators), dflux_dT)) <= 1e-10
temperature_positive_constraint = temperature >= 0
constraints = [lapse_rate_constraint, convective_below_constraint, flux_balance_constraint, temperature_positive_constraint]
problem = cp.Problem(cp.Minimize(cp.sum_squares(convective_indicators)), constraints)
problem.solve(solver=cp.IPOPT, nlp=True, best_of=5)
Expected behavior
The IPOPT output for the optimization problem, which shows up successfully when best_of is not provided.
Output
Starting NLP solve 1 of 5
Traceback (most recent call last):
File "/Users/adityasengupta/playground/pyplay/rcb_mwe.py", line 27, in <module>
problem.solve(solver=cp.IPOPT, nlp=True, best_of=5)
~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/adityasengupta/playground/pyplay/DNLP/cvxpy/problems/problem.py", line 665, in solve
return solve_func(self, *args, **kwargs)
File "/Users/adityasengupta/playground/pyplay/DNLP/cvxpy/problems/problem.py", line 1138, in _solve
canon_problem, inverse_data = nlp_chain.apply(problem=self)
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "/Users/adityasengupta/playground/pyplay/DNLP/cvxpy/reductions/chain.py", line 76, in apply
problem, inv = r.apply(problem)
~~~~~~~^^^^^^^^^
File "/Users/adityasengupta/playground/pyplay/DNLP/cvxpy/reductions/solvers/nlp_solvers/nlp_solver.py", line 56, in apply
problem, data, inv_data = self._prepare_data_and_inv_data(problem)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
File "/Users/adityasengupta/playground/pyplay/DNLP/cvxpy/reductions/solvers/nlp_solvers/nlp_solver.py", line 62, in _prepare_data_and_inv_data
bounds = Bounds(problem)
File "/Users/adityasengupta/playground/pyplay/DNLP/cvxpy/reductions/solvers/nlp_solvers/nlp_solver.py", line 78, in __init__
self.construct_initial_point()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/Users/adityasengupta/playground/pyplay/DNLP/cvxpy/reductions/solvers/nlp_solvers/nlp_solver.py", line 133, in construct_initial_point
raise ValueError("Variable %s has no value. This is a bug and should be reported."
% var.name())
ValueError: Variable var1 has no value. This is a bug and should be reported.
Version
- OS: MacOS Sequoia 15.2
- CVXPY Version: 1.9.0.dev0+0.4ef4cd1
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels