Optimization of Model Parameters in KDB

This example demonstrates how to use PanPython SDK to optimize the kinetic parameters in the precipitation data file (.KDB) needed by precipitation simulation. The precipitation data file (.KDB) adopts the XML format, which defines the kinetic model for each precipitate phase and the corresponding model parameters. In this example, interfacial energy and nucleation site parameter are optimized simultaneously for aluminum alloys AA6xxx using experimental data.

Step-by-step guide

Note

A video guide will be available very soon.

  1. Open the demo folder

    /Solution_Demos/precipitation_kopt/” from PyCharm IDE. See Installation to setup the IDE environment.

  2. Build a task script

    An example script kopt_test.py has already been included. Following the steps the create your script:

    Import packages
    import os
    from panpython.system import System
    from panpython.task.kopt import KOpt
    
    Setup Pandat.exe path:
    pandat = "YOUR_PATH_TO_PANDAT_EXE/Pandat.exe"
    
    Setup working folders and input files:
    dir_name = os.path.abspath(__file__)
    file_name = os.path.basename(__file__)
    task_path = dir_name[:-len(file_name)]
    
    dump_path = os.path.join(task_path, "output")
    batch_file = os.path.join(task_path, "resource", "AA6xxx_6005_opt.pbfx")
    opt_file = os.path.join(task_path, "resource", "PanAl.opt")
    

    Note

    The calculation type in the batch file template must be “precipitation”:

    <calculation name="AA6xxx_6005_precipitation" type="precipitation">
    

    Note

    A .KDB file with special format is used for optimization. Please see KDB file for optimization for details. The tdb and kdb file is set in the batch file template AA6xxx_6005_opt.pbfx:

    <databases>
       <database type="kdb" file_name="AA6xxx_opt.kdb"/>
       <database type="tdb" file_name="AlMgSi.tdb"/>
    </databases>
    

    Note

    Experimental data used for optimization must be declared in batch file template. The data declared in batch file template and must be consistent with data definition inside .OPT file. See Configuration file of kinetic optimization for details. An example of the data declaration is:

    <tables>
        <table source="size_exp.dat" name="size_exp"/>
        <table source="nd_exp.dat" name="nd_exp"/>
        <table source="hv_exp.dat" name="hv_exp"/>
    </tables>
    

    These data must be defined inside .OPT file at the same time:

    <TargetProperty filename="size_exp.dat" type="kinetic">
        <property condition="log10(t)" value="log10(s(*)*1e10)"/>
    </TargetProperty>
    <TargetProperty filename="nd_exp.dat" type="kinetic">
        <property condition="log10(t)" value="log10(nd(*))"/>
    </TargetProperty>
    <TargetProperty filename="hv_exp.dat" type="strength">
        <property condition="log10(t)" value="hv(*)"/>
    </TargetProperty>
    

    Note

    Format of .OPT file (PanAl.opt) is explained in Configuration file of kinetic optimization. The .OPT file defines parameter initial value, upper and lower bounds, and experimental data.

    Initialize the kinetic optimization task instance:
    #################
    m_system = System(pandat=pandat, dump_path=dump_path)
    
    ##################
    m_system.add_task(task_instance=KOpt(batch_file=batch_file, opt_file=opt_file))
    
    Run the kinetic optimization task instance:
    ##################
    if __name__ == '__main__':
        m_system.run()
    
  3. Run the script

    After the kinetic optimization is finished, KDB file with optimized parameters is avaiable as /output/kopt_result_TIME_STAMP/*.kdb. See Inputs and outputs of this kinetic optimization for details.

Inputs and outputs of this kinetic optimization

The following figure displays inputs and outputs of this kinetic optimization.

cKOPT diagram
  • File structure

    The follow diagram displays the file structure used by this kinetic optimization:

precipitation_kopt
 |- output  # outputs
 |    |- intermediate
 |    |   |- *.kdb    # .KDB file for each step of optimization
 |    |   └─ *.table  # Result Table from each step of optimization
 |    |
 |    └─ kopt_result_TIME_STAMP
 |        |- *.kdb       # final .KDB file with optimized parameters
 |        └─ report.txt  # A summary of optimization, for example value of optimized parameters, standard deviation and predictions
 |
 └─ resource  # inputs
      |- AlMgSi.tdb         # Thermodynamic database to be used
      |- AA6xxx_opt.kdb     # Kinetic database (with special format) to be used
      |- PanAl.opt          # A Config. file for kinetic optimization
      |- PAA6xxx_6005.pbfx  # A template of batch file
      |- size_exp.dat       # Experimental data of particle size
      |- nd_exp.dat         # Experimental data of particle number density
      └─ PAA6xxx_6005.dat   # Experimental data of particle number density
  • Inputs

    The input files are under /resource folder.

    • Configuration file of kinetic optimization: A Configuration file for kinetic optimization. The file name is /resource/PanAl.opt.

    • KDB file for optimization: A .KDB file with special format for optimization. The file name is /resource/*.kdb

    • Thermodynamic Database: A .tdb or .pdb file. The file name is /resource/*.tdb or /resource/*.pdb.

    • Batch file: A template of batch file for precipitation calculation. The file name is /resource/*.pbfx.

    • Experimental data for optimization:: Experimental data which are used to perform regression analysis. The file name is /resource/*.dat

  • Outputs

    The output files are under /output folder.

    • .KDB file with optimized parameters: the final .KDB file from kinetic optimization. The final .KDB file name is /output/kopt_result_TIME_STAMP/*.kdb.

    • Summary of optimization: a txt file containing parameter value, deviation, and prediction from the final step of optimization. The file name is /output/kopt_result_TIME_STAMP/report.txt.

    • Tables from Pandat calculation: The original tables from Pandat. The tables are stored under /output/intermediate/ folder.

    • .KDB files for each step of optimization: the .KDB file for each step is recorded under intermediate folder for easily retrieving calculation conditions. The .KDB files are stored under /output/intermediate/ folder.

Configuration file of kinetic optimization

One of the input files. The file name is /resource/PanAl.opt. An example of Config. file as an input to HTC:

<?xml version="1.0" encoding="iso-8859-1"?>
<PanPython_Optimization version="1.0">

    <Header copyright="CompuTherm, LLC">
        <!-- example syntax for optimization of model parameters by using PanPython -->
        <Application name="PanPython" version="2018" />
    </Header>

    <TargetDatabase filename="AA6xxx_opt.kdb">
        <optimization name="opt_activation_Energy_factor" value="4.5e12" lb="1e10" ub="4.5e13"/>
        <optimization name="opt_Interfacial_Energy" value="0.1" lb="0.1" ub="0.5"/>
        <optimization name="opt_Nucleation_Site_Parameter" value="1e-7" lb="1e-7" ub="1e-5"/>
        <optimization name="opt_Strength_Parameter" value="5.0e-5" lb="1e-7" ub="1e-4"/>
        <optimization name="opt_Shearing_Critical_Radius" value="9.0e-9" lb="2.0e-9" ub="10.0e-9"/>
    </TargetDatabase >

    <TargetProperty filename="size_exp.dat" type="kinetic">
        <property condition="log10(t)" value="log10(s(*)*1e10)"/>
    </TargetProperty>

    <TargetProperty filename="nd_exp.dat" type="kinetic">
        <property condition="log10(t)" value="log10(nd(*))"/>
    </TargetProperty>

    <TargetProperty filename="hv_exp.dat" type="strength">
        <property condition="log10(t)" value="hv(*)"/>
    </TargetProperty>

</PanPython_Optimization>
The tags of the xml file is defined in the following table:

Tag

Definition

TargetDatabase

Name of kinetic database to be optimized

optimization

Optimization setting for a parameter

TargetProperty

Experimental data for optimization

property

The properties from experimental data to be used fo optimization

The properties of optimization tag is defined in the following table:

Property

Definition

name

Name of parameter

value

Initial value of parameter

lb

Lower bound of parameter

ub

Upper bound of parameter

Note

Initial value and bounds of parameter are based on domain knowledge of the materials. A bad guess would trigger meaningless result of optimization

The properties of TargetProperty tag is defined in the following table:

Property

Definition

filename

File name of experimental data

type

Type of experimental data

Note

To use the data files in optimization, the data files must be declared in batch file template ‘PAA6xxx_6005.pbfx’:

<tables>
    <table source="size_exp.dat" name="size_exp"/>
    <table source="nd_exp.dat" name="nd_exp"/>
    <table source="hv_exp.dat" name="hv_exp"/>
</tables>

Note

The type of TargetProperty decides the priority of optimization. Generally, optimization is performed in two steps: - Step one: optimization uses experimental data with type = kinetic. In this example, ‘size_exp.dat’ and ‘nd_exp.dat’ belong to this category. - Step two: optimization uses experimental data with type = strength. In this example, ‘hv_exp.dat’ (hardness) belongs to this category. This two step optimization avoids overfitting. It makes sure that kinetic properties such as particle size and particle number density are the primary data. Strength data such as hardness is only fitted when kinetic data are well fitted.

The properties of property tag is defined in the following table:

Property

Definition

condition

The independent dimension of the property (Usually be time)

value

The dependent dimension of the property

KDB file for optimization

In order to use PanPython to optimize interfacial energy and nucleation site parameter, in /resource/AA6xxx_opt.kdb values of corresponding parameters are replaced by optimization parameters from /resource/PanAl.opt. In the following block from /resource/AA6xxx_opt.kdb

value in the two highlighted lines are replace by optimization parameters opt_Interfacial_Energy and opt_Nucleation_Site_Parameter. These two optimization parameters have been defined in /resource/PanAl.opt:

Experimental data for optimization

In order to use experimental data to optimize interfacial energy and nucleation site parameter, experimental data must be defined in /resource/PanAl.opt as well as declared in /resource/PAA6xxx_6005.pbfx. In /resource/PanAl.opt, the experimental data is defined as:

<TargetProperty filename="size_exp.dat" type="kinetic">
    <property condition="log10(t)" value="log10(s(*)*1e10)"/>
</TargetProperty>
<TargetProperty filename="nd_exp.dat" type="kinetic">
    <property condition="log10(t)" value="log10(nd(*))"/>
</TargetProperty>
<TargetProperty filename="hv_exp.dat" type="strength">
    <property condition="log10(t)" value="hv(*)"/>
</TargetProperty>

In /resource/PAA6xxx_6005.pbfx, the experimental data is declared as:

<tables>
    <table source="size_exp.dat" name="size_exp"/>
    <table source="nd_exp.dat" name="nd_exp"/>
    <table source="hv_exp.dat" name="hv_exp"/>
</tables>

Format of experimental data is tab delimited text file. Unit is not necessary, since SI is assumed. For example, the size_exp.dat file is:

log10(t)    log10(s(*)*1e10)
3.257923344 1.523540202
3.556580792 1.600797312
4.161301119 1.674385599
4.474345776 1.708836949
4.7804256   1.700406282
5.44081375  2.13133624
-3.0        1.3
-3.0        1.3
-3.0        1.3
-3.0        1.3
4.161301119 1.674385599
4.474345776 1.708836949
4.161301119 1.674385599
4.474345776 1.708836949