Skip to content

Variable bounds defined via @variables are not enforced during nonlinear equation solving #3438

@ysyecust

Description

@ysyecust

Problem:
When defining variables with bounds using @variables (e.g., @variables x [bounds=(0, 1)]), these bounds are not enforced during nonlinear equation solving with NonlinearSolve.jl. This leads to solutions violating the specified physical/domain constraints, requiring manual post-solution checks.

Expected Behavior:
Bounds defined in variable metadata should automatically constrain the solution space. For example, a variable with bounds=(0, 1) should only accept solutions within [0, 1], either via:

Automatic variable transformation (e.g., logit transforms for (0,1))

Constraint-aware nonlinear solvers

Clear warnings/errors if bounds are ignored

Alternatives Considered:

Manually adding penalty functions to equations (cumbersome and solver-dependent)

Post-processing solutions to check bounds (defeats the purpose of declarative modeling)

Context:
Example use case:

julia
@variables z[1:numcomp] [bounds=(0,1), guess=0.2]  
@variables T [bounds=(100,500), guess=298.15]  

Suggested Path:

Add bounds validation/transforms in MTK variable processing

Integrate with constrained nonlinear solvers (e.g., via NonlinearSolve.jl or Optimization.jl)

At minimum, throw clear warnings when bounds are declared but unused

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions