Skip to content

Commit

Permalink
Update cibuildwheel vars
Browse files Browse the repository at this point in the history
  • Loading branch information
peekxc committed Dec 5, 2023
1 parent a8dfe45 commit 832dc60
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 33 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

Matrix function approximations are obtained via the _Lanczos_[^1] and _stochastic Lanczos quadrature_ (SLQ)[^2] methods. These methods are most useful for sparse or highly structured operators with fast [quadratic forms](https://en.wikipedia.org/wiki/Quadratic_form#Associated_symmetric_matrix).
Matrix function approximations are obtained via the _Lanczos_[^1] and _stochastic Lanczos quadrature_[^2] methods, which are well-suited for sparse or highly structured operators with fast [quadratic forms](https://en.wikipedia.org/wiki/Quadratic_form#Associated_symmetric_matrix).

Notable features of `primate` include:

Expand All @@ -15,7 +15,7 @@ Notable features of `primate` include:
<!-- 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. -->

`primate` was partially inspired by the (excellent) [`imate` package](https://github.com/ameli/imate)---for a comparison of the two, see [here](https://peekxc.github.io/primate/imate_compare.html).
`primate` was partially inspired by the [`imate` package](https://github.com/ameli/imate)---for a comparison of the two, see [here](https://peekxc.github.io/primate/imate_compare.html).

[^1]: Musco, Cameron, Christopher Musco, and Aaron Sidford. "Stability of the Lanczos method for matrix function approximation." Proceedings of the Twenty-Ninth Annual ACM-SIAM Symposium on Discrete Algorithms. Society for Industrial and Applied Mathematics, 2018.
[^2]: Ubaru, S., Chen, J., & Saad, Y. (2017). Fast estimation of tr(f(A)) via stochastic Lanczos quadrature.
Expand Down
40 changes: 11 additions & 29 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -307,16 +307,7 @@
<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 @@ -339,28 +330,20 @@ <h1 class="title">Package overview</h1>

</header>

<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><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 a Python package that provides estimators of quantities derived from <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"> f(A) \triangleq U f(\Lambda) U^{\intercal}, \quad \quad f : [a,b] \to \mathbb{R}</span></p>
<p>Matrix function approximations are obtained via the <em>Lanczos</em><a href="#fn1" class="footnote-ref" id="fnref1" role="doc-noteref"><sup>1</sup></a> and <em>stochastic Lanczos quadrature</em><a href="#fn2" class="footnote-ref" id="fnref2" role="doc-noteref"><sup>2</sup></a> methods, which are well-suited for sparse or highly structured operators with fast <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 (SLQ)</li>
<li>Efficient methods for trace, quadrature, and matrix function approximation</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> matrix functions, i.e.&nbsp;<code>Callable</code>’s (Python) and <code>invocable</code>’s<a href="#fn3" class="footnote-ref" id="fnref3" role="doc-noteref"><sup>3</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>
<li>Matrix-free interface to the <em>Lanczos</em>, <em>Golub-Welsch</em>, and <em>Gram Schmidt</em> methods</li>
</ul>
<!-- 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>
<p><code>primate</code> was partially inspired by the <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>
<!--
`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:
Expand All @@ -382,15 +365,14 @@ <h2 class="anchored" data-anchor-id="compilation-development">Compilation &amp;
[^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.<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>
<li id="fn1"><p>Musco, Cameron, Christopher Musco, and Aaron Sidford. “Stability of the Lanczos method for matrix function approximation.” Proceedings of the Twenty-Ninth Annual ACM-SIAM Symposium on Discrete Algorithms. Society for Industrial and Applied Mathematics, 2018.<a href="#fnref1" class="footnote-back" role="doc-backlink">↩︎</a></p></li>
<li id="fn2"><p>Ubaru, S., Chen, J., &amp; Saad, Y. (2017). Fast estimation of tr(f(A)) via stochastic Lanczos quadrature.<a href="#fnref2" class="footnote-back" role="doc-backlink">↩︎</a></p></li>
<li id="fn3"><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="#fnref3" class="footnote-back" role="doc-backlink">↩︎</a></p></li>
</ol>
</aside></div></main> <!-- /main -->
<script id="quarto-html-after-body" type="application/javascript">
Expand Down
2 changes: 1 addition & 1 deletion docs/search.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
"href": "index.html",
"title": "Package overview",
"section": "",
"text": "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:\n \\mathrm{tr}(f(A)) \\triangleq \\mathrm{tr}(U f(\\Lambda) U^{\\intercal}), \\quad \\quad f : [a,b] \\to \\mathbb{R}\nTrace 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.\nNotable features of primate include:\n\nA highly-parametrizable trace estimator (SLQ)\nVarious distribution / engine choices for random vector generation (the stochastic part!)\nOrthogonalization routines, such as the Lanczos, Golub Kahan, and Gram Schmidt methods\nSupport for arbitrary matrix functions, i.e. Callable’s (Python) and invocable’s2 (C++)\nSupport for arbitrary LinearOperator’s, e.g. those in SciPy or Pylops\n\n\n\nMuch of primate’s computational code was directly ported from the (excellent) imate package—for a comparison of the two, see here.\n\n\nprimate relies on BLAS libraries\n\npipx run cibuildwheel –platform linux",
"text": "primate, short for Probabalistic Implicit Matrix Trace Estimator, is a Python package that provides estimators of quantities derived from matrix functions; that is, matrices parameterized by functions:\n f(A) \\triangleq U f(\\Lambda) U^{\\intercal}, \\quad \\quad f : [a,b] \\to \\mathbb{R}\nMatrix function approximations are obtained via the Lanczos1 and stochastic Lanczos quadrature2 methods, which are well-suited for sparse or highly structured operators with fast quadratic forms.\nNotable features of primate include:\n\nEfficient methods for trace, quadrature, and matrix function approximation\nVarious distribution / engine choices for random vector generation (the stochastic part!)\nSupport for arbitrary matrix functions, i.e. Callable’s (Python) and invocable’s3 (C++)\nSupport for arbitrary LinearOperator’s, e.g. those in SciPy or Pylops\nMatrix-free interface to the Lanczos, Golub-Welsch, and Gram Schmidt methods\n\n\n\nprimate was partially inspired by the imate package—for a comparison of the two, see here.\n\n\n\n\n\nFootnotes\n\n\nMusco, Cameron, Christopher Musco, and Aaron Sidford. “Stability of the Lanczos method for matrix function approximation.” Proceedings of the Twenty-Ninth Annual ACM-SIAM Symposium on Discrete Algorithms. Society for Industrial and Applied Mathematics, 2018.↩︎\nUbaru, S., Chen, J., & Saad, Y. (2017). Fast estimation of tr(f(A)) via stochastic Lanczos quadrature.↩︎\nThis includes std::function’s, C-style function pointers, functors, and lambda expressions.↩︎",
"crumbs": [
"Overview"
]
Expand Down
10 changes: 9 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,12 @@ include = [
]

[tool.meson-python.args]
setup = ['--default-library=static']
setup = ['--default-library=static']

[tool.cibuildwheel.macos]
before-build = "brew install libomp llvm openblas"
environment = { CXX = "/usr/local/opt/llvm/bin/clang" }

[tool.cibuildwheel.windows]
before-build = "choco install rtools -y --no-progress --force --version=4.0.0.20220206"
environment = { PATH = "C:\\rtools40\\ucrt64\\bin;$PATH" }
40 changes: 40 additions & 0 deletions tools/build_wheels.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

set -e
set -x

# OpenMP is not present on macOS by default
if [[ $(uname) == "Darwin" ]]; then
# Make sure to use a libomp version binary compatible with the oldest
# supported version of the macos SDK as libomp will be vendored into the wheels for macos.

if [[ "$CIBW_BUILD" == *-macosx_arm64 ]]; then
# SciPy requires 12.0 on arm to prevent kernel panics: https://github.com/scipy/scipy/issues/14688
export MACOSX_DEPLOYMENT_TARGET=12.0
OPENMP_URL="https://anaconda.org/conda-forge/llvm-openmp/11.1.0/download/osx-arm64/llvm-openmp-11.1.0-hf3c4609_1.tar.bz2"
else
export MACOSX_DEPLOYMENT_TARGET=10.9
OPENMP_URL="https://anaconda.org/conda-forge/llvm-openmp/11.1.0/download/osx-64/llvm-openmp-11.1.0-hda6cdc1_1.tar.bz2"
fi

sudo conda create -n build $OPENMP_URL
PREFIX="$CONDA_HOME/envs/build"

export CC=/usr/bin/clang
export CXX=/usr/bin/clang++
export CPPFLAGS="$CPPFLAGS -Xpreprocessor -fopenmp"
export CFLAGS="$CFLAGS -I$PREFIX/include"
export CXXFLAGS="$CXXFLAGS -I$PREFIX/include"
export LDFLAGS="$LDFLAGS -Wl,-rpath,$PREFIX/lib -L$PREFIX/lib -lomp"

if [[ $(uname -m) == "arm64" && "$CIBW_BUILD" == "cp38-macosx_arm64" ]]; then
# Enables native building and testing for macosx arm on Python 3.8. For details see:
# https://cibuildwheel.readthedocs.io/en/stable/faq/#macos-building-cpython-38-wheels-on-arm64
curl -o /tmp/Python38.pkg https://www.python.org/ftp/python/3.8.10/python-3.8.10-macos11.pkg
sudo installer -pkg /tmp/Python38.pkg -target /
sh "/Applications/Python 3.8/Install Certificates.command"
fi
fi

python -m pip install cibuildwheel
python -m cibuildwheel --output-dir wheelhouse

0 comments on commit 832dc60

Please sign in to comment.