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

Numerical stability issue with equilibrium calculation #23

Closed
broshe opened this issue Sep 24, 2015 · 33 comments

Comments

Projects
None yet
2 participants
@broshe
Copy link

commented Sep 24, 2015

Hello Richard,
Shana Tova.
I tried to calculate entropy of formation of a compound as function of composition.
The calculation of entropy is done by numerical differentiation of Gibbs energy of formation.
See code below.
The result, as can be seen in the attached figure is noisy.
Perhaps this can be corrected by calculating the entropy not by numerical differentiation.
Is there a way to use symbolic algebra for this?

Thanks,
Eli

from pycalphad import Database, equilibrium
import pycalphad.variables as v
from numpy import *
from pylab import *




db = Database('/home/ebrosh/Documents/ebroshWorks/tcworks/Al-Fe-solidification/alfe_sei.TDB')



def sb(T,phase_name,x_liquid,x_phase,db):
    dT=1.0

    f1m=dG(T-1*dT,phase_name,x_liquid,x_phase,db)
    f0=dG(T+0*dT,phase_name,x_liquid,x_phase,db)

    DG=f0-f1m
    s=DG/(1.0*dT)
    print(T,x_liquid,s)
    return s



def dG(T,phase_name,x_liquid,x_phase,db):
        data = equilibrium(db, ['AL', 'FE'], 'LIQUID', {v.X('FE'): x_liquid, v.T: T, v.P: 1e5},verbose=False)
        muFe=data['MU'].sel( component='FE').data[0].flatten()
        muAl=data['MU'].sel( component='AL').data[0].flatten()
        data = equilibrium(db, ['AL', 'FE','VA'], phase_name, {v.X('FE'): x_phase, v.T: T, v.P: 1e5},verbose=False)
        G=data['GM'].data[0].flatten()
        dG=(G-(1-x_phase)*muAl-(x_phase)*muFe)

        return dG


n=100.0
irange=arange(0,n+1,1)    
xrange=irange/n
xrange[0]=1.0e-4
xrange[-1]=.9999
T=1000*ones(size(irange))
S=zeros(size(irange))

for i in irange: 
    S[i]=sb(T[i],'AL13FE4',xrange[i],4/17.0,db)


plot(xrange,S)
xlabel('x(liquid,Fe)')
ylabel('Delta(S) formation of AL13FE4' )


show(block=False)

noise in entropy of formation

@richardotis

This comment has been minimized.

Copy link
Collaborator

commented Sep 24, 2015

Hi Eli,

As an easy fix, you can try making your dT smaller for your finite difference, perhaps 0.1 K step size instead.

There is support for computing derivatives without finite differences. This code uses automatic differentiation to compute the entropy.

from pycalphad import calculate, equilibrium
x_phase = 0.3
T= 2000
data = equilibrium(db, ['AL', 'FE','VA'], 'AL13FE4', {v.X('FE'): x_phase, v.T: T, v.P: 1e5},verbose=False)
entropy = calculate(db, ['AL', 'FE', 'VA'], 'AL13FE4', output='SM', T=T, P=1e5,
                    points=data['Y'].isel(vertex=1, X_AL=0).values)
entropy = entropy['SM'].isel(P=0)
print(entropy)

Here's an example from the documentation (without the equilibrium step): http://pycalphad.readthedocs.org/en/latest/examples/CementiteAnalysis.html

There is a list of a few built-in symbols available here, including mixing entropy ('MIX_SM'): http://pycalphad.readthedocs.org/en/latest/api/pycalphad.html#pycalphad.model.Model

There are no built-in functions for formation entropy or any partial molar quantities besides chemical potential, at the moment. If you know the formula for the quantity you need, it's possible in pycalphad to access the symbolic expression for the energy and manipulate it directly, like in Mathematica. This uses the Model.energy attribute.

@richardotis

This comment has been minimized.

Copy link
Collaborator

commented Sep 24, 2015

I modified the above code example slightly because the previous version was typed from memory and didn't work.

@broshe

This comment has been minimized.

Copy link
Author

commented Sep 25, 2015

Hi Richard,
I would like to try to keep using the numerical differentiation for
calculation of entropy.
However, perhaps the "noise" in the results can be avoided by using the
calculate module instead of the equilibrium module.

If I see it correctly, the equilibrium module depends on calculating an
energy surface which has a finite resolution. Perhaps this is what produces
the noise.

Now in your letter, you give first calculate with the equilibrium model and
than with calculate:

data = equilibrium(db, ['AL', 'FE','VA'], 'AL13FE4', {v.X('FE'): x_phase,
v.T: T, v.P: 1e5},verbose=False)

entropy = calculate(db, ['AL', 'FE', 'VA'], 'AL13FE4', output='SM', T=T, P=1e5,
points=data['Y'].isel(vertex=1, X_AL=0).values)

What is the logic in the option:"points=data['Y'].isel(vertex=1,
X_AL=0).values"
?

Could I avoid the data=equilibrium(..) calculation and supply the points
myself (I need just one)?

Another question,

Can I calculate the chemical potential MU with the calculate model,
instead of the equilibrium module?

Thanks,

Eli

On Thu, Sep 24, 2015 at 8:17 PM, Richard Otis notifications@github.com
wrote:

I modified the above code example slightly because the previous version
was typed from memory and didn't work.


Reply to this email directly or view it on GitHub
#23 (comment)
.

@richardotis

This comment has been minimized.

Copy link
Collaborator

commented Sep 25, 2015

First question: The .isel() function (notice the i) is selection by order something comes in the index. If I do a calculation at X(AL)=0.1, 0.2, 0.3 and then write .sel(X_AL=0.3) (no i here), that means return the values where X(AL)=0.3. If I write instead .isel(X_AL=0), that means return the values of the first column in the index, i.e., X(AL)=0.1. It's essentially the same thing as writing data[0] except it guarantees that I'm indexing over the correct dimension. In this case, .isel(vertex=1, X_AL=0) means return the second point on the equilibrium tieline (vertex=1) for the first calculated value of X(AL). In this case that value coresponds to 1 - x_phase.

For your second question, yes. The points keyword in calculate() accepts a list of points. If you already know the equilibrium site fractions, you can specify them like points=[[1, 1, 0.99, 0.01], [1, 1, 1-1e-12, 1e-12]] in the case of AL13FE4 configuration of (AL:FE:AL,VA). Each column is sorted in sublattice order, then in alphabetical order.

Third question: Chemical potentials have to be calculated using equilibrium() because in general chemical potentials cannot be defined analytically for all phases. For example, phases with fixed composition like A2B3 (all site fractions equal to 1) only have chemical potentials defined when in equilibrium with another phase. This is because one cannot draw a tangent line with only one point on the energy surface.

@broshe

This comment has been minimized.

Copy link
Author

commented Sep 27, 2015

Hi Richard,
I am still having problems with the equilibrium calculations.
For example, running the following script results in an error code.

Script:

from pycalphad import Database, equilibrium

import pycalphad.variables as v

db =
Database('/home/ebrosh/Documents/ebroshWorks/tcworks/Al-Fe-solidification/alfe_sei.TDB')

data = equilibrium(db, ['AL', 'FE','VA'], ['LIQUID','AL13FE4'], {v.X('FE'):
.82, v.T: 450, v.P: 1e5},verbose=False)

print(data)

Output:

Traceback (most recent call last):
File "", line 1, in
File
"/usr/lib/python3/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py",
line 586, in runfile
execfile(filename, namespace)
File
"/usr/lib/python3/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py",
line 48, in execfile
exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace)
File
"/home/ebrosh/Documents/ebroshWorks/tcworks/Al-Fe-solidification/showBug.py",
line 13, in
data = equilibrium(db, ['AL', 'FE','VA'], ['LIQUID','AL13FE4'],
{v.X('FE'): .82, v.T: 450, v.P: 1e5},verbose=False)
File
"/usr/local/lib/python3.4/dist-packages/pycalphad-0.2.1-py3.4.egg/pycalphad/core/equilibrium.py",
line 175, in equilibrium
File
"/usr/local/lib/python3.4/dist-packages/pycalphad-0.2.1-py3.4.egg/pycalphad/core/lower_convex_hull.py",
line 72, in lower_convex_hull
File
"/usr/local/lib/python3.4/dist-packages/pycalphad-0.2.1-py3.4.egg/pycalphad/core/lower_convex_hull.py",
line 19, in _initialize_array
ValueError: Input energy surface contains one or more NaNs.

