Skip to content

Commit

Permalink
More GH Workflow changes; swapping to msvc to see if OMP works; speci…
Browse files Browse the repository at this point in the history
…alizing test suite to isolate the seg fault
  • Loading branch information
peekxc committed Dec 4, 2023
1 parent c48bc0c commit a6c2352
Show file tree
Hide file tree
Showing 16 changed files with 1,014 additions and 745 deletions.
25 changes: 1 addition & 24 deletions .github/workflows/build_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
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
coverage report -m
14 changes: 5 additions & 9 deletions .github/workflows/build_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
coverage report -m
17 changes: 10 additions & 7 deletions .github/workflows/build_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
# - 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
Expand All @@ -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
2 changes: 1 addition & 1 deletion docs/guide/slq_guide.html
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ <h1 class="title">SLQ Trace guide</h1>
</header>

<p><code>primate</code> 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:</p>
<div id="alg-slq" class="pseudocode-container" data-pseudocode-index="1" data-line-number="true" data-alg-title="Algorithm" data-indent-size="1.1em" data-no-end="true" data-line-number-punc=":" data-comment-delimiter="//">
<div id="alg-slq" class="pseudocode-container" data-alg-title="Algorithm" data-pseudocode-index="1" data-no-end="true" data-line-number="true" data-comment-delimiter="//" data-indent-size="1.1em" data-line-number-punc=":">
<div class="pseudocode">
\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 &lt; Do something with the node/weight pairs $(\theta_i, \tau_i^2)$ &gt; \EndFor \EndFunction \end{algorithmic} \end{algorithm}
</div>
Expand Down
50 changes: 45 additions & 5 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,16 @@
<div id="quarto-sidebar-glass" data-bs-toggle="collapse" data-bs-target="#quarto-sidebar,#quarto-sidebar-glass"></div>
<!-- margin-sidebar -->
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">

<nav id="TOC" role="doc-toc" class="toc-active">
<h2 id="toc-title">On this page</h2>

<ul>
<li><a href="#primate" id="toc-primate" class="nav-link active" data-scroll-target="#primate">primate</a>
<ul class="collapse">
<li><a href="#compilation-development" id="toc-compilation-development" class="nav-link" data-scroll-target="#compilation-development">Compilation &amp; Development</a></li>
</ul></li>
</ul>
</nav>
</div>
<!-- main -->
<main class="content" id="quarto-document-content">
Expand All @@ -330,26 +339,57 @@ <h1 class="title">Package overview</h1>

</header>

