Complex numbers

I am new to fenics and somewhat baffled by the complex number support. My OS is Ubuntu 22.04 and believe I have installed the complex number packages for petsc, slepc and fenics. Changing the PETSC_DIR and SLEPC_DIR environment variables changes the PETSc scalar type as expected. The Poisson demo with complex numbers seemed to run as expected (although a hanging pyvista required addressing). The “Solving PDEs with different scalar (float) types” demo however fails with:

NotImplementedError: Type <class ‘numpy.complex64’> not supported.

The error is independent of the PETSc scalar type and looks similar to the types of errors appearing in my own code. I appreciate fenicsx is still under development but are complex numbers and this demo program expected to work? Are the ubuntu 22.04 packages expected to work? Is compiling from source expected to work? Have I got something obvious wrong?

Could you be more specific as to what line of: Solving PDEs with different scalar (float) types — DOLFINx 0.5.1 documentation
produces this error?

Secondly, could you provide the full traceback of your error message, encapsulated as

```
Add traceback here
```

Finally, how did you install dolfin?

What are the exact instructions you used, and what is the output of the installation commands?

The output from the demo was:

andy@tavy:~/work/fenicsx/modanal$ python test4.py
Traceback (most recent call last):
  File "/home/andy/work/fenicsx/modanal/test4.py", line 126, in <module>
    uh = solve(dtype=np.complex64)
  File "/home/andy/work/fenicsx/modanal/test4.py", line 72, in solve
    a0 = fem.form(a, dtype=dtype)
  File "/usr/lib/petscdir/petsc3.15/x86_64-linux-gnu-complex/lib/python3/dist-packages/dolfinx/fem/forms.py", line 121, in form
    raise NotImplementedError(f"Type {dtype} not supported.")
NotImplementedError: Type <class 'numpy.complex64'> not supported.
andy@tavy:~/work/fenicsx/modanal$

The initial installation on Ubuntu 22.04 was:

1054  add-apt-repository ppa:fenics-packages/fenics
1055  sudo add-apt-repository ppa:fenics-packages/fenics
1056  sudo apt update
1057  sudo apt install fenicsx

This was later followed by adding additional complex number related packages via synaptic and pip as I tried to get complex numbers to work. I don’t have a full record but it was all done with packages rather than compilation.

As the error message states np.complex64 is not implemented, but np.complex128 (for v0.5.1 dolfinx/forms.py at v0.5.1 · FEniCS/dolfinx · GitHub).

Complex 64 is implemented for v0.6.0, Ref Pass std::span by value (rather than reference) by garth-wells · Pull Request #2437 · FEniCS/dolfinx · GitHub

The demo program you linked to runs correctly. It doesn’t include the complex64 type unlike the (presumably earlier?) demo program I was using. Apologies for the misinformation.

My problems are with a refusal to create complex128 stiffness matrices but now I have a working example it may help me to work out what is going on. Thanks for your help.

I guess you were running the demo for v0.6.0 or the main branch, while 0.5.1 is the latest version on apt.

A working example did guide me to what I was doing wrong within a few minutes. Thanks again.