In [35]:
from pycalphad import Database, Model
from pycalphad.core.utils import make_callable, point_sample
import pycalphad.variables as v
import numpy as np
from sympy import Matrix

In [36]:
db_alpt = Database('alpt_2015.tdb')
my_phases_alpt = ['PT2AL', 'PT5AL21', 'PT5AL3', 'LIQUID', 'AL3NI2', 'PT8AL21', 'PT2AL3', 'FCC_L12', 'BCC_B2']
mod = Model(db_alpt, ['AL', 'PT', 'VA'], 'FCC_L12', parameters={'VX45': 0., 'VX46': 0., 'VX47': 0.})

In [37]:
func = make_callable(Matrix([mod.ast]).jacobian(mod.variables), mod.variables, mode='numpy')

In [39]:
numexpr_func = func = make_callable(Matrix([mod.ast]).jacobian(mod.variables), mod.variables, mode='numexpr')


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-39-59d3b80d137b> in <module>()
----> 1 numexpr_func = func = make_callable(Matrix([mod.ast]).jacobian(mod.variables), mod.variables, mode='numexpr')

/home/rotis/git/pycalphad/pycalphad/core/utils.py in make_callable(model, variables, mode)
    258     elif mode == 'numexpr':
    259         energy = lambdify(tuple(variables), model, dummify=True,
--> 260                           modules='numexpr', printer=SpecialNumExprPrinter)
    261     else:
    262         energy = lambdify(tuple(variables), model, dummify=True,

/home/rotis/.virtualenvs/calphad/lib/python3.4/site-packages/sympy-0.7.6-py3.4.egg/sympy/utilities/lambdify.py in lambdify(args, expr, modules, printer, use_imps, dummify)
    368 
    369     # Create lambda function.
--> 370     lstr = lambdastr(args, expr, printer=printer, dummify=dummify)
    371     flat = '__flatten_args__'
    372 

/home/rotis/.virtualenvs/calphad/lib/python3.4/site-packages/sympy-0.7.6-py3.4.egg/sympy/utilities/lambdify.py in lambdastr(args, expr, printer, dummify)
    527         else:
    528             expr = sub_expr(expr, dummies_dict)
--> 529     expr = lambdarepr(expr)
    530 
    531     return "lambda %s: (%s)" % (args, expr)

/home/rotis/.virtualenvs/calphad/lib/python3.4/site-packages/sympy-0.7.6-py3.4.egg/sympy/utilities/lambdify.py in <lambda>(expr)
    454         else:
    455             if inspect.isclass(printer):
--> 456                 lambdarepr = lambda expr: printer().doprint(expr)
    457             else:
    458                 lambdarepr = lambda expr: printer.doprint(expr)

/home/rotis/.virtualenvs/calphad/lib/python3.4/site-packages/sympy-0.7.6-py3.4.egg/sympy/printing/lambdarepr.py in doprint(self, expr)
    149 
    150     def doprint(self, expr):
--> 151         lstr = super(NumExprPrinter, self).doprint(expr)
    152         return "evaluate('%s')" % lstr
    153 

/home/rotis/.virtualenvs/calphad/lib/python3.4/site-packages/sympy-0.7.6-py3.4.egg/sympy/printing/printer.py in doprint(self, expr)
    231     def doprint(self, expr):
    232         """Returns printer's representation for expr (as a string)"""
--> 233         return self._str(self._print(expr))
    234 
    235     def _print(self, expr, *args, **kwargs):

/home/rotis/.virtualenvs/calphad/lib/python3.4/site-packages/sympy-0.7.6-py3.4.egg/sympy/printing/printer.py in _print(self, expr, *args, **kwargs)
    255                 printmethod = '_print_' + cls.__name__
    256                 if hasattr(self, printmethod):
--> 257                     return getattr(self, printmethod)(expr, *args, **kwargs)
    258 
    259             # Unknown object, fall back to the emptyPrinter.

/home/rotis/.virtualenvs/calphad/lib/python3.4/site-packages/sympy-0.7.6-py3.4.egg/sympy/printing/lambdarepr.py in blacklisted(self, expr)
    128     def blacklisted(self, expr):
    129         raise TypeError("numexpr cannot be used with %s" %
--> 130                         expr.__class__.__name__)
    131 
    132     # blacklist all Matrix printing

TypeError: numexpr cannot be used with ImmutableMatrix

In [34]:
from itertools import chain
points = point_sample([2, 2, 2, 2, 1], pdof=1000)
print(points.shape)
print(mod.variables)
%timeit numexpr_func(*chain([700.], points.T))
%timeit func(*chain([700.], points.T))


(4000, 9)
[T, FCC_L120AL, FCC_L120PT, FCC_L121AL, FCC_L121PT, FCC_L122AL, FCC_L122PT, FCC_L123AL, FCC_L123PT, FCC_L124VA]
The slowest run took 91.15 times longer than the fastest. This could mean that an intermediate result is being cached 
1 loops, best of 3: 3.42 ms per loop
100 loops, best of 3: 4.3 ms per loop

In [ ]: