-
-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Overload operator application for ComposedOperator
#159
Comments
@gaurav-arya , would you be able to help with this? |
Hey, I'd be happy to help, but: I don't think I agree this is a mistake? Shouldn't In a similar vein (but different context), I was also confused by lines such as https://github.com/SciML/SciMLOperators.jl/blob/31275d4e2b2f3671fb4c2811656dd555c4e1f24a/test/matrix.jl#LL174-L176C24 in tests. The Maybe we have different understandings of what |
It is a mistake for the simple reason that julia> A(B(C(u, p, t), p, t), p, t) ≈ (A ∘ B ∘ C)(u, p, t)
false
julia> A(B(C(u, p, t), p, t), p, t)
4-element Vector{Float64}:
1.0000000000000008e-8
1.0000000000000008e-8
1.0000000000000008e-8
1.0000000000000008e-8
julia> (A ∘ B ∘ C)(u, p, t)
4-element Vector{Float64}:
0.00010000000000000003
0.00010000000000000003
0.00010000000000000003
0.00010000000000000003 This problem occurs specifically when you want to compose nonlinear operators, i.e N = 4
uODE = rand(N)
A = DiagonalOperator(rand(N); update_func = (d, u, p, t) -> copy!(d, uODE)) # A * u = uODE .* u
B = DiagonalOperator(rand(N); update_func = (d, u, p, t) -> copy!(d, uODE))
C = DiagonalOperator(rand(N); update_func = (d, u, p, t) -> copy!(d, uODE))
L = A ∘ B ∘ C
u = rand(N)
v = L(u, nothing, 0.0) # ≈ uODE .^3 .* u In my applications till now, I haven't needed to compose multiple nonlinear operations. I have only needed to compose nonlinear operations with linear operations, thus I never came across this error. For example, to solve 1D Burgers, A = nu * D2x
C = DiagonalOperator(u0, update_func = (v, u, p, t) -> copy!(v, u)) * Dx
dudt = A - C So when I pass However, we should do things correctly. uODE
A = DiagonalOperator(zeros(N), update_func = (d, u, p, t; uODE) -> copy!(d, uODE))) |
I think I kind of see where you're coming from, but it still does seem weird to me to represent arbitrary nonlinear operators through this weird back and forth between |
Correct |
We should always use |
update_coeffs
for ComposedOperator
ComposedOperator
ComposedOperator
ComposedOperator
For
ComposedOperator
the presentupdate_coeffs(L, u, p, t)
interface will update eachop in L.ops
withu
, which is not it's input.SciMLOperators.jl/src/interface.jl
Lines 22 to 27 in 31275d4
For example, with
In this case, what we want to get by composing three squaring operations is
u .^ 8
, but we will getu .^ 4
becauseA,B,C
will be updated byu, u, u
, notu, u^2, u^4
respectively. What we want is to updateC
withu
,B
with its inputC * u = u .^ 2
, andA
withB * C * u = u .^ 4
. The operator update procedure must necessarily be interlaced with multiplication.So we need to overload update-coeffs and operator application for
ComposedOperator
. It would be wise to take a second look at other composite operators to ensure such a thing isn't happening anywhere else. Maybe we need to defineupdate_coeffs
overload forAdjointOperator, TransposedOperator
to pass inu'
. Should also take a second look at FunctionOperator.The text was updated successfully, but these errors were encountered: