Unable to cast python instances as c++type

Dear all, for my code d and e are constant. I want to store the value of d and e as pvd file. but while running it shows, “RuntimeError: Unable to cast Python instance to C++ type (compile in debug mode for details)”. How can i get rid out of it?

from dolfin import *
from fenics import *
from fenics_adjoint import *

rho = Constant(500.0) 
C= Constant(20.0)
dt=1
num_steps=10               

mesh = RectangleMesh(Point(0,0),Point(1,1), 10, 10)  
V = FunctionSpace(mesh, "Lagrange", 1) 
x=SpatialCoordinate(mesh)    
M = FunctionSpace(mesh,"CG",1) 
u = Function(V, name="State")

Q_heat = 20000.0
Q = Constant(0.0)                                          
g = Expression('Q_heat', degree=1, Q_heat=Constant(Q_heat))

#Define boudary conditions
u_0 = Constant(0.0)  
u0=interpolate(u_0, V)

#Define Left Boundary
def left_boundary( x, on_boundary):
    return on_boundary and (abs(x[0])< DOLFIN_EPS)

bc= DirichletBC(V, Constant(0.0), left_boundary)


# Define right bounday
class right(SubDomain):
    def inside(self, x, on_boundary):
           return on_boundary and ((abs(x[0] - 1.) < DOLFIN_EPS))

vertical = right()
tdim = mesh.topology().dim()    
boundaries = MeshFunction('size_t', mesh, tdim-1)
boundaries.set_all(0)                                        
vertical.mark(boundaries, 1)    
dsB = Measure("ds", subdomain_id=1, subdomain_data=boundaries)    

d_target=Constant(20.0)
e_target=Constant(100.0)

def forward(d, e):
    u = TrialFunction(V)                       
    v = TestFunction(V)                            
    u0 = Function(V, name="State")   
 
    #Define Thermal conductivity
    def k():
        return d + e*x[1] 
      
    a= rho*C*u*v*dx+ dt*inner(grad(v),k()*grad(u))*dx

    L= dt*g*v*dsB+rho*C*inner(u0,v)*dx+dt*Q*v*dx
  
    u = Function(V, name="State")                                           


    t = 0
    for n in range (num_steps):
        t += dt
        #Compute solution
        solve(a==L, u, bc)  

        plot(u)
        #update solution
    
        u0.assign(u)
          
    return u,d,e		
[u_target, d_target_1, e_target_1] = forward(d_target, e_target)
File("forward/target_d_modified.pvd") << d_target_1
File("forward/target_e_up.pvd") << e_target_1

d_target_1 and e_target_1 are constant values, which are not supported to write to file.
You can output them by calling float(d_target_1), float(e_target_1)

print(type(d_target), float(d_target))
print(type(e_target), float(e_target))

returning

<class 'fenics_adjoint.types.constant.Constant'> 20.0
<class 'fenics_adjoint.types.constant.Constant'> 100.0

Okay. Thank you a lot