Parametric sweep

How to run multiple simulations with varied parameters

The examples/, shows an example of how one can run several simulations one after another so that the input file remains the same except for one parameter. In this example, we sweep the temperature parameter T in the input file called as defined as temperatures = [4, 100, 200, 300] list. Below, a typical script is provided:

import subprocess


def update_config_file(config_file, temperature):
    with open(config_file, 'r') as f:
        lines = f.readlines()
    for i, line in enumerate(lines):
        if line.startswith("OUTPUT_FOLDER_NAME"):
            lines[i] = f"OUTPUT_FOLDER_NAME = '{temperature}'\n"
        if line.startswith("T "):
            lines[i] = f"T = {temperature}\n"

    with open(config_file, 'w') as f:

temperatures = [4, 100, 200, 300]
for temp in temperatures:
    update_config_file(FILENAME, temp)['python', '-m', 'freepaths', FILENAME])

Essentially, for each temperature, the script changes and saves the input file, runs the simulation, and proceeds to the next temperature. Note, that this is not an input file, this is a separate python script that runs the simulations, so you must launch it as:


As a result, several folders will appear in the Results folder for different temperatures.

Last updated