For other temperatures the calculation seems to be OK.

Is this a bug?

Regards,

Eli

@richardotis

This comment has been minimized.

Copy link
Collaborator

commented Sep 27, 2015

Interesting! Seems to behave for me on Python 2. Can you try changing the temperature from "450" to "450.0"?

@richardotis

This comment has been minimized.

Copy link
Collaborator

commented Sep 27, 2015

Also I can't reproduce the above behavior on Python 3.4. I did a clean install of pycalphad 0.2.1.post1 from Anaconda (0.2.1 and 0.2.1.post1 should have no difference in behavior)

@richardotis

This comment has been minimized.

Copy link
Collaborator

commented Sep 27, 2015

Other things to check:

  • your version of numpy (mine is 1.9.3) Check the value of numpy.__version__
  • your TDB file, to make sure it hasn't been changed from the version in the repository (still shouldn't fail in principle, but this will help to reproduce the bug)
@broshe

This comment has been minimized.

Copy link
Author

commented Sep 27, 2015

It gives the same output for 450.0

Traceback (most recent call last):
File "", line 1, in
File
"/usr/lib/python3/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py",
line 586, in runfile
execfile(filename, namespace)
File
"/usr/lib/python3/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py",
line 48, in execfile
exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace)
File
"/home/ebrosh/Documents/ebroshWorks/tcworks/Al-Fe-solidification/showBug.py",
line 13, in
data = equilibrium(db, ['AL', 'FE','VA'], ['LIQUID','AL13FE4'],
{v.X('FE'): .82, v.T: 450.0, v.P: 1e5},verbose=False)
File
"/usr/local/lib/python3.4/dist-packages/pycalphad-0.2.1-py3.4.egg/pycalphad/core/equilibrium.py",
line 175, in equilibrium
File
"/usr/local/lib/python3.4/dist-packages/pycalphad-0.2.1-py3.4.egg/pycalphad/core/lower_convex_hull.py",
line 72, in lower_convex_hull
File
"/usr/local/lib/python3.4/dist-packages/pycalphad-0.2.1-py3.4.egg/pycalphad/core/lower_convex_hull.py",
line 19, in _initialize_array
ValueError: Input energy surface contains one or more NaNs.

On Sun, Sep 27, 2015 at 5:48 PM, Richard Otis notifications@github.com
wrote:

Interesting! Seems to behave for me on Python 2. Can you try changing the
temperature from "450" to "450.0"?


Reply to this email directly or view it on GitHub
#23 (comment)
.

@broshe

This comment has been minimized.

Copy link
Author

commented Sep 27, 2015

My numpy version is
numpy.version
'1.8.2'
The TDB file was just downloaded from the pycalphad site
https://raw.githubusercontent.com/richardotis/pycalphad/develop/research/alfe_sei.TDB

On Sun, Sep 27, 2015 at 5:57 PM, Richard Otis notifications@github.com
wrote:

Other things to check:

  • your version of numpy (mine is 1.9.3)
  • your TDB file, to make sure it hasn't been changed from the version
    in the repository (still shouldn't fail in principle, but this will help to
    reproduce the bug)


Reply to this email directly or view it on GitHub
#23 (comment)
.

@broshe

This comment has been minimized.

Copy link
Author

commented Sep 27, 2015

I updated the numpy to 1.9.2 and pycalphad to 0.2.1post.
numpy.version
'1.9.2'

The output remains the same:
runfile('/home/ebrosh/Documents/ebroshWorks/tcworks/Al-Fe-solidification/showBug.py',
wdir=r'/home/ebrosh/Documents/ebroshWorks/tcworks/Al-Fe-solidification')
Components: AL FE VA
Phases: AL13FE4 LIQUID [done]
Computing initial grid [38 points, 3.6KB]
Computing convex hull [iteration 1]
progress 71507.32973997333
Refining convex hull
Rebuilding grid [42 points, 3.9KB]
Computing convex hull [iteration 2]
progress 1311.6354015906982
Refining convex hull
Rebuilding grid [46 points, 4.3KB]
Computing convex hull [iteration 3]
progress 654.5935045386577
Refining convex hull
Rebuilding grid [50 points, 4.7KB]
Computing convex hull [iteration 4]
progress 330.8731461801799
Refining convex hull
Rebuilding grid [54 points, 5.0KB]
Computing convex hull [iteration 5]
progress 164.54234854092647
Refining convex hull
Rebuilding grid [58 points, 5.4KB]
Computing convex hull [iteration 6]
progress 82.25370727134577
Refining convex hull
Rebuilding grid [62 points, 5.8KB]
Computing convex hull [iteration 7]
progress 41.122579879069235
Refining convex hull
Rebuilding grid [66 points, 6.1KB]
Computing convex hull [iteration 8]
progress 20.575308559753466
Refining convex hull
Rebuilding grid [70 points, 6.5KB]
Computing convex hull [iteration 9]
progress 10.288003174413461
Refining convex hull
Rebuilding grid [74 points, 6.9KB]
Computing convex hull [iteration 10]
progress 5.144108241889626
Refining convex hull
Rebuilding grid [78 points, 7.2KB]
Computing convex hull [iteration 11]
progress 2.572232151927892
Refining convex hull
Rebuilding grid [82 points, 7.6KB]
Computing convex hull [iteration 12]
progress 1.2867356642673258
Refining convex hull
Rebuilding grid [86 points, 8.0KB]
Computing convex hull [iteration 13]
progress 0.6446643312228844
Refining convex hull
Rebuilding grid [90 points, 8.3KB]
Computing convex hull [iteration 14]
progress 0.32360991949099116
Refining convex hull
Rebuilding grid [94 points, 8.7KB]
Computing convex hull [iteration 15]
progress 663.8516619015718
Refining convex hull
Rebuilding grid [98 points, 9.1KB]
Computing convex hull [iteration 16]
progress 341.047389697429
Refining convex hull
Rebuilding grid [102 points, 9.4KB]
Computing convex hull [iteration 17]
progress 170.59389066518634
Refining convex hull
Rebuilding grid [106 points, 9.8KB]
Computing convex hull [iteration 18]
progress 85.31497009018494
Refining convex hull
Rebuilding grid [110 points, 10.2KB]
Computing convex hull [iteration 19]
progress 42.66206568497
Refining convex hull
Rebuilding grid [114 points, 10.6KB]
Computing convex hull [iteration 20]
progress 21.33228006727586
Refining convex hull
Rebuilding grid [118 points, 10.9KB]
Computing convex hull [iteration 21]
progress 10.666563655075151
Refining convex hull
Rebuilding grid [122 points, 11.3KB]
Computing convex hull [iteration 22]
progress 5.334282200143207
Refining convex hull
Rebuilding grid [126 points, 11.7KB]
Computing convex hull [iteration 23]
progress 2.6675240943586687
Refining convex hull
Rebuilding grid [130 points, 12.0KB]
Computing convex hull [iteration 24]
progress 1.3347493140754523
Refining convex hull
Rebuilding grid [134 points, 12.4KB]
Computing convex hull [iteration 25]
progress 0.6671286203782074
Refining convex hull
Rebuilding grid [138 points, 12.8KB]
Computing convex hull [iteration 26]
Traceback (most recent call last):
File "", line 1, in
File
"/usr/lib/python3/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py",
line 586, in runfile
execfile(filename, namespace)
File
"/usr/lib/python3/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py",
line 48, in execfile
exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace)
File
"/home/ebrosh/Documents/ebroshWorks/tcworks/Al-Fe-solidification/showBug.py",
line 13, in
data = equilibrium(db, ['AL', 'FE','VA'], ['LIQUID','AL13FE4'],
{v.X('FE'): .82, v.T: 450.0, v.P: 1e5},verbose=True)
File
"/usr/local/lib/python3.4/dist-packages/pycalphad-0.2.1.post1-py3.4.egg/pycalphad/core/equilibrium.py",
line 175, in equilibrium
lower_convex_hull(grid, properties)
File
"/usr/local/lib/python3.4/dist-packages/pycalphad-0.2.1.post1-py3.4.egg/pycalphad/core/lower_convex_hull.py",
line 72, in lower_convex_hull
_initialize_array(global_grid, result_array)
File
"/usr/local/lib/python3.4/dist-packages/pycalphad-0.2.1.post1-py3.4.egg/pycalphad/core/lower_convex_hull.py",
line 19, in _initialize_array
raise ValueError('Input energy surface contains one or more NaNs.')
ValueError: Input energy surface contains one or more NaNs.

