espei.error_functions package

Submodules

espei.error_functions.activity_error module

Calculate error due to measured activities.

espei.error_functions.activity_error.calculate_activity_error(dbf, comps, phases, datasets, parameters=None, phase_models=None, callables=None)

Return the sum of square error from activity data

Parameters:
  • dbf (pycalphad.Database) – Database to consider
  • comps (list) – List of active component names
  • phases (list) – List of phases to consider
  • datasets (espei.utils.PickleableTinyDB) – Datasets that contain single phase data
  • parameters (dict) – Dictionary of symbols that will be overridden in pycalphad.equilibrium
  • phase_models (dict) – Phase models to pass to pycalphad calculations
  • callables (dict) – Callables to pass to pycalphad
Returns:

A single float of the sum of square errors

Return type:

float

Notes

General procedure: 1. Get the datasets 2. For each dataset

  1. Calculate reference state equilibrium
  2. Calculate current chemical potentials
  3. Find the target chemical potentials
  4. Calculate error due to chemical potentials
espei.error_functions.activity_error.chempot_error(sample_chempots, target_chempots)

Return the sum of square error from chemical potentials

sample_chempots : numpy.ndarray
Calculated chemical potentials
target_activity : numpy.ndarray
Chemical potentials to target
Returns:Error due to chemical potentials
Return type:float
espei.error_functions.activity_error.target_chempots_from_activity(component, target_activity, temperatures, reference_result)

Return an array of experimental chemical potentials for the component

Parameters:
  • component (str) – Name of the component
  • target_activity (numpy.ndarray) – Array of experimental activities
  • temperatures (numpy.ndarray) – Ravelled array of temperatures (of same size as exp_activity).
  • reference_result (xarray.Dataset) – Dataset of the equilibrium reference state. Should contain a singe point calculation.
Returns:

Array of experimental chemical potentials

Return type:

numpy.ndarray

espei.error_functions.thermochemical_error module

Calculate error due to thermochemical quantities: heat capacity, entropy, enthalpy.

espei.error_functions.thermochemical_error.calculate_points_array(phase_constituents, configuration, occupancies=None)

Calculate the points array to use in pycalphad calculate calls.

Converts the configuration data (and occupancies for mixing data) into the points array by looking up the indices in the active phase constituents.

Parameters:
  • phase_constituents (list) – List of active constituents in a phase
  • configuration (list) – List of the sublattice configuration
  • occupancies (list) – List of sublattice occupancies. Required for mixing sublattices, otherwise takes no effect.
Returns:

Return type:

numpy.ndarray

Notes

Errors will be raised if components in the configuration are not in the corresponding phase constituents sublattice.

espei.error_functions.thermochemical_error.calculate_thermochemical_error(dbf, comps, phases, datasets, parameters=None, phase_models=None, callables=None)

Calculate the weighted single phase error in the Database

Parameters:
  • dbf (pycalphad.Database) – Database to consider
  • comps (list) – List of active component names
  • phases (list) – List of phases to consider
  • datasets (espei.utils.PickleableTinyDB) – Datasets that contain single phase data
  • parameters (dict) – Dictionary of symbols that will be overridden in pycalphad.calculate
  • phase_models (dict) – Phase models to pass to pycalphad calculations. Ideal mixing contributions must be removed.
  • callables (dict) – Dictionary of {output_property: callables_dict} where callables_dict is a dictionary of {phase_name: callables} to pass to pycalphad. These must have ideal mixing portions removed.
Returns:

A single float of the residual sum of square errors

Return type:

float

Notes

There are different single phase values, HM_MIX, SM_FORM, CP_FORM, etc. Each of these have different units and the error cannot be compared directly. To normalize all of the errors, a normalization factor must be used. Equation 2.59 and 2.60 in Lukas, Fries, and Sundman “Computational Thermodynamics” shows how this can be considered. Each type of error will be weighted by the reciprocal of the estimated uncertainty in the measured value and conditions. The weighting factor is calculated by $ p_i = (Delta L_i)^{-1} $ where $ Delta L_i $ is the uncertainty in the measurement. We will neglect the uncertainty for quantities such as temperature, assuming they are small.

espei.error_functions.thermochemical_error.get_prop_data(comps, phase_name, prop, datasets)

Return datasets that match the components, phase and property

Parameters:
  • comps (list) – List of components to get data for
  • phase_name (str) – Name of the phase to get data for
  • prop (str) – Property to get data for
  • datasets (espei.utils.PickleableTinyDB) – Datasets to search for data
Returns:

List of dictionary datasets that match the criteria

Return type:

list

