I am trying create child scripts from one parent script where a few parameters are modified (48 child scripts, so automation would be preferred). My intention for this is to run different Modelica scripts as individual Slurm jobs. I would normally do this with the Modelica scripting language, but since I need to submit each script individually I will need to create multiple scripts. The pseudocode is as follows. Note: The search strings are unique
load('model.mo') # modelica file, parent script
# change the control strategy in the script
for i in ['control_1', 'control_2', 'control_3', 'control 4']:
# change the amount of electricity generation
find and replace r'moduleName = "control"' with 'moduleName = control_' + str(i)
for j in [3, 7]:
find and replace '.CombiTimeTable solar_data(columns = {2}' with '.CombiTimeTable solar_data(columns = {' + str(j) + '}'
# change the battery size
for k in [2000000000, 4000000000, 6000000000]:
find and replace 'Storage.Battery BESS(EMax = 2000000000, SOC_start = 0.5, pf = 0.9)' with 'Storage.Battery BESS(EMax = ' + str(k) + ', SOC_start = 0.5, pf = 0.9)'
for l in ['4', '8']:
find and replace '.CombiTimeTable ev_data(columns = {2}' with '.CombiTimeTable ev_data(columns = {' + str(i) + '}'
export('child_model_#.mo')
My goal is to change the actual text of each new script, not just the variables. I am not sure if I should use Python, Bash, or something else for this task, especially since I am modifying a non-.txt file.
#in the export file name should be a combination of thei,j,k, andlvalues?