On Sun, Sep 27, 2015 at 6:05 PM, Eli Brosh ebrosh1@gmail.com wrote:

My numpy version is
numpy.version
'1.8.2'
The TDB file was just downloaded from the pycalphad site

https://raw.githubusercontent.com/richardotis/pycalphad/develop/research/alfe_sei.TDB

On Sun, Sep 27, 2015 at 5:57 PM, Richard Otis notifications@github.com
wrote:

Other things to check:

  • your version of numpy (mine is 1.9.3)
  • your TDB file, to make sure it hasn't been changed from the version
    in the repository (still shouldn't fail in principle, but this will help to
    reproduce the bug)


Reply to this email directly or view it on GitHub
#23 (comment)
.

@broshe

This comment has been minimized.

Copy link
Author

commented Sep 28, 2015

Hi Richard,
I installed anaconda.
This time the calculation is ok for v.X('FE'): .82, v.T: 450
However, it gets an error message for
data = equilibrium(db, ['AL', 'FE','VA'], ['LIQUID','AL13FE4'], {v.X('FE'):
.58, v.T: 875, v.P: 1e5},verbose=False)

raceback (most recent call last):
File "showBug.py", line 18, in
data = equilibrium(db, ['AL', 'FE','VA'], ['LIQUID','AL13FE4'],
{v.X('FE'): .58, v.T: 875, v.P: 1e5},verbose=False)
File
"/home/ebrosh/anaconda3/lib/python3.4/site-packages/pycalphad-0.2.1.post1-py3.4.egg/pycalphad/core/equilibrium.py",
line 271, in equilibrium
File
"/home/ebrosh/anaconda3/lib/python3.4/site-packages/numpy/linalg/linalg.py",
line 520, in inv
ainv = _umath_linalg.inv(a, signature=signature, extobj=extobj)
File
"/home/ebrosh/anaconda3/lib/python3.4/site-packages/numpy/linalg/linalg.py",
line 90, in _raise_linalgerror_singular
raise LinAlgError("Singular matrix")
numpy.linalg.linalg.LinAlgError: Singular matrix

The python is anaconda. numpy vrsion is 1.9.3, pycalphad is 0.2.1.post1.

What's wrong?

Eli

On Sun, Sep 27, 2015 at 7:06 PM, Eli Brosh ebrosh1@gmail.com wrote:

I updated the numpy to 1.9.2 and pycalphad to 0.2.1post.
numpy.version
'1.9.2'

The output remains the same:
runfile('/home/ebrosh/Documents/ebroshWorks/tcworks/Al-Fe-solidification/showBug.py',
wdir=r'/home/ebrosh/Documents/ebroshWorks/tcworks/Al-Fe-solidification')
Components: AL FE VA
Phases: AL13FE4 LIQUID [done]
Computing initial grid [38 points, 3.6KB]
Computing convex hull [iteration 1]
progress 71507.32973997333
Refining convex hull
Rebuilding grid [42 points, 3.9KB]
Computing convex hull [iteration 2]
progress 1311.6354015906982
Refining convex hull
Rebuilding grid [46 points, 4.3KB]
Computing convex hull [iteration 3]
progress 654.5935045386577
Refining convex hull
Rebuilding grid [50 points, 4.7KB]
Computing convex hull [iteration 4]
progress 330.8731461801799
Refining convex hull
Rebuilding grid [54 points, 5.0KB]
Computing convex hull [iteration 5]
progress 164.54234854092647
Refining convex hull
Rebuilding grid [58 points, 5.4KB]
Computing convex hull [iteration 6]
progress 82.25370727134577
Refining convex hull
Rebuilding grid [62 points, 5.8KB]
Computing convex hull [iteration 7]
progress 41.122579879069235
Refining convex hull
Rebuilding grid [66 points, 6.1KB]
Computing convex hull [iteration 8]
progress 20.575308559753466
Refining convex hull
Rebuilding grid [70 points, 6.5KB]
Computing convex hull [iteration 9]
progress 10.288003174413461
Refining convex hull
Rebuilding grid [74 points, 6.9KB]
Computing convex hull [iteration 10]
progress 5.144108241889626
Refining convex hull
Rebuilding grid [78 points, 7.2KB]
Computing convex hull [iteration 11]
progress 2.572232151927892
Refining convex hull
Rebuilding grid [82 points, 7.6KB]
Computing convex hull [iteration 12]
progress 1.2867356642673258
Refining convex hull
Rebuilding grid [86 points, 8.0KB]
Computing convex hull [iteration 13]
progress 0.6446643312228844
Refining convex hull
Rebuilding grid [90 points, 8.3KB]
Computing convex hull [iteration 14]
progress 0.32360991949099116
Refining convex hull
Rebuilding grid [94 points, 8.7KB]
Computing convex hull [iteration 15]
progress 663.8516619015718
Refining convex hull
Rebuilding grid [98 points, 9.1KB]
Computing convex hull [iteration 16]
progress 341.047389697429
Refining convex hull
Rebuilding grid [102 points, 9.4KB]
Computing convex hull [iteration 17]
progress 170.59389066518634
Refining convex hull
Rebuilding grid [106 points, 9.8KB]
Computing convex hull [iteration 18]
progress 85.31497009018494
Refining convex hull
Rebuilding grid [110 points, 10.2KB]
Computing convex hull [iteration 19]
progress 42.66206568497
Refining convex hull
Rebuilding grid [114 points, 10.6KB]
Computing convex hull [iteration 20]
progress 21.33228006727586
Refining convex hull
Rebuilding grid [118 points, 10.9KB]
Computing convex hull [iteration 21]
progress 10.666563655075151
Refining convex hull
Rebuilding grid [122 points, 11.3KB]
Computing convex hull [iteration 22]
progress 5.334282200143207
Refining convex hull
Rebuilding grid [126 points, 11.7KB]
Computing convex hull [iteration 23]
progress 2.6675240943586687
Refining convex hull
Rebuilding grid [130 points, 12.0KB]
Computing convex hull [iteration 24]
progress 1.3347493140754523
Refining convex hull
Rebuilding grid [134 points, 12.4KB]
Computing convex hull [iteration 25]
progress 0.6671286203782074
Refining convex hull
Rebuilding grid [138 points, 12.8KB]
Computing convex hull [iteration 26]
Traceback (most recent call last):
File "", line 1, in
File
"/usr/lib/python3/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py",
line 586, in runfile
execfile(filename, namespace)
File
"/usr/lib/python3/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py",
line 48, in execfile
exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace)
File
"/home/ebrosh/Documents/ebroshWorks/tcworks/Al-Fe-solidification/showBug.py",
line 13, in
data = equilibrium(db, ['AL', 'FE','VA'], ['LIQUID','AL13FE4'],
{v.X('FE'): .82, v.T: 450.0, v.P: 1e5},verbose=True)
File
"/usr/local/lib/python3.4/dist-packages/pycalphad-0.2.1.post1-py3.4.egg/pycalphad/core/equilibrium.py",
line 175, in equilibrium
lower_convex_hull(grid, properties)
File
"/usr/local/lib/python3.4/dist-packages/pycalphad-0.2.1.post1-py3.4.egg/pycalphad/core/lower_convex_hull.py",
line 72, in lower_convex_hull
_initialize_array(global_grid, result_array)
File
"/usr/local/lib/python3.4/dist-packages/pycalphad-0.2.1.post1-py3.4.egg/pycalphad/core/lower_convex_hull.py",
line 19, in _initialize_array
raise ValueError('Input energy surface contains one or more NaNs.')
ValueError: Input energy surface contains one or more NaNs.

