Skip to content

Commit

Permalink
Merge pull request #272 from slimgroup/pro-misc
Browse files Browse the repository at this point in the history
Fix elastic modeling
  • Loading branch information
mloubout authored Oct 3, 2024
2 parents 5264592 + e5f497a commit edc3ad9
Show file tree
Hide file tree
Showing 24 changed files with 416 additions and 381 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
uses: actions/checkout@v4

- name: Setup julia
uses: julia-actions/setup-julia@v1
uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
arch: x64
Expand Down
31 changes: 24 additions & 7 deletions .github/workflows/ci-judi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
name: JUDI base on Julia ${{ matrix.version }} - ${{ matrix.os }}
runs-on: ${{ matrix.os }}
env:
DEVITO_ARCH: gcc-11
DEVITO_ARCH: ${{ matrix.cc }}
DEVITO_LANGUAGE: "openmp"
OMP_NUM_THREADS: 4
GROUP: "JUDI"
Expand All @@ -28,28 +28,44 @@ jobs:
fail-fast: false

matrix:
version: ['1.6', '1.7', '1.8', '1.9', '1.10']
os: [ubuntu-latest, macos-13]
version: ['lts', '1.7', '1.8', '1.9', '1.10']
os: [ubuntu-latest]
arch: ['x64']
cc: ['gcc-12']

include:
- os: macos-15
version: '1'
arch: ARM64
cc: clang

steps:
- name: Checkout JUDI
uses: actions/checkout@v4

- name: Setup julia
uses: julia-actions/setup-julia@v1
uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
arch: x64
arch: ${{ matrix.arch }}

- name: Setup clang for osx
if: runner.os == 'macOS'
run: |
brew install llvm libomp
echo "/opt/homebrew/bin:/opt/homebrew/opt/llvm/bin" >> $GITHUB_PATH
- name: Set up Python 3.9
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.9

- name: Set julia python
run: |
echo "PYTHON=$(which python3)" >> $GITHUB_ENV
PYTHON=$(which python3) julia -e 'using Pkg;Pkg.add("PyCall");Pkg.build("PyCall")'
echo "PYCALL_JL_RUNTIME_PYTHON=$(which python3)" >> $GITHUB_ENV
python3 -m pip install devito[tests,extras]@git+https://github.com/devitocodes/devito.git
PYCALL_JL_RUNTIME_PYTHON=$(which python3) PYTHON=$(which python3) julia -e 'using Pkg;Pkg.add("PyCall");Pkg.build("PyCall")'
- name: Build JUDI
uses: julia-actions/julia-buildpkg@latest
Expand All @@ -60,6 +76,7 @@ jobs:
annotate: true

- uses: julia-actions/julia-processcoverage@v1

- uses: codecov/codecov-action@v4
with:
file: lcov.info
Expand Down
41 changes: 31 additions & 10 deletions .github/workflows/ci-op.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
name: ${{ matrix.op }} on Julia ${{ matrix.version }} - ${{ matrix.os }}
runs-on: ${{ matrix.os }}
env:
DEVITO_ARCH: gcc-11
DEVITO_ARCH: ${{ matrix.cc }}
DEVITO_LANGUAGE: "openmp"
DEVITO_LOGGING: "INFO"
OMP_NUM_THREADS: ${{ matrix.omp }}
Expand All @@ -33,52 +33,72 @@ jobs:
op: ["ISO_OP", "ISO_OP_FS", "TTI_OP", "TTI_OP_FS", "BASICS"]
version: ['1']
omp: [2]
cc: ['gcc-11']
arch: ['x64']

include:
- os: macos-13
version: '1.6'
- os: macos-15
version: '1'
op: "ISO_OP"
omp: 1
cc: clang
arch: ARM64

- os: macos-13
- os: macos-15
version: '1.8'
op: "ISO_OP"
omp: 1
cc: clang
arch: ARM64

- os: macos-13
- os: macos-15
version: '1.9'
op: "ISO_OP"
omp: 1
cc: clang
arch: ARM64

- os: ubuntu-latest
version: '1.9'
op: "VISCO_AC_OP"
omp: 2
cc: gcc-11
arch: x64

- os: ubuntu-latest
version: '1.10'
op: "ISO_OP"
omp: 2
cc: gcc-11
arch: x64

steps:
- name: Checkout JUDI
uses: actions/checkout@v4

- name: Setup julia
uses: julia-actions/setup-julia@v1
uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
arch: x64
arch: ${{ matrix.arch }}

- name: Setup clang for osx
if: runner.os == 'macOS'
run: |
brew install llvm libomp
echo "/opt/homebrew/bin:/opt/homebrew/opt/llvm/bin" >> $GITHUB_PATH
- name: Set up Python 3.9
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.9

