diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..7bf0d26 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,29 @@ +name: Run PBE tests + +on: push + # workflow_dispatch: + # schedule: + # - cron: "0 5 * * *" + +jobs: + setup_and_test: + name: Setup and run tests + runs-on: ubuntu-latest + environment: PBE + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Bootstrap + run: | + chmod +x bootstrap.sh + sh ./bootstrap.sh + - name: Build SimCenter Applications + run: | + chmod +x build_backend_apps.sh + sh ./build_backend_apps.sh + - name: Run Examples + run: | + chmod +x run_examples.sh + sh ./run_examples.sh diff --git a/bootstrap.sh b/bootstrap.sh new file mode 100644 index 0000000..105258c --- /dev/null +++ b/bootstrap.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +# Set Timezone (needed for python install) +sudo ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone + +# Updates the package lists for upgrades and new package installations +apt-get update +apt-get install sudo -y +apt-get install wget -y +sudo apt install -y software-properties-common cmake git + +# Installs the python 3.9 package. The '-y' flag automatically answers yes to prompts. +sudo add-apt-repository ppa:deadsnakes/ppa -y +sudo apt update +sudo apt install python3.9 python3.9-dev python3.9-venv python3.9-distutils -y + +# Install pip +wget https://bootstrap.pypa.io/get-pip.py +python3.9 get-pip.py + +# Upgrades pip (Python package installer) to the latest version +sudo python3.9 -m pip install -U pip + +# Installs the Conan package manager +python3.9 -m pip install conan==1.60.1 +python3.9 -m pip install nheri-simcenter + +python3.9 --version + +sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.9.20 +sudo update-alternatives --install /usr/bin/python python3 /usr/bin/python3.9.20 +sudo update-alternatives --config python + +which python3 + +which conan + +wget https://github.com/snl-dakota/dakota/releases/download/v6.15.0/dakota-6.15.0-public-src-cli.tar.gz +sudo apt-get install -y cmake libboost-dev libboost-all-dev libopenmpi-dev openmpi-bin xorg-dev libmotif-dev libblas-dev liblapack-dev g++ +tar zxBf dakota-6.15.0-public-src-cli.tar.gz +mv dakota-6.15.0-public-src-cli dakota-6.15.0 +cd dakota-6.15.0 +mkdir build; cd build +cmake .. +make -j 16 +cd ../.. +export PATH=$PWD/dakota-6.15.0/build/src:$PATH +alias python3=python3.9 + +sudo apt-get install -y cmake liblapack-dev libomp-dev libssl-dev apt-transport-https ca-certificates wget +wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null +sudo apt-add-repository -y "deb https://apt.kitware.com/ubuntu/ $(lsb_release -cs) main" +sudo apt-get update +sudo apt-get install -y cmake gfortran gcc g++ +git clone -b v3.7.0 --single-branch https://github.com/OpenSees/OpenSees.git +cd OpenSees +mkdir build; cd build +conan install .. --build missing +cmake .. +cmake --build . --config Release +cmake --install . +sudo mv ./lib/* /usr/local/lib +cd ../.. + +export PATH=$PATH:/usr/local/OpenSees/bin:/usr/local/Dakota/bin +sudo sh ~/.profile diff --git a/build_backend_apps.sh b/build_backend_apps.sh new file mode 100644 index 0000000..2b7e135 --- /dev/null +++ b/build_backend_apps.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +git clone --depth 1 https://github.com/NHERI-SimCenter/SimCenterBackendApplications.git + +cp ./SimCenterBackendApplications/modules/performUQ/SimCenterUQ/nataf_gsa/CMakeLists.txt.UBUNTU ./SimCenterBackendApplications/modules/performUQ/SimCenterUQ/nataf_gsa/CMakeLists.txt + +rm -fr ~/.conan + +sudo apt-get install -y liblapack-dev libomp-dev libssl-dev apt-transport-https ca-certificates \ + +sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test + +sudo apt-get update + +sudo apt-get install -y gcc-11 g++-11 gfortran-11 + +export CC=gcc-11 + +export CXX=g++-11 + +export FC=gfortran-11 + +cd SimCenterBackendApplications + +mkdir build + +cd build + +conan install .. --build missing + +cmake .. + +cmake --build . --config Release + +cmake --install . + +cd ../.. diff --git a/pbe_input_cleaner.py b/pbe_input_cleaner.py new file mode 100644 index 0000000..2294521 --- /dev/null +++ b/pbe_input_cleaner.py @@ -0,0 +1,12 @@ +import sys + +if __name__ == "__main__": + path = sys.argv[1] + text = None + with open(path, "r") as f: + text = f.read() + + text = text.replace("{Current_Dir}", "templatedir") + + with open(path, "w") as f: + f.write(text) \ No newline at end of file diff --git a/run_examples.sh b/run_examples.sh new file mode 100644 index 0000000..15d2cc1 --- /dev/null +++ b/run_examples.sh @@ -0,0 +1,86 @@ +#!/bin/bash + + +export PATH=$PATH:/usr/local/OpenSees/bin:/usr/local/Dakota/bin +echo In folder $PWD + +# Clone the examples +git clone --branch master https://github.com/NHERI-SimCenter/PBE.git + +# make sure all packages are installed +python3 -m pip install --upgrade pip +python3 -m pip install nheri-simcenter --upgrade +python3 -m pip install GPy==1.13.2 + +# Read JSON from file +json_file="$PWD/PBE/Examples/Examples.json" + +# Install jq +sudo apt-get install -y jq +rm -rf cache +mkdir cache +# Iterate over array elements +jq -c '.Examples[]' "$json_file" | while read -r example; do + + name=$(echo "$example" | jq -r '.name') + description=$(echo "$example" | jq -r '.description') + inputfile=$(echo "$example" | jq -r '.inputFile') + + inputfile="$PWD/PBE/Examples/$inputfile" + srcDir="$(dirname $inputfile)" + examplenumber="$(dirname $srcDir)" + examplenumber="$(basename $examplenumber)" + + echo "===========================================" + echo "Example Number: $examplenumber" + echo "Example Name: $name" + echo "Example Description: $description" + echo "Input File: $inputfile" + echo "srcDir: $srcDir" + echo "---------------------------" + # Change {Current_Dir} in input to templatedir + python3 pbe_input_cleaner.py $inputfile + + # Add JSON Arguments to input + echo "Adding json params to input file..." + echo $(cat $inputfile | jq '. + { "runDir": "'"$PWD/tmp.SimCenter"'" }') > $inputfile + echo $(cat $inputfile | jq '. + { "localAppDir": "'"$PWD/SimCenterBackendApplications"'" }') > $inputfile + echo $(cat $inputfile | jq '. + { "remoteAppDir": "'"$PWD/SimCenterBackendApplications"'" }') > $inputfile + echo $(cat $inputfile | jq '. + { "runType": "runningLocal" }') > $inputfile + + echo "copying files" + rm -rf tmp.SimCenter + mkdir tmp.SimCenter + mkdir tmp.SimCenter/templatedir + cp -a $srcDir/. $PWD/tmp.SimCenter/templatedir/ + + + + #echo "Input file contents:" + #python3 -m json.tool $inputfile + + #echo "Template dir contents" + #ls $PWD/tmp.SimCenter/templatedir + + + # Run the example in the backend + echo "Running python:" + echo "===============" + python3 $PWD/SimCenterBackendApplications/applications/Workflow/sWHALE.py "runningLocal" $inputfile $PWD/SimCenterBackendApplications/applications/Workflow/WorkflowApplications.json + mkdir "cache/tmp.SimCenter.$examplenumber/" + cp -r tmp.SimCenter/. "cache/tmp.SimCenter.$examplenumber/" +done + +# Check with archives have a dakotaTab.out file +echo "" +echo "" +echo "======================================" +for dir in $PWD/cache/*; do + if [ -f "$dir/dakotaTab.out" ]; then + echo "$dir: PASS" + # Do something if the file exists + else + echo "$dir: FAIL" + # Do something else if the file does not exist + fi +done