Skip to content

Disable named expressions for MB+LD2#71

Open
Robbybp wants to merge 5 commits into
mainfrom
named-expr-workaround
Open

Disable named expressions for MB+LD2#71
Robbybp wants to merge 5 commits into
mainfrom
named-expr-workaround

Conversation

@Robbybp

@Robbybp Robbybp commented Jun 29, 2026

Copy link
Copy Markdown
Owner

There is some odd behavior for the MB+LD2 model-method combination. Here are a few lines of output from analyze_solvetime.py:

EXIT: Optimal Solution Found.
[+   0.08] Solve model
WARNING: Constraints in the reduced-space model are violated
WARNING: Result is not valid!
[+   0.05] Validate result

The first line above is the last line of output from IPOPT: We converge to an optimal solution, but our post-solve constraint evaluation identifies an infeasible solution. What's unusual is that, on further inspection, the constraint violation magnitude is 0.17. This is much too large to be a difference due to scaled/unscaled models, IPOPT's bound relaxation, or any other solver-specific idiosyncrasy. I've found that this behavior only occurs when we use named expressions, so I'm patching our scripts to avoid using named expressions for this model-method combination.

I've looked into this discrepancy a bit and I think this is most likely an NL writer bug. I will open a Pyomo issue once I'm happy with this workaround.

This needs:

  • Comparison of runtime results
  • Comparison of convergence results
  • Controls in place so this doesn't come up again (and we're sure it isn't happening for other model-method combinations)

@Robbybp

Robbybp commented Jun 29, 2026

Copy link
Copy Markdown
Owner Author

Runtime results

These are MB+LD2

With named expressions

Identifier                                                          ncalls   cumtime   percall      %
-----------------------------------------------------------------------------------------------------
root                                                                     1     1.288     1.288  100.0
     ------------------------------------------------------------------------------------------------
     mb-steady-linear-d2                                                 1     1.288     1.288  100.0
                        -----------------------------------------------------------------------------
                        elimination                                      1     1.155     1.155   89.7
                                   ------------------------------------------------------------------
                                   eliminate                            13     0.182     0.014   15.7
                                   eliminate-nodes                      13     0.133     0.010   11.5
                                   get-d1                               14     0.492     0.035   42.6
                                   get-d2                                2     0.107     0.053    9.2
                                   igraph                                1     0.098     0.098    8.5
                                   linear-igraph                         1     0.103     0.103    8.9
                                   subgraph                              1     0.040     0.040    3.4
                                   other                               n/a     0.002       n/a    0.1
                                   ==================================================================
                        solver                                           1     0.084     0.084    6.5
                                   ------------------------------------------------------------------
                                   solve                                 1     0.012     0.012   14.2
                                                  ---------------------------------------------------
                                                  constraint-jac        10     0.000     0.000    3.9
                                                  constraints            9     0.001     0.000    6.5
                                                  intermediate-cb        9     0.000     0.000    0.1
                                                  lagrangian-hess        8     0.002     0.000   14.7
                                                  objective              9     0.000     0.000    0.6
                                                  objective-grad        10     0.000     0.000    1.1
                                                  other                n/a     0.009       n/a   73.1
                                                  ===================================================
                                   other                               n/a     0.072       n/a   85.8
                                   ==================================================================
                        other                                          n/a     0.049       n/a    3.8
                        =============================================================================
     other                                                             n/a     0.000       n/a    0.0
     ================================================================================================
=====================================================================================================

Without named expressions

Identifier                                                          ncalls   cumtime   percall      %
-----------------------------------------------------------------------------------------------------
root                                                                     1     1.296     1.296  100.0
     ------------------------------------------------------------------------------------------------
     mb-steady-linear-d2                                                 1     1.296     1.296  100.0
                        -----------------------------------------------------------------------------
                        elimination                                      1     1.161     1.161   89.6
                                   ------------------------------------------------------------------
                                   eliminate                            13     0.178     0.014   15.4
                                   eliminate-nodes                      13     0.118     0.009   10.2
                                   get-d1                               14     0.490     0.035   42.2
                                   get-d2                                2     0.125     0.062   10.7
                                   igraph                                1     0.100     0.100    8.6
                                   linear-igraph                         1     0.108     0.108    9.3
                                   subgraph                              1     0.041     0.041    3.5
                                   other                               n/a     0.002       n/a    0.1
                                   ==================================================================
                        solver                                           1     0.088     0.088    6.8
                                   ------------------------------------------------------------------
                                   solve                                 1     0.011     0.011   13.0
                                                  ---------------------------------------------------
                                                  constraint-jac        10     0.000     0.000    4.0
                                                  constraints            9     0.001     0.000    7.1
                                                  intermediate-cb        9     0.000     0.000    0.1
                                                  lagrangian-hess        8     0.002     0.000   15.4
                                                  objective              9     0.000     0.000    0.7
                                                  objective-grad        10     0.000     0.000    1.1
                                                  other                n/a     0.008       n/a   71.6
                                                  ===================================================
                                   other                               n/a     0.076       n/a   87.0
                                   ==================================================================
                        other                                          n/a     0.048       n/a    3.7
                        =============================================================================
     other                                                             n/a     0.000       n/a    0.0
     ================================================================================================
=====================================================================================================

No appreciable difference.

@Robbybp

Robbybp commented Jun 30, 2026

Copy link
Copy Markdown
Owner Author

Convergence results

All MB results, run on Darwin.

With named expressions for method (main branch)

       model     method  n-success  n-total  percent-success  ave-elim-time  ave-solve-time
0  mb-steady    no-elim         88      121        72.727273       0.000039        1.056338
1  mb-steady         d1         89      121        73.553719       4.647681        1.095656
2  mb-steady       ecd2         89      121        73.553719       4.475969        1.124023
3  mb-steady  linear-d2         88      121        72.727273       5.194716        0.998081
4  mb-steady         d2         96      121        79.338843            NaN        0.918361
5  mb-steady     greedy        105      121        86.776860       1.365976        0.845214
6  mb-steady   matching        101      121        83.471074       2.431153        1.042989

Without named expressions for LD2 (this branch)

       model     method  n-success  n-total  percent-success  ave-elim-time  ave-solve-time
0  mb-steady    no-elim         88      121        72.727273       0.000031        1.002411
1  mb-steady         d1         89      121        73.553719       4.452170        1.033757
2  mb-steady       ecd2         89      121        73.553719       4.469480        0.948522
3  mb-steady  linear-d2         90      121        74.380165       5.077071        0.925272
4  mb-steady         d2         96      121        79.338843            NaN        0.744996
5  mb-steady     greedy        105      121        86.776860       1.353755        0.876362
6  mb-steady   matching        101      121        83.471074       2.430085        0.904619

Without named expressions, we LD2 converges two extra instances.

@Robbybp

Robbybp commented Jun 30, 2026

Copy link
Copy Markdown
Owner Author

In summarize_sweep_results.py, we now print a warning when success is True but feasible is False. Other than the MB+LD2 instances, this happens for some pipeline instances with infeasibilities near 1e-5. When I change feastol to 1e-4, This only happens for three instances:

WARNING: pipeline, no-elim: success=True but feasible=False at index 79; infeasibility=0.000100078221294
WARNING: pipeline, ecd2: success=True but feasible=False at index 79; infeasibility=0.000100112039945
WARNING: pipeline, d2: success=True but feasible=False at index 79; infeasibility=0.0001000009942799

I think I'm fine with accepting these instances. These are likely just "acceptable" infeasibilities (to IPOPT) that get exacerbated by unscaling the model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant