Skip to content

Commit

Permalink
Test all examples in CI - integration testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Saransh-cpp committed Sep 17, 2023
1 parent 7ec14ec commit 80f1c69
Show file tree
Hide file tree
Showing 22 changed files with 272,003 additions and 29 deletions.
121 changes: 107 additions & 14 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ concurrency:
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}

jobs:
build:
build_with_tensorflow_v1:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.8", "3.9", "3.10", "3.11"]
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
Expand All @@ -35,41 +35,134 @@ jobs:
- name: List environment
run: python -m pip freeze

- name: Test build with TensorFlow v1
- name: Integration tests with TensorFlow v1
env:
DDE_BACKEND: tensorflow.compat.v1
run: |
python -m pip install tensorflow
python -c "import deepxde"
cd examples/
make run_all_examples
make clean
- name: Test build with TensorFlow
build_with_tensorflow:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install DeepXDE with requirements
run: python -m pip install -e .

- name: List environment
run: python -m pip freeze

- name: Integration tests with TensorFlow
env:
DDE_BACKEND: tensorflow
run: |
python -m pip install tensorflow-probability
python -c "import deepxde"
python -m pip install tensorflow tensorflow-probability
cd examples/
make run_all_examples
make clean
build_with_pytorch:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install DeepXDE with requirements
run: python -m pip install -e .

- name: List environment
run: python -m pip freeze

- name: Test build with PyTorch
- name: Integration tests with PyTorch
env:
DDE_BACKEND: pytorch
run: |
python -m pip install torch
python -c "import deepxde"
cd examples/
make run_all_examples
make clean
- name: Test build with Jax
if: matrix.os != 'windows-latest' # jaxlib is not available on windows
build_with_jax:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
os: [ubuntu-latest, macos-latest]

steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install DeepXDE with requirements
run: python -m pip install -e .

- name: List environment
run: python -m pip freeze

- name: Integration tests with Jax
env:
DDE_BACKEND: jax
run: |
python -m pip install jax flax optax
python -c "import deepxde"
cd examples/
make run_all_examples
make clean
build_with_paddle:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install DeepXDE with requirements
run: python -m pip install -e .

- name: List environment
run: python -m pip freeze

- name: Test build with Paddle
- name: Integration tests with Paddle
env:
DDE_BACKEND: paddle
ubuntu-latest: "https://www.paddlepaddle.org.cn/whl/linux/cpu-mkl/develop.html"
macos-latest: "https://www.paddlepaddle.org.cn/whl/mac/cpu/develop.html"
windows-latest: "https://www.paddlepaddle.org.cn/whl/windows/cpu-mkl-avx/develop.html"
run: |
python -m pip install paddlepaddle==0.0.0 -f ${{ env[matrix.os] }}
python -c "import deepxde"
cd examples/
make run_all_examples
make clean
7 changes: 4 additions & 3 deletions deepxde/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import sys
import random

import numpy as np
Expand Down Expand Up @@ -52,7 +53,7 @@
elif backend_name == "jax":
xla_jit = True
if xla_jit:
print("Enable just-in-time compilation with XLA.\n")
print("Enable just-in-time compilation with XLA.\n", file=sys.stderr, flush=True)


def default_float():
Expand Down Expand Up @@ -179,9 +180,9 @@ def enable_xla_jit(mode=True):
global xla_jit
xla_jit = mode
if xla_jit:
print("Enable just-in-time compilation with XLA.\n")
print("Enable just-in-time compilation with XLA.\n", file=sys.stderr, flush=True)
else:
print("Disable just-in-time compilation with XLA.\n")
print("Disable just-in-time compilation with XLA.\n", file=sys.stderr, flush=True)


def disable_xla_jit():
Expand Down
2 changes: 1 addition & 1 deletion docs/demos/pinn_forward/heat.resample.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ We then train the model for 20000 iterations:

.. code-block:: python
losshistory, train_state = model.train(epochs=200000, callbacks=[pde_resampler])
losshistory, train_state = model.train(iterations=200000, callbacks=[pde_resampler])
After we train the network using Adam, we continue to train the network using L-BFGS to achieve a smaller loss:

Expand Down
4 changes: 2 additions & 2 deletions docs/demos/pinn_forward/helmholtz.2d.sound.hard.abc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Then, we begin by defining the general parameters for the problem. The PINN will
.. code-block:: python
weights = 1
epochs = 10000
iterations = 10000
learning_rate = 1e-3
num_dense_layers = 3
num_dense_nodes = 350
Expand Down Expand Up @@ -216,7 +216,7 @@ We first train the model for 5000 iterations with Adam optimizer:

.. code-block:: python
losshistory, train_state = model.train(epochs=epochs)
losshistory, train_state = model.train(iterations=iterations)
Complete code
Expand Down
2 changes: 1 addition & 1 deletion docs/demos/pinn_inverse/lorenz.inverse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ We then train the model for 60000 iterations:

.. code-block:: python
losshistory, train_state = model.train(epochs=60000, callbacks=[variable])
losshistory, train_state = model.train(iterations=60000, callbacks=[variable])
Complete code
--------------
Expand Down
6 changes: 3 additions & 3 deletions examples/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Directories where to look for *.py example scripts
EXAMPLE_DIRECTORIES := function pinn_forward pinn_inverse
EXAMPLE_DIRECTORIES := function operator pinn_forward pinn_inverse

# Environment variables for the scripts
# Note that the PYTHONPATH is relative to each example subdirectory, not the
Expand All @@ -24,12 +24,12 @@ run_all_examples: $(example_files)
@echo -----------------------------------------------------
@echo $@
@echo -----------------------------------------------------
@cd $(dir $@) && $(DDE_TEST_ENV) python ../sample_to_test.py $(notdir $@) | PYTHONPATH=../.. python -
@cd $(dir $@) && $(DDE_TEST_ENV) python3 ../sample_to_test.py $(notdir $@) | PYTHONPATH=../.. python3 -
@echo
@echo
@cd ..


# Clean all data files in example directories
clean: $(foreach dir,$(EXAMPLE_DIRECTORIES),$(wildcard $(dir)/*.dat)) $(foreach dir,$(EXAMPLE_DIRECTORIES),$(wildcard $(dir)/*.npz))
clean: $(foreach dir,$(EXAMPLE_DIRECTORIES),$(wildcard $(dir)/*.dat)) $(foreach dir,$(EXAMPLE_DIRECTORIES),$(wildcard $(dir)/*.npz)) $(foreach dir,$(EXAMPLE_DIRECTORIES),$(wildcard $(dir)/*.pdf))
rm $^
3 changes: 3 additions & 0 deletions examples/function/loss.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# step, loss_train, loss_test, metrics_test
0.000000000000000000e+00 4.099467849731445312e+01 4.577549743652343750e+01 8.006751537322998047e-01 8.234747314453125000e+01 2.167162132263183594e+01 8.006751537322998047e-01 1.014482021331787109e+00 9.883788228034973145e-01
1.000000000000000000e+00 4.060080718994140625e+01 4.556640625000000000e+01 7.994772791862487793e-01 8.193739318847656250e+01 2.162880516052246094e+01 7.994772791862487793e-01 1.009474158287048340e+00 9.873472452163696289e-01
Loading

0 comments on commit 80f1c69

Please sign in to comment.