Error with sin and cos function after update NeuralPDE

I have updated to the latest version of package NeuralPDE and used the res = Optimization.solve(prob,OptimizationOptimJL.BFGS(); callback = callback, maxiters = 1500) to solve the ODE system on Jupyter notebook. I got the message:

MethodError: no method matching cos(::Matrix{Float64})
You may have intended to import Base.cos

This issue did not occur when I used the older version (I forgot the exact version that I used before the update).
How could I fix this error?

Does this happen after a fresh start? It is possible you have re-defined cos somewhere that would give this error. For example, this works:

C:\Users\User>julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.9.2 (2023-07-05)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> A=rand(5,5)
5×5 Matrix{Float64}:
 0.909718  0.108619  0.995858   0.234943  0.0742485
 0.965059  0.638944  0.0691136  0.618132  0.436923
 0.74908   0.351674  0.0514817  0.66934   0.992477
 0.211503  0.774835  0.134928   0.632693  0.0331376
 0.226476  0.294484  0.88037    0.554454  0.154767

julia> cos(A)
5×5 Matrix{Float64}:
  0.427955  -0.166231  -0.331578   -0.324861  -0.400794
 -0.560274   0.641195  -0.496704   -0.388002  -0.101208
 -0.394016  -0.35062    0.376286   -0.438875  -0.0776861
 -0.367901  -0.389009  -0.0493614   0.654608  -0.148705
 -0.385263  -0.322394  -0.0887973  -0.417086   0.608369

but if you first defined some new method for cos, it fails:

C:\Users\User>julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.9.2 (2023-07-05)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> cos(A::String) = A # just any definition
cos (generic function with 1 method)

julia> cos(rand(5, 5))
ERROR: MethodError: no method matching cos(::Matrix{Float64})
You may have intended to import Base.cos

Closest candidates are:
  cos(::String)
   @ Main REPL[1]:1

Stacktrace:
 [1] top-level scope
   @ REPL[2]:1

(P.S. cos(A) is compute the matrix cosine of A rather than cos of each element of A, which is cos.(A), just in case that’s what you intend to do.)

But before I update all packages and Julia version 1.9.2, this error did not occur. Actually, I use the cos and sin function for variables in the ODE problem and use NeuralPDE to solve it.

In the model, if I remove the equation with the sin and cos functions it can run well.
the equations with sin and cos are:

D(omega1(t)) ~ (TM1(t)-(E1^2*Y1[1,1].re + E1*E2*sin(delta1(t)-delta2(t))*Y1[1,2].im + E1*E2*cos(delta1(t)-delta2(t))*Y1[1,2].re + E1*E3*sin(delta1(t)-delta3(t))*Y1[1,3].im + 
        E1*E3*cos(delta1(t)-delta3(t))*Y1[1,3].re))/(2*data["H"][1])*omega_s,
    #
D(omega2(t)) ~ (TM2(t)-(E2^2*Y1[2,2].re + E1*E2*sin(delta2(t)-delta1(t))*Y1[2,1].im + E1*E2*cos(delta2(t)-delta1(t))*Y1[2,1].re + E2*E3*sin(delta2(t)-delta3(t))*Y1[2,3].im + 
        E2*E3*cos(delta2(t)-delta3(t))*Y1[2,3].re))/(2*data["H"][2])*omega_s,
    #
D(omega3(t)) ~ (TM3(t)-(E3^2*Y1[3,3].re + E3*E1*sin(delta3(t)-delta1(t))*Y1[3,1].im + E3*E1*cos(delta3(t)-delta1(t))*Y1[3,1].re + E3*E2*sin(delta3(t)-delta2(t))*Y1[3,2].im + 
        E3*E2*cos(delta3(t)-delta2(t))*Y1[3,2].re))/(2*data["H"][3])*omega_s.

how could I fix this error?

Try changing those to cos.? @xtalax is this supposed to broadcast automatically?

yes and got the same message:

D(omega1(t)) ~ (TM1(t) - (E1^2*Y1[1,1].re + E1*E2*sin.(delta1(t)-delta2(t))*Y1[1,2].im + E1*E2*cos.(delta1(t)-delta2(t))*Y1[1,2].re + E1*E3*sin.(delta1(t)-delta3(t))*Y1[1,3].im + 
        E1*E3*cos.(delta1(t)-delta3(t))*Y1[1,3].re))/(2*data["H"][1])*omega_s,
    #
    D(omega2(t)) ~ (TM2(t) - (E2^2*Y1[2,2].re + E1*E2*sin.(delta2(t)-delta1(t))*Y1[2,1].im + E1*E2*cos.(delta2(t)-delta1(t))*Y1[2,1].re + E2*E3*sin.(delta2(t)-delta3(t))*Y1[2,3].im + 
        E2*E3*cos.(delta2(t)-delta3(t))*Y1[2,3].re))/(2*data["H"][2])*omega_s,
    #
    D(omega3(t)) ~ (TM3(t) - (E3^2*Y1[3,3].re + E3*E1*sin.(delta3(t)-delta1(t))*Y1[3,1].im + E3*E1*cos.(delta3(t)-delta1(t))*Y1[3,1].re + E3*E2*sin.(delta3(t)-delta2(t))*Y1[3,2].im + 
        E3*E2*cos.(delta3(t)-delta2(t))*Y1[3,2].re))/(2*data["H"][3])*omega_s];
MethodError: no method matching cos(::Matrix{Float64})
You may have intended to import Base.cos

Closest candidates are:
  cos(::ForwardDiff.Dual{T}) where T
   @ ForwardDiff C:\Users\htran\.julia\packages\ForwardDiff\vXysl\src\dual.jl:238
  cos(::DualNumbers.Dual)
   @ DualNumbers C:\Users\htran\.julia\packages\DualNumbers\5knFX\src\dual.jl:327
  cos(::Float64)
   @ NaNMath C:\Users\htran\.julia\packages\NaNMath\ceWIc\src\NaNMath.jl:9
  ...MethodError: no method matching cos(::Matrix{Float64})
You may have intended to import Base.cos

Closest candidates are:
  cos(::ForwardDiff.Dual{T}) where T
   @ ForwardDiff C:\Users\htran\.julia\packages\ForwardDiff\vXysl\src\dual.jl:238
  cos(::DualNumbers.Dual)
   @ DualNumbers C:\Users\htran\.julia\packages\DualNumbers\5knFX\src\dual.jl:327
  cos(::Float64)
   @ NaNMath C:\Users\htran\.julia\packages\NaNMath\ceWIc\src\NaNMath.jl:9
  ...

Yes, this should be automatically broadcasting, the __dot__ function that does this seems really picky about when it wants to work properly however.

I’ll add a test for this and check on 1.9.2

Was this error resolved? I get this error while running the neuralPDE example from documentation. Introduction to NeuralPDE for PDEs · NeuralPDE.jl

It was solved a few months back. What versions are you using?