Skip to content
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

fix mul! for JOLI operator and judiVector #114

Merged
merged 14 commits into from
Jul 12, 2022
Merged

fix mul! for JOLI operator and judiVector #114

merged 14 commits into from
Jul 12, 2022

Conversation

ziyiyin97
Copy link
Member

This PR makes

lsqr!(x, J*Mr, dobs)

work. Especially this works when Mr takes complex input (e.g. debiasing for curvelet)

@codecov
Copy link

codecov bot commented May 3, 2022

Codecov Report

Merging #114 (867f9d4) into master (850f4b5) will decrease coverage by 0.03%.
The diff coverage is 50.00%.

❗ Current head 867f9d4 differs from pull request most recent head 7f2b6c3. Consider uploading reports for the commit 7f2b6c3 to get more accurate results

@@            Coverage Diff             @@
##           master     #114      +/-   ##
==========================================
- Coverage   82.42%   82.39%   -0.04%     
==========================================
  Files          24       24              
  Lines        1861     1863       +2     
==========================================
+ Hits         1534     1535       +1     
- Misses        327      328       +1     
Impacted Files Coverage Δ
src/TimeModeling/LinearOperators/operators.jl 81.57% <33.33%> (-1.46%) ⬇️
src/TimeModeling/Types/abstract.jl 77.96% <66.66%> (ø)
src/TimeModeling/LinearOperators/basics.jl 77.27% <0.00%> (+2.27%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 850f4b5...7f2b6c3. Read the comment docs.

Copy link
Member

@mloubout mloubout left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get what the aim is but it's not done correctly

@@ -174,7 +174,7 @@ adjoint(L::LazyScal) = LazyScal(L.s, adjoint(L.P))

mul!(out::SourceType{T}, F::judiPropagator{T, O}, q::SourceType{T}) where {T<:Number, O} = begin y = F*q; copyto!(out, y) end
mul!(out::SourceType{T}, F::judiPropagator{T, O}, q::Vector{T}) where {T<:Number, O} = begin y = F*q; copyto!(out, y) end
mul!(out::SourceType{T}, F::joLinearFunction{T, T}, q::SourceType{T}) where {T<:Number} = begin y = F*q; copyto!(out, y) end
mul!(out::Union{SourceType{T1},SourceType{T2}}, F::joAbstractLinearOperator{T2, T1}, q::SourceType{T2}) where {T1<:Number, T2<:Number} = begin y = F*q; copyto!(out, y) end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No this is wrong has to be T1 to match F

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems there is a problem in IterativeSolvers.jl JuliaLinearAlgebra/IterativeSolvers.jl#313 correct me if I am wrong

(msv::judiMultiSourceVector{T})(x::Vector{T}) where {T<:AbstractFloat} = x
(msv::judiMultiSourceVector{T})(x::judiMultiSourceVector{T}) where {T} = x
(msv::judiMultiSourceVector{mT})(x::Vector{T}) where {mT, T<:Array} = begin y = deepcopy(msv); y.data .= x; return y end
(msv::judiMultiSourceVector{mT})(x::AbstractVector{T}) where {mT<:Number, T<:Number} = x
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No have to match and you are removing a case

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

judiMultiSourceVector{T} is AbstractVector so it includes the both cases already

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type has to match mT!=T is not valid.

(msv::judiMultiSourceVector{T})(x::judiMultiSourceVector{T}) where {T} = x
(msv::judiMultiSourceVector{mT})(x::Vector{T}) where {mT, T<:Array} = begin y = deepcopy(msv); y.data .= x; return y end
(msv::judiMultiSourceVector{mT})(x::AbstractVector{T}) where {mT<:Number, T<:Number} = x
(msv::judiMultiSourceVector{mT})(x::AbstractVector{T}) where {mT, T<:Array} = begin y = deepcopy(msv); y.data .= x; return y end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

@@ -172,6 +172,20 @@ ylabel("Depth (m)")
title("RTM image")
display(fig)

#' notice that we can conduct a simplistic least-squares reverse-time migration via LSQR thanks to the linear algebraic abstraction
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completely wrong file please make an effort

@@ -174,7 +174,8 @@ adjoint(L::LazyScal) = LazyScal(L.s, adjoint(L.P))

mul!(out::SourceType{T}, F::judiPropagator{T, O}, q::SourceType{T}) where {T<:Number, O} = begin y = F*q; copyto!(out, y) end
mul!(out::SourceType{T}, F::judiPropagator{T, O}, q::Vector{T}) where {T<:Number, O} = begin y = F*q; copyto!(out, y) end
mul!(out::SourceType{T}, F::joLinearFunction{T, T}, q::SourceType{T}) where {T<:Number} = begin y = F*q; copyto!(out, y) end
mul!(out::Union{SourceType{T1},SourceType{T2}}, F::joAbstractLinearOperator{T2, T1}, q::SourceType{T2}) where {T1<:Number, T2<:Number} = begin y = F*q; copyto!(out, y) end
mul!(out::Union{SourceType{T1},SourceType{T2}}, F::joAbstractLinearOperator{T2, T1}, q::Array{T2, N}) where {T1<:Number, T2<:Number, N} = begin y = F*q[:]; copyto!(out, y) end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JoAbstractLinearOperator is too general

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. What's the potential problem of being too general?
  2. It should at least contain the joLinearOperator and joLinearFunction

@ziyiyin97 ziyiyin97 changed the title fix mul! add associated test fix mul! for JOLI operator and judiVector May 3, 2022
@ziyiyin97 ziyiyin97 requested a review from mloubout May 11, 2022 15:28
test/test_linear_algebra.jl Outdated Show resolved Hide resolved
title("LS-RTM with SGD"); xlabel("Lateral position [km]"); ylabel("Depth [km]")
title("SPLS-RTM with SGD"); xlabel("Lateral position [km]"); ylabel("Depth [km]")

#' LSQR
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please try to make a proper example. It's supposed to help new users so hiding this at the bottom of a file about sparsity isn't very friendly.

@mloubout mloubout added the bug label Jun 9, 2022
@ziyiyin97 ziyiyin97 force-pushed the fixabstractvec branch 2 times, most recently from 4489654 to a2360a4 Compare June 24, 2022 02:47
@ziyiyin97 ziyiyin97 requested a review from mloubout June 24, 2022 03:32
niter = parse(Int, get(ENV, "NITER", "10"))
lsqr_sol = zeros(Float32, prod(n))
Ml = judiMarineTopmute2D(30, d_lin[1].geometry)
lsqr!(lsqr_sol, Ml*J[1]*Mr, Ml*d_lin[1]; maxiter=niter) # only invert the first shot record
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why only the first?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

otherwise too long time in CI

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an example, not a test you can't hardcode stuff like that in it. Like if anyone runs that the results is gonna look like JUDI produces shit.

(msv::judiMultiSourceVector{T})(x::Vector{T}) where {T<:AbstractFloat} = x
(msv::judiMultiSourceVector{T})(x::judiMultiSourceVector{T}) where {T} = x
(msv::judiMultiSourceVector{mT})(x::Vector{T}) where {mT, T<:Array} = begin y = deepcopy(msv); y.data .= x; return y end
(msv::judiMultiSourceVector{mT})(x::AbstractVector{T}) where {mT<:Number, T<:Number} = x
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type has to match mT!=T is not valid.

@ziyiyin97
Copy link
Member Author

Without (msv::judiMultiSourceVector{mT})(x::AbstractVector{T}) where {mT<:Number, T<:Number} = x then

dm1 = adjoint(J*DFT') * dlin

is not passing. I do think we need to add this because again x and msv might live in different space.

@mloubout
Copy link
Member

. I do think we need to add this because again x and msv might live in different space.

Then need to be added but properly:

  • add domain range in mul! and split back into Vector and judiMultiSource because judiMultiSource op cannot change data type unless they return a dense vector

@ziyiyin97 ziyiyin97 force-pushed the fixabstractvec branch 3 times, most recently from aa59d06 to 5835aed Compare July 5, 2022 19:57
@ziyiyin97 ziyiyin97 requested a review from mloubout July 5, 2022 21:39
@ziyiyin97
Copy link
Member Author

any other comment on this one?

niter = parse(Int, get(ENV, "NITER", "10"))
lsqr_sol = zeros(Float32, prod(n))

# only invert for the randomly picked indices so that this example can run a bit faster
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are still hardoding a "want CI to run fast" into a user example. The default new user who runs it should get a decent result and the example produce a result, not "just run".

@ziyiyin97
Copy link
Member Author

Hmm the memory blows up in the CI test https://github.com/slimgroup/JUDI.jl/runs/7285219825?check_suite_focus=true any suggestion?

@ziyiyin97
Copy link
Member Author

Correct me if wrong but this parallelization seems to be the culprit

@async remotecall_wait(local_reduce!, futures[i].where, futures[i], futures[i+1])
because in principal it shouldn't insist to run the born/migration with all sources if not enough memory

@mloubout
Copy link
Member

Correct me if wrong but this parallelization seems to be the culprit

I have no idea why this would be related to it this just reduces results pair by pairs.

@mloubout
Copy link
Member

Also once again, please learn to rebase your branches I cannot do it for you every time.

@mloubout mloubout force-pushed the fixabstractvec branch 2 times, most recently from 867f9d4 to d4d1aab Compare July 12, 2022 13:43
@mloubout mloubout added enhancement and removed bug labels Jul 12, 2022
@mloubout mloubout merged commit 405115d into master Jul 12, 2022
@mloubout mloubout deleted the fixabstractvec branch July 12, 2022 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants