Skip to content

Commit

Permalink
deploy: cca6287
Browse files Browse the repository at this point in the history
  • Loading branch information
mrava87 committed Mar 29, 2024
1 parent 5bbc394 commit 0103540
Show file tree
Hide file tree
Showing 93 changed files with 1,674 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 2b995ed0f2cc84754bcc4807ea617af1
config: 6d660a6109fc62d4ade0f1a8479bb7b8
tags: 645f666f9bcd5a90fca523b33c5a78b7
Binary file modified .doctrees/api/generated/pylops_mpi.DistributedArray.doctree
Binary file not shown.
Binary file modified .doctrees/api/generated/pylops_mpi.MPILinearOperator.doctree
Binary file not shown.
Binary file not shown.
Binary file modified .doctrees/api/generated/pylops_mpi.Partition.doctree
Binary file not shown.
Binary file not shown.
Binary file modified .doctrees/api/generated/pylops_mpi.asmpilinearoperator.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified .doctrees/api/generated/pylops_mpi.optimization.basic.cg.doctree
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified .doctrees/api/index.doctree
Binary file not shown.
Binary file modified .doctrees/environment.pickle
Binary file not shown.
Binary file modified .doctrees/gallery/plot_cgls.doctree
Binary file not shown.
Binary file modified .doctrees/gallery/plot_derivative.doctree
Binary file not shown.
Binary file modified .doctrees/gallery/plot_distributed_array.doctree
Binary file not shown.
Binary file modified .doctrees/gallery/plot_mpilinop.doctree
Binary file not shown.
Binary file modified .doctrees/gallery/plot_stacked_array.doctree
Binary file not shown.
Binary file modified .doctrees/gallery/plot_stacking.doctree
Binary file not shown.
Binary file modified .doctrees/gallery/sg_execution_times.doctree
Binary file not shown.
Binary file modified .doctrees/sg_execution_times.doctree
Binary file not shown.
Binary file modified .doctrees/tutorials/lsm.doctree
Binary file not shown.
Binary file modified .doctrees/tutorials/poststack.doctree
Binary file not shown.
Binary file modified .doctrees/tutorials/sg_execution_times.doctree
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.18"
"version": "3.9.19"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.18"
"version": "3.9.19"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.18"
"version": "3.9.19"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.18"
"version": "3.9.19"
}
},
"nbformat": 4,
Expand Down
34 changes: 34 additions & 0 deletions _downloads/b2b09bb3558d30e9fdb35def7ca44029/plot_derivative.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,37 @@
plt.colorbar(im, ax=axs[2])
plt.tight_layout()
plt.subplots_adjust(top=0.8)

###############################################################################
# We now consider the :py:class:`pylops_mpi.basicoperators.MPIGradient` operator.
# Given a 2-dimensional array, this operator applies first-order derivatives on both
# dimensions and concatenates them.
Gop = pylops_mpi.MPIGradient(dims=(nx, ny), dtype=np.float64)

y_grad_dist = Gop @ x_dist
# Reshaping to (ndims, nx, ny) for plotting
y_grad = y_grad_dist.asarray().reshape((2, nx, ny))
y_grad_adj_dist = Gop.H @ y_grad_dist
# Reshaping to (nx, ny) for plotting
y_grad_adj = y_grad_adj_dist.asarray().reshape((nx, ny))

