From a4462157c0be08e75cd8ac1e39dea40999a8eced Mon Sep 17 00:00:00 2001 From: mloubout Date: Thu, 11 Jul 2024 13:58:35 -0400 Subject: [PATCH] bump devito version req to sympy 1.13 --- .github/workflows/ci-judi.yml | 1 + .github/workflows/ci-op.yml | 1 + Project.toml | 22 +++++++++++----------- deps/build.jl | 23 ++++++++++++----------- src/JUDI.jl | 3 +-- src/pysource/FD_utils.py | 23 ++++++++++++----------- src/pysource/kernels.py | 3 +-- 7 files changed, 39 insertions(+), 37 deletions(-) diff --git a/.github/workflows/ci-judi.yml b/.github/workflows/ci-judi.yml index 96b4aeeec..2ab51793a 100644 --- a/.github/workflows/ci-judi.yml +++ b/.github/workflows/ci-judi.yml @@ -48,6 +48,7 @@ jobs: - name: Set julia python run: | + echo "PYTHON=$(which python3)" >> $GITHUB_ENV PYTHON=$(which python3) julia -e 'using Pkg;Pkg.add("PyCall");Pkg.build("PyCall")' - name: Build JUDI diff --git a/.github/workflows/ci-op.yml b/.github/workflows/ci-op.yml index 21caa36d5..6beb24926 100644 --- a/.github/workflows/ci-op.yml +++ b/.github/workflows/ci-op.yml @@ -77,6 +77,7 @@ jobs: - name: Set julia python run: | + echo "PYTHON=$(which python3)" >> $GITHUB_ENV PYTHON=$(which python3) julia -e 'using Pkg;Pkg.add("PyCall");Pkg.build("PyCall")' - name: Build JUDI diff --git a/Project.toml b/Project.toml index 39c522f0a..d68e277ec 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "JUDI" uuid = "f3b833dc-6b2e-5b9c-b940-873ed6319979" authors = ["Philipp Witte, Mathias Louboutin"] -version = "3.4.4" +version = "3.4.5" [deps] ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" @@ -17,16 +17,6 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" Requires = "ae029012-a4dd-5104-9daa-d747884805df" SegyIO = "157a0f19-4d44-4de5-a0d0-07e2f0ac4dfa" -[weakdeps] -Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c" -JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" -Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f" - -[extensions] -FluxJUDIExt = "Flux" -JLD2JUDIExt = "JLD2" -ZygoteJUDIExt = "Zygote" - [compat] Aqua = "0.5" ChainRulesCore = "1" @@ -42,6 +32,11 @@ SegyIO = "0.7.7 - 0.8.5" TimerOutputs = "0.5" julia = "1.6" +[extensions] +FluxJUDIExt = "Flux" +JLD2JUDIExt = "JLD2" +ZygoteJUDIExt = "Zygote" + [extras] Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c" @@ -52,3 +47,8 @@ TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f" [targets] test = ["Aqua", "JLD2", "Printf", "Test", "TimerOutputs", "Flux"] + +[weakdeps] +Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c" +JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" +Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f" \ No newline at end of file diff --git a/deps/build.jl b/deps/build.jl index 346f12c35..248533380 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -5,24 +5,28 @@ struct DevitoException <: Exception msg::String end -python = PyCall.pyprogramname +if PyCall.pyversion >= VersionNumber("3.12.0") + install = ["install", "--user"] +else + install = ["install"] +end pk = try pyimport("pkg_resources") catch e - Cmd([python, "-m", "pip", "install", "--user", "setuptools"]) - run(cmd) + run(PyCall.python_cmd(`-m pip install --user setuptools`)) pyimport("pkg_resources") end ################## Devito ################## # pip command -cmd = Cmd([python, "-m", "pip", "install", "-U", "--user", "devito[extras,tests]>=4.4"]) +dvver = "4.8.10" +cmd = PyCall.python_cmd(`-m pip install --user devito\[extras,tests\]\>\=$(dvver)`) try - dv_ver = split(pk.get_distribution("devito").version, "+")[1] - if cmp(dv_ver, "4.8.7") < 0 - @info "Devito version too low, updating to >=4.8.7" + dv_ver = VersionNumber(split(pk.get_distribution("devito").version, "+")[1]) + if dv_ver < VersionNumber(dvver) + @info "Devito version too low, updating to >=$(dvver)" run(cmd) end catch e @@ -30,12 +34,9 @@ catch e run(cmd) end - ################## Matplotlib ################## -# pip command -cmd = Cmd([python, "-m", "pip", "install", "--user", "matplotlib"]) try mpl = pyimport("matplotlib") catch e - run(cmd) + run(PyCall.python_cmd(`-m pip install --user matplotlib`)) end diff --git a/src/JUDI.jl b/src/JUDI.jl index 7ca1b71db..9eeb1ca40 100644 --- a/src/JUDI.jl +++ b/src/JUDI.jl @@ -9,7 +9,6 @@ module JUDI export JUDIPATH, set_verbosity, ftp_data, get_serial, set_serial, set_parallel JUDIPATH = dirname(pathof(JUDI)) - # Only needed if extension not available (julia < 1.9) if !isdefined(Base, :get_extension) using Requires @@ -102,7 +101,7 @@ function _worker_pool() return nothing end p = default_worker_pool() - pool = length(p) < 2 ? nothing : p + pool = length(workers()) < 2 ? nothing : p return pool end diff --git a/src/pysource/FD_utils.py b/src/pysource/FD_utils.py index 2dd7977cf..c04db1cac 100644 --- a/src/pysource/FD_utils.py +++ b/src/pysource/FD_utils.py @@ -1,6 +1,10 @@ from sympy import rot_axis2, rot_axis3 +from devito import TensorFunction, Differentiable, div, grad, cos, sin -from devito import TensorFunction, Differentiable, div, grad + +trig_mapper = {cos.__sympy_class__: cos, sin.__sympy_class__: sin} +r2 = lambda x: rot_axis2(x).applyfunc(lambda i: trig_mapper.get(i.func, i.func)(*i.args)) +r3 = lambda x: rot_axis3(x).applyfunc(lambda i: trig_mapper.get(i.func, i.func)(*i.args)) def laplacian(v, irho): @@ -27,22 +31,19 @@ def R_mat(model): """ # Rotation matrix try: - Rt = rot_axis2(model.theta) + Rt = r2(model.theta) except AttributeError: - Rt = rot_axis2(0) + Rt = r2(0) if model.dim == 3: try: - Rt *= rot_axis3(model.phi) + Rt *= r3(model.phi) except AttributeError: - Rt *= rot_axis3(0) + Rt *= r3(0) else: Rt = Rt[[0, 2], [0, 2]] - R = TensorFunction(name="R", grid=model.grid, components=Rt, symmetric=False) - try: - R.name == "R" - return R - except AttributeError: - return Rt + # Rebuild sin/cos + + return TensorFunction(name="R", grid=model.grid, components=Rt, symmetric=False) def thomsen_mat(model): diff --git a/src/pysource/kernels.py b/src/pysource/kernels.py index ff13a9d8b..e549d0f6a 100644 --- a/src/pysource/kernels.py +++ b/src/pysource/kernels.py @@ -118,7 +118,6 @@ def SLS_2nd_order(model, p, fw=True, q=None, f0=0.015): b * r.forward - q + (1 - damp) * p.dt u_p = Eq(p.forward, solve(pde_p, p.forward)) - return [u_r, u_p] else: # Attenuation Memory variable pde_r = r.dt.T + b * p + (1 / t_s) * r @@ -130,7 +129,7 @@ def SLS_2nd_order(model, p, fw=True, q=None, f0=0.015): u_p = Eq(p.backward, solve(pde_p, p.backward)) - return [u_r, u_p], [] + return [u_r, u_p], [] def tti_kernel(model, u1, u2, fw=True, q=None):