We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Error whil using mindtpy
I was trying to start the MINLP example presented here:
https://pyomo.readthedocs.io/en/stable/contributed_packages/mindtpy.html

When i run the code:

```
from pyomo.environ import *

# Create a simple model
model = ConcreteModel()

model.x = Var(bounds=(1.0, 10.0), initialize=5.0)
model.y = Var(within=Binary)

model.c1 = Constraint(expr=(model.x-3.0)**2 <= 50.0*(1-model.y))
model.c2 = Constraint(expr=model.x*log(model.x)+5.0 <= 50.0*(model.y))

model.objective = Objective(expr=abs(model.x*model.x), sense=minimize)

# Solve the model using MindtPy
SolverFactory('mindtpy').solve(model, mip_solver='glpk', nlp_solver='ipopt')
model.objective.display()
model.display()
model.pprint()
```

I get the following error:

pyomo.common.errors.DeveloperError: Internal Pyomo implementation error:
        "sympy expression type 're' not found in the operator map"
        Please report this to the Pyomo Developers.

I have installed pyomo 5.6.6, pyomo.extras 3.3, and pyomo.solvers 1.0 using Anaconda on Windows 10.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pyomo/core/expr/sympy_tools.py`
Content:
```
1 #  ___________________________________________________________________________
2 #
3 #  Pyomo: Python Optimization Modeling Objects
4 #  Copyright 2017 National Technology and Engineering Solutions of Sandia, LLC
5 #  Under the terms of Contract DE-NA0003525 with National Technology and
6 #  Engineering Solutions of Sandia, LLC, the U.S. Government retains certain
7 #  rights in this software.
8 #  This software is distributed under the 3-clause BSD License.
9 #  ___________________________________________________________________________
10 
11 from six import StringIO, iterkeys
12 import pyutilib.misc
13 from pyomo.core.expr import current
14 from pyomo.common import DeveloperError
15 from pyomo.core.expr import current as EXPR, native_types
16 from pyomo.core.expr.numvalue import value
17 from pyomo.core.kernel.component_map import ComponentMap
18 from pyomo.common.errors import NondifferentiableError
19 
20 sympy_available = True
21 try:
22     import sympy
23 
24     def _prod(*x):
25         ans = x[0]
26         for i in x[1:]:
27             ans *= i
28         return ans
29 
30     def _sum(*x):
31         return sum(x_ for x_ in x)
32 
33     def _nondifferentiable(*x):
34         if type(x[1]) is tuple:
35             # sympy >= 1.3 returns tuples (var, order)
36             wrt = x[1][0]
37         else:
38             # early versions of sympy returned the bare var
39             wrt = x[1]
40         raise NondifferentiableError(
41             "The sub-expression '%s' is not differentiable with respect to %s"
42             % (x[0], wrt) )
43 
44     _operatorMap = {
45         sympy.Add: _sum,
46         sympy.Mul: _prod,
47         sympy.Pow: lambda x, y: x**y,
48         sympy.exp: lambda x: current.exp(x),
49         sympy.log: lambda x: current.log(x),
50         sympy.sin: lambda x: current.sin(x),
51         sympy.asin: lambda x: current.asin(x),
52         sympy.sinh: lambda x: current.sinh(x),
53         sympy.asinh: lambda x: current.asinh(x),
54         sympy.cos: lambda x: current.cos(x),
55         sympy.acos: lambda x: current.acos(x),
56         sympy.cosh: lambda x: current.cosh(x),
57         sympy.acosh: lambda x: current.acosh(x),
58         sympy.tan: lambda x: current.tan(x),
59         sympy.atan: lambda x: current.atan(x),
60         sympy.tanh: lambda x: current.tanh(x),
61         sympy.atanh: lambda x: current.atanh(x),
62         sympy.ceiling: lambda x: current.ceil(x),
63         sympy.floor: lambda x: current.floor(x),
64         sympy.sqrt: lambda x: current.sqrt(x),
65         sympy.Derivative: _nondifferentiable,
66         sympy.Tuple: lambda *x: x,
67     }
68 
69     _pyomo_operator_map = {
70         EXPR.SumExpression: sympy.Add,
71         EXPR.ProductExpression: sympy.Mul,
72         EXPR.NPV_ProductExpression: sympy.Mul,
73         EXPR.MonomialTermExpression: sympy.Mul,
74     }
75 
76     _functionMap = {
77         'exp': sympy.exp,
78         'log': sympy.log,
79         'log10': lambda x: sympy.log(x)/sympy.log(10),
80         'sin': sympy.sin,
81         'asin': sympy.asin,
82         'sinh': sympy.sinh,
83         'asinh': sympy.asinh,
84         'cos': sympy.cos,
85         'acos': sympy.acos,
86         'cosh': sympy.cosh,
87         'acosh': sympy.acosh,
88         'tan': sympy.tan,
89         'atan': sympy.atan,
90         'tanh': sympy.tanh,
91         'atanh': sympy.atanh,
92         'ceil': sympy.ceiling,
93         'floor': sympy.floor,
94         'sqrt': sympy.sqrt,
95     }
96 except ImportError:
97     sympy_available = False
98 
99 class PyomoSympyBimap(object):
100     def __init__(self):
101         self.pyomo2sympy = ComponentMap()
102         self.sympy2pyomo = {}
103         self.i = 0
104 
105     def getPyomoSymbol(self, sympy_object, default=None):
106         return self.sympy2pyomo.get(sympy_object, default)
107 
108     def getSympySymbol(self, pyomo_object):
109         if pyomo_object in self.pyomo2sympy:
110             return self.pyomo2sympy[pyomo_object]
111         sympy_obj = sympy.Symbol("x%d" % self.i)
112         self.i += 1
113         self.pyomo2sympy[pyomo_object] = sympy_obj
114         self.sympy2pyomo[sympy_obj] = pyomo_object
115         return sympy_obj
116 
117     def sympyVars(self):
118         return iterkeys(self.sympy2pyomo)
119 
120 # =====================================================
121 # sympyify_expression
122 # =====================================================
123 
124 class Pyomo2SympyVisitor(EXPR.StreamBasedExpressionVisitor):
125 
126     def __init__(self, object_map):
127         super(Pyomo2SympyVisitor, self).__init__()
128         self.object_map = object_map
129 
130     def exitNode(self, node, values):
131         if node.__class__ is EXPR.UnaryFunctionExpression:
132             return _functionMap[node._name](values[0])
133         _op = _pyomo_operator_map.get(node.__class__, None)
134         if _op is None:
135             return node._apply_operation(values)
136         else:
137             return _op(*tuple(values))
138 
139     def beforeChild(self, node, child):
140         #
141         # Don't replace native or sympy types
142         #
143         if type(child) in native_types:
144             return False, child
145         #
146         # We will descend into all expressions...
147         #
148         if child.is_expression_type():
149             return True, None
150         #
151         # Replace pyomo variables with sympy variables
152         #
153         if child.is_potentially_variable():
154             return False, self.object_map.getSympySymbol(child)
155         #
156         # Everything else is a constant...
157         #
158         return False, value(child)
159 
160 class Sympy2PyomoVisitor(EXPR.StreamBasedExpressionVisitor):
161 
162     def __init__(self, object_map):
163         super(Sympy2PyomoVisitor, self).__init__()
164         self.object_map = object_map
165 
166     def enterNode(self, node):
167         return (node._args, [])
168 
169     def exitNode(self, node, values):
170         """ Visit nodes that have been expanded """
171         _sympyOp = node
172         _op = _operatorMap.get( type(_sympyOp), None )
173         if _op is None:
174             raise DeveloperError(
175                 "sympy expression type '%s' not found in the operator "
176                 "map" % type(_sympyOp) )
177         return _op(*tuple(values))
178 
179     def beforeChild(self, node, child):
180         if not child._args:
181             item = self.object_map.getPyomoSymbol(child, None)
182             if item is None:
183                 item = float(child.evalf())
184             return False, item
185         return True, None
186 
187 def sympyify_expression(expr):
188     """Convert a Pyomo expression to a Sympy expression"""
189     #
190     # Create the visitor and call it.
191     #
192     object_map = PyomoSympyBimap()
193     visitor = Pyomo2SympyVisitor(object_map)
194     is_expr, ans = visitor.beforeChild(None, expr)
195     if not is_expr:
196         return object_map, ans
197 
198     return object_map, visitor.walk_expression(expr)
199 
200 
201 def sympy2pyomo_expression(expr, object_map):
202     visitor = Sympy2PyomoVisitor(object_map)
203     is_expr, ans = visitor.beforeChild(None, expr)
204     if not is_expr:
205         return ans
206     return visitor.walk_expression(expr)
207
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pyomo/core/expr/sympy_tools.py b/pyomo/core/expr/sympy_tools.py
--- a/pyomo/core/expr/sympy_tools.py
+++ b/pyomo/core/expr/sympy_tools.py
@@ -62,6 +62,7 @@
         sympy.ceiling: lambda x: current.ceil(x),
         sympy.floor: lambda x: current.floor(x),
         sympy.sqrt: lambda x: current.sqrt(x),