<p><code>primate</code>, short for <strong>Pr</strong>obabalistic <strong>I</strong>mplicit <strong>Ma</strong>trix <strong>T</strong>race <strong>E</strong>stimator, is Python package that performs randomized matrix trace estimation of <a href="https://en.wikipedia.org/wiki/Analytic_function_of_a_matrix">matrix functions</a>—that is, matrices parameterized by functions:</p>
<section id="primate" class="level1">
<h1>primate</h1>
<p><code>primate</code>, short for <strong>Pr</strong>obabalistic <strong>I</strong>mplicit <strong>Ma</strong>trix <strong>T</strong>race <strong>E</strong>stimator, is Python package that performs randomized matrix trace estimation of <a href="https://en.wikipedia.org/wiki/Analytic_function_of_a_matrix">matrix functions</a>; that is, matrices parameterized by functions:</p>
<p><span class="math display"> \mathrm{tr}(f(A)) \triangleq \mathrm{tr}(U f(\Lambda) U^{\intercal}), \quad \quad f : [a,b] \to \mathbb{R}</span></p>
<p>Trace estimates are obtained in a Monte-Carlo fashion via the <em>stochastic Lanczos method</em> (SLQ)<a href="#fn1" class="footnote-ref" id="fnref1" role="doc-noteref"><sup>1</sup></a>. This method is useful for sparse or highly structured matrices with efficiently computable <a href="https://en.wikipedia.org/wiki/Quadratic_form#Associated_symmetric_matrix">quadratic forms</a>.</p>
<p>Notable features of <code>primate</code> include:</p>
<ul>
<li>A highly-parametrizable trace estimator (see SLQ)</li>
<li>A highly-parametrizable trace estimator (SLQ)</li>
<li>Various distribution / engine choices for random vector generation (the stochastic part!)</li>
<li>Orthogonalization routines, such as the <em>Lanczos</em>, <em>Golub Kahan</em>, and <em>Gram Schmidt</em> methods</li>
<li>Support for <em>arbitrary</em> matrix functions, i.e.&nbsp;<code>Callable</code>’s (Python) and <code>invocable</code>’s<a href="#fn2" class="footnote-ref" id="fnref2" role="doc-noteref"><sup>2</sup></a> (C++)</li>
<li>Support for <em>arbitrary</em> <code>LinearOperator</code>’s, e.g.&nbsp;those in <a href="https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.linalg.LinearOperator.html#scipy-sparse-linalg-linearoperator">SciPy</a> or <a href="https://pylops.readthedocs.io/en/stable/index.html">Pylops</a></li>
</ul>
<p>Much of <code>primate</code>’s computational code was directly ported from the (excellent) <a href="https://github.com/ameli/imate"><code>imate</code> package</a>—for a comparison of the two, see <a href="./imate_compare.html">here</a>.</p>
<!-- Moreover, `primate`'s C++ API uses a generic template interface written with [C++20 Concepts](https://en.cppreference.com/w/cpp/language/constraints)---thus, any `LinearOperator` [fitting the constraints](https://github.com/peekxc/primate/blob/d09459c017fcba68a11eaeb56296ef0c97d6c053/include/_linear_operator/linear_operator.h#L21-L49). -->
<!-- To use,, the library is is [header-only](https://en.wikipedia.org/wiki/Header-only), so integration is a si. -->
<p>Much of <code>primate</code>’s computational code was directly ported from the (excellent) <a href="https://github.com/ameli/imate"><code>imate</code> package</a>—for a comparison of the two, see <a href="https://peekxc.github.io/primate/imate_compare.html">here</a>.</p>
<section id="compilation-development" class="level2">
<h2 class="anchored" data-anchor-id="compilation-development">Compilation &amp; Development</h2>
<p><code>primate</code> relies on BLAS libraries</p>
<blockquote class="blockquote">
<p>pipx run cibuildwheel –platform linux</p>
</blockquote>
<!--
`primate`, short for **Pr**obabalistic **I**mplicit **Ma**trix **T**race **E**stimator, is Python package that performs randomized matrix trace estimation of [matrix functions](https://en.wikipedia.org/wiki/Analytic_function_of_a_matrix)---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](https://en.wikipedia.org/wiki/Quadratic_form#Associated_symmetric_matrix).
Notable features of `primate` include:
- A highly-parametrizable trace estimator (see 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`'s[^2] (C++)
- Support for _arbitrary_ `LinearOperator`'s, e.g. those in [SciPy](https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.linalg.LinearOperator.html#scipy-sparse-linalg-linearoperator) or [Pylops](https://pylops.readthedocs.io/en/stable/index.html)
Much of `primate`'s computational code was directly ported from the (excellent) [`imate` package](https://github.com/ameli/imate)---for a comparison of the two, see [here](imate_compare.qmd).
[^1]: Ubaru, S., Chen, J., & Saad, Y. (2017). Fast estimation of tr(f(A)) via stochastic Lanczos quadrature. SIAM Journal on Matrix Analysis and Applications, 38(4), 1075-1099.
[^2]: This includes [std::function](https://en.cppreference.com/w/cpp/utility/functional/function)'s, C-style function pointers, [functors](https://stackoverflow.com/questions/356950/what-are-c-functors-and-their-uses), and [lambda expressions](https://en.cppreference.com/w/cpp/language/lambda). -->


</section>
</section>


<div id="quarto-appendix" class="default"><aside id="footnotes" class="footnotes footnotes-end-of-document" role="doc-endnotes"><h2 class="anchored quarto-appendix-heading">Footnotes</h2>

<ol>
<li id="fn1"><p>Ubaru, S., Chen, J., &amp; Saad, Y. (2017). Fast estimation of tr(f(A)) via stochastic Lanczos quadrature. SIAM Journal on Matrix Analysis and Applications, 38(4), 1075-1099.<a href="#fnref1" class="footnote-back" role="doc-backlink">↩︎</a></p></li>
<li id="fn1"><p>Ubaru, S., Chen, J., &amp; Saad, Y. (2017). Fast estimation of tr(f(A)) via stochastic Lanczos quadrature.<a href="#fnref1" class="footnote-back" role="doc-backlink">↩︎</a></p></li>
<li id="fn2"><p>This includes <a href="https://en.cppreference.com/w/cpp/utility/functional/function">std::function</a>’s, C-style function pointers, <a href="https://stackoverflow.com/questions/356950/what-are-c-functors-and-their-uses">functors</a>, and <a href="https://en.cppreference.com/w/cpp/language/lambda">lambda expressions</a>.<a href="#fnref2" class="footnote-back" role="doc-backlink">↩︎</a></p></li>
</ol>
</aside></div></main> <!-- /main -->
Expand Down
20 changes: 10 additions & 10 deletions docs/integration/python_integration.html

Large diffs are not rendered by default.

Loading

0 comments on commit a6c2352

Please sign in to comment.