def _configure_sympy(sympy, available): if not available: return _operatorMap.update({ sympy.Add: _sum, sympy.Mul: _prod, sympy.Pow: lambda x, y: x**y, sympy.exp: lambda x: EXPR.exp(x), sympy.log: lambda x: EXPR.log(x), sympy.sin: lambda x: EXPR.sin(x), sympy.asin: lambda x: EXPR.asin(x), sympy.sinh: lambda x: EXPR.sinh(x), sympy.asinh: lambda x: EXPR.asinh(x), sympy.cos: lambda x: EXPR.cos(x), sympy.acos: lambda x: EXPR.acos(x), sympy.cosh: lambda x: EXPR.cosh(x), sympy.acosh: lambda x: EXPR.acosh(x), sympy.tan: lambda x: EXPR.tan(x), sympy.atan: lambda x: EXPR.atan(x), sympy.tanh: lambda x: EXPR.tanh(x), sympy.atanh: lambda x: EXPR.atanh(x), sympy.ceiling: lambda x: EXPR.ceil(x), sympy.floor: lambda x: EXPR.floor(x), sympy.sqrt: lambda x: EXPR.sqrt(x), sympy.Abs: lambda x: abs(x), sympy.Derivative: _nondifferentiable, sympy.Tuple: lambda *x: x, }) _pyomo_operator_map.update({ EXPR.SumExpression: sympy.Add, EXPR.ProductExpression: sympy.Mul, EXPR.NPV_ProductExpression: sympy.Mul, EXPR.MonomialTermExpression: sympy.Mul, }) _functionMap.update({ 'exp': sympy.exp, 'log': sympy.log, 'log10': lambda x: sympy.log(x) / sympy.log(10), 'sin': sympy.sin, 'asin': sympy.asin, 'sinh': sympy.sinh, 'asinh': sympy.asinh, 'cos': sympy.cos, 'acos': sympy.acos, 'cosh': sympy.cosh, 'acosh': sympy.acosh, 'tan': sympy.tan, 'atan': sympy.atan, 'tanh': sympy.tanh, 'atanh': sympy.atanh, 'ceil': sympy.ceiling, 'floor': sympy.floor, 'sqrt': sympy.sqrt, })
wrt = x[1][0] else: # early versions of sympy returned the bare var wrt = x[1] raise NondifferentiableError( "The sub-expression '%s' is not differentiable with respect to %s" % (x[0], wrt)) _operatorMap = { sympy.Add: _sum, sympy.Mul: _prod, sympy.Pow: lambda x, y: x**y, sympy.exp: lambda x: current.exp(x), sympy.log: lambda x: current.log(x), sympy.sin: lambda x: current.sin(x), sympy.asin: lambda x: current.asin(x), sympy.sinh: lambda x: current.sinh(x), sympy.asinh: lambda x: current.asinh(x), sympy.cos: lambda x: current.cos(x), sympy.acos: lambda x: current.acos(x), sympy.cosh: lambda x: current.cosh(x), sympy.acosh: lambda x: current.acosh(x), sympy.tan: lambda x: current.tan(x), sympy.atan: lambda x: current.atan(x), sympy.tanh: lambda x: current.tanh(x), sympy.atanh: lambda x: current.atanh(x), 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,