Assertion error while using functionspace with MixedElement

I am trying to use two function spaces V and Q for variable u and p of Navier Stokes equation. I need to combine the spaces so as to use Newton Solver to solve the steady state equation. But I getting AssertionError. My code is as follows:

from dolfinx.io import (gmshio)
from mpi4py import MPI
from ufl.finiteelement import MixedElement
from dolfinx.fem import Function
from ufl import (TestFunction, TrialFunction,split)
gdim = 2
mesh_comm = MPI.COMM_WORLD
model_rank = 0
mesh, _, ft =gmshio.read_from_msh("cylinder.msh", mesh_comm, model_rank, gdim)
##function spaces
v_cg2 = element("Lagrange", mesh.topology.cell_name(), 2,shape=(mesh.geometry.dim, ))
s_cg1 = element("Lagrange", mesh.topology.cell_name(), 1)
mixEl = MixedElement([v_cg2, s_cg1])
#combined space
W = functionspace(mesh, mixEl)
# Test and trial functions: monolithic
(v, q) = TestFunctions(W)
dup = TrialFunction(W)
uh  = fem.Function(W)
(u, p) = split(uh)
The error message is:
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Cell In[9], line 6
      4 mixEl = MixedElement([v_cg2, s_cg1])
      5 #combined space
----> 6 W = functionspace(mesh, mixEl)
      7         # Test and trial functions: monolithic
      8 (v, q) = TestFunctions(W)

File /usr/lib/petsc/lib/python3/dist-packages/dolfinx/fem/function.py:655, in functionspace(mesh, element, form_compiler_options, jit_options)
    653     form_compiler_options = dict()
    654 form_compiler_options["scalar_type"] = dtype
--> 655 (ufcx_element, ufcx_dofmap), module, code = jit.ffcx_jit(
    656     mesh.comm,
    657     ufl_e,
    658     form_compiler_options=form_compiler_options,
    659     jit_options=jit_options,
    660 )
    662 ffi = module.ffi
    663 if np.issubdtype(dtype, np.float32):

File /usr/lib/petsc/lib/python3/dist-packages/dolfinx/jit.py:51, in mpi_jit_decorator.<locals>.mpi_jit(comm, *args, **kwargs)
     47 @functools.wraps(local_jit)
     48 def mpi_jit(comm, *args, **kwargs):
     49     # Just call JIT compiler when running in serial
     50     if comm.size == 1:
---> 51         return local_jit(*args, **kwargs)
     53     # Default status (0 == ok, 1 == fail)
     54     status = 0

File /usr/lib/petsc/lib/python3/dist-packages/dolfinx/jit.py:203, in ffcx_jit(ufl_object, form_compiler_options, jit_options)
    201     r = ffcx.codegeneration.jit.compile_forms([ufl_object], options=p_ffcx, **p_jit)
    202 elif isinstance(ufl_object, ufl.AbstractFiniteElement):
--> 203     r = ffcx.codegeneration.jit.compile_elements([ufl_object], options=p_ffcx, **p_jit)
    204 elif isinstance(ufl_object, ufl.Mesh):
    205     r = ffcx.codegeneration.jit.compile_coordinate_maps([ufl_object], options=p_ffcx, **p_jit)

File /usr/lib/python3/dist-packages/ffcx/codegeneration/jit.py:158, in compile_elements(elements, options, cache_dir, timeout, cffi_extra_compile_args, cffi_verbose, cffi_debug, cffi_libraries, visualise)
    156 names = []
    157 for e in elements:
--> 158     name = ffcx.naming.finite_element_name(e, module_name)
    159     names.append(name)
    160     name = ffcx.naming.dofmap_name(e, module_name)

File /usr/lib/python3/dist-packages/ffcx/naming.py:107, in finite_element_name(ufl_element, prefix)
    105 def finite_element_name(ufl_element: basix.ufl._ElementBase, prefix: str) -> str:
    106     """Get finite element name."""
--> 107     assert isinstance(ufl_element, basix.ufl._ElementBase)
    108     sig = compute_signature([ufl_element], prefix)
    109     return f"element_{sig}"

AssertionError: 

Any help is appreciated.

Please note that you havent provided a minimal reproducible example, as we do not have the mesh. Could you provide a minimal example using a unit square mesh?

Please also note that I did modify your code by adding

```python
# code here
```

to make it properly format.

Thanks for pointing out.
here is the minimalist code:

from dolfinx.io import (gmshio)
from mpi4py import MPI
from ufl.finiteelement import MixedElement
from basix.ufl import element
from dolfinx import mesh
from dolfinx.fem import Function, functionspace
from ufl import (TestFunction, TrialFunction,split)
gdim = 2
mesh_comm = MPI.COMM_WORLD
model_rank = 0

dom = mesh.create_unit_square(MPI.COMM_WORLD, 10, 10)

##function spaces
v_cg2 = element("Lagrange", dom.topology.cell_name(), 2,shape=(dom.geometry.dim, ))
s_cg1 = element("Lagrange", dom.topology.cell_name(), 1)
mixEl = MixedElement([v_cg2, s_cg1])
#combined space
W = functionspace(dom, mixEl)
# Test and trial functions: monolithic
(v, q) = TestFunctions(W)
dup = TrialFunction(W)
uh  = fem.Function(W)
(u, p) = split(uh)

You should use basix.ufl.mixed_element.
MWE below:

from mpi4py import MPI
from basix.ufl import element, mixed_element
from dolfinx import mesh
from dolfinx.fem import Function, functionspace
from ufl import (TestFunctions, TrialFunction,split)
gdim = 2
mesh_comm = MPI.COMM_WORLD
model_rank = 0

dom = mesh.create_unit_square(MPI.COMM_WORLD, 10, 10)

##function spaces
v_cg2 = element("Lagrange", dom.topology.cell_name(), 2,shape=(dom.geometry.dim, ))
s_cg1 = element("Lagrange", dom.topology.cell_name(), 1)
mixEl = mixed_element([v_cg2, s_cg1])
#combined space
W = functionspace(dom, mixEl)
# Test and trial functions: monolithic
(v, q) = TestFunctions(W)
dup = TrialFunction(W)
uh  = Function(W)
(u, p) = split(uh)