Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
181 changes: 181 additions & 0 deletions .github/workflows/tests_workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
# Run Tests

name: UQPCE Tests

on:
# Trigger on push, pull request
push:
branches: [ main ]
pull_request:
branches: [ main, develop ]

# Trigger via workflow_dispatch event
workflow_dispatch:

jobs:

test_ubuntu:
runs-on: ubuntu-22.04

timeout-minutes: 90

strategy:
fail-fast: false
matrix:
include:
# baseline versions except with pyoptsparse but no SNOPT
# build docs to verify those that use pyoptsparse do not use SNOPT
- NAME: baseline_no_snopt
PY: '3.11'
NUMPY: '1.26'
SCIPY: '1.13'
PYYAML: '6.0.2'
JAX: '0.6.1'
OPENMDAO: 'latest'
DYMOS: 'latest'
MPI4PY: '3.1.4'
OPTIONAL: '[docs]'
PUBLISH_DOCS: 1

# # make sure the latest versions of things don't break the docs
# # sticking with Python 3.12 for now, 3.13 requires NumPy 2.1 which does not work yet with PETSc/pyoptsparse
# # Pin PETSc back to 3.22.2
# - NAME: latest
# PY: '3.12'
# NUMPY: 1
# SCIPY: 1
# PETSc: 3.21.0
# PYOPTSPARSE: 'latest'
# SNOPT: 7.7
# OPENMDAO: 'dev'
# OPTIONAL: '[docs]'
# JAX: 'latest'
# PUBLISH_DOCS: 0

steps:
- name: Display run details
run: |
echo "============================================================="
echo "Run #${GITHUB_RUN_NUMBER}"
echo "Run ID: ${GITHUB_RUN_ID}"
echo "Testing: ${GITHUB_REPOSITORY}"
echo "Triggered by: ${GITHUB_EVENT_NAME}"
echo "Initiated by: ${GITHUB_ACTOR}"
echo "============================================================="

- name: Checkout code
uses: actions/checkout@v4

- name: Setup conda
uses: conda-incubator/setup-miniconda@v3
with:
python-version: ${{ matrix.PY }}
channels: conda-forge
conda-remove-defaults: true

- name: Install Numpy/Scipy
shell: bash -l {0}
run: |
echo "============================================================="
echo "Install Numpy/Scipy"
echo "============================================================="
conda install numpy=${{ matrix.NUMPY }} scipy=${{ matrix.SCIPY }} -q -y

- name: Install OpenMDAO
if: matrix.OPENMDAO
shell: bash -l {0}
run: |
echo "============================================================="
echo "Install OpenMDAO"
echo "============================================================="
if [[ "${{ matrix.OPENMDAO }}" == "dev" ]]; then
pip install git+https://github.com/OpenMDAO/OpenMDAO
elif [[ "${{ matrix.OPENMDAO }}" == "latest" ]]; then
pip install openmdao
else
pip install openmdao==${{ matrix.OPENMDAO }}
fi

- name: Install Dymos
if: matrix.DYMOS
shell: bash -l {0}
run: |
echo "============================================================="
echo "Install Dymos"
echo "============================================================="
if [[ "${{ matrix.DYMOS }}" == "dev" ]]; then
pip install git+https://github.com/OpenMDAO/dymos
elif [[ "${{ matrix.DYMOS }}" == "latest" ]]; then
pip install dymos
else
pip install dymos==${{ matrix.DYMOS }}
fi

- name: Install PyYAML
if: matrix.PYYAML
shell: bash -l {0}
run: |
echo "============================================================="
echo "Install PyYAML"
echo "============================================================="
pip install PyYAML==${{ matrix.PYYAML }}

- name: Install JAX
if: matrix.JAX
shell: bash -l {0}
run: |
echo "============================================================="
echo "Install JAX"
echo "============================================================="
pip install jax==${{ matrix.JAX }}

- name: Install mpi4py
if: matrix.MPI4PY
shell: bash -l {0}
run: |
echo "============================================================="
echo "Install mpi4py"
echo "============================================================="
conda install mpi4py==${{ matrix.MPI4PY }} -q -y

- name: Install UQPCE
shell: bash -l {0}
run: |
echo "============================================================="
echo "Install UQPCE"
echo "============================================================="
pip install .${{ matrix.OPTIONAL }}

- name: Display environment info
id: env_info
shell: bash -l {0}
run: |
conda info
conda list

echo "============================================================="
echo "Check installed versions of Python, Numpy and Scipy"
echo "============================================================="
python -c "import sys; assert str(sys.version).startswith(str(${{ matrix.PY }})), \
f'Python version {sys.version} is not the requested version (${{ matrix.PY }})'"

python -c "import numpy; assert str(numpy.__version__).startswith(str(${{ matrix.NUMPY }})), \
f'Numpy version {numpy.__version__} is not the requested version (${{ matrix.NUMPY }})'"

python -c "import scipy; assert str(scipy.__version__).startswith(str(${{ matrix.SCIPY }})), \
f'Scipy version {scipy.__version__} is not the requested version (${{ matrix.SCIPY }})'"

- name: Display dependency tree
if: failure() && steps.env_info.outcome == 'failure'
run: |
pip install pipdeptree
pipdeptree

- name: Run tests
shell: bash -l {0}
run: |
echo "============================================================="
echo "Run Tests"
echo "============================================================="
cd $HOME/work/UQPCE/UQPCE
python -m unittest discover uqpce "test*.py"
36 changes: 18 additions & 18 deletions uqpce/test_suite/test_uqpce/mdao/cdf/test_cdfgroup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from scipy.stats import beta, nbinom, expon

