UFLException: Expecting only Index and FixedIndex objects Error

Hi there,

I am currently trying to implement boundary markets into my code such that different Robin boundary conditions are present on different faces on my cylindrical mesh. I have implemented these boundary markers as shown below:

#-----Define Markers for the different parts of the boundary-------
boundary_markers = MeshFunction("size_t", mesh, mesh.topology().dim()-1)
tol = 1E-14
class BoundaryR(SubDomain):
    tol = 1E-14
    def inside(self, x, on_boundary):
        return on_boundary and near(sqrt(x[0]*x[0] + x[1]*x[1]), R, tol)
    
br = BoundaryR()
br.mark(boundary_markers, 0)

class BoundaryZ0(SubDomain):
    tol = 1E-14
    def inside(self, x, on_boundary):
        return on_boundary and near(x[2], -8, tol)
    
bz0 = BoundaryZ0()
bz0.mark(boundary_markers, 1)

class BoundaryZ1(SubDomain):
    tol = 1E-14
    def inside(self, x, on_boundary):
        return on_boundary and near(x[2], 0, tol)
    
bz1 = BoundaryZ1()
bz1.mark(boundary_markers, 2)


# For the implimentation of these boundary conditions to be general, we can let the user specify what kind of boundary condition that applies to each of the four boundaries. We set up a Python dictionary for this purpose.


#ENCODE BOUNDARY CONDITIONS (MAY NEED ALTERING OR REMOVAL)
boundary_conditions = {0: {'Robin':     (es, T_a4)},
                       1: {'Robin':     (es, T_a4)},
                       2: {'Robin':     (es, T_a4)}}


ds = Measure('ds', domain=mesh, subdomain_data = boundary_markers, metadata = {'quadrature_degree': 2})

#da = Measure('ds', domain=mesh, subdomain_data = facets, metadata = {'quadrature_degree': 2})  #area element
dv = Measure('dx', domain=mesh, subdomain_data = cells, metadata = {'quadrature_degree': 2})   #volume element

initial_T = Expression("Tini", Tini=T_am, degree=3) # extrapolate an expression for the temperature before heating
T0 = interpolate(initial_T, Space)
T = Function(Space)         # Temperature
V = TestFunction(Space)     # Test Function used for FEA
dT = TrialFunction(Space)   # Temperature Derivative
q0 = Function(VectorSpace)  # heat flux at previous time step
i = Index()
G = as_tensor(T.dx(i), (i))  #gradient of T
G0 = as_tensor(T0.dx(i), (i)) # gradient of T at previous time step 

I then obtain a weak form to solve non-linearly, that looks like:

q = as_tensor(dtime/(dtime + tau_q) * (tau_q/dtime*q0[i] - kappa*(1+tau_T/dtime)*G[i] + kappa*tau_T/dtime*G0[i]),(i)) #heat
F = (rho*c/dtime*(T-T0)*V - q[i]*V.dx(i)) * dv - Laser*V*ds(2) + es*(T**4 - T_a4)*V*ds(1) + es*(T**4 - T_a4)*V*ds(2) + es*(T**4 - T_a4)*V*ds(3)   #final form to solve

However, when this runs, I get this error:

    q = as_tensor(dtime/(dtime + tau_q) * (tau_q/dtime*q0[i] - kappa*(1+tau_T/dtime)*G[i] + kappa*tau_T/dtime*G0[i]),(i)) #heat
  File "/usr/local/lib/python3.6/dist-packages/ufl/tensors.py", line 263, in as_tensor
    indices = MultiIndex(indices)
  File "/usr/local/lib/python3.6/dist-packages/ufl/core/multiindex.py", line 146, in __new__
    error("Expecting only Index and FixedIndex objects.")
  File "/usr/local/lib/python3.6/dist-packages/ufl/log.py", line 172, in error
    raise self._exception_type(self._format_raw(*message))
ufl.log.UFLException: Expecting only Index and FixedIndex objects.

Where does this error come from and how can I fix it? Do I need to change how I define these boundary markers?

Thanks in advance