On Sun, Sep 27, 2015 at 6:05 PM, Eli Brosh ebrosh1@gmail.com wrote:

My numpy version is
numpy.version
'1.8.2'
The TDB file was just downloaded from the pycalphad site

https://raw.githubusercontent.com/richardotis/pycalphad/develop/research/alfe_sei.TDB

On Sun, Sep 27, 2015 at 5:57 PM, Richard Otis notifications@github.com
wrote:

Other things to check:

  • your version of numpy (mine is 1.9.3)
  • your TDB file, to make sure it hasn't been changed from the
    version in the repository (still shouldn't fail in principle, but this will
    help to reproduce the bug)


Reply to this email directly or view it on GitHub
#23 (comment)
.

@broshe

This comment has been minimized.

Copy link
Author

commented Sep 28, 2015

The same with v.T: 875.0

On Mon, Sep 28, 2015 at 9:24 AM, Eli Brosh ebrosh1@gmail.com wrote:

Hi Richard,
I installed anaconda.
This time the calculation is ok for v.X('FE'): .82, v.T: 450
However, it gets an error message for
data = equilibrium(db, ['AL', 'FE','VA'], ['LIQUID','AL13FE4'],
{v.X('FE'): .58, v.T: 875, v.P: 1e5},verbose=False)

raceback (most recent call last):
File "showBug.py", line 18, in
data = equilibrium(db, ['AL', 'FE','VA'], ['LIQUID','AL13FE4'],
{v.X('FE'): .58, v.T: 875, v.P: 1e5},verbose=False)
File
"/home/ebrosh/anaconda3/lib/python3.4/site-packages/pycalphad-0.2.1.post1-py3.4.egg/pycalphad/core/equilibrium.py",
line 271, in equilibrium
File
"/home/ebrosh/anaconda3/lib/python3.4/site-packages/numpy/linalg/linalg.py",
line 520, in inv
ainv = _umath_linalg.inv(a, signature=signature, extobj=extobj)
File
"/home/ebrosh/anaconda3/lib/python3.4/site-packages/numpy/linalg/linalg.py",
line 90, in _raise_linalgerror_singular
raise LinAlgError("Singular matrix")
numpy.linalg.linalg.LinAlgError: Singular matrix

The python is anaconda. numpy vrsion is 1.9.3, pycalphad is 0.2.1.post1.

What's wrong?

Eli

On Sun, Sep 27, 2015 at 7:06 PM, Eli Brosh ebrosh1@gmail.com wrote:

I updated the numpy to 1.9.2 and pycalphad to 0.2.1post.
numpy.version
'1.9.2'

The output remains the same:
runfile('/home/ebrosh/Documents/ebroshWorks/tcworks/Al-Fe-solidification/showBug.py',
wdir=r'/home/ebrosh/Documents/ebroshWorks/tcworks/Al-Fe-solidification')
Components: AL FE VA
Phases: AL13FE4 LIQUID [done]
Computing initial grid [38 points, 3.6KB]
Computing convex hull [iteration 1]
progress 71507.32973997333
Refining convex hull
Rebuilding grid [42 points, 3.9KB]
Computing convex hull [iteration 2]
progress 1311.6354015906982
Refining convex hull
Rebuilding grid [46 points, 4.3KB]
Computing convex hull [iteration 3]
progress 654.5935045386577
Refining convex hull
Rebuilding grid [50 points, 4.7KB]
Computing convex hull [iteration 4]
progress 330.8731461801799
Refining convex hull
Rebuilding grid [54 points, 5.0KB]
Computing convex hull [iteration 5]
progress 164.54234854092647
Refining convex hull
Rebuilding grid [58 points, 5.4KB]
Computing convex hull [iteration 6]
progress 82.25370727134577
Refining convex hull
Rebuilding grid [62 points, 5.8KB]
Computing convex hull [iteration 7]
progress 41.122579879069235
Refining convex hull
Rebuilding grid [66 points, 6.1KB]
Computing convex hull [iteration 8]
progress 20.575308559753466
Refining convex hull
Rebuilding grid [70 points, 6.5KB]
Computing convex hull [iteration 9]
progress 10.288003174413461
Refining convex hull
Rebuilding grid [74 points, 6.9KB]
Computing convex hull [iteration 10]
progress 5.144108241889626
Refining convex hull
Rebuilding grid [78 points, 7.2KB]
Computing convex hull [iteration 11]
progress 2.572232151927892
Refining convex hull
Rebuilding grid [82 points, 7.6KB]
Computing convex hull [iteration 12]
progress 1.2867356642673258
Refining convex hull
Rebuilding grid [86 points, 8.0KB]
Computing convex hull [iteration 13]
progress 0.6446643312228844
Refining convex hull
Rebuilding grid [90 points, 8.3KB]
Computing convex hull [iteration 14]
progress 0.32360991949099116
Refining convex hull
Rebuilding grid [94 points, 8.7KB]
Computing convex hull [iteration 15]
progress 663.8516619015718
Refining convex hull
Rebuilding grid [98 points, 9.1KB]
Computing convex hull [iteration 16]
progress 341.047389697429
Refining convex hull
Rebuilding grid [102 points, 9.4KB]
Computing convex hull [iteration 17]
progress 170.59389066518634
Refining convex hull
Rebuilding grid [106 points, 9.8KB]
Computing convex hull [iteration 18]
progress 85.31497009018494
Refining convex hull
Rebuilding grid [110 points, 10.2KB]
Computing convex hull [iteration 19]
progress 42.66206568497
Refining convex hull
Rebuilding grid [114 points, 10.6KB]
Computing convex hull [iteration 20]
progress 21.33228006727586
Refining convex hull
Rebuilding grid [118 points, 10.9KB]
Computing convex hull [iteration 21]
progress 10.666563655075151
Refining convex hull
Rebuilding grid [122 points, 11.3KB]
Computing convex hull [iteration 22]
progress 5.334282200143207
Refining convex hull
Rebuilding grid [126 points, 11.7KB]
Computing convex hull [iteration 23]
progress 2.6675240943586687
Refining convex hull
Rebuilding grid [130 points, 12.0KB]
Computing convex hull [iteration 24]
progress 1.3347493140754523
Refining convex hull
Rebuilding grid [134 points, 12.4KB]
Computing convex hull [iteration 25]
progress 0.6671286203782074
Refining convex hull
Rebuilding grid [138 points, 12.8KB]
Computing convex hull [iteration 26]
Traceback (most recent call last):
File "", line 1, in
File
"/usr/lib/python3/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py",
line 586, in runfile
execfile(filename, namespace)
File
"/usr/lib/python3/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py",
line 48, in execfile
exec(compile(open(filename, 'rb').read(), filename, 'exec'),
namespace)
File
"/home/ebrosh/Documents/ebroshWorks/tcworks/Al-Fe-solidification/showBug.py",
line 13, in
data = equilibrium(db, ['AL', 'FE','VA'], ['LIQUID','AL13FE4'],
{v.X('FE'): .82, v.T: 450.0, v.P: 1e5},verbose=True)
File
"/usr/local/lib/python3.4/dist-packages/pycalphad-0.2.1.post1-py3.4.egg/pycalphad/core/equilibrium.py",
line 175, in equilibrium
lower_convex_hull(grid, properties)
File
"/usr/local/lib/python3.4/dist-packages/pycalphad-0.2.1.post1-py3.4.egg/pycalphad/core/lower_convex_hull.py",
line 72, in lower_convex_hull
_initialize_array(global_grid, result_array)
File
"/usr/local/lib/python3.4/dist-packages/pycalphad-0.2.1.post1-py3.4.egg/pycalphad/core/lower_convex_hull.py",
line 19, in _initialize_array
raise ValueError('Input energy surface contains one or more NaNs.')
ValueError: Input energy surface contains one or more NaNs.

