trnsparse 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. trnsparse-0.1.1/.github/workflows/ci.yml +20 -0
  2. trnsparse-0.1.1/.github/workflows/publish.yml +56 -0
  3. trnsparse-0.1.1/.gitignore +19 -0
  4. trnsparse-0.1.1/CHANGELOG.md +29 -0
  5. trnsparse-0.1.1/CLAUDE.md +58 -0
  6. trnsparse-0.1.1/CODE_OF_CONDUCT.md +25 -0
  7. trnsparse-0.1.1/CONTRIBUTING.md +69 -0
  8. trnsparse-0.1.1/LICENSE +201 -0
  9. trnsparse-0.1.1/PKG-INFO +85 -0
  10. trnsparse-0.1.1/README.md +58 -0
  11. trnsparse-0.1.1/docs/api.md +33 -0
  12. trnsparse-0.1.1/docs/architecture.md +37 -0
  13. trnsparse-0.1.1/docs/aws_setup.md +79 -0
  14. trnsparse-0.1.1/docs/benchmarks.md +24 -0
  15. trnsparse-0.1.1/docs/index.md +34 -0
  16. trnsparse-0.1.1/docs/installation.md +21 -0
  17. trnsparse-0.1.1/docs/quickstart.md +48 -0
  18. trnsparse-0.1.1/examples/sparse_fock.py +78 -0
  19. trnsparse-0.1.1/infra/terraform/README.md +58 -0
  20. trnsparse-0.1.1/infra/terraform/main.tf +150 -0
  21. trnsparse-0.1.1/mkdocs.yml +34 -0
  22. trnsparse-0.1.1/pyproject.toml +45 -0
  23. trnsparse-0.1.1/scripts/bench_to_md.py +129 -0
  24. trnsparse-0.1.1/scripts/run_benchmarks.sh +159 -0
  25. trnsparse-0.1.1/scripts/run_neuron_tests.sh +140 -0
  26. trnsparse-0.1.1/setup.cfg +4 -0
  27. trnsparse-0.1.1/tests/conftest.py +5 -0
  28. trnsparse-0.1.1/tests/test_formats.py +68 -0
  29. trnsparse-0.1.1/tests/test_ops.py +109 -0
  30. trnsparse-0.1.1/tests/test_screening.py +46 -0
  31. trnsparse-0.1.1/trnsparse/__init__.py +22 -0
  32. trnsparse-0.1.1/trnsparse/formats.py +167 -0
  33. trnsparse-0.1.1/trnsparse/nki/__init__.py +3 -0
  34. trnsparse-0.1.1/trnsparse/nki/dispatch.py +41 -0
  35. trnsparse-0.1.1/trnsparse/ops.py +137 -0
  36. trnsparse-0.1.1/trnsparse/screening.py +90 -0
  37. trnsparse-0.1.1/trnsparse.egg-info/PKG-INFO +85 -0
  38. trnsparse-0.1.1/trnsparse.egg-info/SOURCES.txt +39 -0
  39. trnsparse-0.1.1/trnsparse.egg-info/dependency_links.txt +1 -0
  40. trnsparse-0.1.1/trnsparse.egg-info/requires.txt +11 -0
  41. trnsparse-0.1.1/trnsparse.egg-info/top_level.txt +1 -0
