Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes gh-468.
In some cases the outer loop of the global minimizer (
eqsolver.pyx
) will add phases that exceed the number allowed by the Gibbs phase rule. Infeasible solutions passed to the minimizer aren't, themselves, a problem, and can ultimately help us find minimum-energy solutions. However, the minimizer must ensure that the final solution returned is compliant.Prior to this change, the minimizer could become 'stuck' with a solution that violates the Gibbs phase rule and is also metastable with respect to the sampled grid of points. The minimizer would nonetheless (falsely) converge and return, e.g., a four-phase stable equilibrium in an isothermal-isobaric binary system. It would then be unable to recover, either returning the non-physical solution or raising a difficult-to-interpret error.
The fix is two-fold: First,
change_phases
is usually only called when the convergence criteria are otherwise satisfied so, in this change, when a Gibbs phase rule violation of the candidate solution is detected, the minimum tolerated phase amount is increased by several orders of magnitude (currently from1e-9
to1e-4
). This will force smaller-amount composition sets to be automatically removed, resetting the convergence, and continuing the optimization. For the case reported in gh-468, this fixes the issue, and should generalize to similar scenarios.Second, as a failsafe, Gibbs phase rule compliance is explicitly checked at the end of
run_loop
to prevent the minimizer from reportingconverged=True
for any violating (non-physical) case we've failed to catch with the revised logic.Thanks @tobiasspt for reporting.