From a6c2352c72dde843222f10f011e4e70e2bc40f98 Mon Sep 17 00:00:00 2001 From: peekxc Date: Mon, 4 Dec 2023 11:55:01 -0500 Subject: [PATCH] More GH Workflow changes; swapping to msvc to see if OMP works; specializing test suite to isolate the seg fault --- .github/workflows/build_linux.yml | 25 +- .github/workflows/build_macos.yml | 14 +- .github/workflows/build_windows.yml | 17 +- docs/guide/slq_guide.html | 2 +- docs/index.html | 50 +- docs/integration/python_integration.html | 20 +- docs/reference/diagonalize.lanczos.html | 113 +++- docs/reference/get_include.html | 113 +++- docs/reference/primate.trace.sl_trace.html | 133 +++- docs/reference/random.normal.html | 113 +++- docs/reference/random.rademacher.html | 113 +++- docs/reference/trace.html | 131 +++- docs/search.json | 711 ++++++--------------- docs/src/index.qmd | 6 +- tests/test_lanczos.py | 94 +-- tests/test_slq.py | 104 +++ 16 files changed, 1014 insertions(+), 745 deletions(-) create mode 100644 tests/test_slq.py diff --git a/.github/workflows/build_linux.yml b/.github/workflows/build_linux.yml index 37087b0..5625702 100644 --- a/.github/workflows/build_linux.yml +++ b/.github/workflows/build_linux.yml @@ -44,27 +44,4 @@ jobs: - name: Test with pytest run: | python -m pytest tests/ --cov=primate --benchmark-skip - coverage run --source=./primate -m pytest tests/ --benchmark-skip - coverage json -o tests/test_results.json - coverage report -m - - if: matrix.os == 'ubuntu-latest' - run: | - COV_RESULT=$(cat tests/test_results.json) - COV_PERCENT=$(echo $COV_RESULT | python3 -c 'import json,sys;obj=json.load(sys.stdin);print(obj["totals"]["percent_covered_display"])') - echo "COV_PERCENT=$COV_PERCENT" >> $GITHUB_ENV - - if: matrix.os == 'ubuntu-latest' - name: Create coverage badge - uses: schneegans/dynamic-badges-action@v1.6.0 - with: - auth: ${{ secrets.GIST_SECRET }} - gistID: ef42349965f40edf4232737026690c5f - filename: coverage_info.json - label: coverage - message: ${{ env.COV_PERCENT }}% - valColorRange: ${{ env.COV_PERCENT }} - maxColorRange: 100 - minColorRange: 0 - namedLogo: Pytest - - name: Send coverage report - run: | - coveralls --service=github \ No newline at end of file + coverage report -m \ No newline at end of file diff --git a/.github/workflows/build_macos.yml b/.github/workflows/build_macos.yml index 1316b71..80ce2d2 100644 --- a/.github/workflows/build_macos.yml +++ b/.github/workflows/build_macos.yml @@ -33,7 +33,10 @@ jobs: source ~/.bash_profile - name: Verify Clang version run: | - clang --version + /usr/local/opt/llvm/bin/clang --version + env: + CC: /usr/local/opt/llvm/bin/clang + CXX: /usr/local/opt/llvm/bin/clang - name: Install OpenBLAS run: | brew install openblas @@ -57,11 +60,4 @@ jobs: - name: Test with pytest run: | python -m pytest tests/ --cov=primate --benchmark-skip - coverage run --source=./primate -m pytest tests/ --benchmark-skip - coverage json -o tests/test_results.json - coverage report -m - - if: matrix.os == 'ubuntu-latest' - run: | - COV_RESULT=$(cat tests/test_results.json) - COV_PERCENT=$(echo $COV_RESULT | python3 -c 'import json,sys;obj=json.load(sys.stdin);print(obj["totals"]["percent_covered_display"])') - echo "COV_PERCENT=$COV_PERCENT" >> $GITHUB_ENV \ No newline at end of file + coverage report -m \ No newline at end of file diff --git a/.github/workflows/build_windows.yml b/.github/workflows/build_windows.yml index c3e931b..3be7375 100644 --- a/.github/workflows/build_windows.yml +++ b/.github/workflows/build_windows.yml @@ -30,11 +30,13 @@ jobs: # with: # version: latest # platform: x64 - - name: Install Clang with OpenMP support using Chocolatey - run: | - choco install -y llvm --params "clang;compiler=clang" --version 13.0.0 - $env:PATH = "C:\Program Files\LLVM\bin;$env:PATH" - clang --version + - name: Setup MSVC + uses: ilammy/msvc-dev-cmd@v1.4.1 + # - name: Install Clang with OpenMP support using Chocolatey + # run: | + # choco install -y llvm --params "clang;compiler=clang" --version 13.0.0 + # $env:PATH = "C:\Program Files\LLVM\bin;$env:PATH" + # clang --version # - name: Install OpenBLAS using Chocolatey # run: | # choco install -y openblas @@ -51,9 +53,10 @@ jobs: - name: Install package run: | pip install --verbose . + env: + CC: msvc + CXX: msvc - name: Test with pytest run: | python -m pytest tests/ --cov=primate --benchmark-skip - coverage run --source=./primate -m pytest tests/ --benchmark-skip - coverage json -o tests/test_results.json coverage report -m \ No newline at end of file diff --git a/docs/guide/slq_guide.html b/docs/guide/slq_guide.html index 1aaf9c4..5657658 100644 --- a/docs/guide/slq_guide.html +++ b/docs/guide/slq_guide.html @@ -375,7 +375,7 @@

