tum-pbs/PhiFlow

Error running the tutorial `Variables_Boundaries`

Opened this issue · 1 comments

Running the notebook Variable_Boundaries.ipynb I obtain an error on step function, both in my machine and in Google Colab.

The error stack is:

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
[<ipython-input-17-b160c332cf08>](https://localhost:8080/#) in <cell line: 9>()
      7 
      8 v0 = StaggeredGrid(0, boundary, domain, x=50, y=32)
----> 9 v, p = step(v0, None)
     10 plot({'velocity': v, 'pressure': p})

10 frames
[<ipython-input-17-b160c332cf08>](https://localhost:8080/#) in step(v, pressure, dt)
      1 def step(v: Field, pressure, dt=1.):  # velocity, pressure, time increment
      2     v = advect.semi_lagrangian(v, v, dt)
----> 3     v = diffuse.explicit(v, 0.01, dt)
      4     v, pressure = fluid.make_incompressible(v, solve=Solve(x0=pressure))
      5     return v, pressure

[/usr/local/lib/python3.10/dist-packages/phi/physics/diffuse.py](https://localhost:8080/#) in explicit(u, diffusivity, dt, substeps, order, implicit, gradient, upwind, correct_skew)
     57         amount = amount.at(u)
     58     for i in range(substeps):
---> 59         u += differential(u, amount, gradient=gradient, order=order, implicit=implicit, upwind=upwind, correct_skew=correct_skew)
     60     return u
     61 

[/usr/local/lib/python3.10/dist-packages/phi/physics/diffuse.py](https://localhost:8080/#) in differential(u, diffusivity, gradient, order, implicit, upwind, correct_skew)
    138             raise NotImplementedError("spatially-varying diffusion currently only supported for centered grids")
    139     else:
--> 140         lap = laplace(u, weights=diffusivity, gradient=gradient, order=order, implicit=implicit, upwind=upwind, correct_skew=correct_skew)
    141     return lap.with_extrapolation(u.boundary - u.boundary)  # remove constants from extrapolation
    142 

[/usr/local/lib/python3.10/dist-packages/phi/field/_field_math.py](https://localhost:8080/#) in laplace(u, axes, gradient, order, implicit, implicitness, weights, upwind, correct_skew)
    124     for f in fields:
    125         if order == 2:
--> 126             result.append(math.map_d2c(math.laplace)(f.values, dx=f.dx, padding=f.extrapolation, dims=axes, weights=weights))  # uses ghost cells
    127         else:
    128             result_components = [perform_finite_difference_operation(f.values, dim, 2, f.dx.vector[dim], f.extrapolation,

[/usr/local/lib/python3.10/dist-packages/phiml/math/_functional.py](https://localhost:8080/#) in retyped_f(*args, **kwargs)
   1182             retyped_arg, input_types = forward_retype(arg, input_types)
   1183             retyped_args.append(retyped_arg)
-> 1184         output = f(*retyped_args, **kwargs)
   1185         restored_output = reverse_retype(output, input_types)
   1186         return restored_output

[/usr/local/lib/python3.10/dist-packages/phiml/math/_nd.py](https://localhost:8080/#) in laplace(x, dx, padding, dims, weights)
    850     if isinstance(x, Extrapolation):
    851         return x.spatial_gradient()
--> 852     left, center, right = shift(wrap(x), (-1, 0, 1), dims, padding, stack_dim=batch('_laplace'))
    853     result = (left + right - 2 * center) / (dx ** 2)
    854     if weights is not None:

[/usr/local/lib/python3.10/dist-packages/phiml/math/_nd.py](https://localhost:8080/#) in shift(x, offsets, dims, padding, stack_dim, extend_bounds)
    520     pad_upper = max(0, max(offsets))
    521     if padding is not None:
--> 522         x = math.pad(x, {axis: (pad_lower + extend_bounds, pad_upper + extend_bounds) for axis in dims}, mode=padding)
    523     if extend_bounds:
    524         assert padding is not None

[/usr/local/lib/python3.10/dist-packages/phiml/math/_ops.py](https://localhost:8080/#) in pad(value, widths, mode, **kwargs)
    834         slices = {dim: slice(max(0, -w[0]), min(0, w[1]) or None) for dim, w in widths.items()}
    835         widths = {dim: (max(0, w[0]), max(0, w[1])) for dim, w in widths.items()}
--> 836     result_padded = mode.pad(value, widths, **kwargs) if has_positive_widths else value
    837     result_sliced = result_padded[slices] if has_negative_widths else result_padded
    838     return result_sliced

[/usr/local/lib/python3.10/dist-packages/phiml/math/extrapolation.py](https://localhost:8080/#) in pad(self, value, widths, already_padded, **kwargs)
   1299         for ext in extrapolations:
   1300             ext_widths = {dim: (l if self._at_boundary(dim+'-') == ext else 0, u if self._at_boundary(dim+'+') == ext else 0) for dim, (l, u) in widths.items()}
-> 1301             value = ext.pad(value, ext_widths, already_padded=already_padded, **kwargs)
   1302             already_padded.update(ext_widths)
   1303         return value

[/usr/local/lib/python3.10/dist-packages/phiml/math/extrapolation.py](https://localhost:8080/#) in pad(self, value, widths, already_padded, **kwargs)
    114             values = []
    115             if width[False] > 0:
--> 116                 values.append(self.pad_values(value, width[False], dim, False, already_padded=already_padded, **kwargs))
    117             values.append(value)
    118             if width[True] > 0:

[/usr/local/lib/python3.10/dist-packages/phi/field/_embed.py](https://localhost:8080/#) in pad_values(self, value, width, dim, upper_edge, bounds, already_padded, **kwargs)
     54 
     55     def pad_values(self, value: Tensor, width: int, dim: str, upper_edge: bool, bounds: Box = None, already_padded: dict = None, **kwargs) -> Tensor:
---> 56         assert bounds is not None, f"{type(self)}.pad() requires 'bounds' argument"
     57         if value.shape.is_non_uniform:
     58             unstacked = unstack(value, value.shape.non_uniform_shape)

AssertionError: <class 'phi.field._embed.FieldEmbedding'>.pad() requires 'bounds' argument

The version I've installed are:

  • phiflow 3.0.1
  • phiml 1.8.0

Hi, thanks for the bug report! I've pushed a fix to the dev+3d branch and you'll need phiml==1.9.0

pip uninstall phiflow
pip install --upgrade git+https://github.com/tum-pbs/PhiFlow@dev+3d