On Sun, Sep 27, 2015 at 6:05 PM, Eli Brosh ebrosh1@gmail.com wrote:

My numpy version is
numpy.version
'1.8.2'
The TDB file was just downloaded from the pycalphad site

https://raw.githubusercontent.com/richardotis/pycalphad/develop/research/alfe_sei.TDB

On Sun, Sep 27, 2015 at 5:57 PM, Richard Otis notifications@github.com
wrote:

Other things to check:

  • your version of numpy (mine is 1.9.3)
  • your TDB file, to make sure it hasn't been changed from the
    version in the repository (still shouldn't fail in principle, but this will
    help to reproduce the bug)


Reply to this email directly or view it on GitHub
#23 (comment)
.

@broshe

This comment has been minimized.

Copy link
Author

commented Sep 28, 2015

Perhaps the bug appears at different combinations of T and x in different
installations.
In this case, I think it should appear t some stage of running the attached
script.
That is a simple script to calculate the liquidus temperature of a compound
in Al-Fe.
For me it got stuck at v.X('FE'): .58, v.T: 875.0.

Eli

On Mon, Sep 28, 2015 at 9:26 AM, Eli Brosh ebrosh1@gmail.com wrote:

The same with v.T: 875.0

On Mon, Sep 28, 2015 at 9:24 AM, Eli Brosh ebrosh1@gmail.com wrote:

Hi Richard,
I installed anaconda.
This time the calculation is ok for v.X('FE'): .82, v.T: 450
However, it gets an error message for
data = equilibrium(db, ['AL', 'FE','VA'], ['LIQUID','AL13FE4'],
{v.X('FE'): .58, v.T: 875, v.P: 1e5},verbose=False)

raceback (most recent call last):
File "showBug.py", line 18, in
data = equilibrium(db, ['AL', 'FE','VA'], ['LIQUID','AL13FE4'],
{v.X('FE'): .58, v.T: 875, v.P: 1e5},verbose=False)
File
"/home/ebrosh/anaconda3/lib/python3.4/site-packages/pycalphad-0.2.1.post1-py3.4.egg/pycalphad/core/equilibrium.py",
line 271, in equilibrium
File
"/home/ebrosh/anaconda3/lib/python3.4/site-packages/numpy/linalg/linalg.py",
line 520, in inv
ainv = _umath_linalg.inv(a, signature=signature, extobj=extobj)
File
"/home/ebrosh/anaconda3/lib/python3.4/site-packages/numpy/linalg/linalg.py",
line 90, in _raise_linalgerror_singular
raise LinAlgError("Singular matrix")
numpy.linalg.linalg.LinAlgError: Singular matrix

The python is anaconda. numpy vrsion is 1.9.3, pycalphad is 0.2.1.post1.

What's wrong?

Eli

On Sun, Sep 27, 2015 at 7:06 PM, Eli Brosh ebrosh1@gmail.com wrote:

I updated the numpy to 1.9.2 and pycalphad to 0.2.1post.
numpy.version
'1.9.2'

The output remains the same:
runfile('/home/ebrosh/Documents/ebroshWorks/tcworks/Al-Fe-solidification/showBug.py',
wdir=r'/home/ebrosh/Documents/ebroshWorks/tcworks/Al-Fe-solidification')
Components: AL FE VA
Phases: AL13FE4 LIQUID [done]
Computing initial grid [38 points, 3.6KB]
Computing convex hull [iteration 1]
progress 71507.32973997333
Refining convex hull
Rebuilding grid [42 points, 3.9KB]
Computing convex hull [iteration 2]
progress 1311.6354015906982
Refining convex hull
Rebuilding grid [46 points, 4.3KB]
Computing convex hull [iteration 3]
progress 654.5935045386577
Refining convex hull
Rebuilding grid [50 points, 4.7KB]
Computing convex hull [iteration 4]
progress 330.8731461801799
Refining convex hull
Rebuilding grid [54 points, 5.0KB]
Computing convex hull [iteration 5]
progress 164.54234854092647
Refining convex hull
Rebuilding grid [58 points, 5.4KB]
Computing convex hull [iteration 6]
progress 82.25370727134577
Refining convex hull
Rebuilding grid [62 points, 5.8KB]
Computing convex hull [iteration 7]
progress 41.122579879069235
Refining convex hull
Rebuilding grid [66 points, 6.1KB]
Computing convex hull [iteration 8]
progress 20.575308559753466
Refining convex hull
Rebuilding grid [70 points, 6.5KB]
Computing convex hull [iteration 9]
progress 10.288003174413461
Refining convex hull
Rebuilding grid [74 points, 6.9KB]
Computing convex hull [iteration 10]
progress 5.144108241889626
Refining convex hull
Rebuilding grid [78 points, 7.2KB]
Computing convex hull [iteration 11]
progress 2.572232151927892
Refining convex hull
Rebuilding grid [82 points, 7.6KB]
Computing convex hull [iteration 12]
progress 1.2867356642673258
Refining convex hull
Rebuilding grid [86 points, 8.0KB]
Computing convex hull [iteration 13]
progress 0.6446643312228844
Refining convex hull
Rebuilding grid [90 points, 8.3KB]
Computing convex hull [iteration 14]
progress 0.32360991949099116
Refining convex hull
Rebuilding grid [94 points, 8.7KB]
Computing convex hull [iteration 15]
progress 663.8516619015718
Refining convex hull
Rebuilding grid [98 points, 9.1KB]
Computing convex hull [iteration 16]
progress 341.047389697429
Refining convex hull
Rebuilding grid [102 points, 9.4KB]
Computing convex hull [iteration 17]
progress 170.59389066518634
Refining convex hull
Rebuilding grid [106 points, 9.8KB]
Computing convex hull [iteration 18]
progress 85.31497009018494
Refining convex hull
Rebuilding grid [110 points, 10.2KB]
Computing convex hull [iteration 19]
progress 42.66206568497
Refining convex hull
Rebuilding grid [114 points, 10.6KB]
Computing convex hull [iteration 20]
progress 21.33228006727586
Refining convex hull
Rebuilding grid [118 points, 10.9KB]
Computing convex hull [iteration 21]
progress 10.666563655075151
Refining convex hull
Rebuilding grid [122 points, 11.3KB]
Computing convex hull [iteration 22]
progress 5.334282200143207
Refining convex hull
Rebuilding grid [126 points, 11.7KB]
Computing convex hull [iteration 23]
progress 2.6675240943586687
Refining convex hull
Rebuilding grid [130 points, 12.0KB]
Computing convex hull [iteration 24]
progress 1.3347493140754523
Refining convex hull
Rebuilding grid [134 points, 12.4KB]
Computing convex hull [iteration 25]
progress 0.6671286203782074
Refining convex hull
Rebuilding grid [138 points, 12.8KB]
Computing convex hull [iteration 26]
Traceback (most recent call last):
File "", line 1, in
File
"/usr/lib/python3/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py",
line 586, in runfile
execfile(filename, namespace)
File
"/usr/lib/python3/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py",
line 48, in execfile
exec(compile(open(filename, 'rb').read(), filename, 'exec'),
namespace)
File
"/home/ebrosh/Documents/ebroshWorks/tcworks/Al-Fe-solidification/showBug.py",
line 13, in
data = equilibrium(db, ['AL', 'FE','VA'], ['LIQUID','AL13FE4'],
{v.X('FE'): .82, v.T: 450.0, v.P: 1e5},verbose=True)
File
"/usr/local/lib/python3.4/dist-packages/pycalphad-0.2.1.post1-py3.4.egg/pycalphad/core/equilibrium.py",
line 175, in equilibrium
lower_convex_hull(grid, properties)
File
"/usr/local/lib/python3.4/dist-packages/pycalphad-0.2.1.post1-py3.4.egg/pycalphad/core/lower_convex_hull.py",
line 72, in lower_convex_hull
_initialize_array(global_grid, result_array)
File
"/usr/local/lib/python3.4/dist-packages/pycalphad-0.2.1.post1-py3.4.egg/pycalphad/core/lower_convex_hull.py",
line 19, in _initialize_array
raise ValueError('Input energy surface contains one or more NaNs.')
ValueError: Input energy surface contains one or more NaNs.

