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

TypeError when running Real Function Space example #39

Closed
dhalatsis opened this issue Oct 2, 2024 · 9 comments
Closed

TypeError when running Real Function Space example #39

dhalatsis opened this issue Oct 2, 2024 · 9 comments

Comments

@dhalatsis
Copy link

dhalatsis commented Oct 2, 2024

Running the https://github.com/scientificcomputing/scifem/blob/main/examples/real_function_space.py. I get the following error.
I am running scifem on WSL2 with dolfinx 0.8

{
	"name": "TypeError",
	"message": "create_real_functionspace_float64(): incompatible function arguments. The following argument types are supported:
    1. create_real_functionspace_float64(arg0: dolfinx::mesh::Mesh<double>, arg1: collections.abc.Sequence[int], /) -> dolfinx::fem::FunctionSpace<double>

Invoked with types: dolfinx.cpp.mesh.Mesh_float64, tuple",
	"stack": "---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[6], line 82
     78 h = assemble_scalar(u_exact(x) * ufl.dx)
     80 # We then create the Lagrange multiplier space
---> 82 R = create_real_functionspace(mesh)
     84 # Next, we can create a mixed-function space for our problem
     86 if dolfinx.__version__ == \"0.8.0\":

File ~/miniconda3/envs/scifem/lib/python3.10/site-packages/scifem/__init__.py:49, in create_real_functionspace(mesh, value_shape)
     44 ufl_e = basix.ufl.element(
     45     \"P\", mesh.basix_cell(), 0, dtype=dtype, discontinuous=True, shape=value_shape
     46 )
     48 if (dtype := mesh.geometry.x.dtype) == np.float64:
---> 49     cppV = _scifem.create_real_functionspace_float64(mesh._cpp_object, value_shape)
     50 elif dtype == np.float32:
     51     cppV = _scifem.create_real_functionspace_float32(mesh._cpp_object, value_shape)

TypeError: create_real_functionspace_float64(): incompatible function arguments. The following argument types are supported:
    1. create_real_functionspace_float64(arg0: dolfinx::mesh::Mesh<double>, arg1: collections.abc.Sequence[int], /) -> dolfinx::fem::FunctionSpace<double>

Invoked with types: dolfinx.cpp.mesh.Mesh_float64, tuple"
}```

@jorgensd
Copy link
Member

jorgensd commented Oct 2, 2024

Could you explain how you installed dolfinx and then scifem on top of it?

@dhalatsis
Copy link
Author

I created a fresh enviroment and immediately installed fenicsx using conda followed by installing scifem using python3 -m pip install scifem --no-build-isolation
(I also installed nanobind and skbuild-core that where missing apparently)

@jorgensd
Copy link
Member

jorgensd commented Oct 2, 2024

The issue is that you have installed nanobind with pip i guess?
@minrk is there a way of instructing pip to use the nanobind used for building DOLFINx when adding packages on top?
Or do I need to make a conda recipe for scifem?

@dhalatsis
Copy link
Author

I did install it with pip? Is something different recommended?

Thanks!

@jorgensd
Copy link
Member

jorgensd commented Oct 2, 2024

I did install it with pip? Is something different recommended?

Thanks!

The issue is that DOLFINx on conda has been built with a given nanobind version, and one has to use the same version when building scifem to get the correct compatibility.

@finsberg
Copy link
Member

finsberg commented Oct 2, 2024

I think we should add scifem to conda-forge as well, so that conda user don’t run into problems like this. I can take a look at this tomorrow

@bnherrerac
Copy link

I am having the exact same error here. I'm using dolfinx 0.8.0 on WSL2, which I installed in a conda environment, and scifem 0.2.5 + nanobind 2.1.0 (same version as in conda list), which I installed through pip in the conda environment. As suggested in a similar issue on dolfinx_mpc, conda install gxx=12 worked fine as a workaround, but the error persists for scifem.create_real_functionspace.

I'm not very experienced with this, maybe forcing a specific nanobind version before building dolfinx works?

Thank you all for your help!

@minrk
Copy link
Contributor

minrk commented Oct 3, 2024

I think installing from pip within conda is going to be tricky because assuming it does a standard pip installation, the build of scifem will use an isolated env with its own nanobind, the latest version that satisfies the constraint in scifem's pyproject.toml. dolfinx 0.8 is also incompatible with nanobind 2, so you cannot install nanobind 2.1 with conda and dolfinx 0.8:

The following packages are incompatible
├─ fenics-dolfinx 0.8**  is installable and it requires
│  └─ nanobind >=1.9.2,<1.10.0a0 , which can be installed;
└─ nanobind 2.1**  is not installable because it conflicts with any installable versions previously reported.

pip has no such version compatibility enforcement.

I can work on getting scifem in conda-forge.

@jorgensd
Copy link
Member

jorgensd commented Oct 8, 2024

Should be fixed in a few moments, as scifem is on conda-forge: https://anaconda.org/conda-forge/scifem

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

5 participants