PyHydroGeophysX.solvers package

Submodules

PyHydroGeophysX.solvers.linear_solvers module

Linear solvers for geophysical inversion.

class PyHydroGeophysX.solvers.linear_solvers.CGLSSolver(max_iterations=200, tolerance=1e-08, use_gpu=False, parallel=False, n_jobs=-1, damping=0.0, verbose=False)[source]

Bases: LinearSolver

CGLS (Conjugate Gradient Least Squares) solver.

class PyHydroGeophysX.solvers.linear_solvers.IterativeRefinement(max_iterations=5, tolerance=1e-10, use_double_precision=True)[source]

Bases: object

Iterative refinement to improve accuracy of a solution to a linear system.

refine(A, b, x0, solver_func)[source]

Perform iterative refinement.

Parameters:
  • A – System matrix

  • b – Right-hand side vector

  • x0 – Initial solution

  • solver_func – Function that solves A*x = b

Returns:

Improved solution

class PyHydroGeophysX.solvers.linear_solvers.LSQRSolver(max_iterations=200, tolerance=1e-08, use_gpu=False, parallel=False, n_jobs=-1, damping=0.0, verbose=False)[source]

Bases: LinearSolver

LSQR solver for least squares problems.

class PyHydroGeophysX.solvers.linear_solvers.LinearSolver(method='cgls', max_iterations=200, tolerance=1e-08, use_gpu=False, parallel=False, n_jobs=-1, damping=0.0, verbose=False)[source]

Bases: object

Base class for linear system solvers.

solve(A, b, x0=None)[source]

Solve linear system Ax = b.

Parameters:
  • A – System matrix

  • b – Right-hand side vector

  • x0 – Initial guess (None for zeros)

Returns:

Solution vector

class PyHydroGeophysX.solvers.linear_solvers.RRLSQRSolver(max_iterations=200, tolerance=1e-08, use_gpu=False, parallel=False, n_jobs=-1, damping=0.1, verbose=False)[source]

Bases: LinearSolver

Regularized LSQR solver.

class PyHydroGeophysX.solvers.linear_solvers.RRLSSolver(max_iterations=200, tolerance=1e-08, use_gpu=False, parallel=False, n_jobs=-1, damping=0.0, verbose=False)[source]

Bases: LinearSolver

Range-Restricted Least Squares solver.

class PyHydroGeophysX.solvers.linear_solvers.TikhonvRegularization(regularization_matrix=None, alpha=1.0, regularization_type='identity')[source]

Bases: object

Tikhonov regularization for ill-posed problems.

apply(A, b, solver=None)[source]

Apply Tikhonov regularization to the linear system.

Parameters:
  • A – System matrix

  • b – Right-hand side vector

  • solver – Solver to use (None for direct solver)

Returns:

Regularized solution

create_regularization_matrix(n)[source]

Create regularization matrix based on the selected type.

Parameters:

n – Size of model vector

Returns:

Regularization matrix

PyHydroGeophysX.solvers.linear_solvers.direct_solver(A, b, method='lu', **kwargs)[source]

Solve a linear system using direct methods.

Parameters:
  • A – System matrix

  • b – Right-hand side vector

  • method – Direct solver method (‘lu’, ‘qr’, ‘svd’, ‘cholesky’)

  • **kwargs – Additional parameters for specific methods

Returns:

Solution vector

PyHydroGeophysX.solvers.linear_solvers.generalized_solver(A, b, method='cgls', x=None, maxiter=200, tol=1e-08, verbose=False, damp=0.0, use_gpu=False, parallel=False, n_jobs=-1)[source]

Generalized solver for Ax = b with optional GPU acceleration and parallelism.

Parameters:

Aarray_like or sparse matrix

The system matrix (Jacobian or forward operator).

barray_like

Right-hand side vector.

methodstr, optional

Solver method: ‘lsqr’, ‘rrlsqr’, ‘cgls’, or ‘rrls’. Default is ‘cgls’.

xarray_like, optional

Initial guess for the solution. If None, zeros are used.

maxiterint, optional

Maximum number of iterations.

tolfloat, optional

Convergence tolerance.

verbosebool, optional

Print progress information every 10 iterations.

dampfloat, optional

Damping factor (Tikhonov regularization).

use_gpubool, optional

Use GPU acceleration with CuPy (if available).

parallelbool, optional

Use parallel CPU computations.

n_jobsint, optional

Number of parallel jobs (if parallel is True).

Returns:

xarray_like

The computed solution vector.

PyHydroGeophysX.solvers.linear_solvers.get_optimal_solver(A, b, estimate_condition=True, time_limit=None, memory_limit=None)[source]

Automatically select the optimal solver for a given linear system.

Parameters:
  • A – System matrix

  • b – Right-hand side vector

  • estimate_condition – Whether to estimate condition number

  • time_limit – Maximum allowed solution time (seconds)

  • memory_limit – Maximum allowed memory usage (bytes)

Returns:

Tuple of (solver_object, solver_info)

PyHydroGeophysX.solvers.solver module

PyHydroGeophysX.solvers.solver.generalized_solver(A, b, method='cgls', x=None, maxiter=2000, tol=1e-08, verbose=False, damp=0.0, use_gpu=False, parallel=False, n_jobs=-1)[source]

Generalized solver for Ax = b with optional GPU acceleration and parallelism.

Parameters:
  • A (array_like or sparse matrix) – The system matrix (Jacobian or forward operator).

  • b (array_like) – Right-hand side vector.

  • method (str, optional) – Solver method: ‘lsqr’, ‘rrlsqr’, ‘cgls’, or ‘rrls’. Default is ‘cgls’.

  • x (array_like, optional) – Initial guess for the solution. If None, zeros are used.

  • maxiter (int, optional) – Maximum number of iterations.

  • tol (float, optional) – Convergence tolerance.

  • verbose (bool, optional) – Print progress information every 10 iterations.

  • damp (float, optional) – Damping factor (Tikhonov regularization).

  • use_gpu (bool, optional) – Use GPU acceleration with CuPy (if available).

  • parallel (bool, optional) – Use parallel CPU computations.

  • n_jobs (int, optional) – Number of parallel jobs (if parallel is True).

Returns:

x – The computed solution vector.

Return type:

array_like

Module contents