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

Solver improvements via IPOPT #124

Merged
merged 101 commits into from
Nov 25, 2017
Merged
Show file tree
Hide file tree
Changes from 79 commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
922d137
WIP: Initial memory cleanup work
richardotis May 20, 2017
813ba0b
WIP: Profiling and memory and speed perf attempts
richardotis May 22, 2017
4dffa3c
WIP: eqsolver constraints and add_new_phases: perf improvements by pr…
richardotis May 22, 2017
7c0d71a
WIP: eqsolver: Remove debugging code
richardotis May 22, 2017
d1cfc5b
WIP: nogil in eval_energy
richardotis May 23, 2017
ea0db25
WIP: eval_energy nogil
richardotis May 23, 2017
962b3b0
WIP: _eval_disordered_energy and _eval_energy_gradient nogil
richardotis May 23, 2017
40df868
WIP: revert _eval_energy_gradient nogil
richardotis May 23, 2017
bf89e78
WIP: _eval_energy_gradient nogil fixed with calloc
richardotis May 23, 2017
ec3264c
WIP: eval_energy_gradient nogil
richardotis May 23, 2017
7d45404
WIP: eval_energy_hessian and update nogil
richardotis May 23, 2017
b046204
WIP: eqsolver: type declaration cleanup
richardotis May 23, 2017
599880c
ENH: eqsolver: Add more line search iterations for performance
richardotis May 24, 2017
43dcecc
WIP: eval_energy: change to pointer for out argument
richardotis May 24, 2017
955baef
WIP: eval_energy_gradient and eval_energy fully release gil
richardotis May 25, 2017
5a995f7
WIP: eval_energy_hessian fully release gil
richardotis May 25, 2017
b174eee
FIX: eqsolver: Add guard for singular matrices during solve
richardotis May 25, 2017
be80820
FIX: eqsolver: Convergence at lower point density by fixing bugs in a…
richardotis May 26, 2017
580ef69
FIX: eqsolver: Performance and stability improvements
richardotis May 26, 2017
563e407
WIP: eqsolver: Incomplete attempt at getting Hillert's two-step metho…
richardotis Jun 14, 2017
38ef883
ENH/WIP: eqsolver: Add constant-potential refinement to add_new_phase…
richardotis Jun 16, 2017
9de0ced
Merge branch 'fix_memory' of github.com:pycalphad/pycalphad into fix_…
richardotis Jun 16, 2017
e56fd2f
FIX: eqsolver: Snapshot with tests passing
richardotis Jun 17, 2017
f5910a5
WIP: Snapshot with passing tests and two conv failures on Al-Zn
richardotis Jun 17, 2017
02c0e2a
WIP: Snapshot with good Al-Zn but many single-phase failures
richardotis Jun 18, 2017
72dba20
WIP: Snapshot with no wrong answers but lots of conv failures. Tests …
richardotis Jun 19, 2017
e9e4ffc
WIP: Snapshot of really slow but seemingly robust solver. Having trou…
richardotis Jun 19, 2017
62470e8
WIP: eqsolver: Add initial remove_degenerate_phases() back
richardotis Jun 19, 2017
7a8504c
WIP: Snapshot with all but one test passing
richardotis Jun 20, 2017
c56d5ac
WIP: py27 compat for add_new_phases
richardotis Jun 20, 2017
5f4e7cd
WIP: eqsolver: TESTS PASS SHIP IT
richardotis Jun 21, 2017
6909333
WIP: eqsolver: Tests passing but still Al-Zn convergence failures
richardotis Jun 21, 2017
130981e
WIP: eqsolver: Tests pass relatively quickly
richardotis Jun 22, 2017
ea8afb4
WIP: Set MIN_PHASE_FRACTION and remove dead code
richardotis Jun 22, 2017
d5ab926
WIP: hyperplane: Fixes for edge cases
richardotis Jun 28, 2017
1d901c5
WIP: eqsolver: Key tests pass
richardotis Jun 28, 2017
64d8417
WIP: eqsolver: Change phases if alpha==0
richardotis Jun 28, 2017
12d070a
WIP: System class for abstracting the problem details from the solver
richardotis Jul 2, 2017
1a395d4
WIP: System: Minimal implementation
richardotis Jul 2, 2017
2d656a0
WIP: System/eqsolver: Initial attempt at ipopt support
richardotis Jul 3, 2017
5b4e8f1
WIP: System: Fix indexing for constraint calculation
richardotis Jul 3, 2017
dcb7e27
WIP: System: Fix indexing errors so derivative checker passes
richardotis Jul 3, 2017
8c0d5e9
WIP:System: Remove extraneous debugging print
richardotis Jul 3, 2017
9067a6c
WIP: eqsolver: Initial hacky attempt to switch ipopt on in the solver
richardotis Jul 3, 2017
e0c6db8
WIP: eqsolver: Indexing fixes and some attempts at integrating global…
richardotis Jul 3, 2017
8137646
WIP: eqsolver: Fixes for global min integration and result calculation
richardotis Jul 3, 2017
ac963a7
WIP: eqsolver/hyperplane/system: Fiddle with convergence settings unt…
richardotis Jul 8, 2017
689e238
REF/MAINT: Rename System to Problem
richardotis Jul 8, 2017
38b4767
REF: Create Solver class and abstract away some of the details from t…
richardotis Jul 9, 2017
650202d
ENH: CompositionSet: Add GM to CompositionSet.__str__
richardotis Jul 9, 2017
ae2afb0
Merge remote-tracking branch 'origin/fix_memory' into fix_memory
richardotis Jul 10, 2017
513576b
WIP: Progress with making chemical potentials primal variables
richardotis Jul 10, 2017
194a7b2
Revert "WIP: Progress with making chemical potentials primal variables"
richardotis Jul 11, 2017
13bcc26
FIX: hyperplane: Memory corruption during phase fraction calculation
richardotis Jul 11, 2017
0a66b94
WIP: Loosen upper bounds and debugging output
richardotis Jul 11, 2017
6259361
WIP: More debugging output and an updated test
richardotis Jul 12, 2017
d7ac61e
WIP/FIX: hyperplane fixes and continued convergence tweaks
richardotis Jul 13, 2017
d40a2b0
WIP/FIX: Disable hyperplane debugging output and stop calling ipopt i…
richardotis Jul 13, 2017
5a7ce8c
WIP: More solver debugging tweaks without globmin
richardotis Jul 14, 2017
c9ebb7b
WIP: Progress in finding optimal points without globmin
richardotis Jul 15, 2017
0eaa74a
WIP: eqsolver: All tests converge, though not necessarily optimally
richardotis Jul 15, 2017
10ca65e
WIP: Remove dead code
richardotis Jul 16, 2017
bd2e833
WIP: Disable debugging code
richardotis Jul 16, 2017
6645aeb
FIX: eqsolver: Inf norm calculation
richardotis Jul 18, 2017
20eaf0c
ENH/FIX: eqsolver: Mostly working and passing (modified) tests
richardotis Jul 18, 2017
5762f38
FIX/WIP: solver: Tweak complementarity tol to get convergence on one …
richardotis Jul 19, 2017
f2f5301
TST/FIX: Add cyipopt to dependencies
richardotis Jul 20, 2017
87b9ae0
FIX: Remove NumPyPrinter due to sympy 1.1 incompatibility. Other symp…
richardotis Jul 20, 2017
d1cfd9f
MAINT: eqsolver: Remove dead code
richardotis Jul 29, 2017
006aa37
Merge branch 'develop' into fix_memory
richardotis Aug 1, 2017
6242690
FIX: add_new_phases: Misalignment of phase fractions array due to non…
richardotis Aug 1, 2017
ea367db
WIP: add_new_phases: Force endmembers to always be candidates for inc…
richardotis Aug 7, 2017
4fd5a0c
WIP: Continued attempts at global minimization improvement.
richardotis Aug 7, 2017
31252b3
WIP: add_new_phases: Add all stable phases plus the phase with the la…
richardotis Aug 7, 2017
8dcd56c
Merge branch 'develop' into fix_memory
richardotis Aug 14, 2017
00d2d6a
ENH: CompositionSet: deepcopy support
richardotis Sep 6, 2017
4f66221
WIP: eqsolver: Clean up and simplify global minimization code. Doesn'…
richardotis Sep 6, 2017
b598900
FIX/WIP: Get tests passing at pdens=500 with ipopt. Use a two-step ap…
richardotis Sep 14, 2017
66e3fc2
WIP: eqsolver: For pdens=50, pass all tests with solver tweaks for ca…
richardotis Sep 14, 2017
804f875
DOC/FIX: BinaryExamples: Bump results and fix error in energy plot.
richardotis Nov 3, 2017
c64c3b2
FIX: equilibrium: Reset default pdens to 500 to address ternary misci…
richardotis Nov 4, 2017
4ef8a7a
BLD/FIX: appveyor: Bump miniconda to fix broken conda
richardotis Nov 4, 2017
4790d65
WIP: Merge latest develop
richardotis Nov 13, 2017
147094d
Merge branch 'develop' into fix_memory
richardotis Nov 13, 2017
16ccba3
MAINT: core: Remove obsolete cymem-related code
richardotis Nov 13, 2017
d21a36b
MAINT: compiled_model: Remove cython debugging directives
richardotis Nov 13, 2017
2169906
MAINT: hyperplane: Remove extraneous print statements
richardotis Nov 13, 2017
eea3d1c
MAINT: Problem: Remove extraneous comments on hessian implementation
richardotis Nov 13, 2017
7fe6f42
MAINT: solver: Remove extraneous commented-out print statements
richardotis Nov 13, 2017
eeeb854
TST/MAINT: test_equilibrium: Clean up assertions
richardotis Nov 13, 2017
a861daf
BLD/TST: travis: Drop py34 and disable Dockerization to ease dependen…
richardotis Nov 13, 2017
bde216c
MAINT: core: Refactor solver constants to be in core.constants
richardotis Nov 13, 2017
fe7e0db
FIX/TST: Use matplotlib 'Agg' backend in tests to avoid issues no DIS…
bocklund Nov 13, 2017
eae81ff
BLD: appveyor: Add msys2 and pycalphad channels to enable ipopt
richardotis Nov 24, 2017
5c3a778
Merge branch 'develop' into fix_memory
richardotis Nov 24, 2017
1ae47d5
BLD/WIP: appveyor: Fix conda channel add
richardotis Nov 24, 2017
f1f868e
FIX: equilibrium: dask module rename compat
richardotis Nov 24, 2017
12f485a
FIX: calculate: Remove fast_concat due to reliance on xarray internal…
richardotis Nov 24, 2017
83d1e1c
FIX: custom_autowrap: Import correctly on Windows
richardotis Nov 24, 2017
533b580
FIX: solver: Increase ipopt max_iter to fix Windows
richardotis Nov 24, 2017
ee5cda8
BLD: appveyor: Bump py27 to 64-bit
richardotis Nov 24, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ install:
if [ -z "$DOCKER_TAG" ]; then
source $HOME/miniconda2/bin/activate condaenv
conda install --yes python=$TRAVIS_PYTHON_VERSION numpy scipy matplotlib nose pandas sympy pyparsing dask dill
conda install --yes xarray gcc cython
conda install --yes xarray gcc cython cyipopt
pip install -e .
fi

