Parallel High-Throughput Precipitation Calculation (HTC)

This example demonstrates how to use PanPython SDK to perform parallel high-throughput precipitation simulations concurrently.

About precipitation HTC

Precipitation HTC allows a user to perform simulations for numerous compositions/heat treatments in the user-defined state space by a simple setting. Alloy compositions and heat treatment conditions that satisfy user-defined criteria can then be identified through data mining of the simulated results.

Four types of precipitation HTC are discussed here:

Post-processing and visualization of a HTC result are discussed in Post-Processing of data from Precipitation HTC.

Step-by-step guide

Note

A video guide will be available very soon.

  1. Open the demo folder

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

  2. Build a task script

    An example script parallel_htc_precipitation.py has already been include. Following the steps the create your script:

    Import packages
    import os
    import socket
    import multiprocessing as mp
    from panpython.system import System
    from panpython.task.htc import HtcMesh
    
    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_htc")
    batch_file = os.path.join(task_path, "resource", "AA6xxx_6005_original.pbfx")
    config_file = os.path.join(task_path, "resource", "Input_precipitation.json")
    

    Note

    The calculation type is set in Input_precipitation.json:

    {
        "Type": "precipitation",
    }
    

    The calculation type in the batch file template must be consistent with this type, or an exception will be raised:

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

    Note

    The tdb and kdb file is set in the batch file template AA6xxx_6005_original.pbfx:

    <databases>
       <database type="kdb" file_name="AA6xxx_original.kdb"/>
       <database type="tdb" file_name="AlMgSi.tdb"/>
    </databases>
    
    Set thread(s) number:
    #################
    # set thread number
    # note: if your number is bigger than system capability, the number will set to max
    # available thread number on your system
    thread_number: int = 4
    print('>> Max thread  number on machine: ', socket.gethostname(), ' is ', mp.cpu_count())
    if thread_number > mp.cpu_count():
        thread_number = mp.cpu_count()
    print('>> Thread number is set to ', thread_number)
    
    Initialize the HTC task instance:
    #################
    m_system = System(pandat=pandat, dump_path=dump_path)
    
    ##################
    m_system.add_task(task_definition=HtcMesh(batch_file=batch_file, config_file=config_file, thread_num=thread_number))
    
    Run HTC task instance in multi-thread mode:
    ##################
    if __name__ == '__main__':
        mp.freeze_support()  # required to run multi-thread
        m_system.run()
    
  3. Run the script

    After the HTC is finished, generated tables/files are ready to use. See Inputs and outputs of this HTC task for details.

Inputs and outputs of this HTC task

The following figure displays inputs and outputs of this HTC task.

cHTC diagram precipitation
  • File structure

    The follow diagram displays the file structure used by this HTC task:

precipitation_htc_defined_cooling
 |- output  # outputs
 |    |- intermediate
 |    |   |- *.dat    # Result Tables in csv format
 |    |   └─ *.table  # Result Tables
 |    |
 |    |- failed_calculation.json  # Record of failed calculations
 |    └─ task_id.txt              # Condition Dictionary
 └─ resource  # inputs
      |- AlMgSi.tdb                # Database to be used by HTC calculation
      |- AA6xxx_original.kdb       # Kinetic Database to be used by HTC calculation
      |- Input_precipitation.json  # A Config. file (JSON) defining an HTC mesh grid
      |- cooling_curve.txt         # An input cooling curve file
      |- cooling_curve_general.txt # An input cooling curve file
      └─ AA6xxx_6005_original.pbfx # A template of batch file used calculation

Configuration file of continuous cooling

One of the input files. The file name is /resource/Input_precipitation.json.

In this example, the following continuous cooling is defined by the configuration file:

  • staring temperature: 500 C

  • ending temperature: 100 C

  • cooling rate (HTC mesh): form 1 C/hour to 10 C/hour, mesh grid size is 1 C/hour

An example of Config. file as an input to HTC:

{
  "Type": "precipitation",

  "Units": {
    "n": "w%",
    "T": "C",
    "time": "hour"
  },

  "Mode": "default",

  "thermal_history_mesh": {
    "mesh": {
      "description": "continuous cooling",

      "start_T": {
        "start": 500,
        "end": 500,
        "step size": 0
      },

      "cooling_rate": {
        "start": 1,
        "end": 10,
        "step size": 1,
        "end_T": 100
      }
    }
  }
}

The keys of the JSON file is defined in the following table:

Key

Definition

Type

Calculation type of Pandat

Units

Units following Pandat’s convention

thermal_history_mesh

Set of multiple grids of heat treatment conditions defined in JSON format

mesh

A grid of heat treatment conditions

description

Thermal treatment method related to this grid

start_T

A grid of Starting temperature

cooling_rate

A grid of Cooling rate (its unit follows the units defined by “Units” key)

The properties of each key’s value is defined in the following table:

Property

Definition

start

Starting value of a grid

end

Ending value of a grid

step size

Step size of grid

end_T

Ending temperature used to calculate cooling duration

Configuration file of isothermal

One of the input files. The file name is /resource/Input_precipitation.json.

In this example, the following isothermal condition is defined by the configuration file:

  • isothermal temperature (HTC mesh): form 100 C to 200 C, mesh grid size is 10 hour

  • isothermal duration: 100 hours

An example of Config. file as an input to HTC:

{
  "Type": "precipitation",

  "Units": {
    "n": "w%",
    "T": "C",
    "time": "hour"
  },

  "Mode": "default",

  "thermal_history_mesh": {
    "mesh": {
      "description": "isothermal",

      "start_T": {
        "start": 100,
        "end": 200,
        "step size": 20
      },

      "cooling_rate": {
        "start": 0,
        "end": 0,
        "step size": 0,
        "end_time": 100
      }
    }
  }
}