if rank == 0:
fig, axs = plt.subplots(2, 2, figsize=(10, 6), sharex=True, sharey=True)
fig.suptitle("Gradient", fontsize=12, fontweight="bold", y=0.95)
im = axs[0, 0].imshow(x, interpolation="nearest", cmap="rainbow")
axs[0, 0].axis("tight")
axs[0, 0].set_title("x")
plt.colorbar(im, ax=axs[0, 0])
im = axs[0, 1].imshow(y_grad[0, ...], interpolation="nearest", cmap="rainbow")
axs[0, 1].axis("tight")
axs[0, 1].set_title("y - 1st direction")
plt.colorbar(im, ax=axs[0, 1])
im = axs[1, 1].imshow(y_grad[1, ...], interpolation="nearest", cmap="rainbow")
axs[1, 1].axis("tight")
axs[1, 1].set_title("y - 2nd direction")
plt.colorbar(im, ax=axs[1, 1])
im = axs[1, 0].imshow(y_grad_adj, interpolation="nearest", cmap="rainbow")
axs[1, 0].axis("tight")
axs[1, 0].set_title("xadj")
plt.colorbar(im, ax=axs[1, 0])
plt.tight_layout()
2 changes: 1 addition & 1 deletion _downloads/d5dae76a02f3b395d667034f44fd5555/lsm.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.18"
"version": "3.9.19"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.18"
"version": "3.9.19"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,24 @@
"source": [
"nx, ny = (12, 21)\nx = np.zeros((nx, ny))\nx[nx // 2, ny // 2] = 1.0\n\n# Symmetrical\nL2symop = pylops_mpi.MPILaplacian(dims=(nx, ny), weights=(1, 1), dtype=np.float64)\n\n# Asymmetrical\nL2asymop = pylops_mpi.MPILaplacian(dims=(nx, ny), weights=(3, 1), dtype=np.float64)\n\nx_dist = pylops_mpi.DistributedArray.to_dist(x=x.flatten())\nysym_dist = L2symop @ x_dist\nysym = ysym_dist.asarray().reshape((nx, ny))\nyasym_dist = L2asymop @ x_dist\nyasym = yasym_dist.asarray().reshape((nx, ny))\n\nif rank == 0:\n fig, axs = plt.subplots(1, 3, figsize=(10, 3), sharey=True)\n fig.suptitle(\"Laplacian\", fontsize=12, fontweight=\"bold\", y=0.95)\n im = axs[0].imshow(x, interpolation=\"nearest\", cmap=\"rainbow\")\n axs[0].axis(\"tight\")\n axs[0].set_title(\"x\")\n plt.colorbar(im, ax=axs[0])\n im = axs[1].imshow(ysym, interpolation=\"nearest\", cmap=\"rainbow\")\n axs[1].axis(\"tight\")\n axs[1].set_title(\"y sym\")\n plt.colorbar(im, ax=axs[1])\n im = axs[2].imshow(yasym, interpolation=\"nearest\", cmap=\"rainbow\")\n axs[2].axis(\"tight\")\n axs[2].set_title(\"y asym\")\n plt.colorbar(im, ax=axs[2])\n plt.tight_layout()\n plt.subplots_adjust(top=0.8)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We now consider the :py:class:`pylops_mpi.basicoperators.MPIGradient` operator.\nGiven a 2-dimensional array, this operator applies first-order derivatives on both\ndimensions and concatenates them.\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"Gop = pylops_mpi.MPIGradient(dims=(nx, ny), dtype=np.float64)\n\ny_grad_dist = Gop @ x_dist\n# Reshaping to (ndims, nx, ny) for plotting\ny_grad = y_grad_dist.asarray().reshape((2, nx, ny))\ny_grad_adj_dist = Gop.H @ y_grad_dist\n# Reshaping to (nx, ny) for plotting\ny_grad_adj = y_grad_adj_dist.asarray().reshape((nx, ny))\n\nif rank == 0:\n fig, axs = plt.subplots(2, 2, figsize=(10, 6), sharex=True, sharey=True)\n fig.suptitle(\"Gradient\", fontsize=12, fontweight=\"bold\", y=0.95)\n im = axs[0, 0].imshow(x, interpolation=\"nearest\", cmap=\"rainbow\")\n axs[0, 0].axis(\"tight\")\n axs[0, 0].set_title(\"x\")\n plt.colorbar(im, ax=axs[0, 0])\n im = axs[0, 1].imshow(y_grad[0, ...], interpolation=\"nearest\", cmap=\"rainbow\")\n axs[0, 1].axis(\"tight\")\n axs[0, 1].set_title(\"y - 1st direction\")\n plt.colorbar(im, ax=axs[0, 1])\n im = axs[1, 1].imshow(y_grad[1, ...], interpolation=\"nearest\", cmap=\"rainbow\")\n axs[1, 1].axis(\"tight\")\n axs[1, 1].set_title(\"y - 2nd direction\")\n plt.colorbar(im, ax=axs[1, 1])\n im = axs[1, 0].imshow(y_grad_adj, interpolation=\"nearest\", cmap=\"rainbow\")\n axs[1, 0].axis(\"tight\")\n axs[1, 0].set_title(\"xadj\")\n plt.colorbar(im, ax=axs[1, 0])\n plt.tight_layout()"
]
}
],
"metadata": {
Expand All @@ -89,7 +107,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.18"
"version": "3.9.19"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.18"
"version": "3.9.19"
}
},
"nbformat": 4,
Expand Down
Binary file added _images/sphx_glr_plot_derivative_004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions _modules/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ <h1>All modules for which code is available</h1>
<li><a href="pylops_mpi/StackedLinearOperator.html">pylops_mpi.StackedLinearOperator</a></li>
<li><a href="pylops_mpi/basicoperators/BlockDiag.html">pylops_mpi.basicoperators.BlockDiag</a></li>
<li><a href="pylops_mpi/basicoperators/FirstDerivative.html">pylops_mpi.basicoperators.FirstDerivative</a></li>
<li><a href="pylops_mpi/basicoperators/Gradient.html">pylops_mpi.basicoperators.Gradient</a></li>
<li><a href="pylops_mpi/basicoperators/HStack.html">pylops_mpi.basicoperators.HStack</a></li>
<li><a href="pylops_mpi/basicoperators/Laplacian.html">pylops_mpi.basicoperators.Laplacian</a></li>
<li><a href="pylops_mpi/basicoperators/SecondDerivative.html">pylops_mpi.basicoperators.SecondDerivative</a></li>
Expand Down
46 changes: 42 additions & 4 deletions _modules/pylops_mpi/StackedLinearOperator.html
Original file line number Diff line number Diff line change
Expand Up @@ -463,12 +463,12 @@ <h1>Source code for pylops_mpi.StackedLinearOperator</h1><div class="highlight">
<span class="sd"> for StackedLinearOperators.</span>

