# Issues with PSO within Optim.jl

Hi there,
I am fairly new to Julia and I am struggling to get a PSO to work within Optim.jl, I am using PETLION which is physical based battery simulation tool to get voltage data while changing a single physical parameter and soon to be multiple parameters. I have created an objective function which takes the RMSE of the parameter being selected through the PSO then assessed against a baseline voltage profile that I wish for the value to converge to. It keeps evaluating but does not show any trace or exit due when setting a time limit in optimize which is confusing me.

My Julia Version is 1.6.6, Optim.jl version is 1.7.1 and posted below is the code I am attempting to run

``````using Optim, PETLION, Statistics

p = petlion(LCO;
N_p = 10, # discretizations in the cathode
N_s = 10, # discretizations in the separator
N_n = 10, # discretizations in the anode
N_r_p = 10, # discretizations in the solid cathode particles
N_r_n = 10, # discretizations in the solid anode particles
temperature = false, # temperature enabled or disabled
jacobian = :AD, # :AD (automatic-differenation) for convenience or :symbolic for speed
)

x0 = p.θ[:l_p] # Initial parameter value for cathode thickness

y1 = 10 #10 seconds for testing

println("Starting Baseline")
#Baseline
p.θ[:T₀] = p.θ[:T_amb]
soly_3 = solution()
p.opts.outputs = (:t, :V, :I)
p.opts.SOC = 1
p.bounds.V_min = 2.5
p.bounds.V_max = 4.2
@time soly_3 = simulate(p, y1, I=-0.25)
V_baseline_3 = soly_3.V
println("Baseline complete")

function objective_function(x::Vector)
p.θ[:l_p] = x[1] # taking a value to drive the objective
sol = simulate(p, y1, I=-0.25) #Simulate the same response from the baselin
Delta_V = V_baseline_3 - resize!(sol.V,length(V_baseline_3)) #
if maximum(sol.V) > 5 || minimum(sol.V) < 0 #Plausability check to change anything to NaN
NAN = zeros(length(V_baseline_3))
Delta_V = fill!(NAN,NaN)
println("\$x is out of bounds")
end
RMSE =  [sqrt(mean((Delta_V.^2)))] #RMSE for Baseline against simulated respsonse
return RMSE
end