Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
769926b
feat: added memory_usage and preallocate to Solver
mrava87 May 17, 2025
b0ea5d4
feat: added preallocate to basic solvers
mrava87 May 17, 2025
26101ed
feat: added preallocate to leastsquares solvers
mrava87 May 17, 2025
e0f793e
feat: added preallocate to sparsity solvers
mrava87 May 17, 2025
a8d5f3f
bug: fix wrong dtype in seismicinterpolation
mrava87 May 17, 2025
3b86136
bug: removed unused xcgls in IRLS
mrava87 May 17, 2025
feb05a2
fix: correct internal behaviour of ISTA and FISTA with SOp
mrava87 May 25, 2025
29f5847
feat: restore old behaviour for preallocate=False
mrava87 Jun 7, 2025
5ec9c78
bug: small fixes
mrava87 Jun 7, 2025
a35540b
bug: fix handling of xupdate in ista/fista for preallocate case
mrava87 Jun 7, 2025
dd404e6
minor: restore some behaviors for preallocate=False
mrava87 Jun 8, 2025
f98cc31
feat: added preallocate to IRLS
mrava87 Jun 9, 2025
c75da67
feat: added preallocate to SplitBregman
mrava87 Jun 9, 2025
03dbcfc
CI: Python 3.10 in CI (until scikit-fmm is fixed)
mrava87 Jun 15, 2025
7e8924f
bug: add preallocate to solve of SplitBregman
mrava87 Jun 15, 2025
9deb83f
fix: ensure dtype is preserved in ista/fista
mrava87 Jul 4, 2025
d1b461e
Merge branch 'dev' into feat-inplacesolvers
mrava87 Jul 4, 2025
205f5b3
doc: added preallocate example to solvers tutorial
mrava87 Jul 5, 2025
74682e3
Merge branch 'feat-inplacesolvers' of https://github.com/mrava87/pylo…
mrava87 Jul 5, 2025
aba0184
minor: remove sg_execution_times file
mrava87 Jul 5, 2025
5c751f7
minor: changed to v2.6.0 message for preallocate
mrava87 Jul 5, 2025
da20d35
minor: add JAX warning to preallocate docstring message
mrava87 Jul 5, 2025
ace5f2e
bug: fix initialization of self.r and self.rw in IRLS
mrava87 Jul 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
271 changes: 0 additions & 271 deletions docs/source/sg_execution_times.rst

This file was deleted.

53 changes: 53 additions & 0 deletions pylops/optimization/basesolver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
__all__ = ["Solver"]

import functools
import logging
import time
from abc import ABCMeta, abstractmethod
from typing import TYPE_CHECKING, Any
Expand All @@ -11,6 +12,8 @@
if TYPE_CHECKING:
from pylops.linearoperator import LinearOperator

_units = {"B": 1, "KB": 1024, "MB": 1024**2, "GB": 1024**3}


class Solver(metaclass=ABCMeta):
r"""Solver
Expand All @@ -19,6 +22,8 @@ class Solver(metaclass=ABCMeta):
This class comprises of the following mandatory methods:

- ``__init__``: initialization method to which the operator `Op` must be passed
- ``memory_usage``: a method to compute upfront the memory used by each
step of the solver
- ``setup``: a method that is invoked to setup the solver, basically it will create
anything required prior to applying a step of the solver
- ``step``: a method applying a single step of the solver
Expand Down Expand Up @@ -121,11 +126,55 @@ def wrapper(*args, **kwargs):
),
)

def _setpreallocate(self, preallocate: bool) -> None:
# Check if the solver can work in preallocate mode
# (basically all the time except when JAX arrays are
# used) and force it to be False otherwise.
self.preallocate = preallocate if not self.isjax else False

if preallocate and self.isjax:
logging.warning(
"Preallocation is not supported for JAX arrays. "
"Setting preallocate to False."
)

@abstractmethod
def memory_usage(
self,
show: bool = False,
unit: str = "B",
) -> float:
"""Compute memory usage of the solver

This method computes an estimate of the memory required by the solver given
the shape of the operator. This is useful to assess upfront if the solver
will run out of memory.

Note, that the memory usage of the operator itself is not taken into account
in this estimate.

Parameters
----------
show : :obj:`bool`, optional
Display memory usage
unit: :obj:`str`, optional
Unit used to display memory usage (
``B``, ``KB``, ``MB`` or ``GB``)

Returns
-------
memuse :obj:`float`
Memory usage in bytes

"""
pass

@abstractmethod
def setup(
self,
y: NDArray,
*args,
preallocate: bool = False,
show: bool = False,
**kwargs,
) -> None:
Expand All @@ -138,6 +187,10 @@ def setup(
----------
y : :obj:`np.ndarray`
Data of size :math:`[N \times 1]`
preallocate : :obj:`bool`, optional
.. versionadded:: 2.6.0

Pre-allocate all variables used by the solver.
show : :obj:`bool`, optional
Display setup log

Expand Down
Loading