SURGroup / UQpy

UQpy (Uncertainty Quantification with python) is a general purpose Python toolbox for modeling uncertainty in physical and mathematical systems.
MIT License
267 stars 77 forks source link

Using bash instead of sh in subprocess calls of GNU parallel in Linux/Unix #118

Closed marrov closed 1 year ago

marrov commented 2 years ago

Using bash instead of sh in subprocess calls of GNU parallel in Linux/Unix

Description

When using GNU parallel to run third-party software in parallel (i.e. multi-processing) on Linux the default behavior of subprocess is to use /bin/sh. This clashes with the syntax used for the model_commandstring as /bin/sh shell cannot correctly unpack the numerical sequence ::: {0..n-1} at the end of the GNU parallel command. Therefore, it will try to change directory into a non-existing directory (for example ```cd run{0..9}```, where here n=10). This will produce an error as the GNU parallel command will not be correctly executed and the model will not be run in parallel. By simply checking if the system platform is Linux and explicitly telling subprocess to use /bin/bash instead of /bin/sh this error is fixed.

Motivation and Context

This change is required to run third-party models in parallel in Linux platforms. Due to the error I encountered with the current implementation of RunModel.py in my Linux system, I opened a stackoverflow question. Here, there general form of this question has been solved and so the solution should be applied to RunModel.py.

How Has This Been Tested?

I have tested this change by running a version of the existing sum_scalar Matlab model in Fortran. I was able to get 10 runs in serial but was unable to run those same 10 runs in parallel as I got this error:

/bin/sh: 1: cd: can't cd to run_{0..9}

By applying the proposed change, this error is fixed for Linux platforms without affecting the original code.

Types of changes

Checklist: