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

Import Error: Cannot import name 'getitem_dataclass' #184

Open
sambaPython24 opened this issue Jan 17, 2025 · 4 comments
Open

Import Error: Cannot import name 'getitem_dataclass' #184

sambaPython24 opened this issue Jan 17, 2025 · 4 comments

Comments

@sambaPython24
Copy link

sambaPython24 commented Jan 17, 2025

Hey, thank you for that library and your work. When I try to run the examples, I get the following error:

ImportError: cannot import name 'getitem_dataclass' from 'phiml.math._magic_ops' (.../python3.11/site-packages/phiml/math/_magic_ops.py)
@holl-
Copy link
Collaborator

holl- commented Jan 17, 2025

That looks like a version conflict. Could you upgrade the phiml library to 1.11 and send the full stack trace?

@sambaPython24
Copy link
Author

sambaPython24 commented Jan 17, 2025

@holl-
Thank you for your answer:

The following minimal example yields

import phiml
print("phiml version: ",phiml.__version__)

from phi.flow import Box,Sphere,batch,union,geom,plot

gives the output

1.11.0
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[5], line 4
      1 import phiml
      2 print("phiml version: ",phiml.__version__)
----> 4 from phi.flow import Box,Sphere,batch,union,geom,plot

File ~/anaconda3/envs/ENVNAME/lib/python3.11/site-packages/phi/flow.py:20
     18 from phiml.math import extrapolation
     19 import phi
---> 20 from . import geom, field, physics, vis
     21 from .physics import fluid, advect, diffuse
     23 # Classes

File ~/anaconda3/envs/ENVNAME/lib/python3.11/site-packages/phi/geom/__init__.py:25
     23 from ._grid import UniformGrid, enclosing_grid
     24 from ._graph import Graph, graph
---> 25 from ._mesh import Mesh, mesh, load_su2, load_gmsh, load_stl, mesh_from_numpy, build_mesh
     26 from ._heightmap import Heightmap
     27 from ._sdf_grid import SDFGrid, sample_sdf

File ~/anaconda3/envs/ENVNAME/lib/python3.11/site-packages/phi/geom/_mesh.py:15
     10 from phiml import math
     11 from phiml.math import to_format, is_sparse, non_channel, non_batch, batch, pack_dims, unstack, tensor, si2d, non_dual, nonzero, stored_indices, stored_values, scatter, \
     12     find_closest, sqrt, where, vec_normalize, argmax, broadcast, zeros, EMPTY_SHAPE, meshgrid, mean, reshaped_numpy, range_tensor, convolve, \
     13     assert_close, shift, pad, extrapolation, sum as sum_, dim_mask, math, Tensor, Shape, channel, shape, instance, dual, rename_dims, expand, spatial, wrap, sparse_tensor, \
     14     stack, vec_length, tensor_like, pairwise_distances, concat, Extrapolation, dsum, reshaped_tensor, dmean
---> 15 from phiml.math._magic_ops import getitem_dataclass
     16 from phiml.math._sparse import CompactSparseTensor
     17 from phiml.math.extrapolation import as_extrapolation, PERIODIC

ImportError: cannot import name 'getitem_dataclass' from 'phiml.math._magic_ops' (/.../ENVNAME/lib/python3.11/site-packages/phiml/math/_magic_ops.py)

If we look at the relevant file in the phiml github repository, I indeed don't find a method getitem_dataclass availab

@sambaPython24
Copy link
Author

I tried with some of the versions of the package (versions = "1.11.0, 1.10.2, 1.10.1, 1.10.0, 1.9.3, 1.9.2, 1.9.1, 1.9.0, 1.8.0, 1.7.5, 1.7.4, 1.7.3, 1.7.2, 1.7.1, 1.7.0.post1, 1.7.0, 1.6.0, 1.5.1, 1.5.0, 1.4.0, 1.3.1, 1.3.0, 1.2.1, 1.2.0, 1.1.0, 1.0.4, 1.0.3, 1.0.2, 1.0.1, 1.0.0"), but it is not available in any of them and the same error is coming.

Could that be an import error and you actually wanted to use the following
"""
from _dataclasses.py import getitem
"""
as this is the only method that appears to be close to the error.

@holl-
Copy link
Collaborator

holl- commented Jan 20, 2025

Okay, I'll look into it. In the meantime, this should work

pip uninstall phiflow
pip install git+https://github.com/tum-pbs/PhiFlow@develop
pip uninstall phiml
pip install git+https://github.com/tum-pbs/PhiML@develop

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