+        sympy.Abs: lambda x: abs(x),
         sympy.Derivative: _nondifferentiable,
         sympy.Tuple: lambda *x: x,
     }
@@ -108,7 +109,10 @@
     def getSympySymbol(self, pyomo_object):
         if pyomo_object in self.pyomo2sympy:
             return self.pyomo2sympy[pyomo_object]
-        sympy_obj = sympy.Symbol("x%d" % self.i)
+        # Pyomo currently ONLY supports Real variables (not complex
+        # variables).  If that ever changes, then we will need to
+        # revisit hard-coding the symbol type here
+        sympy_obj = sympy.Symbol("x%d" % self.i, real=True)
         self.i += 1
         self.pyomo2sympy[pyomo_object] = sympy_obj
         self.sympy2pyomo[sympy_obj] = pyomo_object

{"golden_diff": "diff --git a/pyomo/core/expr/sympy_tools.py b/pyomo/core/expr/sympy_tools.py\n--- a/pyomo/core/expr/sympy_tools.py\n+++ b/pyomo/core/expr/sympy_tools.py\n@@ -62,6 +62,7 @@\n         sympy.ceiling: lambda x: current.ceil(x),\n         sympy.floor: lambda x: current.floor(x),\n         sympy.sqrt: lambda x: current.sqrt(x),\n+        sympy.Abs: lambda x: abs(x),\n         sympy.Derivative: _nondifferentiable,\n         sympy.Tuple: lambda *x: x,\n     }\n@@ -108,7 +109,10 @@\n     def getSympySymbol(self, pyomo_object):\n         if pyomo_object in self.pyomo2sympy:\n             return self.pyomo2sympy[pyomo_object]\n-        sympy_obj = sympy.Symbol(\"x%d\" % self.i)\n+        # Pyomo currently ONLY supports Real variables (not complex\n+        # variables).  If that ever changes, then we will need to\n+        # revisit hard-coding the symbol type here\n+        sympy_obj = sympy.Symbol(\"x%d\" % self.i, real=True)\n         self.i += 1\n         self.pyomo2sympy[pyomo_object] = sympy_obj\n         self.sympy2pyomo[sympy_obj] = pyomo_object\n", "issue": "Error whil using mindtpy\nI was trying to start the MINLP example presented here:\r\nhttps://pyomo.readthedocs.io/en/stable/contributed_packages/mindtpy.html\r\n\r\nWhen i run the code:\r\n\r\n```\r\nfrom pyomo.environ import *\r\n\r\n# Create a simple model\r\nmodel = ConcreteModel()\r\n\r\nmodel.x = Var(bounds=(1.0, 10.0), initialize=5.0)\r\nmodel.y = Var(within=Binary)\r\n\r\nmodel.c1 = Constraint(expr=(model.x-3.0)**2 <= 50.0*(1-model.y))\r\nmodel.c2 = Constraint(expr=model.x*log(model.x)+5.0 <= 50.0*(model.y))\r\n\r\nmodel.objective = Objective(expr=abs(model.x*model.x), sense=minimize)\r\n\r\n# Solve the model using MindtPy\r\nSolverFactory('mindtpy').solve(model, mip_solver='glpk', nlp_solver='ipopt')\r\nmodel.objective.display()\r\nmodel.display()\r\nmodel.pprint()\r\n```\r\n\r\nI get the following error:\r\n\r\npyomo.common.errors.DeveloperError: Internal Pyomo implementation error:\r\n        \"sympy expression type 're' not found in the operator map\"\r\n        Please report this to the Pyomo Developers.\r\n\r\nI have installed pyomo 5.6.6, pyomo.extras 3.3, and pyomo.solvers 1.0 using Anaconda on Windows 10.\r\n\n", "before_files": [{"content": "#  ___________________________________________________________________________\n#\n#  Pyomo: Python Optimization Modeling Objects\n#  Copyright 2017 National Technology and Engineering Solutions of Sandia, LLC\n#  Under the terms of Contract DE-NA0003525 with National Technology and\n#  Engineering Solutions of Sandia, LLC, the U.S. Government retains certain\n#  rights in this software.\n#  This software is distributed under the 3-clause BSD License.\n#  ___________________________________________________________________________\n\nfrom six import StringIO, iterkeys\nimport pyutilib.misc\nfrom pyomo.core.expr import current\nfrom pyomo.common import DeveloperError\nfrom pyomo.core.expr import current as EXPR, native_types\nfrom pyomo.core.expr.numvalue import value\nfrom pyomo.core.kernel.component_map import ComponentMap\nfrom pyomo.common.errors import NondifferentiableError\n\nsympy_available = True\ntry:\n    import sympy\n\n    def _prod(*x):\n        ans = x[0]\n        for i in x[1:]:\n            ans *= i\n        return ans\n\n    def _sum(*x):\n        return sum(x_ for x_ in x)\n\n    def _nondifferentiable(*x):\n        if type(x[1]) is tuple:\n            # sympy >= 1.3 returns tuples (var, order)\n            wrt = x[1][0]\n        else:\n            # early versions of sympy returned the bare var\n            wrt = x[1]\n        raise NondifferentiableError(\n            \"The sub-expression '%s' is not differentiable with respect to %s\"\n            % (x[0], wrt) )\n\n    _operatorMap = {\n        sympy.Add: _sum,\n        sympy.Mul: _prod,\n        sympy.Pow: lambda x, y: x**y,\n        sympy.exp: lambda x: current.exp(x),\n        sympy.log: lambda x: current.log(x),\n        sympy.sin: lambda x: current.sin(x),\n        sympy.asin: lambda x: current.asin(x),\n        sympy.sinh: lambda x: current.sinh(x),\n        sympy.asinh: lambda x: current.asinh(x),\n        sympy.cos: lambda x: current.cos(x),\n        sympy.acos: lambda x: current.acos(x),\n        sympy.cosh: lambda x: current.cosh(x),\n        sympy.acosh: lambda x: current.acosh(x),\n        sympy.tan: lambda x: current.tan(x),\n        sympy.atan: lambda x: current.atan(x),\n        sympy.tanh: lambda x: current.tanh(x),\n        sympy.atanh: lambda x: current.atanh(x),\n        sympy.ceiling: lambda x: current.ceil(x),\n        sympy.floor: lambda x: current.floor(x),\n        sympy.sqrt: lambda x: current.sqrt(x),\n        sympy.Derivative: _nondifferentiable,\n        sympy.Tuple: lambda *x: x,\n    }\n\n    _pyomo_operator_map = {\n        EXPR.SumExpression: sympy.Add,\n        EXPR.ProductExpression: sympy.Mul,\n        EXPR.NPV_ProductExpression: sympy.Mul,\n        EXPR.MonomialTermExpression: sympy.Mul,\n    }\n\n    _functionMap = {\n        'exp': sympy.exp,\n        'log': sympy.log,\n        'log10': lambda x: sympy.log(x)/sympy.log(10),\n        'sin': sympy.sin,\n        'asin': sympy.asin,\n        'sinh': sympy.sinh,\n        'asinh': sympy.asinh,\n        'cos': sympy.cos,\n        'acos': sympy.acos,\n        'cosh': sympy.cosh,\n        'acosh': sympy.acosh,\n        'tan': sympy.tan,\n        'atan': sympy.atan,\n        'tanh': sympy.tanh,\n        'atanh': sympy.atanh,\n        'ceil': sympy.ceiling,\n        'floor': sympy.floor,\n        'sqrt': sympy.sqrt,\n    }\nexcept ImportError:\n    sympy_available = False\n\nclass PyomoSympyBimap(object):\n    def __init__(self):\n        self.pyomo2sympy = ComponentMap()\n        self.sympy2pyomo = {}\n        self.i = 0\n\n    def getPyomoSymbol(self, sympy_object, default=None):\n        return self.sympy2pyomo.get(sympy_object, default)\n\n    def getSympySymbol(self, pyomo_object):\n        if pyomo_object in self.pyomo2sympy:\n            return self.pyomo2sympy[pyomo_object]\n        sympy_obj = sympy.Symbol(\"x%d\" % self.i)\n        self.i += 1\n        self.pyomo2sympy[pyomo_object] = sympy_obj\n        self.sympy2pyomo[sympy_obj] = pyomo_object\n        return sympy_obj\n\n    def sympyVars(self):\n        return iterkeys(self.sympy2pyomo)\n\n# =====================================================\n# sympyify_expression\n# =====================================================\n\nclass Pyomo2SympyVisitor(EXPR.StreamBasedExpressionVisitor):\n\n    def __init__(self, object_map):\n        super(Pyomo2SympyVisitor, self).__init__()\n        self.object_map = object_map\n\n    def exitNode(self, node, values):\n        if node.__class__ is EXPR.UnaryFunctionExpression:\n            return _functionMap[node._name](values[0])\n        _op = _pyomo_operator_map.get(node.__class__, None)\n        if _op is None:\n            return node._apply_operation(values)\n        else:\n            return _op(*tuple(values))\n\n    def beforeChild(self, node, child):\n        #\n        # Don't replace native or sympy types\n        #\n        if type(child) in native_types:\n            return False, child\n        #\n        # We will descend into all expressions...\n        #\n        if child.is_expression_type():\n            return True, None\n        #\n        # Replace pyomo variables with sympy variables\n        #\n        if child.is_potentially_variable():\n            return False, self.object_map.getSympySymbol(child)\n        #\n        # Everything else is a constant...\n        #\n        return False, value(child)\n\nclass Sympy2PyomoVisitor(EXPR.StreamBasedExpressionVisitor):\n\n    def __init__(self, object_map):\n        super(Sympy2PyomoVisitor, self).__init__()\n        self.object_map = object_map\n\n    def enterNode(self, node):\n        return (node._args, [])\n\n    def exitNode(self, node, values):\n        \"\"\" Visit nodes that have been expanded \"\"\"\n        _sympyOp = node\n        _op = _operatorMap.get( type(_sympyOp), None )\n        if _op is None:\n            raise DeveloperError(\n                \"sympy expression type '%s' not found in the operator \"\n                \"map\" % type(_sympyOp) )\n        return _op(*tuple(values))\n\n    def beforeChild(self, node, child):\n        if not child._args:\n            item = self.object_map.getPyomoSymbol(child, None)\n            if item is None:\n                item = float(child.evalf())\n            return False, item\n        return True, None\n\ndef sympyify_expression(expr):\n    \"\"\"Convert a Pyomo expression to a Sympy expression\"\"\"\n    #\n    # Create the visitor and call it.\n    #\n    object_map = PyomoSympyBimap()\n    visitor = Pyomo2SympyVisitor(object_map)\n    is_expr, ans = visitor.beforeChild(None, expr)\n    if not is_expr:\n        return object_map, ans\n\n    return object_map, visitor.walk_expression(expr)\n\n\ndef sympy2pyomo_expression(expr, object_map):\n    visitor = Sympy2PyomoVisitor(object_map)\n    is_expr, ans = visitor.beforeChild(None, expr)\n    if not is_expr:\n        return ans\n    return visitor.walk_expression(expr)\n", "path": "pyomo/core/expr/sympy_tools.py"}], "after_files": [{"content": "#  ___________________________________________________________________________\n#\n#  Pyomo: Python Optimization Modeling Objects\n#  Copyright 2017 National Technology and Engineering Solutions of Sandia, LLC\n#  Under the terms of Contract DE-NA0003525 with National Technology and\n#  Engineering Solutions of Sandia, LLC, the U.S. Government retains certain\n#  rights in this software.\n#  This software is distributed under the 3-clause BSD License.\n#  ___________________________________________________________________________\n\nfrom six import StringIO, iterkeys\nimport pyutilib.misc\nfrom pyomo.core.expr import current\nfrom pyomo.common import DeveloperError\nfrom pyomo.core.expr import current as EXPR, native_types\nfrom pyomo.core.expr.numvalue import value\nfrom pyomo.core.kernel.component_map import ComponentMap\nfrom pyomo.common.errors import NondifferentiableError\n\nsympy_available = True\ntry:\n    import sympy\n\n    def _prod(*x):\n        ans = x[0]\n        for i in x[1:]:\n            ans *= i\n        return ans\n\n    def _sum(*x):\n        return sum(x_ for x_ in x)\n\n    def _nondifferentiable(*x):\n        if type(x[1]) is tuple:\n            # sympy >= 1.3 returns tuples (var, order)\n            wrt = x[1][0]\n        else:\n            # early versions of sympy returned the bare var\n            wrt = x[1]\n        raise NondifferentiableError(\n            \"The sub-expression '%s' is not differentiable with respect to %s\"\n            % (x[0], wrt) )\n\n    _operatorMap = {\n        sympy.Add: _sum,\n        sympy.Mul: _prod,\n        sympy.Pow: lambda x, y: x**y,\n        sympy.exp: lambda x: current.exp(x),\n        sympy.log: lambda x: current.log(x),\n        sympy.sin: lambda x: current.sin(x),\n        sympy.asin: lambda x: current.asin(x),\n        sympy.sinh: lambda x: current.sinh(x),\n        sympy.asinh: lambda x: current.asinh(x),\n        sympy.cos: lambda x: current.cos(x),\n        sympy.acos: lambda x: current.acos(x),\n        sympy.cosh: lambda x: current.cosh(x),\n        sympy.acosh: lambda x: current.acosh(x),\n        sympy.tan: lambda x: current.tan(x),\n        sympy.atan: lambda x: current.atan(x),\n        sympy.tanh: lambda x: current.tanh(x),\n        sympy.atanh: lambda x: current.atanh(x),\n        sympy.ceiling: lambda x: current.ceil(x),\n        sympy.floor: lambda x: current.floor(x),\n        sympy.sqrt: lambda x: current.sqrt(x),\n        sympy.Abs: lambda x: abs(x),\n        sympy.Derivative: _nondifferentiable,\n        sympy.Tuple: lambda *x: x,\n    }\n\n    _pyomo_operator_map = {\n        EXPR.SumExpression: sympy.Add,\n        EXPR.ProductExpression: sympy.Mul,\n        EXPR.NPV_ProductExpression: sympy.Mul,\n        EXPR.MonomialTermExpression: sympy.Mul,\n    }\n\n    _functionMap = {\n        'exp': sympy.exp,\n        'log': sympy.log,\n        'log10': lambda x: sympy.log(x)/sympy.log(10),\n        'sin': sympy.sin,\n        'asin': sympy.asin,\n        'sinh': sympy.sinh,\n        'asinh': sympy.asinh,\n        'cos': sympy.cos,\n        'acos': sympy.acos,\n        'cosh': sympy.cosh,\n        'acosh': sympy.acosh,\n        'tan': sympy.tan,\n        'atan': sympy.atan,\n        'tanh': sympy.tanh,\n        'atanh': sympy.atanh,\n        'ceil': sympy.ceiling,\n        'floor': sympy.floor,\n        'sqrt': sympy.sqrt,\n    }\nexcept ImportError:\n    sympy_available = False\n\nclass PyomoSympyBimap(object):\n    def __init__(self):\n        self.pyomo2sympy = ComponentMap()\n        self.sympy2pyomo = {}\n        self.i = 0\n\n    def getPyomoSymbol(self, sympy_object, default=None):\n        return self.sympy2pyomo.get(sympy_object, default)\n\n    def getSympySymbol(self, pyomo_object):\n        if pyomo_object in self.pyomo2sympy:\n            return self.pyomo2sympy[pyomo_object]\n        # Pyomo currently ONLY supports Real variables (not complex\n        # variables).  If that ever changes, then we will need to\n        # revisit hard-coding the symbol type here\n        sympy_obj = sympy.Symbol(\"x%d\" % self.i, real=True)\n        self.i += 1\n        self.pyomo2sympy[pyomo_object] = sympy_obj\n        self.sympy2pyomo[sympy_obj] = pyomo_object\n        return sympy_obj\n\n    def sympyVars(self):\n        return iterkeys(self.sympy2pyomo)\n\n# =====================================================\n# sympyify_expression\n# =====================================================\n\nclass Pyomo2SympyVisitor(EXPR.StreamBasedExpressionVisitor):\n\n    def __init__(self, object_map):\n        super(Pyomo2SympyVisitor, self).__init__()\n        self.object_map = object_map\n\n    def exitNode(self, node, values):\n        if node.__class__ is EXPR.UnaryFunctionExpression:\n            return _functionMap[node._name](values[0])\n        _op = _pyomo_operator_map.get(node.__class__, None)\n        if _op is None:\n            return node._apply_operation(values)\n        else:\n            return _op(*tuple(values))\n\n    def beforeChild(self, node, child):\n        #\n        # Don't replace native or sympy types\n        #\n        if type(child) in native_types:\n            return False, child\n        #\n        # We will descend into all expressions...\n        #\n        if child.is_expression_type():\n            return True, None\n        #\n        # Replace pyomo variables with sympy variables\n        #\n        if child.is_potentially_variable():\n            return False, self.object_map.getSympySymbol(child)\n        #\n        # Everything else is a constant...\n        #\n        return False, value(child)\n\nclass Sympy2PyomoVisitor(EXPR.StreamBasedExpressionVisitor):\n\n    def __init__(self, object_map):\n        super(Sympy2PyomoVisitor, self).__init__()\n        self.object_map = object_map\n\n    def enterNode(self, node):\n        return (node._args, [])\n\n    def exitNode(self, node, values):\n        \"\"\" Visit nodes that have been expanded \"\"\"\n        _sympyOp = node\n        _op = _operatorMap.get( type(_sympyOp), None )\n        if _op is None:\n            raise DeveloperError(\n                \"sympy expression type '%s' not found in the operator \"\n                \"map\" % type(_sympyOp) )\n        return _op(*tuple(values))\n\n    def beforeChild(self, node, child):\n        if not child._args:\n            item = self.object_map.getPyomoSymbol(child, None)\n            if item is None:\n                item = float(child.evalf())\n            return False, item\n        return True, None\n\ndef sympyify_expression(expr):\n    \"\"\"Convert a Pyomo expression to a Sympy expression\"\"\"\n    #\n    # Create the visitor and call it.\n    #\n    object_map = PyomoSympyBimap()\n    visitor = Pyomo2SympyVisitor(object_map)\n    is_expr, ans = visitor.beforeChild(None, expr)\n    if not is_expr:\n        return object_map, ans\n\n    return object_map, visitor.walk_expression(expr)\n\n\ndef sympy2pyomo_expression(expr, object_map):\n    visitor = Sympy2PyomoVisitor(object_map)\n    is_expr, ans = visitor.beforeChild(None, expr)\n    if not is_expr:\n        return ans\n    return visitor.walk_expression(expr)\n", "path": "pyomo/core/expr/sympy_tools.py"}]}