- name: Set julia python
run: |
echo "PYTHON=$(which python3)" >> $GITHUB_ENV
PYTHON=$(which python3) julia -e 'using Pkg;Pkg.add("PyCall");Pkg.build("PyCall")'
echo "PYCALL_JL_RUNTIME_PYTHON=$(which python3)" >> $GITHUB_ENV
python3 -m pip install devito[tests,extras]@git+https://github.com/devitocodes/devito.git
PYCALL_JL_RUNTIME_PYTHON=$(which python3) PYTHON=$(which python3) julia -e 'using Pkg;Pkg.add("PyCall");Pkg.build("PyCall")'
- name: Build JUDI
uses: julia-actions/julia-buildpkg@latest
Expand All @@ -89,7 +109,8 @@ jobs:
annotate: true

- uses: julia-actions/julia-processcoverage@v1

- uses: codecov/codecov-action@v4
with:
file: lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
token: ${{ secrets.CODECOV_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/deploy_doc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- uses: julia-actions/setup-julia@latest

- name: Set up Python 3.9
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.9

Expand Down
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "JUDI"
uuid = "f3b833dc-6b2e-5b9c-b940-873ed6319979"
authors = ["Philipp Witte, Mathias Louboutin"]
version = "3.4.6"
version = "3.4.7"

This comment has been minimized.

Copy link
@mloubout

mloubout Oct 3, 2024

Author Member

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand All @@ -12,6 +12,7 @@ FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
JOLI = "bb331ad6-a1cf-11e9-23da-9bcb53c69f6f"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
Expand Down
6 changes: 3 additions & 3 deletions deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ end
pk = try
pyimport("pkg_resources")
catch e
run(PyCall.python_cmd(`-m pip install --user setuptools`))
run(PyCall.python_cmd(`-m pip install -U --user --no-cache-dir setuptools`))
pyimport("pkg_resources")
end

################## Devito ##################
# pip command
dvver = "4.8.10"
cmd = PyCall.python_cmd(`-m pip install --user devito\[extras,tests\]\>\=$(dvver)`)
cmd = PyCall.python_cmd(`-m pip install --user --no-cache-dir devito\[extras,tests\]\>\=$(dvver)`)

try
dv_ver = VersionNumber(split(pk.get_distribution("devito").version, "+")[1])
Expand All @@ -32,5 +32,5 @@ end
try
mpl = pyimport("matplotlib")
catch e
run(PyCall.python_cmd(`-m pip install --user matplotlib`))
run(PyCall.python_cmd(`-m pip install --user --no-cache-dir matplotlib`))
end
6 changes: 3 additions & 3 deletions examples/scripts/modeling_basic_elastic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ nxrec = 120
nyrec = 100
xrec = range(50f0, stop=1150f0, length=nxrec)
yrec = 0f0
zrec = range(0f0, stop=0f0, length=nxrec)
zrec = range(10f0, stop=10f0, length=nxrec)

# receiver sampling and recording time
timeR = 1500f0 # receiver recording time [ms]
Expand All @@ -41,7 +41,7 @@ recGeometry = Geometry(xrec, yrec, zrec; dt=dtR, t=timeR, nsrc=nsrc)
# Set up source geometry (cell array with source locations for each shot)
xsrc = 600f0
ysrc = 0f0
zsrc = 0f0
zsrc = 10f0

# source sampling and number of time steps
timeS = 1500f0 # source length in [ms]
Expand All @@ -57,7 +57,7 @@ wavelet = ricker_wavelet(timeS, dtS, f0)
###################################################################################################

# Setup operators
F = judiModeling(model, srcGeometry, recGeometry)
F = judiModeling(model, srcGeometry, recGeometry; options=Options(space_order=8, free_surface=true))
q = judiVector(srcGeometry, wavelet)

# Nonlinear modeling
Expand Down
85 changes: 6 additions & 79 deletions src/JUDI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if !isdefined(Base, :get_extension)
end

# Dependencies
using LinearAlgebra, Random
using LinearAlgebra, Random, Printf
using Distributed
using DSP, FFTW, Dierckx
using PyCall
Expand Down Expand Up @@ -57,99 +57,25 @@ import PyCall.NpyArray
import ChainRulesCore: rrule

# Set python paths
export devito, set_devito_config
export devito

const pm = PyNULL()
const ac = PyNULL()
const pyut = PyNULL()
const devito = PyNULL()

set_devito_config(key::String, val::String) = set!(devito."configuration", key, val)
set_devito_config(key::String, val::Bool) = set!(devito."configuration", key, val)

# Create a lock for pycall FOR THREAD/TASK SAFETY
# See discussion at
# https://github.com/JuliaPy/PyCall.jl/issues/882

const PYLOCK = Ref{ReentrantLock}()

# acquire the lock before any code calls Python
pylock(f::Function) = Base.lock(PYLOCK[]) do
prev_gc = GC.enable(false)
try
return f()
finally
GC.enable(prev_gc) # recover previous state
end
end

function rlock_pycall(meth, ::Type{T}, args...; kw...) where T
out::T = pylock() do
pycall(meth, T, args...; kw...)
end
return out
end

# Constants
_serial = false
get_serial() = _serial
set_serial(x::Bool) = begin global _serial = x; end
set_serial() = begin global _serial = true; end
set_parallel() = begin global _serial = false; end

function _worker_pool()
if _serial
return nothing
end
p = default_worker_pool()
pool = nworkers(p) < 2 ? nothing : p
return pool
end

nworkers(::Any) = length(workers())

_TFuture = Future
_verbose = false
_devices = []

# Utility for data loading
JUDI_DATA = joinpath(JUDIPATH, "../data")
ftp_data(ftp::String, name::String) = Base.Downloads().download("$(ftp)/$(name)", "$(JUDI.JUDI_DATA)/$(name)")
ftp_data(ftp::String) = Base.Downloads().download(ftp, "$(JUDI.JUDI_DATA)/$(split(ftp, "/")[end])")

# Some usefull types
const RangeOrVec = Union{AbstractRange, Vector}

set_verbosity(x::Bool) = begin global _verbose = x; end
judilog(msg) = _verbose ? printstyled("JUDI: $(msg) \n", color=:magenta) : nothing

function human_readable_time(t::Float64, decimals=2)
units = ["ns", "μs", "ms", "s", "min", "hour"]
scales = [1e-9, 1e-6, 1e-3, 1, 60, 3600]
if t < 1e-9
tr = round(t/1e-9; sigdigits=decimals)
return "$(tr) ns"
end

for i=2:6
if t < scales[i]
tr = round(t/scales[i-1]; sigdigits=decimals)
return "$(tr) $(units[i-1])"
end
end
tr1 = div(t, 3600)
tr2 = round(Int, rem(t, 3600))
return "$(tr1) h $(tr2) min"
end


macro juditime(msg, ex)
return quote
local t
t = @elapsed $(esc(ex))
tr = human_readable_time(t)
judilog($(esc(msg))*": $(tr)")
end
end
# Utils
include("utilities.jl")

# JUDI time modeling
include("TimeModeling/TimeModeling.jl")
Expand All @@ -170,6 +96,7 @@ include("compat.jl")
# Automatic Differentiation
include("rrules.jl")


# Initialize
function __init__()
pushfirst!(PyVector(pyimport("sys")."path"), joinpath(JUDIPATH, "pysource"))
Expand Down
4 changes: 2 additions & 2 deletions src/TimeModeling/LinearOperators/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ adjoint(L::LazyScal) = LazyScal(L.s, adjoint(L.P))
*(F::judiPropagator{T, O}, q::judiMultiSourceVector{T}) where {T<:Number, O} = multi_src_propagate(F, q)
*(F::judiPropagator{T, O}, q::AbstractVector{T}) where {T<:Number, O} = multi_src_propagate(F, q)
*(F::judiPropagator{T, O}, q::DenseArray{T}) where {T<:Number, O} = multi_src_propagate(F, q)
*(F::judiAbstractJacobian{T, O, FT}, q::dmType{T}) where {T<:Number, O, FT} = multi_src_propagate(F, q)
*(F::judiAbstractJacobian{T, O, FT}, q::dmType{Tq}) where {T<:Number, Tq<:Pdtypes, O, FT} = multi_src_propagate(F, q)

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::judiAbstractJacobian{T, :born, FT}, q::Vector{T}) where {T<:Number, FT} = begin y = F*q[:]; copyto!(out, y) end
Expand Down Expand Up @@ -208,7 +208,7 @@ make_input(F::judiDataModeling, rhs::judiRHS) = (make_src(rhs)..., F.rInterpolat
make_input(F::judiDataSourceModeling, q::SourceType{T}) where {T} = (make_src(q, F.qInjection)..., F.rInterpolation.data[1], nothing, nothing)
make_input(F::judiDataSourceModeling, q::Matrix{T}) where {T} = (F.qInjection.data[1], q, F.rInterpolation.data[1], nothing, nothing)

function make_input(J::judiJacobian{D, :born, FT}, q::dmType{D}) where {D<:Number, FT}
function make_input(J::judiJacobian{D, :born, FT}, q::dmType{Dq}) where {D<:Number, Dq<:Pdtypes, FT}
srcGeom, srcData = make_src(J.q, J.F.qInjection)
return srcGeom, srcData, J.F.rInterpolation.data[1], nothing, reshape(q, size(J.model))
end
Expand Down
Loading

1 comment on commit edc3ad9

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/116538

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v3.4.7 -m "<description of version>" edc3ad98fcfd00e72a0b9e92deae5d0bc9c724ec
git push origin v3.4.7

Please sign in to comment.