MemoryError with binplot

62 views
Skip to first unread message

António Rocha

unread,
Jan 30, 2017, 9:23:58 PM1/30/17
to pycalphad
So I was going around pycalphad and I wrote this script to compute 3 different phase diagrams for different databases. At the end, I can't even get a single plot because I get a MemoryError at the time the program is plotting the first phase diagram. The only way I can think of for solving this type of problems is by using Pickle or something similar but I don't now how to apply it here. So here's my error output:

Traceback (most recent call last):
 
File "<stdin>", line 1, in <module>
 
File "/usr/local/lib/python3.4/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 685, in runfile
    execfile
(filename, namespace)
 
File "/usr/local/lib/python3.4/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 85, in execfile
   
exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace)
 
File "/home/antonio_rocha/Área de Trabalho/untitled0.py", line 33, in <module>
    v
.T: (T2[0], T2[1], 20), v.P:P2},  ax=fig.gca())    
 
File "/home/antonio_rocha/anaconda3/lib/python3.5/site-packages/pycalphad/plot/binary.py", line 49, in binplot
    full_eq
= equilibrium(dbf, comps, phases, conds, **eq_kwargs)
 
File "/home/antonio_rocha/anaconda3/lib/python3.5/site-packages/pycalphad/core/tempfilemanager.py", line 64, in wrapper
   
return func(*args, **kwargs)
 
File "/home/antonio_rocha/anaconda3/lib/python3.5/site-packages/pycalphad/core/equilibrium.py", line 808, in equilibrium
    model
=models, callables=callable_dict, fake_points=True, **grid_opts)
 
File "/home/antonio_rocha/anaconda3/lib/python3.5/site-packages/pycalphad/core/tempfilemanager.py", line 67, in wrapper
   
return func(*args, **kwargs)
 
File "/home/antonio_rocha/anaconda3/lib/python3.5/site-packages/pycalphad/core/calculate.py", line 356, in calculate
    maximum_internal_dof
, broadcast=broadcast)
 
File "/home/antonio_rocha/anaconda3/lib/python3.5/site-packages/pycalphad/core/calculate.py", line 119, in _compute_phase_values
    phase_output
= func(*itertools.chain(statevars, np.rollaxis(points, -1, start=0)))
 
File "/home/antonio_rocha/anaconda3/lib/python3.5/site-packages/pycalphad/core/sympydiff_utils.py", line 47, in __call__
   
return self.kernel(*args, **kwargs)
 
File "/home/antonio_rocha/anaconda3/lib/python3.5/site-packages/pycalphad/core/custom_ufuncify.py", line 188, in lazy_wrapper
   
return self._get_wrapped_function(self._module, funcname)(*args, **kwargs)
MemoryError

And my program:

import matplotlib.pyplot as plt
from pycalphad import Database, binplot
import pycalphad.variables as v
import numpy as np

db_dir
= '/home/antonio_rocha/Área de Trabalho/CALPHAD/Databases/'

db_list
= ['feni_cac.tdb', 'feni_xio.tdb', 'feni_key.tdb', 'feni_lee.tdb', 'feni_ser.tdb']


for i in range(len(db_list)):
    db
= Database(db_dir+db_list[i])
   
    phases
= list(db.phases.keys())
   
print(db)
   
print(phases)
   
    T1
, P1 = [5, 305], 1e-18            
    T2
, P2 = [200, 1100], 101325
    T3
, P3 = [5600, 6500], 3.3e11
   
    fig
= plt.figure(2, figsize=(9,6))
    binplot
(db, ['FE', 'NI', 'VA'] , phases, {v.X('NI'):(0,1,0.02),
                                                           v
.T: (T2[0], T2[1], 20), v.P:P2},  ax=fig.gca())    
    plt
.savefig(db_list[i]+'_conditions_2')
    fig
= plt.figure(3, figsize=(9,6))
    binplot
(db, ['FE', 'NI', 'VA'] , phases, {v.X('NI'):(0,1,0.02),
                                                           v
.T: (T3[0], T3[1], 20), v.P:P3},  ax=fig.gca())    
    plt
.savefig(db_list[i]+'_conditions_3')
    fig
= plt.figure(1, figsize=(9,6))
    binplot
(db, ['FE', 'NI', 'VA'] , phases, {v.X('NI'):(0,1,0.02),
                                                           v
.T: (T1[0], T1[1], 6), v.P:P1},  ax=fig.gca())
    plt
.savefig(db_list[i]+'_conditions_1')

Maybe Cython should do something here?

Waiting for your help,
António Rocha

Brandon Bocklund

unread,
Jan 31, 2017, 3:30:24 PM1/31/17
to pycalphad
Hi António,

I tried your code and ran into the same issue with the first feni_cac.tdb on my machine (16 GB of RAM), but the feni_xio.tdb worked well for me. Currently the databases in pycalphad are parsed into SymPy symbolic functions and compiled to Fortran for speed. This is not the first time we have seen some memory issues from these Fortran-compiled codes, so we are working on moving over to hard-coded models that perform well from a speed and memory standpoint. 

For now, I would suggest not using that database. If you think you want to try more with that database, you might be able to remove some of the phases that you know are above the convex hull that look particularly complicated in the TDB. Although, these phases are probably the ones that are most interesting to you, so this is probably not an option.

António Rocha

unread,
Jan 31, 2017, 6:06:27 PM1/31/17
to pycalphad
Hey Brandon,

Thanks for your help. I thought that Pickle would give some way around it but if it's done that way I don't know how to apply it.
Just by curiosity, what do you mean by "moving over to hard-coded models"?

Best regards,
António Rocha

--
You received this message because you are subscribed to a topic in the Google Groups "pycalphad" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pycalphad/CpSSZKbJJao/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pycalphad+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pycalphad/f99e4aa3-d3cb-4192-b64a-a68d8aec51a5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brandon Bocklund

unread,
Feb 1, 2017, 9:22:04 AM2/1/17
to pycalphad
The problem with memory lies in the compiled Fortran code, rather than the data you are generating, so you would be unable to Pickle that. By hard-coded models, I mean that standard models such as Redlich-Kister polynomials will be calculated natively with Cython/Python rather than using SymPy to compile the models to Fortran with code generation. See here http://docs.sympy.org/dev/modules/utilities/autowrap.html for an idea of how the models are implemented in pycalphad. 
Reply all
Reply to author
Forward
0 new messages