Skip to content

Commit 2bda8ae

Browse files
Transurgeonclaude
andcommitted
Remove dead parameter-to-constant fallthrough in converter
Parameters are always registered via build_parameter_dict, so the fallthrough path that created them as make_constant was dead code. Replace with an explicit error if a parameter is missing from param_dict. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 082611b commit 2bda8ae

1 file changed

Lines changed: 5 additions & 13 deletions

File tree

cvxpy/reductions/solvers/nlp_solvers/diff_engine/converters.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -501,22 +501,14 @@ def convert_expr(expr, var_dict: dict, n_vars: int, param_dict: dict = None):
501501
if isinstance(expr, cp.Variable):
502502
return var_dict[expr.id]
503503

504-
# Base case: parameter lookup (before Constant since both are Leaf subclasses)
504+
# Base case: parameter lookup (before Constant since Parameter is a Constant subclass)
505505
if isinstance(expr, cp.Parameter):
506506
if param_dict is not None and expr.id in param_dict:
507507
return param_dict[expr.id]
508-
# Fall through to constant if no param_dict or not found
509-
c = expr.value
510-
if c is None:
511-
raise ValueError(
512-
f"Parameter '{expr.name()}' has no value set. "
513-
"Set parameter values before converting."
514-
)
515-
if sparse.issparse(c):
516-
c = c.todense()
517-
c = np.asarray(c, dtype=np.float64)
518-
d1, d2 = _normalize_shape(expr.shape)
519-
return _diffengine.make_constant(d1, d2, n_vars, c.flatten(order='F'))
508+
raise ValueError(
509+
f"Parameter '{expr.name()}' not found in param_dict. "
510+
"All parameters must be registered via build_parameter_dict."
511+
)
520512

521513
# Base case: constant
522514
if isinstance(expr, cp.Constant):

0 commit comments

Comments
 (0)