Expand All @@ -60,5 +60,5 @@ script:
coveralls
else
env -u PATH -u PYTHONPATH -u LANG -u PWD -u HOME -u TRAVIS_COMMIT_MESSAGE > ./env.list
docker run --rm --env-file ./env.list -v $(pwd):/pycalphad:rw -it $DOCKER_USER/pycalphad:$DOCKER_TAG /bin/bash -c "cd /pycalphad ; source /work/miniconda/envs/condaenv/bin/activate condaenv ; nosetests --with-coverage ; pip install sphinx sphinx_rtd_theme coveralls ; bash ci/deploy.sh ; coveralls"
docker run --rm --env-file ./env.list -v $(pwd):/pycalphad:rw -it $DOCKER_USER/pycalphad:$DOCKER_TAG /bin/bash -c "cd /pycalphad ; source /work/miniconda/envs/condaenv/bin/activate condaenv && nosetests --with-coverage && pip install sphinx sphinx_rtd_theme coveralls && bash ci/deploy.sh && coveralls"
fi
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ install:
- "conda config --add channels conda-forge"
# install pycalphad and dependencies
- "conda install --yes -n condaenv --quiet pip setuptools nose numpy pandas scipy sympy pyparsing matplotlib xarray dask dill"
- "conda install --yes -n condaenv --quiet tinydb cython"
- "conda install --yes -n condaenv --quiet tinydb cython cyipopt"
- "pip install -e ."

