lululxvi / deepxde

A library for scientific machine learning and physics-informed learning
https://deepxde.readthedocs.io
GNU Lesser General Public License v2.1
2.76k stars 760 forks source link

GeometryXTime random boundary points using a Cuboid #81

Closed ViktorC closed 4 years ago

ViktorC commented 4 years ago

Hi,

When initialising a TimePDE using a Cuboid geometry and the default value for train_distribution ("random"), something goes wrong in the random_boundary_points function of GeometryXTime. Please see the stack trace below.

File "/opt/anaconda3/envs/s1984842/lib/python3.7/site-packages/deepxde/data/pde.py", line 162, in __init__
    num_test=num_test,
  File "/opt/anaconda3/envs/s1984842/lib/python3.7/site-packages/deepxde/data/pde.py", line 44, in __init__
    self.train_next_batch()
  File "/opt/anaconda3/envs/s1984842/lib/python3.7/site-packages/deepxde/utils.py", line 23, in wrapper
    return func(self, *args, **kwargs)
  File "/opt/anaconda3/envs/s1984842/lib/python3.7/site-packages/deepxde/data/pde.py", line 76, in train_next_batch
    self.train_x = self.train_points()
  File "/opt/anaconda3/envs/s1984842/lib/python3.7/site-packages/deepxde/data/pde.py", line 177, in train_points
    self.num_boundary, random="sobol"
  File "/opt/anaconda3/envs/s1984842/lib/python3.7/site-packages/deepxde/geometry/timedomain.py", line 122, in random_boundary_points
    return np.hstack((x, t))
  File "<__array_function__ internals>", line 6, in hstack
  File "/opt/anaconda3/envs/s1984842/lib/python3.7/site-packages/numpy/core/shape_base.py", line 344, in hstack
    return _nx.concatenate(arrs, 1)
  File "<__array_function__ internals>", line 6, in concatenate
ValueError: all the input array dimensions for the concatenation axis must match exactly, but along dimension 0, the array at index 0 has size 40004 and the array at index 1 has size 40000

It should be reproducible in the latest version (0.8.2) using the following code snippet.

from deepxde.data import TimePDE
from deepxde.geometry import GeometryXTime, Cuboid, TimeDomain

data = TimePDE(
    geometryxtime=GeometryXTime(
        Cuboid((.0, .0, .0), (5., 5., 5.)),
        TimeDomain(.0, 1.)),
    pde=lambda x, y: None,  # the PDE makes no difference
    ic_bcs=[],  # neither do ICs or BCs
    num_domain=120000,
    num_boundary=40000,
    num_initial=20000)

If I set train_distribution to "uniform", this issue does not occur. The issue also does not occur if I use a Rectangle or an Interval as the spatial geometry. I did not dig too deep into the code but I noticed that on this line, the points from the time domain are always sampled using the "pseudo" mode as opposed to the actual random parameter which is used to sample points from the spatial boundaries. Could this be causing the discrepancy between the sizes of the arrays?

lululxvi commented 4 years ago

Yes, this is a bug. I have fixed it in the new version v0.8.3