from uqpce.mdao.cdf.cdfgroup import CDFGroup
from uqpce.mdao.cdf.cdfresidcomp import tanh_activation
from openmdao.jax import act_tanh

tanh_omega = 1e-6
aleat_cnt = 75_000
aleat_cnt = 500_000

class TestCDFGroup(unittest.TestCase):
def setUp(self):
Expand Down Expand Up @@ -76,14 +76,14 @@ def test_beta(self):
x = np.sort(self.beta_samples)

plt.figure()
act = tanh_activation(x, omega=1e-12, z=ci_lower, a=1, b=0)
act = act_tanh(x, mu=1e-12, z=ci_lower, a=1, b=0)
plt.plot(x, act, '-o')
plt.plot([ci_lower, ci_lower], [act.min(), act.max()], 'k--')
plt.title('Beta Distribution')
# plt.savefig('beta_lower_ci')

plt.figure()
act = tanh_activation(x, omega=1e-12, z=ci_upper, a=1, b=0)
act = act_tanh(x, mu=1e-12, z=ci_upper, a=1, b=0)
plt.plot(x, act, '-o')
plt.plot([ci_upper, ci_upper], [act.min(), act.max()], 'k--')
plt.title('Beta Distribution')
Expand Down Expand Up @@ -141,14 +141,14 @@ def test_expon(self):
x = np.sort(self.expon_samples)

plt.figure()
act = tanh_activation(x, omega=tanh_omega, z=ci_lower, a=1, b=0)
act = act_tanh(x, mu=tanh_omega, z=ci_lower, a=1, b=0)
plt.plot(x, act, '-o')
plt.plot([ci_lower, ci_lower], [act.min(), act.max()], 'k--')
plt.title('Exponential Distribution')
# plt.savefig('expon_lower_ci')

plt.figure()
act = tanh_activation(x, omega=tanh_omega, z=ci_upper, a=1, b=0)
act = act_tanh(x, mu=tanh_omega, z=ci_upper, a=1, b=0)
plt.plot(x, act, '-o')
plt.plot([ci_upper, ci_upper], [act.min(), act.max()], 'k--')
plt.title('Exponential Distribution')
Expand All @@ -172,7 +172,7 @@ def test_nbinom(self):
'upper',
CDFGroup(
alpha=alpha, tail='upper', vec_size=aleat_cnt, tanh_omega=tanh_omega,
epistemic_cnt=1, aleatory_cnt=aleat_cnt,
epistemic_cnt=1, aleatory_cnt=aleat_cnt,
sample_ref0=float(self.nbinom_samples.min()), sample_ref=float(self.nbinom_samples.max())
), promotes_inputs=['*']
)
Expand Down Expand Up @@ -205,14 +205,14 @@ def test_nbinom(self):
x = np.sort(self.nbinom_samples)

plt.figure()
act = tanh_activation(x, omega=tanh_omega, z=ci_lower, a=1, b=0)
act = act_tanh(x, mu=tanh_omega, z=ci_lower, a=1, b=0)
plt.plot(x, act, '-o')
plt.plot([ci_lower, ci_lower], [act.min()-0.1, act.max()+0.1], 'k--')
plt.title('Binomial Distribution')
# plt.savefig('nbinom_lower_ci')

plt.figure()
act = tanh_activation(x, omega=tanh_omega, z=ci_upper, a=1, b=0)
act = act_tanh(x, mu=tanh_omega, z=ci_upper, a=1, b=0)
plt.plot(x, act, '-o')
plt.plot([ci_upper, ci_upper], [act.min(), act.max()], 'k--')
plt.title('Binomial Distribution')
Expand Down Expand Up @@ -271,14 +271,14 @@ def test_combined(self):
x = np.sort(samps)

plt.figure()
act = tanh_activation(x, omega=tanh_omega, z=ci_lower, a=1, b=0)
act = act_tanh(x, mu=tanh_omega, z=ci_lower, a=1, b=0)
plt.plot(x, act, '-o')
plt.plot([ci_lower, ci_lower], [act.min(), act.max()], 'k--')
plt.title('Combined Distributions')
# plt.savefig('combined_lower_ci')

plt.figure()
act = tanh_activation(x, omega=tanh_omega, z=ci_upper, a=1, b=0)
act = act_tanh(x, mu=tanh_omega, z=ci_upper, a=1, b=0)
plt.plot(x, act, '-o')
plt.plot([ci_upper, ci_upper], [act.min(), act.max()], 'k--')
plt.title('Combined Distributions')
Expand Down Expand Up @@ -338,14 +338,14 @@ def test_combined_high_order(self):
x = np.sort(samps)

plt.figure()
act = tanh_activation(x, omega=1e-12, z=ci_lower, a=1, b=0)
act = act_tanh(x, mu=1e-12, z=ci_lower, a=1, b=0)
plt.plot(x, act, '-o')
plt.plot([ci_lower, ci_lower], [act.min(), act.max()], 'k--')
plt.title('High-Order Combined Distributions')
# plt.savefig('high_order_lower_ci')

plt.figure()
act = tanh_activation(x, omega=1e-12, z=ci_upper, a=1, b=0)
act = act_tanh(x, mu=1e-12, z=ci_upper, a=1, b=0)
plt.plot(x, act, '-o')
plt.plot([ci_upper, ci_upper], [act.min(), act.max()], 'k--')
plt.title('High-Order Combined Distributions')
Expand Down
Loading