The keys of the JSON file is defined in the following table:

Key

Definition

Type

Calculation type of Pandat

Units

Units following Pandat’s convention

thermal_history_mesh

Set of multiple grids of heat treatment conditions defined in JSON format

mesh

A grid of heat treatment conditions

description

Thermal treatment method related to this grid

start_T

A grid of Starting temperature

cooling_rate

A grid of Cooling rate (its unit follows the units defined by “Units” key)

The properties of each key’s value is defined in the following table:

Property

Definition

start

Starting value of a grid

end

Ending value of a grid

step size

Step size of grid

end_time

Duration of isothermal condition

Configuration file of loading heat treatment files

One of the input files. The file name is /resource/Input_precipitation.json.

In this example, customized thermal condition from input files is defined by the configuration file:

  • Cooling curves share time node: /resource/cooling_curve.txt

  • Each cooling curve has its own time node: /resource/cooling_curve_general.txt

An example of Config. file as an input to HTC:

{
  "Type": "precipitation",

  "Units": {
    "n": "w%",
    "T": "C",
    "time": "hour"
  },

  "Mode": "default",

  "thermal_history_file": {
    "cooling_curve 1": "cooling_curve.txt",
    "cooling_curve 2": "cooling_curve_general.txt"
  }
}

The keys of the JSON file is defined in the following table:

Key

Definition

Type

Calculation type of Pandat

Units

Units following Pandat’s convention

thermal_history_file

A set of multiple files that define cooling curves

The properties of each key’s value is defined in the following table:

Property

Definition

cooling_curve 1

A file defining a set of cooling curves

cooling_curve 2

A file defining a set of cooling curves

A set of cooling curves sharing time nodes are defined in cooling_curve.txt as (Emphasized lines are units of corresponding columns):

 time P100    P105    P110    P115    P120    P125    P130    P135    P140    P145    P150    P155    P160    P165    P170    P175    P180    P185    P190    P195    P200    P205    P210
 hour C       C       C       C       C       C       C       C       C       C       C       C       C       C       C       C       C       C       C       C       C       C       C
 0    100     105     110     115     120     125     130     135     140     145     150     155     160     165     170     175     180     185     190     195     200     205     210
 100  100     105     110     115     120     125     130     135     140     145     150     155     160     165     170     175     180     185     190     195     200     205     210
 101  100     110     120     130     140     150     160     170     180     190     200     210     220     230     240     250     260     270     280     290     300     310     320

A set of cooling curves where each curve has its own time nodes are defined in cooling_curve_general.txt as (Emphasized lines are units of corresponding columns):

 time_0       T_0 time_1      T_1     time_2  T_2     time_3  T_3
 hour C       hour    C       hour    C       hour    C
 0    100     0       105     0       110     0       115
 100  100     100     105     100     110     100     115
 101  100     101     110                     101     130
      200     110                         102 140
                          110 150
                          200 150

Configuration file of mixing composition and heat treatment

One of the input files. The file name is /resource/Input_precipitation.json.

In this example,

  • Combined heat treatment mesh: Continuous cooling, isothermal, and input files are combined into a mega heat treatment mesh

  • Add composition (HTC mesh): HTC mesh dimension contains both heat treatment and composition

  • Each cooling curve has its own time node: /resource/cooling_curve_general.txt

An example of Config. file as an input to HTC:

{
  "Type": "precipitation",

  "Units": {
    "n": "w%",
    "T": "C",
    "time": "hour"
  },

  "Mode": "default",

  "Al": {
    "start": 0,
    "end": 100,
    "step size": -1
  },
  "Mg": {
    "start": 10,
    "end": 50,
    "step size": 20
  },
  "Si": {
    "start": 10,
    "end": 10,
    "step size": 0
  },

  "thermal_history_file": {
    "cooling_curve 1": "cooling_curve.txt",
    "cooling_curve 2": "cooling_curve_general.txt"
  },

  "thermal_history_mesh": {
    "mesh 1": {
      "description": "isothermal",

      "start_T": {
        "start": 100,
        "end": 200,
        "step size": 20
      },

      "cooling_rate": {
        "start": 0,
        "end": 0,
        "step size": 0,
        "end_time": 100
      }
    },

    "mesh 2": {
      "description": "continuous cooling",

      "start_T": {
        "start": 500,
        "end": 500,
        "step size": 0
      },

      "cooling_rate": {
        "start": 1,
        "end": 10,
        "step size": 1,
        "end_T": 100
      }
    }
  }
}

The keys of the JSON file related to composition mesh is defined in the following table:

Key

Definition

Type

Calculation type of Pandat

Units

Units following Pandat’s convention

Al

A grid of Aluminum composition

Mg

A grid of Magnesium composition

Si

A grid of Silicon composition

The properties of each key’s value related to composition mesh is defined in the following table:

Property

Definition

start

Starting value of a grid

end

Ending value of a grid

step size

Step size of grid; If its key is an element and set -1, its key is the balance element

Keys and properties related to heat treatment mesh are explained in Configuration file of continuous cooling, Configuration file of isothermal and Configuration file of loading heat treatment files.

Record of HTC conditions

One of the output files. The file name is output/task_id.txt.

A JSON-styled dictionary containing all calculation conditions of HTC. An example of Condition Dictionary as an output from HTC:

{
     "mesh_2_0": {
         "thermal_history": [
             [
                 0.0,
                 500.0
             ],
             [
                 400.0,
                 100.0
             ]
         ]
     },
     "mesh_2_1": {
         "thermal_history": [
             [
                 0.0,
                 500.0
             ],
             [
                 200.0,
                 100.0
             ]
         ]
     },
 }

Keys of the JSON file is the id of a calculation. Properties of the calculation include all the keys from Config. file.