<span class="sd"> This class provides methods to perform matrix-vector product and adjoint matrix-vector</span>
<span class="sd"> products on a stack of MPILinearOperator objects.</span>
<span class="sd"> products on a stack of :class:`pylops_mpi.MPILinearOperator` objects.</span>

<span class="sd"> .. note:: End users of pylops-mpi should not use this class directly but simply</span>
<span class="sd"> use operators that are already implemented. This class is meant for</span>
<span class="sd"> developers only, it has to be used as the parent class of any new operator</span>
<span class="sd"> developed within pylops-mpi.</span>
<span class="sd"> use operators that are already implemented. This class is meant for</span>
<span class="sd"> developers only, it has to be used as the parent class of any new operator</span>
<span class="sd"> developed within pylops-mpi.</span>

<span class="sd"> Parameters</span>
<span class="sd"> ----------</span>
Expand All @@ -493,6 +493,25 @@ <h1>Source code for pylops_mpi.StackedLinearOperator</h1><div class="highlight">
<span class="bp">self</span><span class="o">.</span><span class="n">rank</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">base_comm</span><span class="o">.</span><span class="n">Get_rank</span><span class="p">()</span>

<span class="k">def</span> <span class="nf">matvec</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="n">DistributedArray</span><span class="p">,</span> <span class="n">StackedDistributedArray</span><span class="p">])</span> <span class="o">-&gt;</span> <span class="n">Union</span><span class="p">[</span><span class="n">DistributedArray</span><span class="p">,</span> <span class="n">StackedDistributedArray</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Matrix-vector multiplication.</span>

<span class="sd"> Modified version of :class:`pylops_mpi.MPILinearOperator` matvec.</span>
<span class="sd"> This method makes use of either :class:`pylops_mpi.DistributedArray` or</span>
<span class="sd"> :class:`pylops_mpi.StackedDistributedArray` to calculate matrix vector multiplication</span>
<span class="sd"> in a distributed fashion.</span>

<span class="sd"> Parameters</span>
<span class="sd"> ----------</span>
<span class="sd"> x : :obj:`pylops_mpi.DistributedArray` or :obj:`pylops_mpi.DistributedArray`</span>
<span class="sd"> A StackedDistributedArray or a DistributedArray of global shape (N, )</span>

<span class="sd"> Returns</span>
<span class="sd"> -------</span>
<span class="sd"> y : :obj:`pylops_mpi.DistributedArray` or :obj:`pylops_mpi.DistributedArray`</span>
<span class="sd"> A StackedDistributedArray or a DistributedArray of global shape (M, )</span>

<span class="sd"> &quot;&quot;&quot;</span>

<span class="n">M</span><span class="p">,</span> <span class="n">N</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">shape</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">StackedDistributedArray</span><span class="p">):</span>
<span class="n">stacked_shape</span> <span class="o">=</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">([</span><span class="n">a</span><span class="o">.</span><span class="n">global_shape</span> <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="n">x</span><span class="o">.</span><span class="n">distarrays</span><span class="p">]),</span> <span class="p">)</span>
Expand All @@ -507,6 +526,25 @@ <h1>Source code for pylops_mpi.StackedLinearOperator</h1><div class="highlight">
<span class="k">pass</span>

