Error to run my code

Hello,
Can you help me, please? I develop a nitsche’s method for Darcy problem with permeability equal to 1, but I have the following problem when I run my code (I installed Fenics by using conda install -c conda-forge fenics - spyder)

  File ~/Travaux/FENICS/MyProjects/test_04_Fev_2022.py:106 in <module>
    R = nitscheDarcy(N=4)

  File ~/Travaux/FENICS/MyProjects/test_04_Fev_2022.py:84 in nitscheDarcy
    a= inner(grad(u),grad(v))*dx - inner(dot(grad(u),n),v)*ds-inner(u,dot(grad(v),n))*ds +(gamma/h_E)*inner(u, v)*ds

  File ~/Travaux/Env_Anaconda/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/ufl/operators.py:380 in grad
    f = as_ufl(f)

  File ~/Travaux/Env_Anaconda/anaconda3/envs/fenicsproject/lib/python3.9/site-packages/ufl/constantvalue.py:471 in as_ufl
    raise UFLValueError("Invalid type conversion: %s can not be converted"

UFLValueError: Invalid type conversion: (Argument(FunctionSpace(Mesh(VectorElement(FiniteElement('Lagrange', triangle, 1), dim=2), 156), FiniteElement('Lagrange', triangle, 1)), 1, None),) can not be converted to any UFL type.
from __future__ import print_function
from fenics import *
import numpy as np
from math import isnan, log
import ufl
import mshr
from dolfin import *
from collections import namedtuple

parameters["allow_extrapolation"] = True
parameters["form_compiler"]["cpp_optimize"] = True
set_log_level(20)


class Left(SubDomain): 
    def inside(self, x, on_boundary): 
        return near(x[0], 0.0) 
class Right(SubDomain): 
    def inside(self, x, on_boundary): 
        return near(x[0], 1.0)
class Bottom(SubDomain): 
    def inside(self, x, on_boundary): 
        return near(x[1], 0.0) 
class Top(SubDomain): 
    def inside(self, x, on_boundary): 
        return near(x[1], 1.0) 
class Obstacle(SubDomain): 
    def inside(self, x, on_boundary): 
        return (between(x[1], (0.5, 0.8)) and fe.between(x[0], (0, 1.0)))

Result = namedtuple('Resulat', ['h' , 'L2', 'H10' 'H1'])
f= Expression('2*pow(pi,2)*sin(pi*x[0])*sin(pi*x[1])',degree=1)
u_exact = Expression('x[0]*x[1] + sin(pi*x[0])*sin(pi*x[1])', degree=1)

def nitscheDarcy(N): 
    mesh = UnitSquareMesh(N,N)
    V = FunctionSpace(mesh, 'CG', 1)
    u = TrialFunctions(V)
    v = TestFunctions(V)
    gamma_value = 19.0
    gamma =Constant(gamma_value)
    n = FacetNormal(mesh)
    h_E = MaxFacetEdgeLength(mesh)
    a= inner(grad(u),grad(v))*dx - inner(dot(grad(u),n),v)*ds-inner(u,dot(grad(v),n))*ds +(gamma/h_E)*inner(u, v)*ds
    L = inner(f, v)*dx - inner(u_exact,dot(grad(v),n))*ds + (gamma/h_E)*inner(u_exact,v)*ds
   
    uh = Function(V)
    solve(a == L, uh)
    plot(uh, interactive = True)
    E = FunctionSpace(mesh, 'CG', 4)
    uh = interpolate(u_exact, E)
    e = uh - u
    norm_L2 = assemble(inner(e, e)*dx, mesh=mesh)
    norm_H10 = assemble(inner(grad(e), grad(e))*dx, mesh=mesh)
    norm_edge = assemble(h_E**2-1*inner(e,e)*ds)
    norm_H1 = norm_L2 + norm_H10 + norm_edge
   
    norm_L2 = sqrt(norm_L2)
    norm_H1 = sqrt(norm_H1)
    norm_H10 = sqrt(norm_H10) 
   
    return Result(h=mesh.hmin(), L2=norm_L2, H1=norm_H1, H10=norm_H10)

norm_type = 'L2' 
R = nitscheDarcy(N=4)
h_ = R.h 
e_ = getattr(R, norm_type) 
for N in [8, 16, 32, 64, 128]: 
    R = method(N=N) 
    h = R.h 
    e = getattr(R, norm_type) 
    rate = log(e/(e_))/log(h/(h_)) 
    print('{h:.3E} {e:.3E} {rate:.2f}'.format(h=h, e=e, rate=rate))

Best regards.

should be

 u = TrialFunction(V)
 v = TestFunction(V)

Secondly,

should be

    h_E = MaxCellEdgeLength(mesh)

when you run 2D problems.

Thirdly

should be

  norm_L2 = assemble(inner(e, e)*dx(domain=mesh))
  norm_H10 = assemble(inner(grad(e), grad(e))*dx(domain=mesh))

Thank you very much @dokken