Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: axes don't match array when running "Building Meshes" tutorial #186

Open
sambaPython24 opened this issue Jan 27, 2025 · 1 comment

Comments

@sambaPython24
Copy link

sambaPython24 commented Jan 27, 2025

Hey, when I run your Build Mesh tutorial, I get the following error

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[2], line 9
      7 sphere = Sphere(x=sphere_x, y=.5, radius=.3)
      8 box = Box(x=(1, 3), y=(-1, .5))
----> 9 mesh = geom.build_mesh(domain, x=30, y=10, obstacles=union(sphere, box))
     10 plot(mesh, animate='time')

File ~/.../site-packages/phi/geom/_mesh.py:884, in build_mesh(bounds, resolution, obstacles, method, cell_dim, face_format, max_squish, **resolution_)
    882     boundaries = {b: edges.numpy('edges,~vert') for b, edges in boundaries.items()}
    883     return mesh_from_numpy(points_np, polygon_list, boundaries, cell_dim=cell_dim, face_format=face_format)
--> 884 return math.map(build_single_mesh, vert_pos, polygons, boundaries, dims=batch)

File ~/.../site-packages/phiml/math/_functional.py:1367, in map_(function, dims, range, unwrap_scalars, expand_results, simplify, *args, **kwargs)
   1365     idx_extra_args = list(extra_args)
   1366     idx_all_args = [idx_args.pop(0) if isinstance(v, Shapable) else idx_extra_args.pop(0) for v in args]
-> 1367     f_output = function(*idx_all_args, **idx_kwargs, **extra_kwargs)
   1368     results.append(f_output)
   1369 if isinstance(results[0], tuple):

File ~/.../site-packages/phi/geom/_mesh.py:882, in build_mesh.<locals>.build_single_mesh(vert_pos, polygons, boundaries)
    880 points_np = reshaped_numpy(vert_pos, [..., channel])
    881 polygon_list = reshaped_numpy(polygons, [..., dual])
--> 882 boundaries = {b: edges.numpy('edges,~vert') for b, edges in boundaries.items()}
    883 return mesh_from_numpy(points_np, polygon_list, boundaries, cell_dim=cell_dim, face_format=face_format)

File ~/.../site-packages/phiml/math/_tensors.py:122, in Tensor.numpy(self, order, force_expand)
     97 def numpy(self, order: Union[str, tuple, list, Shape] = None, force_expand=True) -> np.ndarray:
     98     """
     99     Converts this tensor to a `numpy.ndarray` with dimensions ordered according to `order`.
    100     
   (...)
    120         ValueError if the tensor cannot be transposed to match target_shape
    121     """
--> 122     return self.backend.numpy(self.native(order, force_expand))

File ~/.../site-packages/phiml/math/_tensors.py:1490, in TensorStack.native(self, order, force_expand)
   1488 def native(self, order: Union[str, tuple, list, Shape] = None, force_expand=True):
   1489     if force_expand:
-> 1490         return self._reshaped_native(process_groups_for(self._shape, order))
   1491     # ToDo
   1492     return self._reshaped_native(process_groups_for(self._shape, order))

File ~/.../site-packages/phiml/math/_tensors.py:1500, in TensorStack._reshaped_native(self, groups)
   1498 def _reshaped_native(self, groups: Sequence[Shape]):
   1499     if not self.requires_broadcast:
-> 1500         return self._contiguous()._reshaped_native(groups)
   1501     stack_group = [g for g in groups if self._stack_dim in g]
   1502     assert len(stack_group) == 1

File ~/.../site-packages/phiml/math/_tensors.py:1239, in Dense._reshaped_native(self, groups)
   1237             slices.append(None)
   1238             tile.append(dim.size)
-> 1239 native = self._backend.transpose(native, perm)
   1240 native = native[tuple(slices)]
   1241 native = self._backend.tile(native, tile)

File ~/.../site-packages/numpy/core/fromnumeric.py:655, in transpose(a, axes)
    588 @array_function_dispatch(_transpose_dispatcher)
    589 def transpose(a, axes=None):
    590     """
    591     Returns an array with axes transposed.
    592 
   (...)
    653 
    654     """
--> 655     return _wrapfunc(a, 'transpose', axes)

File ~/.../site-packages/numpy/core/fromnumeric.py:59, in _wrapfunc(obj, method, *args, **kwds)
     56     return _wrapit(obj, method, *args, **kwds)
     58 try:
---> 59     return bound(*args, **kwds)
     60 except TypeError:
     61     # A TypeError occurs if the object does have such a method in its
     62     # class, but its signature is not identical to that of NumPy's. This
   (...)
     66     # Call _wrapit from within the except clause to ensure a potential
     67     # exception has a traceback chain.
     68     return _wrapit(obj, method, *args, **kwds)

ValueError: axes don't match array
@holl-
Copy link
Collaborator

holl- commented Jan 27, 2025

Hi, this bug is related to plotting multiple meshes at the same time. If you only plot one mesh, it should work.
I'll fix it for the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants