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

Error using latex_printer with IDAES model #3121

Open
dhill2522 opened this issue Feb 4, 2024 · 1 comment
Open

Error using latex_printer with IDAES model #3121

dhill2522 opened this issue Feb 4, 2024 · 1 comment

Comments

@dhill2522
Copy link

dhill2522 commented Feb 4, 2024

Summary

When using the latex_printer method on an IDAES model an "Internal Pyomo implementation error" is raised. This seems to happen for most any IDAES model. The model solves successfully, so this does not seem to be part of the issue. As far as I can tell this command should print a Latex representation of the IDAES model.

It seems this issue may well be related to issue #3048

Steps to reproduce the issue

  1. Properly install Pyomo and IDAES as described in the IDAES documentation(Linux).

  2. Run the following script

import pyomo.environ as pyo
from idaes.core import FlowsheetBlock
from pyomo.contrib.latex_printer import latex_printer
from idaes.models.properties.activity_coeff_models.BTX_activity_coeff_VLE import BTXParameterBlock
from idaes.models.unit_models import Flash

m = pyo.ConcreteModel()
m.fs = FlowsheetBlock(dynamic=False)
m.fs.properties = BTXParameterBlock(valid_phase=('Liq', 'Vap'), activity_coeff_model='Ideal', state_vars='FTPz')
m.fs.flash = Flash(property_package=m.fs.properties)

# Initialize the system to 0 degrees of freedom
m.fs.flash.inlet.flow_mol.fix(1.0)
m.fs.flash.inlet.mole_frac_comp[0, 'benzene'].fix(0.5)
m.fs.flash.heat_duty.fix(0)
m.fs.flash.inlet.flow_mol.fix(1)
m.fs.flash.inlet.temperature.fix(368)
m.fs.flash.inlet.pressure.fix(101325)
m.fs.flash.inlet.mole_frac_comp[0, "benzene"].fix(0.5)
m.fs.flash.inlet.mole_frac_comp[0, "toluene"].fix(0.5)
m.fs.flash.heat_duty.fix(0)
m.fs.flash.deltaP.fix(0)
m.fs.flash.initialize()

solver = pyo.SolverFactory('ipopt')
status = solver.solve(m, tee=True)

latex_printer(m)

Error Message

The model itself solves successfully, but raises the following exception when trying to print to Latex.

Traceback (most recent call last):
  File "/home/dhill25/miniconda3/envs/idaes/lib/python3.10/site-packages/pyomo/contrib/latex_printer/latex_printer.py", line 400, in exitNode
    return self._operator_handles[node.__class__](self, node, *data)
KeyError: <class 'idaes.core.base.process_block._IndexedActivityCoeffStateBlock'>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/dhill25/miniconda3/envs/idaes/lib/python3.10/site-packages/pyomo/contrib/latex_printer/latex_printer.py", line 904, in latex_printer
    % (visitor.walk_expression(con_template), trailingAligner)
  File "/home/dhill25/miniconda3/envs/idaes/lib/python3.10/site-packages/pyomo/core/expr/visitor.py", line 268, in walk_expression
    result = self._process_node(root, RECURSION_LIMIT)
  File "/home/dhill25/miniconda3/envs/idaes/lib/python3.10/site-packages/pyomo/core/expr/visitor.py", line 351, in _process_node_general
    child_result = self._process_node(child, recursion_limit)
  File "/home/dhill25/miniconda3/envs/idaes/lib/python3.10/site-packages/pyomo/core/expr/visitor.py", line 351, in _process_node_general
    child_result = self._process_node(child, recursion_limit)
  File "/home/dhill25/miniconda3/envs/idaes/lib/python3.10/site-packages/pyomo/core/expr/visitor.py", line 351, in _process_node_general
    child_result = self._process_node(child, recursion_limit)
  [Previous line repeated 3 more times]
  File "/home/dhill25/miniconda3/envs/idaes/lib/python3.10/site-packages/pyomo/core/expr/visitor.py", line 371, in _process_node_general
    return self.exitNode(node, data)
  File "/home/dhill25/miniconda3/envs/idaes/lib/python3.10/site-packages/pyomo/contrib/latex_printer/latex_printer.py", line 402, in exitNode
    raise DeveloperError(
pyomo.common.errors.DeveloperError: Internal Pyomo implementation error:
        "Latex printer encountered an error when processing type <class
        'idaes.core.base.process_block._IndexedActivityCoeffStateBlock'>,
        contact the developers"
    Please report this to the Pyomo Developers.

Information on your system

Pyomo version: 6.7.0
Python version: 3.10.13
IDAES version: 2.2.0
Operating system: Linux 6.6.13 (Fedora)
How Pyomo was installed (PyPI, conda, source): Conda
Solver (if applicable): IPOPT (solution successful)

Additional information

This minimial working example is based on the simple IDAES flash unit model example, but seems to be an issue with most any IDAES model

@dhill2522
Copy link
Author

Searching into this a little deeper the class that seems to cause an issue (idaes.core.base.process_block._IndexedActivityCoeffStateBlock) is not even ever defined in the source code, so the class name itself must be being dynamically generated. An initial search seems to confirm this.

_IndexedActivityCoeffStateBlock seems to be being used by the BTXParameterBlock property package. I tried again with a different model that does not use the BTXParameterBlock property package. This results in the same error, but for a different class:

pyomo.common.errors.DeveloperError: Internal Pyomo implementation error:
        "Latex printer encountered an error when processing type <class
        'pyomo.core.base.units_container._PyomoUnit'>, contact the
        developers"
    Please report this to the Pyomo Developers.

It seems that this issue is not limited to a single class at this point.

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

No branches or pull requests

2 participants