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.
pip install pyamgVerified import paths — ran on the pinned version, not inferred.
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.
Update code to use `scipy.sparse.csr_array` (or `bsr_array`) instead of `csr_matrix` where relevant, and replace `A * x` with `A @ x` for matrix-vector products.
Ensure your Python environment is at least 3.8 and SciPy is version 1.8.0 or newer. For current PyAMG (v5.3.0), Python >=3.9 is required.
Instantiate the `smoothed_aggregation_solver` (or other solver) once, then reuse the `ml.solve()` method. For example: `ml = smoothed_aggregation_solver(A); x1 = ml.solve(b1); x2 = ml.solve(b2)`.
Reinstall PyAMG in a clean virtual environment using `pip install pyamg`. Ensure `numpy` and `scipy` are installed first. If issues persist, try installing from source (refer to PyAMG's GitHub for build instructions). For Anaconda users, `conda install -c anaconda pyamg` is an alternative.
Carefully review the configuration file (e.g., `.cfg` file for SU2) for any malformed lines, duplicate options, or missing parameters required by the PyAMG integration. Ensure all options are correctly formatted (e.g., `OPTION = VALUE`). Refer to the specific integration's documentation for required parameters.
For `smoothed_aggregation_solver`, try reducing the `max_levels` parameter to limit the number of coarse grids, or increasing `max_coarse` to allow coarser grids to be larger, reducing the total memory footprint. Using the CSR matrix format is also recommended for efficiency.