build: false
Expand Down
1 change: 1 addition & 0 deletions ci/Dockerfile.base
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ RUN wget -O miniconda.sh \
&& \
conda config --add channels conda-forge && \
conda create -n condaenv --quiet -y python=$python \
cyipopt \
cython \
matplotlib \
pyparsing \
Expand Down
1 change: 1 addition & 0 deletions conda_recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ requirements:
- numpy >=1.9
- Cython >=0.24
- dill
- cyipopt

build:
script: python setup.py build && python setup.py install
Expand Down
16 changes: 8 additions & 8 deletions pycalphad/core/compiled_model.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ cdef public class CompiledModel(object)[type CompiledModelType, object CompiledM
double *eval_row, double[:] parameters) nogil
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think cymem is dead now so the following needs to be cleaned up

compiled_model.pxd

  • cdef public Pool mem in line 39.
  • As well as the import in line 2.

In compiled_model.pyx:

  • self.mem = Pool()(line 56)
  • import in line 2
  • inst.mem in line 1071
  • Pool() in line 1018

In addition the

  • cymem.pyx and pxd
  • cymem license
  • cymem cythonize in setup.py

cdef void _eval_rk_matrix_gradient(self, double *out, double[:,:] coef_mat, double[:,:] symbol_mat,
double *eval_row, double[:] parameters) nogil
cdef void _compute_disordered_dof(self, double[:,:] disordered_dof, double[:,:] dof) nogil
cdef void _compute_ordered_dof(self, double[:,:] ordered_dof, double[:,:] disordered_dof) nogil
cpdef void _eval_energy(self, double[::1] out, double[:,:] dof, double[:] parameters, double sign)
cdef _eval_disordered_energy(self, double[::1] out, double[:] dof, double[:] parameters, double sign)
cpdef eval_energy(self, double[::1] out, double[:,:] dof, double[:] parameters)
cpdef _eval_energy_gradient(self, double[::1] out_grad, double[:] dof, double[:] parameters, double sign)
cpdef eval_energy_gradient(self, double[::1] out, double[:] dof, double[:] parameters)
cdef void _compute_disordered_dof(self, double *disordered_dof, double *dof, size_t num_pts) nogil
cdef void _compute_ordered_dof(self, double *ordered_dof, double *disordered_dof, size_t num_pts) nogil
cdef void _eval_energy(self, double *out, double *dof, double[:] parameters, double sign, size_t num_pts) nogil
cdef void _eval_disordered_energy(self, double *out, double *dof, double[:] parameters, double sign) nogil
cdef void eval_energy(self, double *out, double *dof, double[:] parameters, size_t num_pts) nogil
cdef void _eval_energy_gradient(self, double *out_grad, double *dof, double[:] parameters, double sign) nogil
cdef void eval_energy_gradient(self, double *out, double *dof, double[:] parameters) nogil
cdef _debug_energy(self, double[::1] debugout, double[:,::1] dof, double[::1] parameters)
cdef _debug_energy_gradient(self, double[::1] debugout, double[::1] dof, double[::1] parameters)
cpdef void eval_energy_hessian(self, double[:, ::1] out, double[:] dof, double[:] parameters)
cdef void eval_energy_hessian(self, double[:, ::1] out, double[:] dof, double[:] parameters) nogil
461 changes: 259 additions & 202 deletions pycalphad/core/compiled_model.pyx

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions pycalphad/core/composition_set.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ cdef public class CompositionSet(object)[type CompositionSetType, object Composi
cdef readonly double[:, ::1] mass_grad
cdef readonly double[:, :, :] mass_hess
cdef public double NP
cdef public int zero_seen
cdef readonly double energy
cdef double[::1] _energy_2d_view
cdef readonly double[::1] grad
Expand All @@ -20,5 +21,5 @@ cdef public class CompositionSet(object)[type CompositionSetType, object Composi
cdef void reset(self)
cdef void _hessian_update(self, double[::1] dof, double[:] prev_dof, double[:,::1] current_hess,
double[:,:] prev_hess, double[:] current_grad, double[:] prev_grad,
double* energy, double* prev_energy)
cdef void update(self, double[::1] site_fracs, double phase_amt, double pressure, double temperature)
double* energy, double* prev_energy) nogil
cdef void update(self, double[::1] site_fracs, double phase_amt, double pressure, double temperature, bint skip_derivatives) nogil
91 changes: 64 additions & 27 deletions pycalphad/core/composition_set.pyx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from pycalphad.core.phase_rec cimport PhaseRecord
cimport numpy as np
import numpy as np
from libc.stdlib cimport malloc, free
from libc.string cimport memset
from libc.math cimport fabs
cimport cython

cdef public class CompositionSet(object)[type CompositionSetType, object CompositionSetObject]:
"""
Expand All @@ -14,13 +18,15 @@ cdef public class CompositionSet(object)[type CompositionSetType, object Composi
def __cinit__(self, PhaseRecord prx):
cdef int has_va = <int>(prx.vacancy_index > -1)
self.phase_record = prx
self.zero_seen = 0
self.dof = np.zeros(len(self.phase_record.variables)+2)
self.X = np.zeros(self.phase_record.composition_matrices.shape[0]-has_va)
self.mass_grad = np.zeros((self.X.shape[0]+has_va, self.phase_record.phase_dof))
self.mass_hess = np.zeros((self.X.shape[0]+has_va, self.phase_record.phase_dof, self.phase_record.phase_dof))
self._dof_2d_view = <double[:1,:self.dof.shape[0]]>&self.dof[0]
self._X_2d_view = <double[:self.X.shape[0],:1]>&self.X[0]
self.energy = 0
self.NP = 0
self._energy_2d_view = <double[:1]>&self.energy
self.grad = np.zeros(self.dof.shape[0])
self.hess = np.zeros((self.dof.shape[0], self.dof.shape[0]))
Expand All @@ -30,28 +36,50 @@ cdef public class CompositionSet(object)[type CompositionSetType, object Composi
self._prev_hess = np.zeros((self.dof.shape[0], self.dof.shape[0]))
self._first_iteration = True

def __deepcopy__(self, memodict=None):
cdef int has_va = <int>(self.phase_record.vacancy_index > -1)
cdef CompositionSet other
memodict = {} if memodict is None else memodict
other = CompositionSet(self.phase_record)
other.phase_record = self.phase_record
other.zero_seen = 0
other.dof[:] = self.dof
other.X[:] = self.X
other.mass_grad[:,:] = self.mass_grad
other.mass_hess[:,:,:] = self.mass_hess
other.energy = 1.0*self.energy
other._energy_2d_view = <double[:1]>&other.energy
other.NP = 1.0*self.NP
other.grad[:] = self.grad
other.hess[:,:] = self.hess
return other

def __repr__(self):
return str(self.__class__.__name__) + "({0}, {1})".format(self.phase_record.phase_name, np.asarray(self.X))
return str(self.__class__.__name__) + "({0}, {1}, NP={2}, GM={3})".format(self.phase_record.phase_name,
np.asarray(self.X), self.NP, self.energy)

cdef void reset(self):
self.zero_seen = 0
self._prev_energy = 0
self._prev_dof[:] = 0
self._prev_grad[:] = 0
self._prev_hess[:,:] = 0
self._first_iteration = True

@cython.boundscheck(False)
@cython.wraparound(False)
cdef void _hessian_update(self, double[::1] dof, double[:] prev_dof, double[:,::1] current_hess,
double[:,:] prev_hess, double[:] current_grad, double[:] prev_grad,
double* energy, double* prev_energy):
double* energy, double* prev_energy) nogil:
# Notation from Nocedal and Wright, 2006, Equation 8.19
cdef int dof_idx, dof_idx_2
cdef int dof_len = dof.shape[0]
cdef double[:] sk = np.empty(dof_len)
cdef double[:] yk = np.empty(dof_len)
cdef double[:] bk_sk = np.empty(dof_len)
cdef double[:] ybk = np.empty(dof_len)
cdef double ybk_norm
cdef denominator = 0
cdef double *sk = <double*>malloc(dof_len * sizeof(double))
cdef double *yk = <double*>malloc(dof_len * sizeof(double))
cdef double *bk_sk = <double*>malloc(dof_len * sizeof(double))
cdef double *ybk = <double*>malloc(dof_len * sizeof(double))
cdef double ybk_norm = 0
cdef double denominator = 0

for dof_idx in range(dof_len):
sk[dof_idx] = dof[dof_idx] - prev_dof[dof_idx]
Expand All @@ -63,11 +91,12 @@ cdef public class CompositionSet(object)[type CompositionSetType, object Composi
for dof_idx_2 in range(dof_len):
bk_sk[dof_idx] += prev_hess[dof_idx, dof_idx_2] * sk[dof_idx_2]
ybk[dof_idx] = yk[dof_idx] - bk_sk[dof_idx]
ybk_norm += ybk[dof_idx] ** 2
denominator += ybk[dof_idx] * sk[dof_idx]
ybk_norm = np.linalg.norm(ybk)
ybk_norm = ybk_norm ** 0.5
# Fall back to finite difference approximation unless it's a "medium-size" step
# This is a really conservative approach and could probably be improved for performance
if abs(denominator) < 1e-2 or (ybk_norm < 1e-2) or (ybk_norm > 10):
if fabs(denominator) < 1e-2 or (ybk_norm < 1e-2) or (ybk_norm > 10):
self.phase_record.hess(current_hess, dof)
else:
# Symmetric Rank 1 (SR1) update
Expand All @@ -77,36 +106,44 @@ cdef public class CompositionSet(object)[type CompositionSetType, object Composi
prev_hess[dof_idx, dof_idx_2] + (ybk[dof_idx] * ybk[dof_idx_2] / denominator)
prev_hess[:,:] = current_hess
prev_energy[0] = energy[0]
free(sk)
free(yk)
free(bk_sk)
free(ybk)

cdef void update(self, double[::1] site_fracs, double phase_amt, double pressure, double temperature):
@cython.boundscheck(False)
@cython.wraparound(False)
cdef void update(self, double[::1] site_fracs, double phase_amt, double pressure, double temperature, bint skip_derivatives) nogil:
cdef int comp_idx
cdef int past_va = 0
self.dof[0] = pressure
self.dof[1] = temperature
self.dof[2:] = site_fracs
self.NP = phase_amt
self.energy = 0
self.grad[:] = 0
self.hess[:,:] = 0
self.X[:] = 0
self.mass_grad[:,:] = 0
self.mass_hess[:,:,:] = 0
memset(&self.grad[0], 0, self.grad.shape[0] * sizeof(double))
memset(&self.hess[0,0], 0, self.hess.shape[0] * self.hess.shape[1] * sizeof(double))
memset(&self.X[0], 0, self.X.shape[0] * sizeof(double))
memset(&self.mass_grad[0,0], 0, self.mass_grad.shape[0] * self.mass_grad.shape[1] * sizeof(double))
memset(&self.mass_hess[0,0,0], 0, self.mass_hess.shape[0] * self.mass_hess.shape[1] * self.mass_hess.shape[2] * sizeof(double))
self.phase_record.obj(self._energy_2d_view, self._dof_2d_view)
self.phase_record.grad(self.grad, self.dof)
if not skip_derivatives:
self.phase_record.grad(self.grad, self.dof)
for comp_idx in range(self.mass_grad.shape[0]):
if comp_idx == self.phase_record.vacancy_index:
past_va = 1
continue
self.phase_record.mass_obj(self._X_2d_view[comp_idx-past_va], site_fracs, comp_idx)
self.phase_record.mass_grad(self.mass_grad[comp_idx], site_fracs, comp_idx)
self.phase_record.mass_hess(self.mass_hess[comp_idx], site_fracs, comp_idx)
if self._first_iteration == True:
self.phase_record.hess(self.hess, self.dof)
self._prev_dof[:] = self.dof
self._prev_energy = self.energy
self._prev_grad[:] = self.grad
self._prev_hess[:,:] = self.hess
self._first_iteration = False
else:
self._hessian_update(self.dof, self._prev_dof, self.hess, self._prev_hess, self.grad, self._prev_grad,
&self.energy, &self._prev_energy)
if not skip_derivatives:
if self._first_iteration == True:
self.phase_record.hess(self.hess, self.dof)
self._prev_dof[:] = self.dof
self._prev_energy = self.energy
self._prev_grad[:] = self.grad
self._prev_hess[:,:] = self.hess
self._first_iteration = False
else:
self._hessian_update(self.dof, self._prev_dof, self.hess, self._prev_hess, self.grad, self._prev_grad,
&self.energy, &self._prev_energy)
4 changes: 2 additions & 2 deletions pycalphad/core/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"""
# Force zero values to this amount, for numerical stability
MIN_SITE_FRACTION = 1e-12
MIN_PHASE_FRACTION = 1e-12
MIN_PHASE_FRACTION = 1e-6
# Phases with mole fractions less than COMP_DIFFERENCE_TOL apart (by Chebyshev distance) are considered "the same" for
# the purposes of CompositionSet addition and removal during energy minimization.
COMP_DIFFERENCE_TOL = 1e-2
COMP_DIFFERENCE_TOL = 1e-4

# 'infinity' for numerical purposes
BIGNUM = 1e60
Loading