diff --git a/.buildinfo b/.buildinfo index 3c158910..e38298dc 100644 --- a/.buildinfo +++ b/.buildinfo @@ -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: 6d660a6109fc62d4ade0f1a8479bb7b8 +config: bba4525ffe87efa3cfac04f45c957dff tags: 645f666f9bcd5a90fca523b33c5a78b7 diff --git a/.doctrees/api/generated/pylops_mpi.StackedDistributedArray.doctree b/.doctrees/api/generated/pylops_mpi.StackedDistributedArray.doctree index 50b713ce..0acaa7ce 100644 Binary files a/.doctrees/api/generated/pylops_mpi.StackedDistributedArray.doctree and b/.doctrees/api/generated/pylops_mpi.StackedDistributedArray.doctree differ diff --git a/.doctrees/api/generated/pylops_mpi.optimization.basic.cg.doctree b/.doctrees/api/generated/pylops_mpi.optimization.basic.cg.doctree index 87b80586..133cd5a5 100644 Binary files a/.doctrees/api/generated/pylops_mpi.optimization.basic.cg.doctree and b/.doctrees/api/generated/pylops_mpi.optimization.basic.cg.doctree differ diff --git a/.doctrees/api/generated/pylops_mpi.optimization.basic.cgls.doctree b/.doctrees/api/generated/pylops_mpi.optimization.basic.cgls.doctree index 0889b014..f71cac5a 100644 Binary files a/.doctrees/api/generated/pylops_mpi.optimization.basic.cgls.doctree and b/.doctrees/api/generated/pylops_mpi.optimization.basic.cgls.doctree differ diff --git a/.doctrees/api/generated/pylops_mpi.optimization.cls_basic.CG.doctree b/.doctrees/api/generated/pylops_mpi.optimization.cls_basic.CG.doctree index ccc37683..879246de 100644 Binary files a/.doctrees/api/generated/pylops_mpi.optimization.cls_basic.CG.doctree and b/.doctrees/api/generated/pylops_mpi.optimization.cls_basic.CG.doctree differ diff --git a/.doctrees/api/generated/pylops_mpi.optimization.cls_basic.CGLS.doctree b/.doctrees/api/generated/pylops_mpi.optimization.cls_basic.CGLS.doctree index ef599d3a..d2f946e7 100644 Binary files a/.doctrees/api/generated/pylops_mpi.optimization.cls_basic.CGLS.doctree and b/.doctrees/api/generated/pylops_mpi.optimization.cls_basic.CGLS.doctree differ diff --git a/.doctrees/api/index.doctree b/.doctrees/api/index.doctree index e8433f09..7e820715 100644 Binary files a/.doctrees/api/index.doctree and b/.doctrees/api/index.doctree differ diff --git a/.doctrees/environment.pickle b/.doctrees/environment.pickle index dd036088..8cc49bf6 100644 Binary files a/.doctrees/environment.pickle and b/.doctrees/environment.pickle differ diff --git a/.doctrees/gallery/plot_cgls.doctree b/.doctrees/gallery/plot_cgls.doctree index d04d6db2..a58c8d13 100644 Binary files a/.doctrees/gallery/plot_cgls.doctree and b/.doctrees/gallery/plot_cgls.doctree differ diff --git a/.doctrees/gallery/plot_derivative.doctree b/.doctrees/gallery/plot_derivative.doctree index ac6688f3..67c0e274 100644 Binary files a/.doctrees/gallery/plot_derivative.doctree and b/.doctrees/gallery/plot_derivative.doctree differ diff --git a/.doctrees/gallery/plot_distributed_array.doctree b/.doctrees/gallery/plot_distributed_array.doctree index 4fa1533c..8b848bda 100644 Binary files a/.doctrees/gallery/plot_distributed_array.doctree and b/.doctrees/gallery/plot_distributed_array.doctree differ diff --git a/.doctrees/gallery/plot_mpilinop.doctree b/.doctrees/gallery/plot_mpilinop.doctree index db8bfd19..74a518fc 100644 Binary files a/.doctrees/gallery/plot_mpilinop.doctree and b/.doctrees/gallery/plot_mpilinop.doctree differ diff --git a/.doctrees/gallery/plot_stacked_array.doctree b/.doctrees/gallery/plot_stacked_array.doctree index 8d3ba68b..c6718e5a 100644 Binary files a/.doctrees/gallery/plot_stacked_array.doctree and b/.doctrees/gallery/plot_stacked_array.doctree differ diff --git a/.doctrees/gallery/plot_stacking.doctree b/.doctrees/gallery/plot_stacking.doctree index c886a102..7d96c019 100644 Binary files a/.doctrees/gallery/plot_stacking.doctree and b/.doctrees/gallery/plot_stacking.doctree differ diff --git a/.doctrees/gallery/sg_execution_times.doctree b/.doctrees/gallery/sg_execution_times.doctree index 030f44e2..50303df6 100644 Binary files a/.doctrees/gallery/sg_execution_times.doctree and b/.doctrees/gallery/sg_execution_times.doctree differ diff --git a/.doctrees/sg_execution_times.doctree b/.doctrees/sg_execution_times.doctree index 4abf6608..205a0742 100644 Binary files a/.doctrees/sg_execution_times.doctree and b/.doctrees/sg_execution_times.doctree differ diff --git a/.doctrees/tutorials/lsm.doctree b/.doctrees/tutorials/lsm.doctree index abd42381..3517cf06 100644 Binary files a/.doctrees/tutorials/lsm.doctree and b/.doctrees/tutorials/lsm.doctree differ diff --git a/.doctrees/tutorials/poststack.doctree b/.doctrees/tutorials/poststack.doctree index b2256498..46e85fb0 100644 Binary files a/.doctrees/tutorials/poststack.doctree and b/.doctrees/tutorials/poststack.doctree differ diff --git a/.doctrees/tutorials/sg_execution_times.doctree b/.doctrees/tutorials/sg_execution_times.doctree index e602fa2f..22f17a7b 100644 Binary files a/.doctrees/tutorials/sg_execution_times.doctree and b/.doctrees/tutorials/sg_execution_times.doctree differ diff --git a/_downloads/59790902f856f463297d6568e11254ee/plot_cgls.ipynb b/_downloads/59790902f856f463297d6568e11254ee/plot_cgls.ipynb index 127581f6..66e0c8f9 100644 --- a/_downloads/59790902f856f463297d6568e11254ee/plot_cgls.ipynb +++ b/_downloads/59790902f856f463297d6568e11254ee/plot_cgls.ipynb @@ -69,7 +69,7 @@ }, "outputs": [], "source": [ - "xinv, istop, niter, r1norm, r2norm, cost = pylops_mpi.cgls(BDiag, y, niter=15, tol=1e-10, show=True)\nxinv_array = xinv.asarray()\n\nif rank == 0:\n print(f\"CGLS Solution xinv={xinv_array}\")\n # Visualize\n plt.figure(figsize=(18, 5))\n plt.plot(cost, lw=2, label=\"CGLS\")\n plt.title(\"Cost Function\")\n plt.legend()\n plt.tight_layout()" + "# Set initial guess `x0` to zeroes\nx0 = pylops_mpi.DistributedArray(BDiag.shape[1], dtype=np.float128)\nx0[:] = 0\nxinv, istop, niter, r1norm, r2norm, cost = pylops_mpi.cgls(BDiag, y, x0=x0, niter=15, tol=1e-10, show=True)\nxinv_array = xinv.asarray()\n\nif rank == 0:\n print(f\"CGLS Solution xinv={xinv_array}\")\n # Visualize\n plt.figure(figsize=(18, 5))\n plt.plot(cost, lw=2, label=\"CGLS\")\n plt.title(\"Cost Function\")\n plt.legend()\n plt.tight_layout()" ] } ], diff --git a/_downloads/afacec718d3958430d53150fa3b27203/lsm.py b/_downloads/afacec718d3958430d53150fa3b27203/lsm.py index 8793358a..9db25795 100644 --- a/_downloads/afacec718d3958430d53150fa3b27203/lsm.py +++ b/_downloads/afacec718d3958430d53150fa3b27203/lsm.py @@ -164,7 +164,10 @@ # solver. # Inverse -minv_dist = pylops_mpi.cgls(VStack, d_dist, niter=100, show=True)[0] +# Initializing x0 to zeroes +x0 = pylops_mpi.DistributedArray(VStack.shape[1], partition=pylops_mpi.Partition.BROADCAST) +x0[:] = 0 +minv_dist = pylops_mpi.cgls(VStack, d_dist, x0=x0, niter=100, show=True)[0] minv = minv_dist.asarray().reshape((nx, nz)) d_inv_dist = VStack @ minv_dist d_inv = d_inv_dist.asarray().reshape(nstot, nr, nt) diff --git a/_downloads/d5dae76a02f3b395d667034f44fd5555/lsm.ipynb b/_downloads/d5dae76a02f3b395d667034f44fd5555/lsm.ipynb index ff60281b..c391aed5 100644 --- a/_downloads/d5dae76a02f3b395d667034f44fd5555/lsm.ipynb +++ b/_downloads/d5dae76a02f3b395d667034f44fd5555/lsm.ipynb @@ -80,7 +80,7 @@ }, "outputs": [], "source": [ - "# Inverse\nminv_dist = pylops_mpi.cgls(VStack, d_dist, niter=100, show=True)[0]\nminv = minv_dist.asarray().reshape((nx, nz))\nd_inv_dist = VStack @ minv_dist\nd_inv = d_inv_dist.asarray().reshape(nstot, nr, nt)" + "# Inverse\n# Initializing x0 to zeroes\nx0 = pylops_mpi.DistributedArray(VStack.shape[1], partition=pylops_mpi.Partition.BROADCAST)\nx0[:] = 0\nminv_dist = pylops_mpi.cgls(VStack, d_dist, x0=x0, niter=100, show=True)[0]\nminv = minv_dist.asarray().reshape((nx, nz))\nd_inv_dist = VStack @ minv_dist\nd_inv = d_inv_dist.asarray().reshape(nstot, nr, nt)" ] }, { diff --git a/_downloads/df45e4bd89b90a14841f9e115c4b2a59/plot_cgls.py b/_downloads/df45e4bd89b90a14841f9e115c4b2a59/plot_cgls.py index e30e4122..713faf71 100644 --- a/_downloads/df45e4bd89b90a14841f9e115c4b2a59/plot_cgls.py +++ b/_downloads/df45e4bd89b90a14841f9e115c4b2a59/plot_cgls.py @@ -45,7 +45,11 @@ # are then obtained in a :py:class:`pylops_mpi.DistributedArray`. To obtain the # overall inversion of the entire MPIBlockDiag, you can utilize the ``asarray()`` # function of the DistributedArray as shown below. -xinv, istop, niter, r1norm, r2norm, cost = pylops_mpi.cgls(BDiag, y, niter=15, tol=1e-10, show=True) + +# Set initial guess `x0` to zeroes +x0 = pylops_mpi.DistributedArray(BDiag.shape[1], dtype=np.float128) +x0[:] = 0 +xinv, istop, niter, r1norm, r2norm, cost = pylops_mpi.cgls(BDiag, y, x0=x0, niter=15, tol=1e-10, show=True) xinv_array = xinv.asarray() if rank == 0: diff --git a/_images/sphx_glr_lsm_001.png b/_images/sphx_glr_lsm_001.png index 6bb92848..244919fa 100644 Binary files a/_images/sphx_glr_lsm_001.png and b/_images/sphx_glr_lsm_001.png differ diff --git a/_images/sphx_glr_lsm_002.png b/_images/sphx_glr_lsm_002.png index a8303697..1e399d28 100644 Binary files a/_images/sphx_glr_lsm_002.png and b/_images/sphx_glr_lsm_002.png differ diff --git a/_images/sphx_glr_lsm_003.png b/_images/sphx_glr_lsm_003.png index 5efe9308..5e2b40d4 100644 Binary files a/_images/sphx_glr_lsm_003.png and b/_images/sphx_glr_lsm_003.png differ diff --git a/_images/sphx_glr_lsm_004.png b/_images/sphx_glr_lsm_004.png index dd581678..1f242e2c 100644 Binary files a/_images/sphx_glr_lsm_004.png and b/_images/sphx_glr_lsm_004.png differ diff --git a/_images/sphx_glr_lsm_005.png b/_images/sphx_glr_lsm_005.png index 27ef6321..435aaaca 100644 Binary files a/_images/sphx_glr_lsm_005.png and b/_images/sphx_glr_lsm_005.png differ diff --git a/_images/sphx_glr_plot_cgls_001.png b/_images/sphx_glr_plot_cgls_001.png index eb54a6b4..544f7d29 100644 Binary files a/_images/sphx_glr_plot_cgls_001.png and b/_images/sphx_glr_plot_cgls_001.png differ diff --git a/_images/sphx_glr_plot_derivative_001.png b/_images/sphx_glr_plot_derivative_001.png index 89e90b0d..5d8c4b3e 100644 Binary files a/_images/sphx_glr_plot_derivative_001.png and b/_images/sphx_glr_plot_derivative_001.png differ diff --git a/_images/sphx_glr_plot_derivative_002.png b/_images/sphx_glr_plot_derivative_002.png index a6f050e9..8c525338 100644 Binary files a/_images/sphx_glr_plot_derivative_002.png and b/_images/sphx_glr_plot_derivative_002.png differ diff --git a/_images/sphx_glr_plot_derivative_003.png b/_images/sphx_glr_plot_derivative_003.png index 4e2f4a22..be842174 100644 Binary files a/_images/sphx_glr_plot_derivative_003.png and b/_images/sphx_glr_plot_derivative_003.png differ diff --git a/_images/sphx_glr_plot_derivative_004.png b/_images/sphx_glr_plot_derivative_004.png index e17c44dc..e6c0744d 100644 Binary files a/_images/sphx_glr_plot_derivative_004.png and b/_images/sphx_glr_plot_derivative_004.png differ diff --git a/_images/sphx_glr_plot_distributed_array_001.png b/_images/sphx_glr_plot_distributed_array_001.png index f2c81162..96ad8f80 100644 Binary files a/_images/sphx_glr_plot_distributed_array_001.png and b/_images/sphx_glr_plot_distributed_array_001.png differ diff --git a/_images/sphx_glr_plot_distributed_array_002.png b/_images/sphx_glr_plot_distributed_array_002.png index 2146f196..c6aeef31 100644 Binary files a/_images/sphx_glr_plot_distributed_array_002.png and b/_images/sphx_glr_plot_distributed_array_002.png differ diff --git a/_images/sphx_glr_plot_distributed_array_003.png b/_images/sphx_glr_plot_distributed_array_003.png index f2c81162..96ad8f80 100644 Binary files a/_images/sphx_glr_plot_distributed_array_003.png and b/_images/sphx_glr_plot_distributed_array_003.png differ diff --git a/_images/sphx_glr_plot_distributed_array_004.png b/_images/sphx_glr_plot_distributed_array_004.png index ab1fc01f..7c87993b 100644 Binary files a/_images/sphx_glr_plot_distributed_array_004.png and b/_images/sphx_glr_plot_distributed_array_004.png differ diff --git a/_images/sphx_glr_plot_distributed_array_005.png b/_images/sphx_glr_plot_distributed_array_005.png index 7cda30e1..044e8d5e 100644 Binary files a/_images/sphx_glr_plot_distributed_array_005.png and b/_images/sphx_glr_plot_distributed_array_005.png differ diff --git a/_images/sphx_glr_plot_distributed_array_006.png b/_images/sphx_glr_plot_distributed_array_006.png index 2974bc41..696b4a69 100644 Binary files a/_images/sphx_glr_plot_distributed_array_006.png and b/_images/sphx_glr_plot_distributed_array_006.png differ diff --git a/_images/sphx_glr_plot_distributed_array_007.png b/_images/sphx_glr_plot_distributed_array_007.png index 48eaea4e..ace9224d 100644 Binary files a/_images/sphx_glr_plot_distributed_array_007.png and b/_images/sphx_glr_plot_distributed_array_007.png differ diff --git a/_images/sphx_glr_plot_distributed_array_008.png b/_images/sphx_glr_plot_distributed_array_008.png index 91f61e26..c49b3145 100644 Binary files a/_images/sphx_glr_plot_distributed_array_008.png and b/_images/sphx_glr_plot_distributed_array_008.png differ diff --git a/_images/sphx_glr_plot_distributed_array_009.png b/_images/sphx_glr_plot_distributed_array_009.png index 9727fcc3..2f86f08c 100644 Binary files a/_images/sphx_glr_plot_distributed_array_009.png and b/_images/sphx_glr_plot_distributed_array_009.png differ diff --git a/_images/sphx_glr_plot_distributed_array_010.png b/_images/sphx_glr_plot_distributed_array_010.png index ec674d81..b1daa85b 100644 Binary files a/_images/sphx_glr_plot_distributed_array_010.png and b/_images/sphx_glr_plot_distributed_array_010.png differ diff --git a/_images/sphx_glr_plot_mpilinop_001.png b/_images/sphx_glr_plot_mpilinop_001.png index 446878a6..3d1f02e5 100644 Binary files a/_images/sphx_glr_plot_mpilinop_001.png and b/_images/sphx_glr_plot_mpilinop_001.png differ diff --git a/_images/sphx_glr_plot_mpilinop_002.png b/_images/sphx_glr_plot_mpilinop_002.png index bbf3cd85..257576f9 100644 Binary files a/_images/sphx_glr_plot_mpilinop_002.png and b/_images/sphx_glr_plot_mpilinop_002.png differ diff --git a/_images/sphx_glr_plot_stacking_001.png b/_images/sphx_glr_plot_stacking_001.png index 312bee41..fae88ac8 100644 Binary files a/_images/sphx_glr_plot_stacking_001.png and b/_images/sphx_glr_plot_stacking_001.png differ diff --git a/_images/sphx_glr_plot_stacking_002.png b/_images/sphx_glr_plot_stacking_002.png index 4df868c3..13417267 100644 Binary files a/_images/sphx_glr_plot_stacking_002.png and b/_images/sphx_glr_plot_stacking_002.png differ diff --git a/_images/sphx_glr_plot_stacking_003.png b/_images/sphx_glr_plot_stacking_003.png index dcdc9372..4dda23db 100644 Binary files a/_images/sphx_glr_plot_stacking_003.png and b/_images/sphx_glr_plot_stacking_003.png differ diff --git a/_images/sphx_glr_poststack_001.png b/_images/sphx_glr_poststack_001.png index f77fd934..6c665ef7 100644 Binary files a/_images/sphx_glr_poststack_001.png and b/_images/sphx_glr_poststack_001.png differ diff --git a/_modules/pylops_mpi/DistributedArray.html b/_modules/pylops_mpi/DistributedArray.html index 5aba5b17..2860af6a 100644 --- a/_modules/pylops_mpi/DistributedArray.html +++ b/_modules/pylops_mpi/DistributedArray.html @@ -1047,12 +1047,17 @@
----------
distarrays : :obj:`list`
List of :class:`pylops_mpi.DistributedArray` objects.
-
+ base_comm : :obj:`mpi4py.MPI.Comm`, optional
+ Base MPI Communicator.
+ Defaults to ``mpi4py.MPI.COMM_WORLD``.
"""
- def __init__(self, distarrays: List):
+ def __init__(self, distarrays: List, base_comm: MPI.Comm = MPI.COMM_WORLD):
self.distarrays = distarrays
self.narrays = len(distarrays)
+ self.base_comm = base_comm
+ self.rank = base_comm.Get_rank()
+ self.size = base_comm.Get_size()
def __getitem__(self, index):
return self.distarrays[index]
@@ -1128,6 +1133,8 @@ Source code for pylops_mpi.DistributedArray
return self
def multiply(self, stacked_array):
+ """Stacked Distributed Multiplication of arrays
+ """
if isinstance(stacked_array, StackedDistributedArray):
self._check_stacked_size(stacked_array)
ProductArray = self.copy()
@@ -1143,6 +1150,8 @@ Source code for pylops_mpi.DistributedArray
return ProductArray
def dot(self, stacked_array):
+ """Dot Product of Stacked Distributed Arrays
+ """
self._check_stacked_size(stacked_array)
dotprod = 0.
for iarr in range(self.narrays):
diff --git a/_modules/pylops_mpi/optimization/basic.html b/_modules/pylops_mpi/optimization/basic.html
index 48d28fbb..d9dcc678 100644
--- a/_modules/pylops_mpi/optimization/basic.html
+++ b/_modules/pylops_mpi/optimization/basic.html
@@ -447,16 +447,21 @@ Source code for pylops_mpi.optimization.basic
from typing import Callable, Optional, Tuple, Union
from pylops.utils import NDArray
-from pylops_mpi import MPILinearOperator, DistributedArray, StackedDistributedArray
+from pylops_mpi import (
+ MPILinearOperator,
+ DistributedArray,
+ StackedDistributedArray,
+ MPIStackedLinearOperator
+)
from pylops_mpi.optimization.cls_basic import CG, CGLS
[docs]
def cg(
- Op: MPILinearOperator,
- y: Union[DistributedArray, StackedDistributedArray] ,
- x0: Optional[DistributedArray] = None,
+ Op: Union[MPILinearOperator, MPIStackedLinearOperator],
+ y: Union[DistributedArray, StackedDistributedArray],
+ x0: Union[DistributedArray, StackedDistributedArray],
niter: int = 10,
tol: float = 1e-4,
show: bool = False,
@@ -465,16 +470,16 @@ Source code for pylops_mpi.optimization.basic
) -> Tuple[Union[DistributedArray, StackedDistributedArray], int, NDArray]:
r"""Conjugate gradient
- Solve a square system of equations given an MPILinearOperator ``Op`` and
+ Solve a square system of equations given either an MPILinearOperator or an MPIStackedLinearOperator ``Op`` and
distributed data ``y`` using conjugate gradient iterations.
Parameters
----------
- Op : :obj:`pylops_mpi.MPILinearOperator`
+ Op : :obj:`pylops_mpi.MPILinearOperator` or :obj:`pylops_mpi.MPIStackedLinearOperator`
Operator to invert of size :math:`[N \times N]`
y : :obj:`pylops_mpi.DistributedArray` or :obj:`pylops_mpi.StackedDistributedArray`
DistributedArray of size (N,)
- x0 : :obj:`pylops_mpi.DistributedArray` or :obj:`pylops_mpi.StackedDistributedArray`, optional
+ x0 : :obj:`pylops_mpi.DistributedArray` or :obj:`pylops_mpi.StackedDistributedArray`
Initial guess
niter : :obj:`int`, optional
Number of iterations
@@ -517,9 +522,9 @@ Source code for pylops_mpi.optimization.basic
[docs]
def cgls(
- Op: MPILinearOperator,
+ Op: Union[MPILinearOperator, MPIStackedLinearOperator],
y: Union[DistributedArray, StackedDistributedArray],
- x0: Optional[Union[DistributedArray, StackedDistributedArray]] = None,
+ x0: Union[DistributedArray, StackedDistributedArray],
niter: int = 10,
damp: float = 0.0,
tol: float = 1e-4,
@@ -529,16 +534,16 @@ Source code for pylops_mpi.optimization.basic
) -> Tuple[DistributedArray, int, int, float, float, NDArray]:
r"""Conjugate gradient least squares
- Solve an overdetermined system of equations given a MPILinearOperator ``Op`` and
+ Solve an overdetermined system of equations given either an MPILinearOperator or an MPIStackedLinearOperator``Op`` and
distributed data ``y`` using conjugate gradient iterations.
Parameters
----------
- Op : :obj:`pylops_mpi.MPILinearOperator`
+ Op : :obj:`pylops_mpi.MPILinearOperator` or :obj:`pylops_mpi.MPIStackedLinearOperator`
MPI Linear Operator to invert of size :math:`[N \times M]`
y : :obj:`pylops_mpi.DistributedArray` or :obj:`pylops_mpi.StackedDistributedArray`
DistributedArray of size (N,)
- x0 : :obj:`pylops_mpi.DistributedArray` or :obj:`pylops_mpi.StackedDistributedArray`, optional
+ x0 : :obj:`pylops_mpi.DistributedArray` or :obj:`pylops_mpi.StackedDistributedArray`
Initial guess
niter : :obj:`int`, optional
Number of iterations
diff --git a/_modules/pylops_mpi/optimization/cls_basic.html b/_modules/pylops_mpi/optimization/cls_basic.html
index f91ef0e8..89aab475 100644
--- a/_modules/pylops_mpi/optimization/cls_basic.html
+++ b/_modules/pylops_mpi/optimization/cls_basic.html
@@ -459,12 +459,12 @@ Source code for pylops_mpi.optimization.cls_basic
class CG(Solver):
r"""Conjugate gradient
- Solve a square system of equations given an MPILinearOperator ``Op`` and
+ Solve a square system of equations given either an MPILinearOperator or an MPIStackedLinearOperator ``Op`` and
distributed data ``y`` using conjugate gradient iterations.
Parameters
----------
- Op : :obj:`pylops_mpi.MPILinearOperator`
+ Op : :obj:`pylops_mpi.MPILinearOperator` or :obj:`pylops_mpi.MPIStackedLinearOperator`
Operator to invert of size :math:`[N \times N]`
Notes
@@ -490,6 +490,8 @@ Source code for pylops_mpi.optimization.cls_basic
print(head1)
def _print_step(self, x: Union[DistributedArray, StackedDistributedArray]) -> None:
+ if isinstance(x, StackedDistributedArray):
+ x = x.distarrays[0]
strx = f"{x[0]:1.2e} " if np.iscomplexobj(x.local_array) else f"{x[0]:11.4e} "
msg = f"{self.iiter:6g} " + strx + f"{self.cost[self.iiter]:11.4e}"
print(msg)
@@ -497,7 +499,7 @@ Source code for pylops_mpi.optimization.cls_basic
def setup(
self,
y: Union[DistributedArray, StackedDistributedArray],
- x0: Optional[Union[DistributedArray, StackedDistributedArray]] = None,
+ x0: Union[DistributedArray, StackedDistributedArray],
niter: Optional[int] = None,
tol: float = 1e-4,
show: bool = False,
@@ -508,9 +510,8 @@ Source code for pylops_mpi.optimization.cls_basic
----------
y : :obj:`pylops_mpi.DistributedArray` or :obj:`pylops_mpi.StackedDistributedArray`
Data of size (N,)
- x0 : :obj:`pylops_mpi.DistributedArray` or :obj:`pylops_mpi.StackedDistributedArray`, optional
- Initial guess of size (N,). If ``None``, initialize
- internally as zero vector (will always default to :obj:`pylops_mpi.DistributedArray`)
+ x0 : :obj:`pylops_mpi.DistributedArray` or :obj:`pylops_mpi.StackedDistributedArray`
+ Initial guess of size (N,).
niter : :obj:`int`, optional
Number of iterations (default to ``None`` in case a user wants to manually step over the solver)
tol : :obj:`float`, optional
@@ -529,16 +530,8 @@ Source code for pylops_mpi.optimization.cls_basic
self.niter = niter
self.tol = tol
- if x0 is None:
- self.r = self.y.copy()
- x = DistributedArray(global_shape=self.Op.shape[1],
- partition=self.r.partition,
- local_shapes=self.r.local_shapes,
- dtype=y.dtype)
- x[:] = 0
- else:
- x = x0.copy()
- self.r = self.y - self.Op.matvec(x)
+ x = x0.copy()
+ self.r = self.y - self.Op.matvec(x)
self.rank = x.rank
self.c = self.r.copy()
self.kold = np.abs(self.r.dot(self.r.conj()))
@@ -549,7 +542,10 @@ Source code for pylops_mpi.optimization.cls_basic
self.iiter = 0
if show and self.rank == 0:
- self._print_setup(np.iscomplexobj(x.local_array))
+ if isinstance(x, StackedDistributedArray):
+ self._print_setup(np.iscomplexobj([x1.local_array for x1 in x.distarrays]))
+ else:
+ self._print_setup(np.iscomplexobj(x.local_array))
return x
def step(self, x: Union[DistributedArray, StackedDistributedArray],
@@ -652,21 +648,20 @@ Source code for pylops_mpi.optimization.cls_basic
def solve(
self,
y: Union[DistributedArray, StackedDistributedArray],
- x0: Optional[Union[DistributedArray, StackedDistributedArray]] = None,
+ x0: Union[DistributedArray, StackedDistributedArray],
niter: int = 10,
tol: float = 1e-4,
show: bool = False,
itershow: Tuple[int, int, int] = (10, 10, 10),
- ) -> Tuple[DistributedArray, int, NDArray]:
+ ) -> Tuple[Union[DistributedArray, StackedDistributedArray], int, NDArray]:
r"""Run entire solver
Parameters
----------
y : :obj:`pylops_mpi.DistributedArray` or :obj:`pylops_mpi.StackedDistributedArray`
Data of size (N,)
- x0 : :obj:`pylops_mpi.DistributedArray` or :obj:`pylops_mpi.StackedDistributedArray`, optional
- Initial guess of size (N,). If ``None``, initialize
- internally as zero vector (will always default to :obj:`pylops_mpi.DistributedArray`)
+ x0 : :obj:`pylops_mpi.DistributedArray` or :obj:`pylops_mpi.StackedDistributedArray`
+ Initial guess of size (N,).
niter : :obj:`int`, optional
Number of iterations
tol : :obj:`float`, optional
@@ -701,12 +696,12 @@ Source code for pylops_mpi.optimization.cls_basic
class CGLS(Solver):
r"""Conjugate gradient least squares
- Solve an overdetermined system of equations given a MPILinearOperator ``Op``
+ Solve an overdetermined system of equations given either an MPILinearOperator or an MPIStackedLinearOperator ``Op``
and distributed data ``y`` using conjugate gradient iterations.
Parameters
----------
- Op : :obj:`pylops_mpi.MPILinearOperator`
+ Op : :obj:`pylops_mpi.MPILinearOperator` or :obj:`pylops_mpi.MPIStackedLinearOperator`
Operator to invert of size :math:`[N \times M]`
Notes
@@ -739,6 +734,8 @@ Source code for pylops_mpi.optimization.cls_basic
print(head1)
def _print_step(self, x: Union[DistributedArray, StackedDistributedArray]) -> None:
+ if isinstance(x, StackedDistributedArray):
+ x = x.distarrays[0]
strx = f"{x[0]:1.2e} " if np.iscomplexobj(x.local_array) else f"{x[0]:11.4e} "
msg = (
f"{self.iiter:6g} "
@@ -749,21 +746,20 @@ Source code for pylops_mpi.optimization.cls_basic
def setup(self,
y: Union[DistributedArray, StackedDistributedArray],
- x0: Optional[DistributedArray] = None,
+ x0: Union[DistributedArray, StackedDistributedArray],
niter: Optional[int] = None,
damp: float = 0.0,
tol: float = 1e-4,
show: bool = False,
- ) -> DistributedArray:
+ ) -> Union[DistributedArray, StackedDistributedArray]:
r"""Setup solver
Parameters
----------
y : :obj:`pylops_mpi.DistributedArray` or :obj:`pylops_mpi.StackedDistributedArray`
Data of size :math:`[N \times 1]`
- x0 : :obj:`pylops_mpi.DistributedArray` or :obj:`pylops_mpi.StackedDistributedArray`, optional
- Initial guess of size (M,). If ``None``, Defaults to a zero vector
- (will always default to :obj:`pylops_mpi.DistributedArray`)
+ x0 : :obj:`pylops_mpi.DistributedArray` or :obj:`pylops_mpi.StackedDistributedArray`
+ Initial guess of size (M,).
niter : :obj:`int`, optional
Number of iterations (default to ``None`` in case a user wants to
manually step over the solver)
@@ -785,19 +781,10 @@ Source code for pylops_mpi.optimization.cls_basic
self.tol = tol
self.niter = niter
- # initialize solver
- if x0 is None:
- self.s = y.copy()
- r = self.Op.rmatvec(self.s)
- x = DistributedArray(global_shape=self.Op.shape[1], dtype=y.dtype,
- local_shapes=r.local_shapes,
- partition=r.partition)
- x[:] = 0
- else:
- x = x0.copy()
- self.s = self.y - self.Op.matvec(x)
- damped_x = damp * x
- r = self.Op.rmatvec(self.s) - damped_x
+ x = x0.copy()
+ self.s = self.y - self.Op.matvec(x)
+ damped_x = x * damp
+ r = self.Op.rmatvec(self.s) - damped_x
self.rank = x.rank
self.c = r.copy()
self.q = self.Op.matvec(self.c)
@@ -812,7 +799,10 @@ Source code for pylops_mpi.optimization.cls_basic
# print setup
if show and self.rank == 0:
- self._print_setup(np.iscomplexobj(x.local_array))
+ if isinstance(x, StackedDistributedArray):
+ self._print_setup(np.iscomplexobj([x1.local_array for x1 in x.distarrays]))
+ else:
+ self._print_setup(np.iscomplexobj(x.local_array))
return x
def step(self, x: Union[DistributedArray, StackedDistributedArray],
@@ -874,7 +864,7 @@ Source code for pylops_mpi.optimization.cls_basic
Returns
-------
- x : :obj:`pylops_mpi.DistributedArray`
+ x : :obj:`pylops_mpi.DistributedArray` or :obj:`pylops_mpi.StackedDistributedArray
Estimated model of size (M, ).
"""
@@ -918,7 +908,7 @@ Source code for pylops_mpi.optimization.cls_basic
def solve(self,
y: Union[DistributedArray, StackedDistributedArray],
- x0: Optional[Union[DistributedArray, StackedDistributedArray]] = None,
+ x0: Union[DistributedArray, StackedDistributedArray],
niter: int = 10,
damp: float = 0.0,
tol: float = 1e-4,
@@ -932,8 +922,7 @@ Source code for pylops_mpi.optimization.cls_basic
y : :obj:`pylops_mpi.DistributedArray` or :obj:`pylops_mpi.StackedDistributedArray`
Data of size (N, )
x0 : :obj:`pylops_mpi.DistributedArray` or :obj:`pylops_mpi.StackedDistributedArray`
- Initial guess of size (M, ). If ``None``, initialize internally as zero vector
- (will always default to :obj:`pylops_mpi.DistributedArray`)
+ Initial guess of size (M, ).
niter : :obj:`int`, optional
Number of iterations (default to ``None`` in case a user wants to
manually step over the solver)
diff --git a/_sources/gallery/plot_cgls.rst.txt b/_sources/gallery/plot_cgls.rst.txt
index bcff517a..816553fa 100644
--- a/_sources/gallery/plot_cgls.rst.txt
+++ b/_sources/gallery/plot_cgls.rst.txt
@@ -102,11 +102,15 @@ are then obtained in a :py:class:`pylops_mpi.DistributedArray`. To obtain the
overall inversion of the entire MPIBlockDiag, you can utilize the ``asarray()``
function of the DistributedArray as shown below.
-.. GENERATED FROM PYTHON SOURCE LINES 48-59
+.. GENERATED FROM PYTHON SOURCE LINES 48-63
.. code-block:: Python
- xinv, istop, niter, r1norm, r2norm, cost = pylops_mpi.cgls(BDiag, y, niter=15, tol=1e-10, show=True)
+
+ # Set initial guess `x0` to zeroes
+ x0 = pylops_mpi.DistributedArray(BDiag.shape[1], dtype=np.float128)
+ x0[:] = 0
+ xinv, istop, niter, r1norm, r2norm, cost = pylops_mpi.cgls(BDiag, y, x0=x0, niter=15, tol=1e-10, show=True)
xinv_array = xinv.asarray()
if rank == 0:
@@ -153,7 +157,7 @@ function of the DistributedArray as shown below.
14 9.9946e-01 3.9693e-03 3.9693e-03
15 1.0000e+00 2.0763e-10 2.0763e-10
- Iterations = 15 Total time (s) = 0.02
+ Iterations = 15 Total time (s) = 0.03
-----------------------------------------------------------------
CGLS Solution xinv=[1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
@@ -164,7 +168,7 @@ function of the DistributedArray as shown below.
.. rst-class:: sphx-glr-timing
- **Total running time of the script:** (0 minutes 0.217 seconds)
+ **Total running time of the script:** (0 minutes 0.213 seconds)
.. _sphx_glr_download_gallery_plot_cgls.py:
diff --git a/_sources/gallery/plot_derivative.rst.txt b/_sources/gallery/plot_derivative.rst.txt
index 93ec6bd3..9e4cf996 100644
--- a/_sources/gallery/plot_derivative.rst.txt
+++ b/_sources/gallery/plot_derivative.rst.txt
@@ -262,7 +262,7 @@ dimensions and concatenates them.
.. rst-class:: sphx-glr-timing
- **Total running time of the script:** (0 minutes 1.453 seconds)
+ **Total running time of the script:** (0 minutes 1.394 seconds)
.. _sphx_glr_download_gallery_plot_derivative.py:
diff --git a/_sources/gallery/plot_distributed_array.rst.txt b/_sources/gallery/plot_distributed_array.rst.txt
index 5ebc3c1d..bb9ed8c0 100644
--- a/_sources/gallery/plot_distributed_array.rst.txt
+++ b/_sources/gallery/plot_distributed_array.rst.txt
@@ -308,7 +308,7 @@ of the array and multiplies the corresponding elements together.
.. rst-class:: sphx-glr-timing
- **Total running time of the script:** (0 minutes 1.871 seconds)
+ **Total running time of the script:** (0 minutes 1.481 seconds)
.. _sphx_glr_download_gallery_plot_distributed_array.py:
diff --git a/_sources/gallery/plot_mpilinop.rst.txt b/_sources/gallery/plot_mpilinop.rst.txt
index 0269792d..e97d3133 100644
--- a/_sources/gallery/plot_mpilinop.rst.txt
+++ b/_sources/gallery/plot_mpilinop.rst.txt
@@ -214,7 +214,7 @@ to ensure that the operators align appropriately with their corresponding
.. rst-class:: sphx-glr-timing
- **Total running time of the script:** (0 minutes 0.415 seconds)
+ **Total running time of the script:** (0 minutes 0.335 seconds)
.. _sphx_glr_download_gallery_plot_mpilinop.py:
diff --git a/_sources/gallery/plot_stacked_array.rst.txt b/_sources/gallery/plot_stacked_array.rst.txt
index d06cfb0c..ccf84bf8 100644
--- a/_sources/gallery/plot_stacked_array.rst.txt
+++ b/_sources/gallery/plot_stacked_array.rst.txt
@@ -403,7 +403,7 @@ of distributed arrays
.. rst-class:: sphx-glr-timing
- **Total running time of the script:** (0 minutes 0.016 seconds)
+ **Total running time of the script:** (0 minutes 0.015 seconds)
.. _sphx_glr_download_gallery_plot_stacked_array.py:
diff --git a/_sources/gallery/plot_stacking.rst.txt b/_sources/gallery/plot_stacking.rst.txt
index 84b80086..976c6b29 100644
--- a/_sources/gallery/plot_stacking.rst.txt
+++ b/_sources/gallery/plot_stacking.rst.txt
@@ -279,7 +279,7 @@ corresponding vector :math:`x`.
.. rst-class:: sphx-glr-timing
- **Total running time of the script:** (0 minutes 0.524 seconds)
+ **Total running time of the script:** (0 minutes 0.426 seconds)
.. _sphx_glr_download_gallery_plot_stacking.py:
diff --git a/_sources/gallery/sg_execution_times.rst.txt b/_sources/gallery/sg_execution_times.rst.txt
index c13fd437..62eec68d 100644
--- a/_sources/gallery/sg_execution_times.rst.txt
+++ b/_sources/gallery/sg_execution_times.rst.txt
@@ -6,7 +6,7 @@
Computation times
=================
-**00:04.495** total execution time for 6 files **from gallery**:
+**00:03.864** total execution time for 6 files **from gallery**:
.. container::
@@ -33,20 +33,20 @@ Computation times
- Time
- Mem (MB)
* - :ref:`sphx_glr_gallery_plot_distributed_array.py` (``plot_distributed_array.py``)
- - 00:01.871
+ - 00:01.481
- 0.0
* - :ref:`sphx_glr_gallery_plot_derivative.py` (``plot_derivative.py``)
- - 00:01.453
+ - 00:01.394
- 0.0
* - :ref:`sphx_glr_gallery_plot_stacking.py` (``plot_stacking.py``)
- - 00:00.524
+ - 00:00.426
- 0.0
* - :ref:`sphx_glr_gallery_plot_mpilinop.py` (``plot_mpilinop.py``)
- - 00:00.415
+ - 00:00.335
- 0.0
* - :ref:`sphx_glr_gallery_plot_cgls.py` (``plot_cgls.py``)
- - 00:00.217
+ - 00:00.213
- 0.0
* - :ref:`sphx_glr_gallery_plot_stacked_array.py` (``plot_stacked_array.py``)
- - 00:00.016
+ - 00:00.015
- 0.0
diff --git a/_sources/sg_execution_times.rst.txt b/_sources/sg_execution_times.rst.txt
index 7f09455b..80b4b88b 100644
--- a/_sources/sg_execution_times.rst.txt
+++ b/_sources/sg_execution_times.rst.txt
@@ -6,7 +6,7 @@
Computation times
=================
-**02:26.632** total execution time for 8 files **from all galleries**:
+**02:25.558** total execution time for 8 files **from all galleries**:
.. container::
@@ -33,26 +33,26 @@ Computation times
- Time
- Mem (MB)
* - :ref:`sphx_glr_tutorials_poststack.py` (``../../tutorials/poststack.py``)
- - 02:18.828
+ - 02:18.540
- 0.0
* - :ref:`sphx_glr_tutorials_lsm.py` (``../../tutorials/lsm.py``)
- - 00:03.308
+ - 00:03.154
- 0.0
* - :ref:`sphx_glr_gallery_plot_distributed_array.py` (``../../examples/plot_distributed_array.py``)
- - 00:01.871
+ - 00:01.481
- 0.0
* - :ref:`sphx_glr_gallery_plot_derivative.py` (``../../examples/plot_derivative.py``)
- - 00:01.453
+ - 00:01.394
- 0.0
* - :ref:`sphx_glr_gallery_plot_stacking.py` (``../../examples/plot_stacking.py``)
- - 00:00.524
+ - 00:00.426
- 0.0
* - :ref:`sphx_glr_gallery_plot_mpilinop.py` (``../../examples/plot_mpilinop.py``)
- - 00:00.415
+ - 00:00.335
- 0.0
* - :ref:`sphx_glr_gallery_plot_cgls.py` (``../../examples/plot_cgls.py``)
- - 00:00.217
+ - 00:00.213
- 0.0
* - :ref:`sphx_glr_gallery_plot_stacked_array.py` (``../../examples/plot_stacked_array.py``)
- - 00:00.016
+ - 00:00.015
- 0.0
diff --git a/_sources/tutorials/lsm.rst.txt b/_sources/tutorials/lsm.rst.txt
index cad4ed21..965365db 100644
--- a/_sources/tutorials/lsm.rst.txt
+++ b/_sources/tutorials/lsm.rst.txt
@@ -246,13 +246,16 @@ product with the broadcasted reflectivity at every location on the subsurface.
We calculate the inverse using the :py:func:`pylops_mpi.optimization.basic.cgls`
solver.
-.. GENERATED FROM PYTHON SOURCE LINES 165-172
+.. GENERATED FROM PYTHON SOURCE LINES 165-175
.. code-block:: Python
# Inverse
- minv_dist = pylops_mpi.cgls(VStack, d_dist, niter=100, show=True)[0]
+ # Initializing x0 to zeroes
+ x0 = pylops_mpi.DistributedArray(VStack.shape[1], partition=pylops_mpi.Partition.BROADCAST)
+ x0[:] = 0
+ minv_dist = pylops_mpi.cgls(VStack, d_dist, x0=x0, niter=100, show=True)[0]
minv = minv_dist.asarray().reshape((nx, nz))
d_inv_dist = VStack @ minv_dist
d_inv = d_inv_dist.asarray().reshape(nstot, nr, nt)
@@ -301,14 +304,14 @@ solver.
99 -1.2546e-02 2.8528e+00 2.8528e+00
100 -1.2389e-02 2.8342e+00 2.8342e+00
- Iterations = 100 Total time (s) = 1.16
+ Iterations = 100 Total time (s) = 1.19
-----------------------------------------------------------------
-.. GENERATED FROM PYTHON SOURCE LINES 173-209
+.. GENERATED FROM PYTHON SOURCE LINES 176-212
.. code-block:: Python
@@ -382,7 +385,7 @@ solver.
.. rst-class:: sphx-glr-timing
- **Total running time of the script:** (0 minutes 3.308 seconds)
+ **Total running time of the script:** (0 minutes 3.154 seconds)
.. _sphx_glr_download_tutorials_lsm.py:
diff --git a/_sources/tutorials/poststack.rst.txt b/_sources/tutorials/poststack.rst.txt
index 829d2e83..ef24482a 100644
--- a/_sources/tutorials/poststack.rst.txt
+++ b/_sources/tutorials/poststack.rst.txt
@@ -284,7 +284,7 @@ normal equations, and :math:`\mathbf{d}^{Norm}` is the data of the normal equati
99 6.1544e-01 6.5026e-01 6.5026e-01
100 6.1561e-01 6.4212e-01 6.4212e-01
- Iterations = 100 Total time (s) = 29.06
+ Iterations = 100 Total time (s) = 29.61
-----------------------------------------------------------------
@@ -349,7 +349,7 @@ normal equations, and :math:`\mathbf{d}^{Norm}` is the data of the normal equati
99 6.3033e-01 1.9903e+02
100 6.3026e-01 1.9777e+02
- Iterations = 100 Total time (s) = 44.87
+ Iterations = 100 Total time (s) = 44.84
-------------------------------------------------------
@@ -481,7 +481,7 @@ Finally, we display the modeling and inversion results
.. rst-class:: sphx-glr-timing
- **Total running time of the script:** (2 minutes 18.828 seconds)
+ **Total running time of the script:** (2 minutes 18.540 seconds)
.. _sphx_glr_download_tutorials_poststack.py:
diff --git a/_sources/tutorials/sg_execution_times.rst.txt b/_sources/tutorials/sg_execution_times.rst.txt
index 6b126c09..ea953856 100644
--- a/_sources/tutorials/sg_execution_times.rst.txt
+++ b/_sources/tutorials/sg_execution_times.rst.txt
@@ -6,7 +6,7 @@
Computation times
=================
-**02:22.137** total execution time for 2 files **from tutorials**:
+**02:21.695** total execution time for 2 files **from tutorials**:
.. container::
@@ -33,8 +33,8 @@ Computation times
- Time
- Mem (MB)
* - :ref:`sphx_glr_tutorials_poststack.py` (``poststack.py``)
- - 02:18.828
+ - 02:18.540
- 0.0
* - :ref:`sphx_glr_tutorials_lsm.py` (``lsm.py``)
- - 00:03.308
+ - 00:03.154
- 0.0
diff --git a/api/generated/pylops_mpi.StackedDistributedArray.html b/api/generated/pylops_mpi.StackedDistributedArray.html
index 7ea2dbb4..51198e5e 100644
--- a/api/generated/pylops_mpi.StackedDistributedArray.html
+++ b/api/generated/pylops_mpi.StackedDistributedArray.html
@@ -492,7 +492,7 @@
pylops_mpi.StackedDistributedArray#
-
-class pylops_mpi.StackedDistributedArray(distarrays)[source]#
+class pylops_mpi.StackedDistributedArray(distarrays, base_comm=<mpi4py.MPI.Intracomm object>)[source]#
Stacked DistributedArrays
Stack DistributedArray objects and power them with basic mathematical operations.
This class allows one to work with a series of distributed arrays to avoid having to create
@@ -502,13 +502,16 @@
pylops_mpi.StackedDistributedArray
- distarrays
list
List of pylops_mpi.DistributedArray
objects.
+- base_comm
mpi4py.MPI.Comm
, optional Base MPI Communicator.
+Defaults to mpi4py.MPI.COMM_WORLD
.
+
Methods
-__init__
(distarrays)
+__init__
(distarrays[, base_comm])
add
(stacked_array)
@@ -524,13 +527,13 @@ pylops_mpi.StackedDistributedArraydot
(stacked_array)
-
+Dot Product of Stacked Distributed Arrays
iadd
(stacked_array)
Stacked Distributed In-Place Addition of arrays
multiply
(stacked_array)
-
+Stacked Distributed Multiplication of arrays
norm
([ord])
numpy.linalg.norm method on stacked Distributed arrays
diff --git a/api/generated/pylops_mpi.optimization.basic.cg.html b/api/generated/pylops_mpi.optimization.basic.cg.html
index 9f85c773..5c3e0707 100644
--- a/api/generated/pylops_mpi.optimization.basic.cg.html
+++ b/api/generated/pylops_mpi.optimization.basic.cg.html
@@ -494,18 +494,18 @@
pylops_mpi.optimization.basic.cg#
-
-pylops_mpi.optimization.basic.cg(Op, y, x0=None, niter=10, tol=0.0001, show=False, itershow=(10, 10, 10), callback=None)[source]#
+pylops_mpi.optimization.basic.cg(Op, y, x0, niter=10, tol=0.0001, show=False, itershow=(10, 10, 10), callback=None)[source]#
Conjugate gradient
-Solve a square system of equations given an MPILinearOperator Op
and
+
Solve a square system of equations given either an MPILinearOperator or an MPIStackedLinearOperator Op
and
distributed data y
using conjugate gradient iterations.
- Parameters:
-- Op
pylops_mpi.MPILinearOperator
Operator to invert of size \([N \times N]\)
+- Op
pylops_mpi.MPILinearOperator
or pylops_mpi.MPIStackedLinearOperator
Operator to invert of size \([N \times N]\)
- y
pylops_mpi.DistributedArray
or pylops_mpi.StackedDistributedArray
DistributedArray of size (N,)
-- x0
pylops_mpi.DistributedArray
or pylops_mpi.StackedDistributedArray
, optional Initial guess
+- x0
pylops_mpi.DistributedArray
or pylops_mpi.StackedDistributedArray
Initial guess
- niter
int
, optional Number of iterations
diff --git a/api/generated/pylops_mpi.optimization.basic.cgls.html b/api/generated/pylops_mpi.optimization.basic.cgls.html
index 428cd63a..81234c54 100644
--- a/api/generated/pylops_mpi.optimization.basic.cgls.html
+++ b/api/generated/pylops_mpi.optimization.basic.cgls.html
@@ -494,18 +494,18 @@
pylops_mpi.optimization.basic.cgls#
-
-pylops_mpi.optimization.basic.cgls(Op, y, x0=None, niter=10, damp=0.0, tol=0.0001, show=False, itershow=(10, 10, 10), callback=None)[source]#
+pylops_mpi.optimization.basic.cgls(Op, y, x0, niter=10, damp=0.0, tol=0.0001, show=False, itershow=(10, 10, 10), callback=None)[source]#
Conjugate gradient least squares
-Solve an overdetermined system of equations given a MPILinearOperator Op
and
+
Solve an overdetermined system of equations given either an MPILinearOperator or an MPIStackedLinearOperator``Op`` and
distributed data y
using conjugate gradient iterations.
- Parameters:
-- Op
pylops_mpi.MPILinearOperator
MPI Linear Operator to invert of size \([N \times M]\)
+- Op
pylops_mpi.MPILinearOperator
or pylops_mpi.MPIStackedLinearOperator
MPI Linear Operator to invert of size \([N \times M]\)
- y
pylops_mpi.DistributedArray
or pylops_mpi.StackedDistributedArray
DistributedArray of size (N,)
-- x0
pylops_mpi.DistributedArray
or pylops_mpi.StackedDistributedArray
, optional Initial guess
+- x0
pylops_mpi.DistributedArray
or pylops_mpi.StackedDistributedArray
Initial guess
- niter
int
, optional Number of iterations
diff --git a/api/generated/pylops_mpi.optimization.cls_basic.CG.html b/api/generated/pylops_mpi.optimization.cls_basic.CG.html
index 6e93cd4c..7ee23963 100644
--- a/api/generated/pylops_mpi.optimization.cls_basic.CG.html
+++ b/api/generated/pylops_mpi.optimization.cls_basic.CG.html
@@ -496,12 +496,12 @@ pylops_mpi.optimization.cls_basic.CG
class pylops_mpi.optimization.cls_basic.CG(Op, callbacks=None)[source]#
Conjugate gradient
-Solve a square system of equations given an MPILinearOperator Op
and
+
Solve a square system of equations given either an MPILinearOperator or an MPIStackedLinearOperator Op
and
distributed data y
using conjugate gradient iterations.
- Parameters:
-- Op
pylops_mpi.MPILinearOperator
Operator to invert of size \([N \times N]\)
+- Op
pylops_mpi.MPILinearOperator
or pylops_mpi.MPIStackedLinearOperator
Operator to invert of size \([N \times N]\)
@@ -524,10 +524,10 @@ pylops_mpi.optimization.cls_basic.CGrun
(x[, niter, show, itershow])
Run solver
-setup
(y[, x0, niter, tol, show])
+setup
(y, x0[, niter, tol, show])
Setup solver
-solve
(y[, x0, niter, tol, show, itershow])
+solve
(y, x0[, niter, tol, show, itershow])
Run entire solver
step
(x[, show])
diff --git a/api/generated/pylops_mpi.optimization.cls_basic.CGLS.html b/api/generated/pylops_mpi.optimization.cls_basic.CGLS.html
index a0f7609c..d0cdbd69 100644
--- a/api/generated/pylops_mpi.optimization.cls_basic.CGLS.html
+++ b/api/generated/pylops_mpi.optimization.cls_basic.CGLS.html
@@ -496,12 +496,12 @@ pylops_mpi.optimization.cls_basic.CGLS
class pylops_mpi.optimization.cls_basic.CGLS(Op, callbacks=None)[source]#
Conjugate gradient least squares
-Solve an overdetermined system of equations given a MPILinearOperator Op
+
Solve an overdetermined system of equations given either an MPILinearOperator or an MPIStackedLinearOperator Op
and distributed data y
using conjugate gradient iterations.
- Parameters:
-- Op
pylops_mpi.MPILinearOperator
Operator to invert of size \([N \times M]\)
+- Op
pylops_mpi.MPILinearOperator
or pylops_mpi.MPIStackedLinearOperator
Operator to invert of size \([N \times M]\)
@@ -527,10 +527,10 @@ pylops_mpi.optimization.cls_basic.CGLSrun
(x[, niter, show, itershow])
Run solver
-setup
(y[, x0, niter, damp, tol, show])
+setup
(y, x0[, niter, damp, tol, show])
Setup solver
-solve
(y[, x0, niter, damp, tol, show, itershow])
+solve
(y, x0[, niter, damp, tol, show, itershow])
Run entire solver
step
(x[, show])
diff --git a/api/index.html b/api/index.html
index a9334f86..435c287f 100644
--- a/api/index.html
+++ b/api/index.html
@@ -499,7 +499,7 @@ DistributedArrayDistributedArray
(global_shape[, base_comm, ...])
Distributed Numpy Arrays
-StackedDistributedArray
(distarrays)
+StackedDistributedArray
(distarrays[, base_comm])
Stacked DistributedArrays
@@ -581,10 +581,10 @@ Basic#<
-cg
(Op, y[, x0, niter, tol, show, itershow, ...])
+cg
(Op, y, x0[, niter, tol, show, itershow, ...])
Conjugate gradient
-cgls
(Op, y[, x0, niter, damp, tol, show, ...])
+cgls
(Op, y, x0[, niter, damp, tol, show, ...])
Conjugate gradient least squares
diff --git a/gallery/plot_cgls.html b/gallery/plot_cgls.html
index d2aec4b1..b48054fe 100644
--- a/gallery/plot_cgls.html
+++ b/gallery/plot_cgls.html
@@ -510,7 +510,10 @@
are then obtained in a pylops_mpi.DistributedArray
. To obtain the
overall inversion of the entire MPIBlockDiag, you can utilize the asarray()
function of the DistributedArray as shown below.
-xinv, istop, niter, r1norm, r2norm, cost = pylops_mpi.cgls(BDiag, y, niter=15, tol=1e-10, show=True)
+# Set initial guess `x0` to zeroes
+x0 = pylops_mpi.DistributedArray(BDiag.shape[1], dtype=np.float128)
+x0[:] = 0
+xinv, istop, niter, r1norm, r2norm, cost = pylops_mpi.cgls(BDiag, y, x0=x0, niter=15, tol=1e-10, show=True)
xinv_array = xinv.asarray()
if rank == 0:
@@ -546,13 +549,13 @@
14 9.9946e-01 3.9693e-03 3.9693e-03
15 1.0000e+00 2.0763e-10 2.0763e-10
-Iterations = 15 Total time (s) = 0.02
+Iterations = 15 Total time (s) = 0.03
-----------------------------------------------------------------
CGLS Solution xinv=[1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]
-Total running time of the script: (0 minutes 0.217 seconds)
+Total running time of the script: (0 minutes 0.213 seconds)
-Total running time of the script: (0 minutes 1.453 seconds)
+Total running time of the script: (0 minutes 1.394 seconds)
-Total running time of the script: (0 minutes 1.871 seconds)
+Total running time of the script: (0 minutes 1.481 seconds)
-Total running time of the script: (0 minutes 0.415 seconds)
+Total running time of the script: (0 minutes 0.335 seconds)