A Python library for solving linear systems using iterative methods, analyzing matrix properties, benchmarking solvers, and visualizing performance. The library is designed to solve large sparse linear systems efficiently, provided in sparse .mtx format.
- Solve linear systems using:
- Jacobi method
- Gauss-Seidel method
- Gradient Descent
- Conjugate Gradient
- Analyze structural matrix properties:
- Symmetry
- Positive-definiteness
- Diagonal dominance
- Condition number
- Benchmark solvers (execution time, number of iterations, convergence behavior)
- Generate comparison plots (execution time, relative error, iterations)
This project uses Python 3 and open-source libraries only.
git clone https://github.com/FerrarioChristian/iterative-linear-solver.git
cd iterative-linear-solverpython3 -m venv .venv
source .venv/bin/activate # On Windows use `venv\Scripts\activate`# Install the dependencies
pip install -e .You can run the full benchmark from the command line:
linear-solver-demo [-h] [-it MAX_ITER] [-sc] [--spy] [-t TOLERANCES ...]
-h, --help: Show this help message and exit
-it, --max-iter: Set maximum iterations (default 20000)
-sc, --skip-check: Skip matrix property check
-o, --output-dir: Specify output directory for the generated plots (Optional *)
--spy: Generate a spy plot of the matrices
-t, --tolerances: Set a list of tolerances (default [1e-4, 1e-6, 1e-8, 1e-10])
- If
-ois omitted the plots are only shown, if-ois specified without value the results will be saved in restults.csv and plots will be generated in theresults/plotsdirectory, if a path is specified the results will be stored in the given directory
You can use any solver directly:
from linear_solver.solvers import JacobiSolver
solver = JacobiSolver(A, b, tolerance=1e-6, max_iterations=10000)
solution = solver.solve()You can benchmark any solver using the benchmark_solver function:
from linear_solver.benchmark import benchmark_solver
from linear_solver.solvers import JacobiSolver
result = benchmark_solver(JacobiSolver, A, b, tol=1e-8, max_iter=5000)
print(result.execution_time, result.iterations)You can analyze matrix properties using the MatrixAnalyzer class:
from linear_solver.matrix_analysis.structure import analyze_matrix
properties = analyze_matrix(A)
print(properties.is_symmetric, properties.is_positive_definite, properties.is_diagonally_dominant)linear-iterative-solver
├── demo
│ ├── cli.py # Parameters options
│ ├── constants.py # Solver settings (matrices, tolerances, etc.)
│ ├── logger.py # Funtions to print the status of the comutation
│ └── main.py # CLI interface
├── linear_solver
│ ├── analysis
│ │ ├── benchmark.py # Benchmarking utilities
│ │ ├── compare_plot.py # Plotting utilities
│ │ └── plot.py
│ ├── convergence
│ │ └── criteria.py # Stopping conditions
│ ├── matrix_analysis
│ │ └── structure.py # Matrix property analysis
│ └── solvers
│ ├── base_solver.py
│ ├── conjugate_gradient.py
│ ├── gauss_seidel.py
│ ├── gradient.py
│ ├── jacobi.py
│ └── lower_triangular.py
├── matrices
│ ├── spa1.mtx
│ ├── spa2.mtx
│ ├── vem1.mtx
│ └── vem2.mtx
└── pyproject.toml