On Sun, Sep 27, 2015 at 6:05 PM, Eli Brosh ebrosh1@gmail.com wrote:

My numpy version is
numpy.version
'1.8.2'
The TDB file was just downloaded from the pycalphad site

https://raw.githubusercontent.com/richardotis/pycalphad/develop/research/alfe_sei.TDB

On Sun, Sep 27, 2015 at 5:57 PM, Richard Otis <notifications@github.com

wrote:

Other things to check:

  • your version of numpy (mine is 1.9.3)
  • your TDB file, to make sure it hasn't been changed from the
    version in the repository (still shouldn't fail in principle, but this will
    help to reproduce the bug)


Reply to this email directly or view it on GitHub
#23 (comment)
.

@broshe

This comment has been minimized.

Copy link
Author

commented Sep 28, 2015

Attachement did not work.
Here the script code is inside.

-- coding: utf-8 --

"""
Created on Wed Sep 9 09:06:53 2015

@author: ebrosh
"""

#import matplotlib.pyplot as plt
from pycalphad import Database, equilibrium
import pycalphad.variables as v
import numpy as np
from pylab import *

db =
Database('/home/ebrosh/Documents/ebroshWorks/tcworks/Al-Fe-solidification/alfe_sei.TDB')

def nsolid(T,phase_name,x_liquid,db):
# calculate number of moles of the solid phase
print (phase_name,' x_liquid=',x_liquid,' T=',T)
data = equilibrium(db, ['AL', 'FE','VA'], ['LIQUID',phase_name],
{v.X('FE'): x_liquid, v.T: T, v.P: 1.0e5},verbose=False)
n=data['NP'].values.flatten()
phases=data['Phase'].values.flatten()
n=sum(n[phases==phase_name])
return n

def Liquidus2(phase_name,x_liquid,db):
# find the first temperature at which the solid does not appear
TlowBound=400.0
ThighBound=2000.0
tol=2.0

min, max =TlowBound , ThighBound

while (max - min) > tol:
    mid = .5*(min + max)

    n= nsolid(mid,phase_name,x_liquid,db)

    if  n== 0:
        max = mid
    else:
        min = mid

T=mid
print('Liquidus found')
return T

make calculation for n points of composition

n=50.0
irange=np.arange(0,n+1,1)
xrange=irange/n
xrange[0]=1.0e-4
xrange[-1]=.9999
T=np.zeros(size(irange))

for i in irange:
T[i]=Liquidus2('AL13FE4',xrange[i],db)

figure(1)
plot(xrange,T)
xlabel('x(liquid,Fe)')
ylabel('T liquidus of AL13FE4' )

show(block=False)

On Mon, Sep 28, 2015 at 12:31 PM, Eli Brosh ebrosh1@gmail.com wrote:

Perhaps the bug appears at different combinations of T and x in different
installations.
In this case, I think it should appear t some stage of running the
attached script.
That is a simple script to calculate the liquidus temperature of a
compound in Al-Fe.
For me it got stuck at v.X('FE'): .58, v.T: 875.0.

Eli

On Mon, Sep 28, 2015 at 9:26 AM, Eli Brosh ebrosh1@gmail.com wrote:

The same with v.T: 875.0

On Mon, Sep 28, 2015 at 9:24 AM, Eli Brosh ebrosh1@gmail.com wrote:

Hi Richard,
I installed anaconda.
This time the calculation is ok for v.X('FE'): .82, v.T: 450
However, it gets an error message for
data = equilibrium(db, ['AL', 'FE','VA'], ['LIQUID','AL13FE4'],
{v.X('FE'): .58, v.T: 875, v.P: 1e5},verbose=False)

raceback (most recent call last):
File "showBug.py", line 18, in
data = equilibrium(db, ['AL', 'FE','VA'], ['LIQUID','AL13FE4'],
{v.X('FE'): .58, v.T: 875, v.P: 1e5},verbose=False)
File
"/home/ebrosh/anaconda3/lib/python3.4/site-packages/pycalphad-0.2.1.post1-py3.4.egg/pycalphad/core/equilibrium.py",
line 271, in equilibrium
File
"/home/ebrosh/anaconda3/lib/python3.4/site-packages/numpy/linalg/linalg.py",
line 520, in inv
ainv = _umath_linalg.inv(a, signature=signature, extobj=extobj)
File
"/home/ebrosh/anaconda3/lib/python3.4/site-packages/numpy/linalg/linalg.py",
line 90, in _raise_linalgerror_singular
raise LinAlgError("Singular matrix")
numpy.linalg.linalg.LinAlgError: Singular matrix

The python is anaconda. numpy vrsion is 1.9.3, pycalphad is 0.2.1.post1.

What's wrong?

Eli

On Sun, Sep 27, 2015 at 7:06 PM, Eli Brosh ebrosh1@gmail.com wrote:

I updated the numpy to 1.9.2 and pycalphad to 0.2.1post.
numpy.version
'1.9.2'

The output remains the same:
runfile('/home/ebrosh/Documents/ebroshWorks/tcworks/Al-Fe-solidification/showBug.py',
wdir=r'/home/ebrosh/Documents/ebroshWorks/tcworks/Al-Fe-solidification')
Components: AL FE VA
Phases: AL13FE4 LIQUID [done]
Computing initial grid [38 points, 3.6KB]
Computing convex hull [iteration 1]
progress 71507.32973997333
Refining convex hull
Rebuilding grid [42 points, 3.9KB]
Computing convex hull [iteration 2]
progress 1311.6354015906982
Refining convex hull
Rebuilding grid [46 points, 4.3KB]
Computing convex hull [iteration 3]
progress 654.5935045386577
Refining convex hull
Rebuilding grid [50 points, 4.7KB]
Computing convex hull [iteration 4]
progress 330.8731461801799
Refining convex hull
Rebuilding grid [54 points, 5.0KB]
Computing convex hull [iteration 5]
progress 164.54234854092647
Refining convex hull
Rebuilding grid [58 points, 5.4KB]
Computing convex hull [iteration 6]
progress 82.25370727134577
Refining convex hull
Rebuilding grid [62 points, 5.8KB]
Computing convex hull [iteration 7]
progress 41.122579879069235
Refining convex hull
Rebuilding grid [66 points, 6.1KB]
Computing convex hull [iteration 8]
progress 20.575308559753466
Refining convex hull
Rebuilding grid [70 points, 6.5KB]
Computing convex hull [iteration 9]
progress 10.288003174413461
Refining convex hull
Rebuilding grid [74 points, 6.9KB]
Computing convex hull [iteration 10]
progress 5.144108241889626
Refining convex hull
Rebuilding grid [78 points, 7.2KB]
Computing convex hull [iteration 11]
progress 2.572232151927892
Refining convex hull
Rebuilding grid [82 points, 7.6KB]
Computing convex hull [iteration 12]
progress 1.2867356642673258
Refining convex hull
Rebuilding grid [86 points, 8.0KB]
Computing convex hull [iteration 13]
progress 0.6446643312228844
Refining convex hull
Rebuilding grid [90 points, 8.3KB]
Computing convex hull [iteration 14]
progress 0.32360991949099116
Refining convex hull
Rebuilding grid [94 points, 8.7KB]
Computing convex hull [iteration 15]
progress 663.8516619015718
Refining convex hull
Rebuilding grid [98 points, 9.1KB]
Computing convex hull [iteration 16]
progress 341.047389697429
Refining convex hull
Rebuilding grid [102 points, 9.4KB]
Computing convex hull [iteration 17]
progress 170.59389066518634
Refining convex hull
Rebuilding grid [106 points, 9.8KB]
Computing convex hull [iteration 18]
progress 85.31497009018494
Refining convex hull
Rebuilding grid [110 points, 10.2KB]
Computing convex hull [iteration 19]
progress 42.66206568497
Refining convex hull
Rebuilding grid [114 points, 10.6KB]
Computing convex hull [iteration 20]
progress 21.33228006727586
Refining convex hull
Rebuilding grid [118 points, 10.9KB]
Computing convex hull [iteration 21]
progress 10.666563655075151
Refining convex hull
Rebuilding grid [122 points, 11.3KB]
Computing convex hull [iteration 22]
progress 5.334282200143207
Refining convex hull
Rebuilding grid [126 points, 11.7KB]
Computing convex hull [iteration 23]
progress 2.6675240943586687
Refining convex hull
Rebuilding grid [130 points, 12.0KB]
Computing convex hull [iteration 24]
progress 1.3347493140754523
Refining convex hull
Rebuilding grid [134 points, 12.4KB]
Computing convex hull [iteration 25]
progress 0.6671286203782074
Refining convex hull
Rebuilding grid [138 points, 12.8KB]
Computing convex hull [iteration 26]
Traceback (most recent call last):
File "", line 1, in
File
"/usr/lib/python3/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py",
line 586, in runfile
execfile(filename, namespace)
File
"/usr/lib/python3/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py",
line 48, in execfile
exec(compile(open(filename, 'rb').read(), filename, 'exec'),
namespace)
File
"/home/ebrosh/Documents/ebroshWorks/tcworks/Al-Fe-solidification/showBug.py",
line 13, in
data = equilibrium(db, ['AL', 'FE','VA'], ['LIQUID','AL13FE4'],
{v.X('FE'): .82, v.T: 450.0, v.P: 1e5},verbose=True)
File
"/usr/local/lib/python3.4/dist-packages/pycalphad-0.2.1.post1-py3.4.egg/pycalphad/core/equilibrium.py",
line 175, in equilibrium
lower_convex_hull(grid, properties)
File
"/usr/local/lib/python3.4/dist-packages/pycalphad-0.2.1.post1-py3.4.egg/pycalphad/core/lower_convex_hull.py",
line 72, in lower_convex_hull
_initialize_array(global_grid, result_array)
File
"/usr/local/lib/python3.4/dist-packages/pycalphad-0.2.1.post1-py3.4.egg/pycalphad/core/lower_convex_hull.py",
line 19, in _initialize_array
raise ValueError('Input energy surface contains one or more NaNs.')
ValueError: Input energy surface contains one or more NaNs.