espei.error_functions.thermochemical_error.get_prop_samples(dbf, comps, phase_name, desired_data)

Return data values and the conditions to calculate them by pycalphad calculate from the datasets

Parameters:
  • dbf (pycalphad.Database) – Database to consider
  • comps (list) – List of active component names
  • phase_name (str) – Name of the phase to consider from the Database
  • desired_data (list) – List of dictionary datasets that contain the values to sample
Returns:

Dictionary of condition kwargs for pycalphad’s calculate and the expected values

Return type:

dict

espei.error_functions.zpf_error module

Calculate error due to ZPF tielines.

The general approach is similar to the PanOptimizer rough search method.

  1. With all phases active, calculate the chemical potentials of the tieline endpoints via equilibrium calls. Done in estimate_hyperplane.
  2. Calculate the target chemical potentials, which are the average chemical potentials of all of the current chemical potentials at the tieline endpoints.
  3. Calculate the current chemical potentials of the desired single phases
  4. The error is the difference between these chemical potentials

There’s some special handling for tieline endpoints where we do not know the composition conditions to calculate chemical potentials at.

espei.error_functions.zpf_error.calculate_zpf_error(dbf, comps, phases, datasets, phase_models, parameters=None, callables=None)

Calculate error due to phase equilibria data

Parameters:
  • dbf (pycalphad.Database) – Database to consider
  • comps (list) – List of active component names
  • phases (list) – List of phases to consider
  • datasets (espei.utils.PickleableTinyDB) – Datasets that contain single phase data
  • phase_models (dict) – Phase models to pass to pycalphad calculations
  • parameters (dict) – Dictionary of symbols that will be overridden in pycalphad.equilibrium
  • callables (dict) – Callables to pass to pycalphad
Returns:

List of errors from phase equilibria data

Return type:

list

espei.error_functions.zpf_error.estimate_hyperplane(dbf, comps, phases, current_statevars, comp_dicts, phase_models, parameters, callables=None)

Calculate the chemical potentials for a hyperplane, one vertex at a time

Parameters:
  • dbf (pycalphad.Database) – Database to consider
  • comps (list) – List of active component names
  • phases (list) – List of phases to consider
  • current_statevars (dict) – Dictionary of state variables, e.g. v.P and v.T, no compositions.
  • comp_dicts (list) – List of tuples of composition dictionaries and phase flags. Composition dictionaries are pycalphad variable dicts and the flag is a string e.g. ({v.X(‘CU’): 0.5}, ‘disordered’)
  • phase_models (dict) – Phase models to pass to pycalphad calculations
  • parameters (dict) – Dictionary of symbols that will be overridden in pycalphad.equilibrium
  • callables (dict) – Callables to pass to pycalphad
Returns:

Array of chemical potentials.

Return type:

numpy.ndarray

Notes

This takes just one set of phase equilibria, e.g. a dataset point of [[‘FCC_A1’, [‘CU’], [0.1]], [‘LAVES_C15’, [‘CU’], [0.3]]] and calculates the chemical potentials given all the phases possible at the given compositions. Then the average chemical potentials of each end point are taken as the target hyperplane for the given equilibria.

espei.error_functions.zpf_error.tieline_error(dbf, comps, current_phase, cond_dict, region_chemical_potentials, phase_flag, phase_models, parameters, debug_mode=False, callables=None)
Parameters:
  • dbf (pycalphad.Database) – Database to consider
  • comps (list) – List of active component names
  • current_phase (list) – List of phases to consider
  • current_statevars (dict) – Dictionary of state variables, e.g. v.P and v.T, no compositions.
  • comp_dicts (list) – List of tuples of composition dictionaries and phase flags. Composition dictionaries are pycalphad variable dicts and the flag is a string e.g. ({v.X(‘CU’): 0.5}, ‘disordered’)
  • phase_models (dict) – Phase models to pass to pycalphad calculations
  • parameters (dict) – Dictionary of symbols that will be overridden in pycalphad.equilibrium
  • callables (dict) – Callables to pass to pycalphad
  • cond_dict
  • region_chemical_potentials (numpy.ndarray) – Array of chemical potentials for target equilibrium hyperplane.
  • phase_flag (str) – String of phase flag, e.g. ‘disordered’.
  • phase_models – Phase models to pass to pycalphad calculations
  • parameters – Dictionary of symbols that will be overridden in pycalphad.equilibrium
  • debug_mode (bool) – If True, will write out scripts when pycalphad fails to find a stable equilibrium. These scripts can be used to debug pycalphad.
Returns:

Single value for the total error between the current hyperplane and target hyperplane.

Return type:

float

Module contents

Functions for calculating error.