Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interface to GiNaC for Simplification #3088

Merged
merged 116 commits into from
May 9, 2024
Merged

Interface to GiNaC for Simplification #3088

merged 116 commits into from
May 9, 2024

Conversation

michaelbynum
Copy link
Contributor

@michaelbynum michaelbynum commented Jan 10, 2024

Summary/Motivation:

This PR provides an interface to GiNaC for expression simplification (although sympy can be used as well).

In [1]: import pyomo.environ as pe

In [2]: from pyomo.core.expr import differentiate

In [3]: from pyomo.contrib.simplification import Simplifier

In [4]: from pyomo.contrib.fbbt.fbbt import compute_bounds_on_expr

In [5]: m = pe.ConcreteModel()
   ...: m.x = pe.Var(bounds=(0, None))
   ...: e = m.x * pe.log(m.x)

In [6]: der1 = differentiate(e, m.x, mode=differentiate.Modes.reverse_symbolic)
   ...: der2 = differentiate(der1, m.x, mode=differentiate.Modes.reverse_symbolic)

In [7]: simp = Simplifier()

In [8]: der2_simp = simp.simplify(der2)

In [9]: print(der2)
1/x - x/x**2 + 1/x

In [10]: print(der2_simp)
x**-1.0

In [11]: compute_bounds_on_expr(der2_simp)
Out[11]: (0.0, None)

Legal Acknowledgement

By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

@michaelbynum michaelbynum marked this pull request as draft January 10, 2024 23:01
@michaelbynum
Copy link
Contributor Author

Thanks for all the help on this one, @jsiirola.

setup.cfg Outdated Show resolved Hide resolved
Copy link
Member

@jsiirola jsiirola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good to go!

@mrmundt mrmundt merged commit c0fd062 into Pyomo:main May 9, 2024
33 checks passed
@michaelbynum
Copy link
Contributor Author

@dallan-keylogic, I believe we did fix the mutable parameter issue as part of the PR (with the sympy interface).

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.

None yet

6 participants