From f6c7ae8e1309c664bcff6ba585580db838422e0b Mon Sep 17 00:00:00 2001 From: mloubout Date: Fri, 2 Jun 2023 11:30:43 -0400 Subject: [PATCH] tiny notebook fix --- Project.toml | 2 +- docs/src/installation.md | 8 +- examples/notebooks/03_constrained_fwi.ipynb | 82 +++++++++++++------- src/TimeModeling/LinearOperators/callable.jl | 2 +- src/TimeModeling/Modeling/misfit_fg.jl | 10 +-- src/TimeModeling/Modeling/twri_objective.jl | 6 +- 6 files changed, 70 insertions(+), 40 deletions(-) diff --git a/Project.toml b/Project.toml index 8aeed290e..579eecc8a 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.3.1" +version = "3.3.2" [deps] ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" diff --git a/docs/src/installation.md b/docs/src/installation.md index d3d543508..6e52f3ea0 100644 --- a/docs/src/installation.md +++ b/docs/src/installation.md @@ -47,11 +47,11 @@ export DEVITO_PLATFORM=nvidiaX ## Running with Docker -If you do not want to install JUDI, you can run [JUDI] as a [docker image](https://hub.docker.com/repository/docker/mloubout/judi). The first possibility is to run the docker container as a Jupyter notebook. [JUDI] provides two docker images for the latest [JUDI] release for Julia versions `1.6` (LTS) and `1.7` (latest stable version). The images names are `mloubout/judi:JVER-latest` where `JVER` is the Julia version. This docker images contain pre-installed compilers for CPUs (gcc-10) and Nvidia GPUs (nvc) via the nvidia HPC sdk. The environment is automatically set for [Devito] based on the hardware available. +If you do not want to install JUDI, you can run [JUDI](https://github.com/slimgroup/JUDI.jl) as a [docker image](https://hub.docker.com/repository/docker/mloubout/judi). The first possibility is to run the docker container as a Jupyter notebook. [JUDI](https://github.com/slimgroup/JUDI.jl) provides two docker images for the latest [JUDI](https://github.com/slimgroup/JUDI.jl) release for Julia versions `1.6` (LTS) and `1.7` (latest stable version). The images names are `mloubout/judi:JVER-latest` where `JVER` is the Julia version. This docker images contain pre-installed compilers for CPUs (gcc-10) and Nvidia GPUs (nvc) via the nvidia HPC sdk. The environment is automatically set for [Devito] based on the hardware available. **Note**: If you wish to use your gpu, you will need to install [nvidia-docker](https://docs.nvidia.com/ai-enterprise/deployment-guide/dg-docker.html) and run `docker run --gpus all` in order to make the GPUs available at runtime from within the image. -To run [JUDI] via docker execute the following command in your terminal: +To run [JUDI](https://github.com/slimgroup/JUDI.jl) via docker execute the following command in your terminal: ```bash docker run -p 8888:8888 mloubout/judi:1.7-latest @@ -65,9 +65,9 @@ docker run -it mloubout/judi:1.7-latest /bin/bash Inside the container, all examples are located in the directory `/app/judi/examples/scripts`. -**Previous versions**: As of version `v2.6.7` of JUDI, we also ship version-tagged images as `mloubout/judi:JVER-ver` where `ver` is the version of [JUDI] wanted, for example the current [JUDI] version with Julia 1.7 is `mloubout/judi:1.7-v2.6.7` +**Previous versions**: As of version `v2.6.7` of JUDI, we also ship version-tagged images as `mloubout/judi:JVER-ver` where `ver` is the version of [JUDI](https://github.com/slimgroup/JUDI.jl) wanted, for example the current [JUDI](https://github.com/slimgroup/JUDI.jl) version with Julia 1.7 is `mloubout/judi:1.7-v2.6.7` -**Development version**: Additionally, we provide two images corresponding to the latest development version of [JUDI] (latest state of the master branch). These images are called `mloubout/judi:JVER-dev` and can be used in a similar way. +**Development version**: Additionally, we provide two images corresponding to the latest development version of [JUDI](https://github.com/slimgroup/JUDI.jl) (latest state of the master branch). These images are called `mloubout/judi:JVER-dev` and can be used in a similar way. ## Testing diff --git a/examples/notebooks/03_constrained_fwi.ipynb b/examples/notebooks/03_constrained_fwi.ipynb index a489a3736..cf6cf9584 100644 --- a/examples/notebooks/03_constrained_fwi.ipynb +++ b/examples/notebooks/03_constrained_fwi.ipynb @@ -1,25 +1,26 @@ { "cells": [ { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# FWI Example\n", "We will peform FWI using the following steps:\n", - "1. [Prepare models](#models)\n", - "2. [Setup Constraints](#constraints) with [SetIntersectionProjection](https://github.com/slimgroup/SetIntersectionProjection.jl)\n", - "3. [Build a small local compute cluster (2 workers)](#cluster)\n", + "1. [Prepare models](#prepare-models)\n", + "2. [Setup Constraints](#setup-constraints-with-setintersectionprojection) with [SetIntersectionProjection](https://github.com/slimgroup/SetIntersectionProjection.jl)\n", + "3. [Build a small local compute cluster (2 workers)](#build-a-small-local-compute-cluster)\n", " * Take care of some HPC details related to thread affinity\n", - "4. [Create source and receivers geometries](#pos)\n", - "5. [Build `F`, the JUDI modeling operator](#buildF)\n", - "6. [Use `F` to create data for both models](#data)\n", - "7. [Visualize data](#vizD)\n", - "8. [Assess if data is cycle skipped at the farthest offsets](#cskiped)\n", - "9. [Build the `objective` function](#objective)\n", - "10. [Perform the FWI using `minConf_PQN`](#inversion) from [JUDI](https://github.com/slimgroup/JUDI.jl)\n", - "11. [Visualize velocity models and objective function](#plotres)\n", - "12. [Visualize data match](#matchD)\n", - "14. [Remove workers](#del)\n", + "4. [Create source and receivers geometries](#create-source-and-receivers-geometries)\n", + "5. [Build `F`, the JUDI modeling operator](#build-F-the-judi-modeling-operator)\n", + "6. [Use `F` to create data for both models](#use-F-to-create-the-data-in-both-models)\n", + "7. [Visualize data](#visualize-data)\n", + "8. [Assess if data is cycle skipped at the farthest offsets](#assess-if-data-is-cycle-skipped-at-the-farthest-offsets)\n", + "9. [Build the `objective` function](#build-the-objective-functions)\n", + "10. [Perform the FWI using `minConf_PQN`](#perform-the-FWI-using-minConf_PQN) from [JUDI](https://github.com/slimgroup/JUDI.jl)\n", + "11. [Visualize velocity models and objective function](#visualize-velocity-models-and-objective-function)\n", + "12. [Visualize data match](#visualize-data-match)\n", + "13. [Remove workers](#remove-workers)\n", "\n", "#### Note on runtime\n", "Warning: this notebook takes more than 1 hour to run for 16 shots with two workers on an Intel 8168.\n", @@ -49,10 +50,11 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ - "## 1. Prepare models " + "## Prepare models" ] }, { @@ -89,6 +91,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -129,10 +132,11 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ - "## 2. Setup Constraints with [SetIntersectionProjection](https://github.com/slimgroup/SetIntersectionProjection.jl) " + "## Setup Constraints with [SetIntersectionProjection](https://github.com/slimgroup/SetIntersectionProjection.jl)" ] }, { @@ -160,6 +164,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -268,10 +273,11 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ - "## 3. Build a small local compute cluster (2 workers) \n", + "## Build a small local compute cluster\n", "\n", "#### Setup OMP environment variables for the cluster\n", "\n", @@ -379,10 +385,11 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ - "## 4. Create source and receivers geometries \n", + "## Create source and receivers geometries\n", "We use 8 shot locations evenly distributed across the left of the model." ] }, @@ -435,6 +442,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -480,10 +488,11 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ - "## 5. Build `F`, the JUDI modeling operator " + "## Build `F`, the JUDI modeling operator" ] }, { @@ -510,10 +519,11 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ - "## 6. Use `F` to create the data in both models " + "## Use `F` to create the data in both models" ] }, { @@ -617,6 +627,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -633,10 +644,11 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ - "## 7. Visualize data " + "## Visualize data" ] }, { @@ -663,6 +675,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -725,10 +738,11 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ - "## 8. Assess if data is cycle skipped at the farthest offsets \n", + "## Assess if data is cycle skipped at the farthest offsets\n", "Next we plot the far offset traces for these three shots in order to assess if the data is cycle skipped. \n", "\n", "You can ovbserve in the plots below that the refraction waveforms (first arrivals) in the initial model are not cycle skipped with respect to the true model, so we can proceed. \n", @@ -768,13 +782,15 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ - "## 9. Build the `objective` functions " + "## Build the `objective` functions" ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -811,6 +827,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -868,6 +885,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -986,10 +1004,11 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ - "## 10. Perform the FWI using `minConf_PQN` \n", + "## Perform the FWI using `minConf_PQN`\n", "We will do 10 functions evaluation cost of projected quasi-Newton with two setup:\n", "- Bounds constraints only\n", "- Bounds + tv constrains" @@ -2546,10 +2565,11 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ - "## 11. Visualize velocity models and objective function " + "## Visualize velocity models and objective function" ] }, { @@ -2587,6 +2607,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -2632,6 +2653,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -2668,6 +2690,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -2705,10 +2728,11 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ - "## 12. Visualize data match \n", + "## Visualize data match\n", "#### Generate data in the FWI velocity model" ] }, @@ -2757,6 +2781,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -2774,6 +2799,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -2841,6 +2867,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -2868,6 +2895,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -2895,6 +2923,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -2922,10 +2951,11 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ - "## 14. Remove workers " + "## Remove workers" ] }, { diff --git a/src/TimeModeling/LinearOperators/callable.jl b/src/TimeModeling/LinearOperators/callable.jl index 7aeca6929..efba77f67 100644 --- a/src/TimeModeling/LinearOperators/callable.jl +++ b/src/TimeModeling/LinearOperators/callable.jl @@ -41,7 +41,7 @@ function (J::judiJacobian{D, O, FT})(q::judiMultiSourceVector) where {D, O, FT} end function (J::judiJacobian{D, O, FT})(x::Array{D, N}) where {D, O, FT, N} - if length(x) == prod(J.model.n) + if length(x) == prod(size(J.model)) return J(;m=m) end new_q = _as_src(J.qInjection.op, J.model, x) diff --git a/src/TimeModeling/Modeling/misfit_fg.jl b/src/TimeModeling/Modeling/misfit_fg.jl index d26c2d9e2..a07b7f544 100644 --- a/src/TimeModeling/Modeling/misfit_fg.jl +++ b/src/TimeModeling/Modeling/misfit_fg.jl @@ -38,8 +38,8 @@ function multi_src_fg(model_full::AbstractModel, source::judiVector, dObs::judiV # Set up coordinates @juditime "Sparse coords setup" begin - src_coords = setup_grid(source.geometry, model.n) # shifts source coordinates by origin - rec_coords = setup_grid(dObs.geometry, model.n) # shifts rec coordinates by origin + src_coords = setup_grid(source.geometry, size(model)) # shifts source coordinates by origin + rec_coords = setup_grid(dObs.geometry, size(model)) # shifts rec coordinates by origin end mfunc = pyfunction(misfit, Matrix{Float32}, Matrix{Float32}) @@ -61,14 +61,14 @@ function multi_src_fg(model_full::AbstractModel, source::judiVector, dObs::judiV end @juditime "Remove padding from gradient" begin - grad = PhysicalParameter(remove_padding(argout[2], modelPy.padsizes; true_adjoint=options.sum_padding), model.d, model.o) + grad = PhysicalParameter(remove_padding(argout[2], modelPy.padsizes; true_adjoint=options.sum_padding), spacing(model), origin(model)) end fval = Ref{Float32}(argout[1]) if illum @juditime "Process illumination" begin - illumu = PhysicalParameter(remove_padding(argout[3], modelPy.padsizes; true_adjoint=false), model.d, model.o) - illumv = PhysicalParameter(remove_padding(argout[4], modelPy.padsizes; true_adjoint=false), model.d, model.o) + illumu = PhysicalParameter(remove_padding(argout[3], modelPy.padsizes; true_adjoint=false), spacing(model), origin(model)) + illumv = PhysicalParameter(remove_padding(argout[4], modelPy.padsizes; true_adjoint=false), spacing(model), origin(model)) end return fval, grad, illumu, illumv end diff --git a/src/TimeModeling/Modeling/twri_objective.jl b/src/TimeModeling/Modeling/twri_objective.jl index 7f146331f..ab554d45e 100644 --- a/src/TimeModeling/Modeling/twri_objective.jl +++ b/src/TimeModeling/Modeling/twri_objective.jl @@ -88,8 +88,8 @@ function twri_objective(model_full::AbstractModel, source::judiVector, dObs::jud isnothing(y) ? Y = nothing : Y = time_resample(make_input(y), y.geometry, dtComp) # Set up coordinates - src_coords = setup_grid(source.geometry, model.n) # shifts source coordinates by origin - rec_coords = setup_grid(dObs.geometry, model.n) # shifts rec coordinates by origin + src_coords = setup_grid(source.geometry, size(model)) # shifts source coordinates by origin + rec_coords = setup_grid(dObs.geometry, size(model)) # shifts rec coordinates by origin ~isempty(options.frequencies) ? freqs = options.frequencies : freqs = nothing ~isempty(options.frequencies) ? (wfilt, freqs) = filter_w(qIn, dtComp, freqs) : wfilt = nothing @@ -104,7 +104,7 @@ function twri_objective(model_full::AbstractModel, source::judiVector, dObs::jud if (optionswri.params in [:m, :all]) gradm = remove_padding(gradm, modelPy.padsizes; true_adjoint=options.sum_padding) - gradm = PhysicalParameter(gradm, model.d, model.o) + gradm = PhysicalParameter(gradm, spacing(model), origin(model)) end if ~isnothing(grady) grady = time_resample(grady, dtComp, dObs.geometry)