Giter VIP home page Giter VIP logo

Comments (33)

richardotis avatar richardotis commented on May 27, 2024

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.

from pycalphad.

richardotis avatar richardotis commented on May 27, 2024

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

from pycalphad.

broshe avatar broshe commented on May 27, 2024

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 [email protected]
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
https://github.com/richardotis/pycalphad/issues/23#issuecomment-142993153
.

from pycalphad.

richardotis avatar richardotis commented on May 27, 2024

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.

from pycalphad.

broshe avatar broshe commented on May 27, 2024

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

from pycalphad.

richardotis avatar richardotis commented on May 27, 2024

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

from pycalphad.

richardotis avatar richardotis commented on May 27, 2024

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)

from pycalphad.

richardotis avatar richardotis commented on May 27, 2024

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)

from pycalphad.

broshe avatar broshe commented on May 27, 2024

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 [email protected]
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
https://github.com/richardotis/pycalphad/issues/23#issuecomment-143563752
.

from pycalphad.

broshe avatar broshe commented on May 27, 2024

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 [email protected]
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
https://github.com/richardotis/pycalphad/issues/23#issuecomment-143564182
.

from pycalphad.

broshe avatar broshe commented on May 27, 2024

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 [email protected] 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 [email protected]
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
https://github.com/richardotis/pycalphad/issues/23#issuecomment-143564182
.

from pycalphad.

broshe avatar broshe commented on May 27, 2024

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 [email protected] 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 [email protected] 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 [email protected]
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
https://github.com/richardotis/pycalphad/issues/23#issuecomment-143564182
.

from pycalphad.

broshe avatar broshe commented on May 27, 2024

The same with v.T: 875.0

On Mon, Sep 28, 2015 at 9:24 AM, Eli Brosh [email protected] 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 [email protected] 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 [email protected] 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 [email protected]
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
https://github.com/richardotis/pycalphad/issues/23#issuecomment-143564182
.

from pycalphad.

broshe avatar broshe commented on May 27, 2024

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 [email protected] wrote:

The same with v.T: 875.0

On Mon, Sep 28, 2015 at 9:24 AM, Eli Brosh [email protected] 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 [email protected] 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 [email protected] 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 <[email protected]

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
https://github.com/richardotis/pycalphad/issues/23#issuecomment-143564182
.

from pycalphad.

broshe avatar broshe commented on May 27, 2024

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 [email protected] 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 [email protected] wrote:

The same with v.T: 875.0

On Mon, Sep 28, 2015 at 9:24 AM, Eli Brosh [email protected] 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 [email protected] 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 [email protected] 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 <
[email protected]> 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
https://github.com/richardotis/pycalphad/issues/23#issuecomment-143564182
.

from pycalphad.

richardotis avatar richardotis commented on May 27, 2024

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.

from pycalphad.

richardotis avatar richardotis commented on May 27, 2024

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.

from pycalphad.

broshe avatar broshe commented on May 27, 2024

Thanks Richard,
This does solve the problem.

Eli

On Tue, Sep 29, 2015 at 11:44 PM, Richard Otis [email protected]
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
https://github.com/richardotis/pycalphad/issues/23#issuecomment-144186338
.

from pycalphad.

broshe avatar broshe commented on May 27, 2024

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

from pycalphad.

richardotis avatar richardotis commented on May 27, 2024

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.

from pycalphad.

richardotis avatar richardotis commented on May 27, 2024

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.

from pycalphad.

broshe avatar broshe commented on May 27, 2024

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 [email protected]
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
https://github.com/richardotis/pycalphad/issues/23#issuecomment-147767630
.

from pycalphad.

richardotis avatar richardotis commented on May 27, 2024

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

from pycalphad.

broshe avatar broshe commented on May 27, 2024

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 [email protected]
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
https://github.com/richardotis/pycalphad/issues/23#issuecomment-148962856
.

from pycalphad.

richardotis avatar richardotis commented on May 27, 2024

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

from pycalphad.

richardotis avatar richardotis commented on May 27, 2024

@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.

from pycalphad.

richardotis avatar richardotis commented on May 27, 2024

@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.

from pycalphad.

richardotis avatar richardotis commented on May 27, 2024

@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.

from pycalphad.

broshe avatar broshe commented on May 27, 2024

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 [email protected]
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
https://github.com/richardotis/pycalphad/issues/23#issuecomment-154889663
.

from pycalphad.

richardotis avatar richardotis commented on May 27, 2024

@broshe The release is out now. Please upgrade.

from pycalphad.

broshe avatar broshe commented on May 27, 2024

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

On Mon, Nov 9, 2015 at 5:36 AM, Richard Otis [email protected]
wrote:

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


Reply to this email directly or view it on GitHub
https://github.com/richardotis/pycalphad/issues/23#issuecomment-154910472
.

from pycalphad.

broshe avatar broshe commented on May 27, 2024

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 [email protected] 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 [email protected]
wrote:

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


Reply to this email directly or view it on GitHub
https://github.com/richardotis/pycalphad/issues/23#issuecomment-154910472
.

from pycalphad.

richardotis avatar richardotis commented on May 27, 2024

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.

from pycalphad.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.