SLQ Trace guide

primate offers an extensible implementation of the stochastic Lanczos method (SLQ). There are many algorithms named the “stochastic Lanczos quadrature” in the literature; though each is typically related, they often have distinct goals. Pseudocode for a generic form of SLQ is given below:

-
+
\begin{algorithm} \caption{Stochastic Lanczos Quadrature} \begin{algorithmic} \Input Symmetric operator ($A \in \mathbb{R}^{n \times n}$) \Require Number of queries ($n_v$), Degree of quadrature ($k$) \Function{SLQ}{$A$, $n_v$, $k$} \State $\Gamma \gets 0$ \For{$j = 1, 2, \dots, n_v$} \State $v_i \sim \mathcal{D}$ where $\mathcal{D}$ satisfies $\mathbb{E}(v v^\top) = I$ \State $T^{(j)}(\alpha, \beta)$ $\gets$ $\mathrm{Lanczos}(A,v_j,k+1)$ \State $[\Theta, Y] \gets \mathrm{eigh\_tridiag}(T^{(j)}(\alpha, \beta))$ \State $\tau_i \gets \langle e_1, y_i \rangle$ \State < Do something with the node/weight pairs $(\theta_i, \tau_i^2)$ > \EndFor \EndFunction \end{algorithmic} \end{algorithm}
diff --git a/docs/index.html b/docs/index.html index 8745127..7124be0 100644 --- a/docs/index.html +++ b/docs/index.html @@ -307,7 +307,16 @@
@@ -330,26 +339,57 @@

Package overview

-

primate, short for Probabalistic Implicit Matrix Trace Estimator, is Python package that performs randomized matrix trace estimation of matrix functions—that is, matrices parameterized by functions:

+
+

primate

+

primate, short for Probabalistic Implicit Matrix Trace Estimator, is Python package that performs randomized matrix trace estimation of matrix functions; that is, matrices parameterized by functions:

\mathrm{tr}(f(A)) \triangleq \mathrm{tr}(U f(\Lambda) U^{\intercal}), \quad \quad f : [a,b] \to \mathbb{R}

Trace estimates are obtained in a Monte-Carlo fashion via the stochastic Lanczos method (SLQ)1. This method is useful for sparse or highly structured matrices with efficiently computable quadratic forms.

Notable features of primate include:

    -
  • A highly-parametrizable trace estimator (see SLQ)
  • +
  • A highly-parametrizable trace estimator (SLQ)
  • Various distribution / engine choices for random vector generation (the stochastic part!)
  • Orthogonalization routines, such as the Lanczos, Golub Kahan, and Gram Schmidt methods
  • Support for arbitrary matrix functions, i.e. Callable’s (Python) and invocable’s2 (C++)
  • Support for arbitrary LinearOperator’s, e.g. those in SciPy or Pylops
-

Much of primate’s computational code was directly ported from the (excellent) imate package—for a comparison of the two, see here.

+ + +

Much of primate’s computational code was directly ported from the (excellent) imate package—for a comparison of the two, see here.

+
+

Compilation & Development

+

primate relies on BLAS libraries

+
+

pipx run cibuildwheel –platform linux

+
+ +
+
diff --git a/docs/integration/python_integration.html b/docs/integration/python_integration.html index 4e822a0..e89232a 100644 --- a/docs/integration/python_integration.html +++ b/docs/integration/python_integration.html @@ -368,25 +368,25 @@

Python Integration

To demonstrate the SLQ method in Python, we start with a simple symmetric matrix A \in \mathbb{R}^{n \times n}.

-
+
import numpy as np
 from primate.random import symmetric
 A = symmetric(150, psd = True)

This generates a random positive semi-definite matrix with eigenvalues in the interval [0, 1].

-
+
from primate.trace import sl_trace
 estimates = sl_trace(A, plot=True)
-
+
-
+
tr_est = np.mean(estimates)
 print(f"Error: {abs(tr_est - A.trace()):.5}")
 print(f"Samples std. deviation: {estimates.std(ddof=1)}")
 print(f"Estimator standard error: {estimates.std(ddof=1)/np.sqrt(len(estimates))}")
-
Error: 0.43677
-Samples std. deviation: 5.014724254608154
-Estimator standard error: 0.35459455262140804
+
Error: 62.002
+Samples std. deviation: 25.753618240356445
+Estimator standard error: 1.8210558097845604
-
+
# from scipy.sparse import csr_array, csc_array
 # from scipy.sparse.linalg import LinearOperator, aslinearoperator
 # tr_true = np.sum(A.diagonal())
diff --git a/docs/reference/diagonalize.lanczos.html b/docs/reference/diagonalize.lanczos.html
index 46511eb..bae92ef 100644
--- a/docs/reference/diagonalize.lanczos.html
+++ b/docs/reference/diagonalize.lanczos.html
@@ -64,6 +64,25 @@
     "search-label": "Search"
   }
 }
+
+
+
 
 
 
@@ -134,18 +153,58 @@
  Installation
   
- + - + - +