# Why this code shows the following error: ERROR: type Float64 has no field layer\_1. In this code I want to optimize 2 unknown parameters g and k for a 2D PDE with 4 boundary conditions and 3 known data points

**URL:** <https://discourse.julialang.org/t/why-this-code-shows-the-following-error-error-type-float64-has-no-field-layer-1-in-this-code-i-want-to-optimize-2-unknown-parameters-g-and-k-for-a-2d-pde-with-4-boundary-conditions-and-3-known-data-points/104289>\
**Category:** Data\
**Tags:** question\
**Created:** [September 26, 2023, 10:13pm UTC](https://discourse.julialang.org/t/why-this-code-shows-the-following-error-error-type-float64-has-no-field-layer-1-in-this-code-i-want-to-optimize-2-unknown-parameters-g-and-k-for-a-2d-pde-with-4-boundary-conditions-and-3-known-data-points/104289 "2023-09-26T22:13:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ShadmanSakief](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shadmansakief/32/51586_2.png) [@ShadmanSakief](https://discourse.julialang.org/u/ShadmanSakief)\
**Post date:** [September 26, 2023, 10:13pm UTC](https://discourse.julialang.org/t/why-this-code-shows-the-following-error-error-type-float64-has-no-field-layer-1-in-this-code-i-want-to-optimize-2-unknown-parameters-g-and-k-for-a-2d-pde-with-4-boundary-conditions-and-3-known-data-points/104289/1 "2023-09-26T22:13:52Z")

</div>

using NeuralPDE, Lux, ModelingToolkit, Optimization, OptimizationOptimJL, DifferentialEquations

@parameters x y g k  
@variables u(..)  
Dx = Differential(x)  
Dy = Differential(y)

# Define the PDE

eq = Dx(Dx(u(x, y))) + Dy(Dy(u(x, y))) + g/k ~ 0

# Boundary conditions

bcs = [u(0, y) ~ 350.0,  
Dx(u(2, y)) ~ 0,  
Dy(u(x, 0)) ~ 0,  
Dy(u(x, 1)) ~ 1000/k\*(298-u(x, 1))]

# Domain definitions

domains = [x ∈ IntervalDomain(0.0, 2.0),  
y ∈ IntervalDomain(0.0, 1.0)]

input\_ = 2  
n = 16  
chain = Lux.Chain(Dense(input\_, n, Lux.σ), Dense(n, n, Lux.σ), Dense(n, 1))

known\_data = [(0.5375, 0.26364, 348.47), (1.2852, 0.85909, 345), (0.17614, 0.16591, 349.09)]

function additional\_loss(phi, θ, p)  
\_loss(u, x, y) = eq.lhs(u(x,y), x, y) - eq.rhs  
l = sum(\_loss(phi[1], x, y)^2 for x in 0:0.1:2, y in 0:0.1:1)  
for bc in bcs  
l += sum(bc.lhs(phi[1], x, y)^2 for x in 0:0.1:2, y in 0:0.1:1)  
end  
# Adding data loss to the total loss  
for (x\_data, y\_data, temp\_data) in known\_data  
predicted\_temp = phi[1](x\_data, y\_data)  
data\_loss = (predicted\_temp - temp\_data)^2  
l += data\_loss  
end  
return l  
end

discretization = NeuralPDE.PhysicsInformedNN([chain], NeuralPDE.GridTraining(0.1),  
param\_estim=true, additional\_loss=additional\_loss)

@named pde\_system = PDESystem(eq, bcs, domains, [x, y], [u(x,y)], [g, k],  
defaults=Dict([g .=\> 500.0, k .=\> 200.0]))  
prob = discretize(pde\_system, discretization)

#Optimizer  
opt = OptimizationOptimJL.BFGS()

callback = function (p, l)  
println(“Current loss is: $l”)  
return false  
end

res = Optimization.solve(prob, opt, callback = callback, maxiters = 5000)  
optimized\_params = res.u[(end - 1):end] # optimized g and k

println("Optimized g and k values: ", optimized\_params)

## Specifically “res = Optimization.solve(prob, opt, callback = callback, maxiters = 5000)” -this syntax shows the mentioned error . I executed the individual syntax and I found this. Is there any solution for it?