@@ -0,0 +1,20 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ matrix:
13
+ python-version: ["3.10", "3.11", "3.12"]
14
+ steps:
15
+ - uses: actions/checkout@v4
16
+ - uses: actions/setup-python@v5
17
+ with:
18
+ python-version: ${{ matrix.python-version }}
19
+ - run: pip install -e ".[dev]"
20
+ - run: pytest tests/ -v -x --tb=short -m "not neuron"
@@ -0,0 +1,56 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ build:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v4
12
+ - uses: actions/setup-python@v5
13
+ with:
14
+ python-version: "3.12"
15
+ - run: pip install build
16
+ - run: python -m build
17
+ - uses: actions/upload-artifact@v4
18
+ with:
19
+ name: dist
20
+ path: dist/
21
+
22
+ publish-pypi:
23
+ needs: build
24
+ runs-on: ubuntu-latest
25
+ # Only publish stable releases (v1.2.3), not pre-releases (v1.2.3-rc1)
26
+ if: ${{ !contains(github.event.release.tag_name, '-') }}
27
+ environment:
28
+ name: pypi
29
+ url: https://pypi.org/project/trnsparse/
30
+ permissions:
31
+ id-token: write
32
+ steps:
33
+ - uses: actions/download-artifact@v4
34
+ with:
35
+ name: dist
36
+ path: dist/
37
+ - uses: pypa/gh-action-pypi-publish@release/v1
38
+
39
+ publish-testpypi:
40
+ needs: build
41
+ runs-on: ubuntu-latest
42
+ # Only publish pre-releases to TestPyPI
43
+ if: ${{ contains(github.event.release.tag_name, '-') }}
44
+ environment:
45
+ name: testpypi
46
+ url: https://test.pypi.org/project/trnsparse/
47
+ permissions:
48
+ id-token: write
49
+ steps:
50
+ - uses: actions/download-artifact@v4
51
+ with:
52
+ name: dist
53
+ path: dist/
54
+ - uses: pypa/gh-action-pypi-publish@release/v1
55
+ with:
56
+ repository-url: https://test.pypi.org/legacy/
@@ -0,0 +1,19 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *$py.class
4
+ *.egg-info/
5
+ dist/
6
+ build/
7
+ .eggs/
8
+ *.egg
9
+ .pytest_cache/
10
+ .tox/
11
+ .venv/
12
+ venv/
13
+ *.so
14
+ .idea/
15
+ .vscode/
16
+ *.swp
17
+ *.swo
18
+ *~
19
+ files.zip
@@ -0,0 +1,29 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.1.1] — 2026-04-12
9
+
10
+ ### Added
11
+
12
+ - mkdocs site with `index`, `installation`, `quickstart`, `api`, `architecture`, `aws_setup`
13
+ - `infra/terraform/` for on-hardware CI instance provisioning
14
+ - `scripts/run_neuron_tests.sh` and benchmark helpers
15
+ - GitHub Actions `ci.yml` for CPU-only pytest matrix
16
+ - `Issues` URL in pyproject.toml
17
+
18
+ ### Changed
19
+
20
+ - Bumped `neuronxcc` floor from `>=2.15` to `>=2.24` to unify with the
21
+ rest of the trnsci suite. `torch-neuronx` floor bumped to `>=2.9`.
22
+
23
+ ## [0.1.0] — 2026-04-12
24
+
25
+ ### Added
26
+
27
+ - Initial scaffold: CSRMatrix / COOMatrix, SpMV / SpMM, Schwarz screening
28
+ - NKI dispatch with gather-matmul-scatter kernel stub
29
+ - `examples/sparse_fock.py` — screened Fock build demo
@@ -0,0 +1,58 @@
1
+ # trnsparse
2
+
3
+ Sparse matrix operations for AWS Trainium via NKI.
4
+ Part of the trnsci scientific computing suite.
5
+
6
+ ## What This Is
7
+
8
+ A cuSPARSE-equivalent for Trainium. CSR/COO formats, SpMV, SpMM,
9
+ and integral screening for sparse scientific computing.
10
+
11
+ **Primary use case:** Schwarz-screened Fock builds for DF-MP2 quantum chemistry.
12
+ At >3000 basis functions, >99% of shell quartets screen to zero.
13
+ Storing and operating on the integral tensor in dense format wastes
14
+ both memory and compute. trnsparse makes the sparsity explicit.
15
+
16
+ ## Architecture
17
+
18
+ ```
19
+ trnsparse/
20
+ ├── trnsparse/
21
+ │ ├── __init__.py
22
+ │ ├── formats.py # CSRMatrix, COOMatrix, conversions, from_dense
23
+ │ ├── ops.py # spmv, spmm, spmv_symmetric, add, scale, transpose
24
+ │ ├── screening.py # schwarz_bounds, screen_quartets, density_screen
25
+ │ └── nki/
26
+ │ ├── __init__.py
27
+ │ └── dispatch.py # Gather-matmul-scatter pattern for SpMM
28
+ ├── tests/
29
+ │ ├── test_formats.py # CSR/COO construction, roundtrips
30
+ │ ├── test_ops.py # SpMV, SpMM vs dense reference
31
+ │ └── test_screening.py
32
+ ├── examples/
33
+ │ └── sparse_fock.py # Screened Fock build demo
34
+ ```
35
+
36
+ ## NKI SpMM Strategy
37
+
38
+ SpMM on Trainium uses a gather-matmul-scatter pattern:
39
+ 1. **DMA engine**: gather non-zero column indices into dense SBUF tiles
40
+ 2. **Tensor Engine**: matmul the dense tile against B columns
41
+ 3. **DMA engine**: scatter results back to output rows
42
+
43
+ This is the same pattern used in sparse attention. The efficiency depends
44
+ on the nnz distribution per row — uniform nnz maps cleanly to fixed-size
45
+ tiles; highly variable nnz needs row-bucketing.
46
+
47
+ ## Dependencies
48
+
49
+ - `torch>=2.1`, `numpy>=1.24`
50
+ - `neuronxcc` (optional)
51
+
52
+ ## Development
53
+
54
+ ```bash
55
+ pip install -e ".[dev]"
56
+ pytest tests/ -v
57
+ python examples/sparse_fock.py --demo
58
+ ```
@@ -0,0 +1,25 @@
1
+ # Code of Conduct
2
+
3
+ This project adopts the [Contributor Covenant](https://www.contributor-covenant.org/), version 2.1, as its code of conduct. The full text is available at:
4
+
5
+ https://www.contributor-covenant.org/version/2/1/code_of_conduct/
6
+
7
+ ## Scope
8
+
9
+ This Code applies within all project spaces — the GitHub repositories under the [trnsci](https://github.com/trnsci) organization, issue trackers, pull request discussions, and any public forums where an individual is representing the project or its community.
10
+
11
+ ## Reporting
12
+
13
+ Concerns about behaviour in project spaces may be reported confidentially to:
14
+
15
+ **3011922+scttfrdmn@users.noreply.github.com**
16
+
17
+ All reports will be reviewed and investigated promptly and fairly. The project maintainers are obligated to respect the privacy and security of the reporter.
18
+
19
+ ## Enforcement
20
+
21
+ Maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
22
+
23
+ ## Attribution
24
+
25
+ This Code of Conduct is adapted from the Contributor Covenant, version 2.1, available at https://www.contributor-covenant.org/version/2/1/code_of_conduct.html. It is licensed under CC BY 4.0.
@@ -0,0 +1,69 @@
1
+ # Contributing to trnsparse
2
+
3
+ Thanks for your interest in contributing. This document covers the whole suite — the same guidelines apply to the umbrella and to each of the six sub-projects (`trnfft`, `trnblas`, `trnrand`, `trnsolver`, `trnsparse`, `trntensor`).
4
+
5
+ ## Where does my change belong?
6
+
7
+ - **Scoped to a single library** — bug fix, new feature, added kernel in one sub-project → open a PR in that sub-project's repo.
8
+ - **Cross-cutting** — integration examples, umbrella docs, CUDA-rosetta content, coordinated version bumps, shared tooling → open a PR against [trnsci/trnsci](https://github.com/trnsci/trnsci).
9
+
10
+ If you aren't sure, open the PR where it's easiest and we'll move it.
11
+
12
+ ## Development setup
13
+
14
+ ```bash
15
+ git clone git@github.com:trnsci/trnsci.git
16
+ cd trnsci
17
+ # Clone sibling sub-projects if you don't already have them:
18
+ for p in trnfft trnblas trnrand trnsolver trnsparse trntensor; do
19
+ [ -d "$p" ] || git clone "git@github.com:trnsci/$p.git"
20
+ done
21
+ make install-dev
22
+ make test-all
23
+ ```
24
+
25
+ A single sub-project in isolation:
26
+
27
+ ```bash
28
+ cd trnfft # or any other
29
+ pip install -e ".[dev]"
30
+ pytest tests/ -v -m "not neuron"
31
+ ```
32
+
33
+ ## Tests
34
+
35
+ - `pytest tests/ -v -m "not neuron"` — the CPU-only suite. Must pass on every PR.
36
+ - `pytest tests/ -v -m neuron` — on-hardware suite, run from a machine with AWS credentials via `scripts/run_neuron_tests.sh`. Not part of standard CI.
37
+
38
+ ## Conventions
39
+
40
+ - **License header** — new files get the Apache 2.0 notice and `Copyright 2026 Scott Friedman` where a notice is customary (long source files, not one-line configs).
41
+ - **Python** — ≥ 3.10; `torch` ≥ 2.1; `numpy` ≥ 1.24.
42
+ - **No emoji** in source, commits, or docs unless the feature is literally about emoji.
43
+ - **Docstrings** only where they help a reader who doesn't have the context you had when writing. Don't restate the signature.
44
+ - **No throwaway files** in the repo root — work-in-progress notes belong in PR descriptions or `docs/`.
45
+
46
+ ## Commit style
47
+
48
+ Conventional-ish prefixes: `fix:`, `feat:`, `docs:`, `test:`, `bench:`, `chore:`, `refactor:`. Keep the subject line ≤ 72 characters. Longer context goes in the body.
49
+
50
+ ## Pull requests
51
+
52
+ Before opening a PR:
53
+
54
+ - [ ] `pytest tests/ -v -m "not neuron"` passes
55
+ - [ ] If you changed public API or behaviour, `CHANGELOG.md` has an `[Unreleased]` entry
56
+ - [ ] If you added a public symbol, the project's `docs/api.md` lists it
57
+ - [ ] PR description says *what* changed and *why*, not just *what*
58
+
59
+ ## Issues
60
+
61
+ Label each issue one of: `bug`, `feature`, `question`, `docs`, `infra`. Bugs include repro steps and expected-vs-actual output. Features describe the use case.
62
+
63
+ ## Code of conduct
64
+
65
+ By participating, you agree to abide by the [Contributor Covenant v2.1](CODE_OF_CONDUCT.md). Report concerns to the contact listed there.
66
+
67
+ ## License
68
+
69
+ Contributions are Apache 2.0, per the repository's [LICENSE](LICENSE). You attest you have the right to submit the code.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ Copyright 2026 Scott Friedman
6
+
7
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ 1. Definitions.
10
+
11
+ "License" shall mean the terms and conditions for use, reproduction,
12
+ and distribution as defined by Sections 1 through 9 of this document.
13
+
14
+ "Licensor" shall mean the copyright owner or entity authorized by
15
+ the copyright owner that is granting the License.
16
+
17
+ "Legal Entity" shall mean the union of the acting entity and all
18
+ other entities that control, are controlled by, or are under common
19
+ control with that entity. For the purposes of this definition,
20
+ "control" means (i) the power, direct or indirect, to cause the
21
+ direction or management of such entity, whether by contract or
22
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
23
+ outstanding shares, or (iii) beneficial ownership of such entity.
24
+
25
+ "You" (or "Your") shall mean an individual or Legal Entity
26
+ exercising permissions granted by this License.
27
+
28
+ "Source" form shall mean the preferred form for making modifications,
29
+ including but not limited to software source code, documentation
30
+ source, and configuration files.
31
+
32
+ "Object" form shall mean any form resulting from mechanical
33
+ transformation or translation of a Source form, including but
34
+ not limited to compiled object code, generated documentation,
35
+ and conversions to other media types.
36
+
37
+ "Work" shall mean the work of authorship, whether in Source or
38
+ Object form, made available under the License, as indicated by a
39
+ copyright notice that is included in or attached to the work
40
+ (an example is provided in the Appendix below).
41
+
42
+ "Derivative Works" shall mean any work, whether in Source or Object
43
+ form, that is based on (or derived from) the Work and for which the
44
+ editorial revisions, annotations, elaborations, or other modifications
45
+ represent, as a whole, an original work of authorship. For the purposes
46
+ of this License, Derivative Works shall not include works that remain
47
+ separable from, or merely link (or bind by name) to the interfaces of,
48
+ the Work and Derivative Works thereof.
49
+
50
+ "Contribution" shall mean any work of authorship, including
51
+ the original version of the Work and any modifications or additions
52
+ to that Work or Derivative Works thereof, that is intentionally
53
+ submitted to Licensor for inclusion in the Work by the copyright owner
54
+ or by an individual or Legal Entity authorized to submit on behalf of
55
+ the copyright owner. For the purposes of this definition, "submitted"
56
+ means any form of electronic, verbal, or written communication sent
57
+ to the Licensor or its representatives, including but not limited to
58
+ communication on electronic mailing lists, source code control systems,
59
+ and issue tracking systems that are managed by, or on behalf of, the
60
+ Licensor for the purpose of discussing and improving the Work, but
61
+ excluding communication that is conspicuously marked or otherwise
62
+ designated in writing by the copyright owner as "Not a Contribution."
63
+
64
+ "Contributor" shall mean Licensor and any individual or Legal Entity
65
+ on behalf of whom a Contribution has been received by Licensor and
66
+ subsequently incorporated within the Work.
67
+
68
+ 2. Grant of Copyright License. Subject to the terms and conditions of
69
+ this License, each Contributor hereby grants to You a perpetual,
70
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
71
+ copyright license to reproduce, prepare Derivative Works of,
72
+ publicly display, publicly perform, sublicense, and distribute the
73
+ Work and such Derivative Works in Source or Object form.
74
+
75
+ 3. Grant of Patent License. Subject to the terms and conditions of
76
+ this License, each Contributor hereby grants to You a perpetual,
77
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
78
+ (except as stated in this section) patent license to make, have made,
79
+ use, offer to sell, sell, import, and otherwise transfer the Work,
80
+ where such license applies only to those patent claims licensable
81
+ by such Contributor that are necessarily infringed by their
82
+ Contribution(s) alone or by combination of their Contribution(s)
83
+ with the Work to which such Contribution(s) was submitted. If You
84
+ institute patent litigation against any entity (including a
85
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
86
+ or a Contribution incorporated within the Work constitutes direct
87
+ or contributory patent infringement, then any patent licenses
88
+ granted to You under this License for that Work shall terminate
89
+ as of the date such litigation is filed.
90
+
91
+ 4. Redistribution. You may reproduce and distribute copies of the
92
+ Work or Derivative Works thereof in any medium, with or without
93
+ modifications, and in Source or Object form, provided that You
94
+ meet the following conditions:
95
+
96
+ (a) You must give any other recipients of the Work or
97
+ Derivative Works a copy of this License; and
98
+
99
+ (b) You must cause any modified files to carry prominent notices
100
+ stating that You changed the files; and
101
+
102
+ (c) You must retain, in the Source form of any Derivative Works
103
+ that You distribute, all copyright, patent, trademark, and
104
+ attribution notices from the Source form of the Work,
105
+ excluding those notices that do not pertain to any part of
106
+ the Derivative Works; and
107
+
108
+ (d) If the Work includes a "NOTICE" text file as part of its
109
+ distribution, then any Derivative Works that You distribute must
110
+ include a readable copy of the attribution notices contained
111
+ within such NOTICE file, excluding those notices that do not
112
+ pertain to any part of the Derivative Works, in at least one
113
+ of the following places: within a NOTICE text file distributed
114
+ as part of the Derivative Works; within the Source form or
115
+ documentation, if provided along with the Derivative Works; or,
116
+ within a display generated by the Derivative Works, if and
117
+ wherever such third-party notices normally appear. The contents
118
+ of the NOTICE file are for informational purposes only and
119
+ do not modify the License. You may add Your own attribution
120
+ notices within Derivative Works that You distribute, alongside
121
+ or as an addendum to the NOTICE text from the Work, provided
122
+ that such additional attribution notices cannot be construed
123
+ as modifying the License.
124
+
125
+ You may add Your own copyright statement to Your modifications and
126
+ may provide additional or different license terms and conditions
127
+ for use, reproduction, or distribution of Your modifications, or
128
+ for any such Derivative Works as a whole, provided Your use,
129
+ reproduction, and distribution of the Work otherwise complies with
130
+ the conditions stated in this License.
131
+
132
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
133
+ any Contribution intentionally submitted for inclusion in the Work
134
+ by You to the Licensor shall be under the terms and conditions of
135
+ this License, without any additional terms or conditions.
136
+ Notwithstanding the above, nothing herein shall supersede or modify
137
+ the terms of any separate license agreement you may have executed
138
+ with Licensor regarding such Contributions.
139
+
140
+ 6. Trademarks. This License does not grant permission to use the trade
141
+ names, trademarks, service marks, or product names of the Licensor,
142
+ except as required for describing the origin of the Work and
143
+ reproducing the content of the NOTICE file.
144
+
145
+ 7. Disclaimer of Warranty. Unless required by applicable law or
146
+ agreed to in writing, Licensor provides the Work (and each
147
+ Contributor provides its Contributions) on an "AS IS" BASIS,
148
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
149
+ implied, including, without limitation, any warranties or conditions
150
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
151
+ PARTICULAR PURPOSE. You are solely responsible for determining the
152
+ appropriateness of using or redistributing the Work and assume any
153
+ risks associated with Your exercise of permissions under this License.
154
+
155
+ 8. Limitation of Liability. In no event and under no legal theory,
156
+ whether in tort (including negligence), contract, or otherwise,
157
+ unless required by applicable law (such as deliberate and grossly
158
+ negligent acts) or agreed to in writing, shall any Contributor be
159
+ liable to You for damages, including any direct, indirect, special,
160
+ incidental, or consequential damages of any character arising as a
161
+ result of this License or out of the use or inability to use the
162
+ Work (including but not limited to damages for loss of goodwill,
163
+ work stoppage, computer failure or malfunction, or any and all
164
+ other commercial damages or losses), even if such Contributor
165
+ has been advised of the possibility of such damages.
166
+
167
+ 9. Accepting Warranty or Additional Liability. While redistributing
168
+ the Work or Derivative Works thereof, You may accept support,
169
+ obligations, or other liability only on behalf of Yourself and on
170
+ Your sole responsibility, not on behalf of any other Contributor,
171
+ and only if You agree to indemnify, defend, and hold each Contributor
172
+ harmless for any liability incurred by, or claims asserted against,
173
+ such Contributor by reason of your accepting any such warranty or
174
+ additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Scott Friedman
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,85 @@
1
+ Metadata-Version: 2.4
2
+ Name: trnsparse
3
+ Version: 0.1.1
4
+ Summary: Sparse matrix operations for AWS Trainium via NKI
5
+ Author-email: Scott Friedman <3011922+scttfrdmn@users.noreply.github.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/trnsci/trnsparse
8
+ Project-URL: Repository, https://github.com/trnsci/trnsparse
9
+ Project-URL: Issues, https://github.com/trnsci/trnsparse/issues
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Science/Research
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Topic :: Scientific/Engineering
14
+ Requires-Python: >=3.10
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: torch>=2.1
18
+ Requires-Dist: numpy>=1.24
19
+ Provides-Extra: neuron
20
+ Requires-Dist: neuronxcc>=2.24; extra == "neuron"
21
+ Requires-Dist: torch-neuronx>=2.9; extra == "neuron"
22
+ Provides-Extra: dev
23
+ Requires-Dist: pytest>=7.0; extra == "dev"
24
+ Requires-Dist: pytest-benchmark>=4.0; extra == "dev"
25
+ Requires-Dist: scipy>=1.11; extra == "dev"
26
+ Dynamic: license-file
27
+
28
+ # trnsparse
29
+
30
+ [![CI](https://github.com/trnsci/trnsparse/actions/workflows/ci.yml/badge.svg)](https://github.com/trnsci/trnsparse/actions/workflows/ci.yml)
31
+ [![PyPI](https://img.shields.io/pypi/v/trnsparse)](https://pypi.org/project/trnsparse/)
32
+ [![Python](https://img.shields.io/pypi/pyversions/trnsparse)](https://pypi.org/project/trnsparse/)
33
+ [![License](https://img.shields.io/github/license/trnsci/trnsparse)](LICENSE)
34
+ [![Docs](https://img.shields.io/badge/docs-mkdocs-blue)](https://trnsci.github.io/trnsparse/)
35
+
36
+ Sparse matrix operations for AWS Trainium via NKI.
37
+
38
+ CSR/COO formats, SpMV, SpMM, and integral screening for sparse scientific computing on Trainium. Part of the trnsci scientific computing suite ([github.com/trnsci](https://github.com/trnsci)).
39
+
40
+ ## Install
41
+
42
+ ```bash
43
+ pip install trnsparse
44
+ ```
45
+
46
+ ## Usage
47
+
48
+ ```python
49
+ import torch
50
+ import trnsparse
51
+
52
+ # Dense → sparse
53
+ A = torch.randn(100, 100)
54
+ A[torch.abs(A) < 1.0] = 0.0
55
+ csr = trnsparse.from_dense(A)
56
+
57
+ # SpMV: y = A @ x
58
+ y = trnsparse.spmv(csr, x, alpha=2.0)
59
+
60
+ # SpMM: C = A @ B
61
+ C = trnsparse.spmm(csr, B)
62
+
63
+ # Integral screening
64
+ Q = trnsparse.schwarz_bounds(diagonal_integrals)
65
+ mask = trnsparse.screen_quartets(Q, threshold=1e-10)
66
+ stats = trnsparse.sparsity_stats(Q)
67
+ ```
68
+
69
+ ## Operations
70
+
71
+ | Operation | Description |
72
+ |-----------|-------------|
73
+ | `spmv` | Sparse × dense vector |
74
+ | `spmm` | Sparse × dense matrix |
75
+ | `spmv_symmetric` | Symmetric SpMV (half storage) |
76
+ | `sparse_add` | C = αA + βB |
77
+ | `sparse_scale` | B = αA |
78
+ | `sparse_transpose` | A^T |
79
+ | `schwarz_bounds` | Schwarz screening bounds |
80
+ | `screen_quartets` | Shell quartet significance mask |
81
+ | `density_screen` | Density-weighted screening |
82
+
83
+ ## License
84
+
85
+ Apache 2.0 — Copyright 2026 Scott Friedman
@@ -0,0 +1,58 @@
1
+ # trnsparse
2
+
3
+ [![CI](https://github.com/trnsci/trnsparse/actions/workflows/ci.yml/badge.svg)](https://github.com/trnsci/trnsparse/actions/workflows/ci.yml)
4
+ [![PyPI](https://img.shields.io/pypi/v/trnsparse)](https://pypi.org/project/trnsparse/)
5
+ [![Python](https://img.shields.io/pypi/pyversions/trnsparse)](https://pypi.org/project/trnsparse/)
6
+ [![License](https://img.shields.io/github/license/trnsci/trnsparse)](LICENSE)
7
+ [![Docs](https://img.shields.io/badge/docs-mkdocs-blue)](https://trnsci.github.io/trnsparse/)
8
+
9
+ Sparse matrix operations for AWS Trainium via NKI.
10
+
11
+ CSR/COO formats, SpMV, SpMM, and integral screening for sparse scientific computing on Trainium. Part of the trnsci scientific computing suite ([github.com/trnsci](https://github.com/trnsci)).
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ pip install trnsparse
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ```python
22
+ import torch
23
+ import trnsparse
24
+
25
+ # Dense → sparse
26
+ A = torch.randn(100, 100)
27
+ A[torch.abs(A) < 1.0] = 0.0
28
+ csr = trnsparse.from_dense(A)
29
+
30
+ # SpMV: y = A @ x
31
+ y = trnsparse.spmv(csr, x, alpha=2.0)
32
+
33
+ # SpMM: C = A @ B
34
+ C = trnsparse.spmm(csr, B)
35
+
36
+ # Integral screening
37
+ Q = trnsparse.schwarz_bounds(diagonal_integrals)
38
+ mask = trnsparse.screen_quartets(Q, threshold=1e-10)
39
+ stats = trnsparse.sparsity_stats(Q)
40
+ ```
41
+
42
+ ## Operations
43
+
44
+ | Operation | Description |
45
+ |-----------|-------------|
46
+ | `spmv` | Sparse × dense vector |
47
+ | `spmm` | Sparse × dense matrix |
48
+ | `spmv_symmetric` | Symmetric SpMV (half storage) |
49
+ | `sparse_add` | C = αA + βB |
50
+ | `sparse_scale` | B = αA |
51
+ | `sparse_transpose` | A^T |
52
+ | `schwarz_bounds` | Schwarz screening bounds |
53
+ | `screen_quartets` | Shell quartet significance mask |
54
+ | `density_screen` | Density-weighted screening |
55
+
56
+ ## License
57
+
58
+ Apache 2.0 — Copyright 2026 Scott Friedman
@@ -0,0 +1,33 @@
1
+ # API Reference
2
+
3
+ ## Formats
4
+
5
+ - `CSRMatrix(indptr, indices, data, shape)` — compressed sparse row
6
+ - `.from_dense(dense, threshold=0)` — construct by thresholding a dense tensor
7
+ - `.to_dense()` — materialize back to a dense `torch.Tensor`
8
+ - `.transpose()` — transpose to CSR (via CSC)
9
+ - `.nnz`, `.shape`, `.dtype`, `.device`
10
+ - `COOMatrix(rows, cols, vals, shape)` — coordinate format
11
+ - `.to_csr()` / `CSRMatrix.to_coo()` — roundtrip conversions
12
+
13
+ ## Ops
14
+
15
+ - `spmv(A, x)` — sparse matrix × dense vector
16
+ - `spmv_symmetric(A, x)` — for symmetric A; skips duplicate work
17
+ - `spmm(A, B)` — sparse matrix × dense matrix (gather-matmul-scatter on NKI)
18
+ - `sparse_add(A, B, alpha=1.0, beta=1.0)` — `α A + β B`
19
+ - `sparse_scale(A, s)` — scalar multiply
20
+ - `transpose(A)` — transpose of CSR / COO
21
+
22
+ ## Screening
23
+
24
+ - `schwarz_bounds(shell_pair_integrals)` — Cauchy-Schwarz bounds $Q_{pq} = \sqrt{(pq|pq)}$
25
+ - `screen_quartets(Q, threshold)` — keep only quartets with $Q_{pq}Q_{rs} > \text{threshold}$
26
+ - `density_screen(Q, P, threshold)` — density-weighted screening
27
+ - `sparsity_stats(mask)` — density, nnz, per-row nnz distribution
28
+
29
+ ## Dispatch
30
+
31
+ - `set_backend("auto" | "pytorch" | "nki")` — select compute backend
32
+ - `get_backend()` — current backend
33
+ - `HAS_NKI` — module-level flag set at import time