<span class="k">def</span> <span class="nf">rmatvec</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">:</span> <span class="n">Union</span><span class="p">[</span><span class="n">DistributedArray</span><span class="p">,</span> <span class="n">StackedDistributedArray</span><span class="p">])</span> <span class="o">-&gt;</span> <span class="n">Union</span><span class="p">[</span><span class="n">DistributedArray</span><span class="p">,</span> <span class="n">StackedDistributedArray</span><span class="p">]:</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Adjoint Matrix-vector multiplication.</span>

<span class="sd"> Modified version of :class:`pylops_mpi.MPILinearOperator` rmatvec</span>
<span class="sd"> This method makes use of either :class:`pylops_mpi.DistributedArray` or</span>
<span class="sd"> :class:`pylops_mpi.StackedDistributedArray` to calculate adjoint matrix vector multiplication</span>
<span class="sd"> in a distributed fashion.</span>

<span class="sd"> Parameters</span>
<span class="sd"> ----------</span>
<span class="sd"> x : :obj:`pylops_mpi.DistributedArray` or :obj:`pylops_mpi.DistributedArray`</span>
<span class="sd"> A StackedDistributedArray or a DistributedArray of global shape (M, )</span>

<span class="sd"> Returns</span>
<span class="sd"> -------</span>
<span class="sd"> y : :obj:`pylops_mpi.DistributedArray` or :obj:`pylops_mpi.DistributedArray`</span>
<span class="sd"> A StackedDistributedArray or a DistributedArray of global shape (N, )</span>

<span class="sd"> &quot;&quot;&quot;</span>

<span class="n">M</span><span class="p">,</span> <span class="n">N</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">shape</span>
<span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">StackedDistributedArray</span><span class="p">):</span>
<span class="n">stacked_shape</span> <span class="o">=</span> <span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">sum</span><span class="p">([</span><span class="n">a</span><span class="o">.</span><span class="n">global_shape</span> <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="n">x</span><span class="o">.</span><span class="n">distarrays</span><span class="p">]),</span> <span class="p">)</span>
Expand Down
Loading

0 comments on commit 0103540

Please sign in to comment.