On Sun, Sep 27, 2015 at 6:05 PM, Eli Brosh ebrosh1@gmail.com wrote:

My numpy version is
numpy.version
'1.8.2'
The TDB file was just downloaded from the pycalphad site

https://raw.githubusercontent.com/richardotis/pycalphad/develop/research/alfe_sei.TDB

On Sun, Sep 27, 2015 at 5:57 PM, Richard Otis <
notifications@github.com> wrote:

Other things to check:

  • your version of numpy (mine is 1.9.3)
  • your TDB file, to make sure it hasn't been changed from the
    version in the repository (still shouldn't fail in principle, but this will
    help to reproduce the bug)


Reply to this email directly or view it on GitHub
#23 (comment)
.

@richardotis

This comment has been minimized.

Copy link
Collaborator

commented Sep 28, 2015

Okay, with this script I can now reproduce your singular matrix error at v.X('FE'): .58, v.T: 875.0. It looks like a numerical instability the code is not catching. I will get some sort of resolution together in the next few days.

@richardotis

This comment has been minimized.

Copy link
Collaborator

commented Sep 29, 2015

I think I have at least a temporary solution. I'm not comfortable merging it into the codebase yet, but you can try adding the following to the top of your script, and let me know if it solves the errors.

import pycalphad.core.equilibrium
pycalphad.core.equilibrium.MIN_STEP_LENGTH = 1e-09

This makes your script run to completion for me, but I've also noticed this bug is very sneaky (as most numerical bugs are) and will disappear when I re-order or slightly perturb the conditions, so I'm going to write some good tests for this before I commit it to the repository.

@broshe

This comment has been minimized.

Copy link
Author

commented Sep 30, 2015

Thanks Richard,
This does solve the problem.

Eli

On Tue, Sep 29, 2015 at 11:44 PM, Richard Otis notifications@github.com
wrote:

I think I have at least a temporary solution. I'm not comfortable merging
it into the codebase yet, but you can try adding the following to the top
of your script, and let me know if it solves the errors.

import pycalphad.core.equilibrium
pycalphad.core.equilibrium.MIN_STEP_LENGTH = 1e-09


Reply to this email directly or view it on GitHub
#23 (comment)
.

@broshe

This comment has been minimized.

Copy link
Author

commented Oct 2, 2015

Hi Richard,
I found that the origin of the noise in my calculation of entropy of formation is the calculated Gibbs energy of Al13Fe4.
Attached are a figure of molar Gibbs energy of Al13Fe4 as function of temperature and a script with which it was calculated. Note the strange spikes around 970K and 1020K.
This is some kind of a numerical problem calculation.
This is done with anaconda python and pycalphad 0.21post.

Eli

Script:

from pycalphad import Database, equilibrium
import pycalphad.core.equilibrium
pycalphad.core.equilibrium.MIN_STEP_LENGTH = 1e-09
import pycalphad.variables as v
import numpy as np
from pylab import *

db = Database('/home/ebrosh/Documents/ebroshWorks/tcworks/Al-Fe-solidification/alfe_sei.TDB')

n=200.0
irange=np.arange(0,n+1,1)

Tlow=950.0
Thigh=1050.0

T=Thigh-(Thigh-Tlow)*irange/n
G=zeros(size(T))

for i in irange:
data = equilibrium(db, ['AL', 'FE','VA'], 'AL13FE4', {v.X('FE'): 4.0/17, v.T: T[i], v.P: 1e5},verbose=False)
G[i]=data['GM'].values.flatten()

print(i,T[i],G[i])

figure(1)
plot(T,G,'ko-')
xlabel('T [K]')
ylabel('Gm for AL13FE4' )

show(block=False)

noise_in_calculation_of_g

@richardotis

This comment has been minimized.

Copy link
Collaborator

commented Oct 2, 2015

I am able to reproduce one of the strange energy results by computing at 973 K. I'll take a look at this and figure out what's going on. It looks like something similar to the previous issue.

@richardotis

This comment has been minimized.

Copy link
Collaborator

commented Oct 13, 2015

Hi Eli, I wanted to give you a brief update. The underlying problem is that under certain, difficult to predict circumstances, a matrix used in the solver to compute steps towards equilibrium can become poorly conditioned. Inverting a poorly conditioned matrix (as the algorithm does) can produce meaningless results. This is a well-known issue in the numerical methods community and there are several methods to address it.

At the moment I have another unrelated project to complete, but after that I will return to this issue, hopefully towards the end of the month.

As a workaround for now, if you see a strange result, try adding or subtracting .001 from the temperature or composition. It shouldn't alter the result too much and you can see if it's the bug.

@broshe

This comment has been minimized.

Copy link
Author

commented Oct 14, 2015

Thanks Richard,
So, in order to avoid an incosistency at a certain temperature, I can
calculate several points around and take the median.
This should do for now.

Eli

On Tue, Oct 13, 2015 at 7:24 PM, Richard Otis notifications@github.com
wrote:

Hi Eli, I wanted to give you a brief update. The underlying problem is
that under certain, difficult to predict circumstances, a matrix used in
the solver to compute steps towards equilibrium can become poorly
conditioned. Inverting a poorly conditioned matrix (as the algorithm does)
can produce meaningless results. This is a well-known issue in the
numerical methods community and there are several methods to address it.

At the moment I have another unrelated project to complete, but after that
I will return to this issue, hopefully towards the end of the month.

As a workaround for now, if you see a strange result, try adding or
subtracting .001 from the temperature or composition. It shouldn't alter
the result too much and you can see if it's the bug.


Reply to this email directly or view it on GitHub
#23 (comment)
.

@richardotis

This comment has been minimized.

