{"library":"pyamg","title":"PyAMG: Algebraic Multigrid Solvers in Python","description":"PyAMG is a Python library providing implementations of Algebraic Multigrid (AMG) solvers and supporting tools for approximating solutions to large, sparse linear systems of algebraic equations (Ax=b). It is actively maintained, with the current version being 5.3.0, and receives regular updates to support newer Python and SciPy versions and introduce new features.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install pyamg"],"cli":null},"imports":["import pyamg","from pyamg import smoothed_aggregation_solver","from pyamg import gallery"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import numpy as np\nfrom scipy.sparse import csr_matrix\nfrom pyamg import gallery\nfrom pyamg import smoothed_aggregation_solver\n\n# 1. Create a sample sparse matrix (e.g., 2D Poisson problem)\nA = gallery.poisson((100, 100), format='csr')\n\n# 2. Create a right-hand side vector\nb = np.random.rand(A.shape[0])\n\n# 3. Construct the Algebraic Multigrid solver\n# max_coarse controls the size of the coarsest grid\nml = smoothed_aggregation_solver(A, max_coarse=10)\n\n# 4. Solve the linear system Ax = b\nx = ml.solve(b, tol=1e-10)\n\nprint(f\"Matrix shape: {A.shape}\")\nprint(f\"Number of nonzeros: {A.nnz}\")\nprint(f\"Solution vector norm: {np.linalg.norm(x)}\")\nprint(f\"Residual norm: {np.linalg.norm(b - A @ x)}\")","lang":"python","description":"This quickstart demonstrates how to set up a 2D Poisson problem using PyAMG's gallery, construct a `smoothed_aggregation_solver`, and solve the resulting sparse linear system. It highlights the typical workflow for using PyAMG as a standalone solver.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}