Skip to content

[Pyomo.DoE] Bug fixes for sensitivities, grey-box Hessian, and FIM initialization - #4128

Open
adowling2 wants to merge 7 commits into
Pyomo:mainfrom
adowling2:pyomo-doe-fix-sept-2026
Open

adowling2 wants to merge 7 commits into
Pyomo:mainfrom
adowling2:pyomo-doe-fix-sept-2026

Conversation

@adowling2

@adowling2 adowling2 commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Fixes # .

Summary/Motivation:

This PR collects a set of correctness fixes for Pyomo.DoE found while auditing
the finite-difference (sequential), k_aug, and grey-box code paths, together
with regression tests and documentation.

Changes proposed in this PR:

  • Bug fix: forward and backward finite differences were incorrect.
    compute_FIM(method="sequential") with fd_formula="forward" or
    "backward" never solved or recorded the nominal point. It used the first
    perturbed scenario as the reference instead, so the first column of the
    sensitivity matrix was identically zero and the remaining columns were
    wrong. For a linear test model with true sensitivities [2, 1] and
    [1, -2], main returns [0, 2.5] and [0, -1.25]. Sensitivities and FIM
    values computed with these formulas are therefore wrong. The nominal response
    is now solved first and used as the reference column. Central differences
    (the default) were not affected by this bug.
  • Sequential finite-difference robustness: the nominal solve also serves as
    the warm start for central differences. Outputs are read before the perturbed
    parameter is reset, so Expression outputs that reference unknown parameters
    directly are correct. Solve failures now name the failing scenario.
  • Bounds crossed by perturbations: widen unknown-parameter bounds only as
    needed, with one clear warning per parameter (naming it, its perturbed range,
    and the old and new bounds) instead of a W1002 warning per scenario.
    Perturbations are not clipped. Sequential evaluation restores the original
    bounds, including when a solve fails.
  • Scenario metadata no longer depends on garbage collection:
    create_doe_model() builds the scenario blocks by cloning a temporary
    base_model and then deletes it. parameter_scenarios used to keep pointing
    at components of that deleted model. Pyomo components hold only a weak
    reference to their parent, so once base_model is garbage-collected those
    parameters are orphaned: they lose their path (theta[0] instead of
    scenario_blocks[0].theta[0]) and param.model() is no longer the DoE model.
    On main the lookups that follow only work while the base model happens to
    still be alive. With a forced gc.collect() between building the scenario
    blocks and assembling the constraints, create_doe_model() on main fails
    with AttributeError: 'NoneType' object has no attribute '_parent' (reproduced
    with an indexed parameter). Whether a normal run hits this depends on when
    the garbage collector runs. parameter_scenarios now points at the matching
    components on scenario_blocks[0], which stay alive with the model.
  • k_aug with Expression measurements: apply the chain rule to k_aug
    sensitivities, include direct dependence on fixed unknown parameters, and
    raise an error (instead of silently using a zero row) when an unfixed
    dependency is missing from the k_aug output.
  • k_aug warning: log a warning when the model has active inequality
    constraints, which k_aug may reject. The model is not modified.
  • Default Jacobian/FIM initialization: derive default jac_initial /
    fim_initial values from the already-solved finite-difference scenarios.
    Explicitly supplied arrays are preserved independently.
  • Grey-box Hessian: FIMExternalGreyBox Hessian now includes the
    output-constraint multiplier, as the ExternalGreyBoxModel interface
    requires. set_output_constraint_multipliers validates the length, and the
    multiplier defaults to 1 for direct use.
  • Measurement error: get_measurement_error_values() returned the values
    of the output variables (the suffix keys) instead of sigma (the suffix
    values). The "Measurement Error" field in run_doe results is built from
    it and was therefore wrong too. The FIM calculation reads the suffix directly
    and was not affected.
  • run_doe(results_file=...): the old exact type() check rejected real
    pathlib.Path objects (their type is PosixPath/WindowsPath). It now
    accepts any pathlib.Path or str.
  • Docs: new sections in the DoE guide and objective pages. New tests in
    test_doe_regressions.py, test_kaug_outputs.py, test_greybox.py, and
    test_doe_build.py.

AI-Use Disclosure

  • AI tools contributed to the development of this PR

    • AI tools generated documentation
    • AI tools generated tests
    • AI tools generated code (apart from tests)

    Review process (select ONE):

    • Reviewed/verified: ...
      • Ran the code and fixed issues
      • Added and ran tests
      • Checked correctness/logic of code and tests
      • Checked for alignment with the contribution guide

Notes for reviewers (including @adowling2):

  • Forward/backward finite differences (_sequential_FIM). The old code skipped the nominal solve at s == 0 and never recorded a nominal response. It then used the first perturbed scenario as the reference column. So the first Jacobian column was exactly zero and the others were biased. The new code solves and records the nominal point and uses it as column 0. Central differences are unchanged apart from warm-starting. Please look at the col_1/col_2 logic closely.
  • Grey-box Hessian is a behavior change. evaluate_hessian_outputs() now returns multiplier × H instead of the raw H. This is what ExternalGreyBoxModel expects, but it changes results for anyone calling it directly with a non-unit multiplier. The multiplier defaults to 1 for direct use, and set_output_constraint_multipliers now checks the length.
  • Bound widening. Perturbations that cross an unknown parameter's bounds widen those bounds instead of being clipped, so the step size is unchanged. Sequential evaluation restores the bounds afterward. Simultaneous scenario blocks keep the widened bounds, because their fixed perturbed values must stay feasible. Please check that this distinction is acceptable.
  • k_aug Expression sensitivities. I'd most like review of the chain-rule logic in _extract_kaug_output_jacobian. A missing unfixed dependency now raises an error instead of silently giving a zero row, which could surface new errors for existing models.
  • Overlap with open PRs. Pyomo. DoE: Sensitivity initialization #3639, [Pyomo.DoE] Add simultaneous design of multiple experiments #3866, Add core symbolic gradient support to Pyomo.DoE #3928 and Enable More Complex Error Structures in ParmEst and Pyomo.DoE #3996 all edit doe.py and the DoE tests, so expect conflicts depending on merge order. Pyomo. DoE: Sensitivity initialization #3639 (sensitivity initialization) is closest to the "initialize FIM from solved scenarios" change.

adowling2 and others added 7 commits December 4, 2026 09:42
…IPOPT

Add rationale for deterministic solve-order and failure-injection tests, expand real-solver coverage across formulas and scaling modes, and document the Hessian interface. Developed with Codex assistance.
…rios

Apply the chain rule to k_aug outputs, reject missing unfixed sensitivities, and retain direct parameter derivatives. Derive default Jacobian/FIM values from solved scenarios while preserving explicit initial arrays and live scenario references. Add analytical, IPOPT, and availability-gated k_aug regressions plus documentation. Developed with Codex assistance.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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