Copy link
Collaborator

commented Oct 18, 2015

Hi Eli, as of version 0.2.2 (just released) this should be fixed. Please upgrade your pycalphad and give it a try.

@broshe

This comment has been minimized.

Copy link
Author

commented Oct 20, 2015

Hi Richard,
I tried it but still does not work consistently.

For example:

data = equilibrium(db, ['AL', 'FE','VA'], 'AL13FE4', {v.X('FE'): 4.0/17,
v.T: 1249.5, v.P: 1e5},verbose=False)

gives error messages:

/home/ebrosh/anaconda3/lib/python3.4/site-packages/numpy/init.py:1:
RuntimeWarning: overflow encountered in power
"""
/home/ebrosh/anaconda3/lib/python3.4/site-packages/pycalphad-0.2.2-py3.4.egg/pycalphad/core/equilibrium.py:289:
RuntimeWarning: invalid value encountered in less
/home/ebrosh/anaconda3/lib/python3.4/site-packages/pycalphad-0.2.2-py3.4.egg/pycalphad/core/equilibrium.py:317:
RuntimeWarning: invalid value encountered in less
Traceback (most recent call last):
File
"/home/ebrosh/Documents/ebroshWorks/tcworks/Al-Fe-solidification/showBug.py",
line 15, in
data = equilibrium(db, ['AL', 'FE','VA'], 'AL13FE4', {v.X('FE'):
4.0/17, v.T: 1249.5, v.P: 1e5},verbose=False)
File
"/home/ebrosh/anaconda3/lib/python3.4/site-packages/pycalphad-0.2.2-py3.4.egg/pycalphad/core/equilibrium.py",
line 175, in equilibrium
File
"/home/ebrosh/anaconda3/lib/python3.4/site-packages/pycalphad-0.2.2-py3.4.egg/pycalphad/core/lower_convex_hull.py",
line 72, in lower_convex_hull
File
"/home/ebrosh/anaconda3/lib/python3.4/site-packages/pycalphad-0.2.2-py3.4.egg/pycalphad/core/lower_convex_hull.py",
line 19, in _initialize_array
ValueError: Input energy surface contains one or more NaNs.

These are similar to what appeared before the correction.
Eli

On Sun, Oct 18, 2015 at 3:08 AM, Richard Otis notifications@github.com
wrote:

Hi Eli, as of version 0.2.2 (just released) this should be fixed. Please
upgrade your pycalphad and give it a try.


Reply to this email directly or view it on GitHub
#23 (comment)
.

@richardotis

This comment has been minimized.

Copy link
Collaborator

commented Oct 20, 2015

I'll take another look and see if I can't work out a more robust solution.

@richardotis

This comment has been minimized.

Copy link
Collaborator

commented Nov 5, 2015

@broshe Just wanted to give you an update. I tore out and rewrote the offending routines. pycalphad will now compute exact Hessians instead of approximations. We take a performance hit but I made up for it with some improvements to the iterative solver. With these changes all your errors will (hopefully) go away. I hope to have something to release next week.

@richardotis

This comment has been minimized.

Copy link
Collaborator

commented Nov 9, 2015

@broshe I think the problem is now fixed in the develop branch, with some performance improvements too. Here is what I get when I plot the liquidus temperature. The graph bottoms out at 400 K since that was set as the lower bound for the search temperature.
image

I am staging the release now and am just verifying that all the tests pass on all platforms and the documentation is up to date. I will post another message when it's released.

@richardotis

This comment has been minimized.

Copy link
Collaborator

commented Nov 9, 2015

@broshe pycalphad 0.2.3 (0.2.3.post1 if you download from conda) is now available. Let me know if it solves your problems.

@broshe

This comment has been minimized.

Copy link
Author

commented Nov 9, 2015

Thank you very much Richard,
I am looking forward to the new release.
Eli

On Mon, Nov 9, 2015 at 2:13 AM, Richard Otis notifications@github.com
wrote:

@broshe https://github.com/broshe I think the problem is now fixed in
the develop branch, with some performance improvements too. Here is what I
get when I plot the liquidus temperature. The graph bottoms out at 400 K
since that was set as the lower bond for the search temperature.
[image: image]
https://cloud.githubusercontent.com/assets/6405510/11023632/b52bbd02-864c-11e5-8155-991cdcdb1dfe.png

I am staging the release now and am just verifying that all the tests pass
on all platforms and the documentation is up to date. I will post another
message when it's released.


Reply to this email directly or view it on GitHub
#23 (comment)
.

@richardotis

This comment has been minimized.

Copy link
Collaborator

commented Nov 9, 2015

@broshe The release is out now. Please upgrade.

@broshe

This comment has been minimized.

Copy link
Author

commented Nov 9, 2015

OK.
I upgraded and checking.
I will write when I have results.
Eli

On Mon, Nov 9, 2015 at 5:36 AM, Richard Otis notifications@github.com
wrote:

@broshe https://github.com/broshe The release is out now. Please
upgrade.


Reply to this email directly or view it on GitHub
#23 (comment)
.

@broshe

This comment has been minimized.

Copy link
Author

commented Nov 12, 2015

Hi Richard,
I ran several tests on the new version.
This is a big improvement.
There are no "spikes" in the calculations of Gibbs energy. The entropy of
formation is now calculable.

There was one instance were i got error messages but the calculation
results were correct.
Here is were the error message appeared:

data = equilibrium(db, ['AL', 'FE','VA'], ['LIQUID','AL13FE4'], {v.X('FE'):
1.0E-4, v.T: 1200.0, v.P: 1e5},verbose=False)

message:
/home/ebrosh/anaconda3/lib/python3.4/site-packages/autograd-1.1.1-py3.4-linux-x86_64.egg/autograd/core.py:161:
RuntimeWarning: divide by zero encountered in power
/home/ebrosh/anaconda3/lib/python3.4/site-packages/autograd-1.1.1-py3.4-linux-x86_64.egg/autograd/numpy/numpy_grads.py:73:
RuntimeWarning: invalid value encountered in multiply
/home/ebrosh/anaconda3/lib/python3.4/site-packages/autograd-1.1.1-py3.4-linux-x86_64.egg/autograd/core.py:161:
RuntimeWarning: divide by zero encountered in log
/home/ebrosh/anaconda3/lib/python3.4/site-packages/autograd-1.1.1-py3.4-linux-x86_64.egg/autograd/core.py:161:
RuntimeWarning: invalid value encountered in multiply
/home/ebrosh/anaconda3/lib/python3.4/site-packages/autograd-1.1.1-py3.4-linux-x86_64.egg/autograd/core.py:161:
RuntimeWarning: invalid value encountered in true_divide
/home/ebrosh/anaconda3/lib/python3.4/site-packages/autograd-1.1.1-py3.4-linux-x86_64.egg/autograd/numpy/numpy_grads.py:74:
RuntimeWarning: invalid value encountered in multiply
/home/ebrosh/anaconda3/lib/python3.4/site-packages/autograd-1.1.1-py3.4-linux-x86_64.egg/autograd/core.py:161:
RuntimeWarning: divide by zero encountered in true_divide

Thank you very much for the effort you are making with these bugs.

Eli

On Mon, Nov 9, 2015 at 5:41 AM, Eli Brosh ebrosh1@gmail.com wrote:

OK.
I upgraded and checking.
I will write when I have results.
Eli

On Mon, Nov 9, 2015 at 5:36 AM, Richard Otis notifications@github.com
wrote:

@broshe https://github.com/broshe The release is out now. Please
upgrade.


Reply to this email directly or view it on GitHub
#23 (comment)
.

@richardotis

This comment has been minimized.

Copy link
Collaborator

commented Nov 12, 2015

Glad to help. For the warnings, those are probably generated by code paths that aren't used in the calculation but still get computed anyway. In the future the calculator will only compute valid code paths, but for now it should be safe to ignore the warnings.

I'm going to close this issue since it looks like you're set. Thanks again for the report.

@richardotis richardotis changed the title molar entropy and partial molar entropy Numerical stability issue with equilibrium calculation Nov 12, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.