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 7a9a893
Show file tree
Hide file tree
Showing 7 changed files with 161 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 $^
48 changes: 43 additions & 5 deletions examples/sample_to_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

import re
import sys
import deepxde as dde


EPOCHS_RE = re.compile(r"^(.*)epochs\s*=\s*(\d+)(.*)$", re.DOTALL)
ITERATIONS_RE = re.compile(r"^(.*)iterations\s*=\s*(\d+)(.*)$", re.DOTALL)

PROLOG = """
from deepxde.optimizers import set_LBFGS_options
Expand All @@ -24,9 +25,9 @@

def transform(line, file_name):
"""Apply transformations to line."""
m = re.match(EPOCHS_RE, line)
m = re.match(ITERATIONS_RE, line)
if m is not None:
line = m.expand(r"\1epochs=1\3")
line = m.expand(r"\1iterations=1\3")

# Burgers_RAR.py has an additional convergence loop: force 1 single pass
if file_name == "Burgers_RAR.py" and line.startswith("while"):
Expand All @@ -45,5 +46,42 @@ def transform(line, file_name):

print(PROLOG)
with open(file_name, "r") as input:
for line in input:
sys.stdout.write(transform(line, file_name))
if file_name not in (
# this example uses skopt which is not maintained
# and uses deprecated numpy API
"Allen_Cahn.py",
# the below examples have different code for different
# backends
"Beltrami_flow.py",
"Helmholtz_Dirichlet_2d_HPO.py",
"Laplace_disk.py",
"Lotka_Volterra.py",
"Poisson_Dirichlet_1d.py",
"Poisson_periodic_1d.py",
"diffusion_1d_exactBC.py",
"diffusion_1d_resample.py",
"diffusion_1d.py",
"diffusion_reaction.py",
"fractional_diffusion_1d.py",
"fractional_Poisson_1d.py",
"fractional_Poisson_2d.py",
"fractional_Poisson_3d.py",
"ide.py",
"diffusion_1d_inverse.py",
"fractional_Poisson_1d_inverse.py",
"fractional_Poisson_2d_inverse.py",
"Poisson_Lshape.py",
"ode_system.py",
"Lorenz_inverse.py",
# gives error with tensorflow.compat.v1
"Volterra_IDE.py",
# the dataset is large and not included in repo
"antiderivative_unaligned.py",
"antiderivative_aligned.py",
):
lines = input.readlines()
if dde.backend.get_preferred_backend() in lines[0].replace(",", "").replace(
'"""', ""
).replace("\n", "").split(" "):
for line in lines:
sys.stdout.write(transform(line, file_name))

0 comments on commit 7a9a893

Please sign in to comment.