trntensor 0.25.2__tar.gz → 0.27.0__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 (118) hide show
  1. trntensor-0.27.0/.github/ISSUE_TEMPLATE/bug_report.md +31 -0
  2. trntensor-0.27.0/.github/ISSUE_TEMPLATE/feature_request.md +17 -0
  3. {trntensor-0.25.2 → trntensor-0.27.0}/CHANGELOG.md +137 -0
  4. {trntensor-0.25.2/trntensor.egg-info → trntensor-0.27.0}/PKG-INFO +6 -1
  5. {trntensor-0.25.2 → trntensor-0.27.0}/README.md +5 -0
  6. trntensor-0.27.0/docs/api/equivariant.md +177 -0
  7. {trntensor-0.25.2 → trntensor-0.27.0}/docs/api/index.md +3 -1
  8. trntensor-0.27.0/docs/api/mlip_edge.md +84 -0
  9. {trntensor-0.25.2 → trntensor-0.27.0}/mkdocs.yml +2 -0
  10. {trntensor-0.25.2 → trntensor-0.27.0}/pyproject.toml +2 -1
  11. trntensor-0.27.0/scripts/conformance_expect.py +65 -0
  12. {trntensor-0.25.2 → trntensor-0.27.0}/tests/conftest.py +72 -0
  13. trntensor-0.27.0/tests/fixtures/mace_mp0b2_edge.pt +0 -0
  14. trntensor-0.27.0/tests/fixtures/mace_mp0b2_tiny.pt +0 -0
  15. trntensor-0.27.0/tests/mlip_reference.py +126 -0
  16. {trntensor-0.25.2 → trntensor-0.27.0}/tests/test_conformance.py +53 -0
  17. trntensor-0.27.0/tests/test_device_known.py +57 -0
  18. trntensor-0.27.0/tests/test_edge.py +489 -0
  19. trntensor-0.27.0/tests/test_edge_native.py +313 -0
  20. trntensor-0.27.0/tests/test_edge_neuron.py +457 -0
  21. trntensor-0.27.0/tests/test_edge_nki.py +209 -0
  22. trntensor-0.27.0/tests/test_equivariant.py +632 -0
  23. trntensor-0.27.0/tests/test_equivariant_native.py +421 -0
  24. trntensor-0.27.0/tests/test_equivariant_neuron.py +436 -0
  25. trntensor-0.27.0/tests/test_equivariant_nki.py +221 -0
  26. trntensor-0.27.0/tests/test_psum_accumulate_lint.py +188 -0
  27. {trntensor-0.25.2 → trntensor-0.27.0}/trntensor/__init__.py +42 -1
  28. trntensor-0.27.0/trntensor/_region.py +108 -0
  29. trntensor-0.27.0/trntensor/edge.py +785 -0
  30. trntensor-0.27.0/trntensor/equivariant.py +1153 -0
  31. trntensor-0.27.0/trntensor/linear.py +424 -0
  32. trntensor-0.27.0/trntensor/nki/_edge.py +449 -0
  33. trntensor-0.27.0/trntensor/nki/_edge_kernels.py +779 -0
  34. trntensor-0.27.0/trntensor/nki/_equivariant.py +377 -0
  35. trntensor-0.27.0/trntensor/nki/_equivariant_kernels.py +566 -0
  36. {trntensor-0.25.2 → trntensor-0.27.0}/trntensor/nki/_kernels.py +218 -141
  37. trntensor-0.27.0/trntensor/nki/_native_edge.py +146 -0
  38. trntensor-0.27.0/trntensor/nki/_native_equivariant.py +167 -0
  39. {trntensor-0.25.2 → trntensor-0.27.0/trntensor.egg-info}/PKG-INFO +6 -1
  40. {trntensor-0.25.2 → trntensor-0.27.0}/trntensor.egg-info/SOURCES.txt +28 -0
  41. {trntensor-0.25.2 → trntensor-0.27.0}/.github/workflows/ci.yml +0 -0
  42. {trntensor-0.25.2 → trntensor-0.27.0}/.github/workflows/notify-umbrella.yml +0 -0
  43. {trntensor-0.25.2 → trntensor-0.27.0}/.github/workflows/publish.yml +0 -0
  44. {trntensor-0.25.2 → trntensor-0.27.0}/.gitignore +0 -0
  45. {trntensor-0.25.2 → trntensor-0.27.0}/.pre-commit-config.yaml +0 -0
  46. {trntensor-0.25.2 → trntensor-0.27.0}/CLAUDE.md +0 -0
  47. {trntensor-0.25.2 → trntensor-0.27.0}/CODE_OF_CONDUCT.md +0 -0
  48. {trntensor-0.25.2 → trntensor-0.27.0}/CONTRIBUTING.md +0 -0
  49. {trntensor-0.25.2 → trntensor-0.27.0}/LICENSE +0 -0
  50. {trntensor-0.25.2 → trntensor-0.27.0}/benchmarks/__init__.py +0 -0
  51. {trntensor-0.25.2 → trntensor-0.27.0}/benchmarks/bench_einsum.py +0 -0
  52. {trntensor-0.25.2 → trntensor-0.27.0}/docs/api/decompose.md +0 -0
  53. {trntensor-0.25.2 → trntensor-0.27.0}/docs/api/einsum.md +0 -0
  54. {trntensor-0.25.2 → trntensor-0.27.0}/docs/api/nki.md +0 -0
  55. {trntensor-0.25.2 → trntensor-0.27.0}/docs/api/plan.md +0 -0
  56. {trntensor-0.25.2 → trntensor-0.27.0}/docs/api/quantum.md +0 -0
  57. {trntensor-0.25.2 → trntensor-0.27.0}/docs/api/stream.md +0 -0
  58. {trntensor-0.25.2 → trntensor-0.27.0}/docs/architecture.md +0 -0
  59. {trntensor-0.25.2 → trntensor-0.27.0}/docs/aws_setup.md +0 -0
  60. {trntensor-0.25.2 → trntensor-0.27.0}/docs/benchmarks.md +0 -0
  61. {trntensor-0.25.2 → trntensor-0.27.0}/docs/contraction_patterns.md +0 -0
  62. {trntensor-0.25.2 → trntensor-0.27.0}/docs/design/matmul_dispatch_findings.md +0 -0
  63. {trntensor-0.25.2 → trntensor-0.27.0}/docs/design/matmul_kernel_profile.md +0 -0
  64. {trntensor-0.25.2 → trntensor-0.27.0}/docs/developing_kernels.md +0 -0
  65. {trntensor-0.25.2 → trntensor-0.27.0}/docs/index.md +0 -0
  66. {trntensor-0.25.2 → trntensor-0.27.0}/docs/installation.md +0 -0
  67. {trntensor-0.25.2 → trntensor-0.27.0}/docs/quickstart.md +0 -0
  68. {trntensor-0.25.2 → trntensor-0.27.0}/docs/tutorial_df_mp2.md +0 -0
  69. {trntensor-0.25.2 → trntensor-0.27.0}/examples/df_mp2_einsum.py +0 -0
  70. {trntensor-0.25.2 → trntensor-0.27.0}/infra/terraform/README.md +0 -0
  71. {trntensor-0.25.2 → trntensor-0.27.0}/infra/terraform/main.tf +0 -0
  72. {trntensor-0.25.2 → trntensor-0.27.0}/scripts/autotune_dispatch.py +0 -0
  73. {trntensor-0.25.2 → trntensor-0.27.0}/scripts/bench_ao2mo_nocc.py +0 -0
  74. {trntensor-0.25.2 → trntensor-0.27.0}/scripts/bench_eager_handle.py +0 -0
  75. {trntensor-0.25.2 → trntensor-0.27.0}/scripts/bench_native_einsum.py +0 -0
  76. {trntensor-0.25.2 → trntensor-0.27.0}/scripts/bench_native_kernels.py +0 -0
  77. {trntensor-0.25.2 → trntensor-0.27.0}/scripts/bench_to_md.py +0 -0
  78. {trntensor-0.25.2 → trntensor-0.27.0}/scripts/run_benchmarks.sh +0 -0
  79. {trntensor-0.25.2 → trntensor-0.27.0}/scripts/run_neuron_profile.sh +0 -0
  80. {trntensor-0.25.2 → trntensor-0.27.0}/scripts/run_neuron_tests.sh +0 -0
  81. {trntensor-0.25.2 → trntensor-0.27.0}/scripts/run_reduce_parallel_multirank.py +0 -0
  82. {trntensor-0.25.2 → trntensor-0.27.0}/scripts/run_simulator_tests.sh +0 -0
  83. {trntensor-0.25.2 → trntensor-0.27.0}/setup.cfg +0 -0
  84. {trntensor-0.25.2 → trntensor-0.27.0}/tests/test_decompose.py +0 -0
  85. {trntensor-0.25.2 → trntensor-0.27.0}/tests/test_einsum.py +0 -0
  86. {trntensor-0.25.2 → trntensor-0.27.0}/tests/test_host_output.py +0 -0
  87. {trntensor-0.25.2 → trntensor-0.27.0}/tests/test_kernel_dtype_guard.py +0 -0
  88. {trntensor-0.25.2 → trntensor-0.27.0}/tests/test_native_dispatch.py +0 -0
  89. {trntensor-0.25.2 → trntensor-0.27.0}/tests/test_neuron_int_exact.py +0 -0
  90. {trntensor-0.25.2 → trntensor-0.27.0}/tests/test_neuron_span.py +0 -0
  91. {trntensor-0.25.2 → trntensor-0.27.0}/tests/test_neuron_span_device.py +0 -0
  92. {trntensor-0.25.2 → trntensor-0.27.0}/tests/test_nki.py +0 -0
  93. {trntensor-0.25.2 → trntensor-0.27.0}/tests/test_nki_compile.py +0 -0
  94. {trntensor-0.25.2 → trntensor-0.27.0}/tests/test_nki_kernels.py +0 -0
  95. {trntensor-0.25.2 → trntensor-0.27.0}/tests/test_nki_native.py +0 -0
  96. {trntensor-0.25.2 → trntensor-0.27.0}/tests/test_nki_sim.py +0 -0
  97. {trntensor-0.25.2 → trntensor-0.27.0}/tests/test_nki_tail_audit.py +0 -0
  98. {trntensor-0.25.2 → trntensor-0.27.0}/tests/test_parallel.py +0 -0
  99. {trntensor-0.25.2 → trntensor-0.27.0}/tests/test_plan.py +0 -0
  100. {trntensor-0.25.2 → trntensor-0.27.0}/tests/test_quantum.py +0 -0
  101. {trntensor-0.25.2 → trntensor-0.27.0}/tests/test_sr_runtime.py +0 -0
  102. {trntensor-0.25.2 → trntensor-0.27.0}/tests/test_stream.py +0 -0
  103. {trntensor-0.25.2 → trntensor-0.27.0}/tests/test_trace_cache_safety.py +0 -0
  104. {trntensor-0.25.2 → trntensor-0.27.0}/trntensor/decompose.py +0 -0
  105. {trntensor-0.25.2 → trntensor-0.27.0}/trntensor/einsum.py +0 -0
  106. {trntensor-0.25.2 → trntensor-0.27.0}/trntensor/nki/__init__.py +0 -0
  107. {trntensor-0.25.2 → trntensor-0.27.0}/trntensor/nki/_native.py +0 -0
  108. {trntensor-0.25.2 → trntensor-0.27.0}/trntensor/nki/collectives.py +0 -0
  109. {trntensor-0.25.2 → trntensor-0.27.0}/trntensor/nki/dispatch.py +0 -0
  110. {trntensor-0.25.2 → trntensor-0.27.0}/trntensor/parallel.py +0 -0
  111. {trntensor-0.25.2 → trntensor-0.27.0}/trntensor/plan.py +0 -0
  112. {trntensor-0.25.2 → trntensor-0.27.0}/trntensor/py.typed +0 -0
  113. {trntensor-0.25.2 → trntensor-0.27.0}/trntensor/quantum.py +0 -0
  114. {trntensor-0.25.2 → trntensor-0.27.0}/trntensor/stream.py +0 -0
  115. {trntensor-0.25.2 → trntensor-0.27.0}/trntensor.egg-info/dependency_links.txt +0 -0
  116. {trntensor-0.25.2 → trntensor-0.27.0}/trntensor.egg-info/requires.txt +0 -0
  117. {trntensor-0.25.2 → trntensor-0.27.0}/trntensor.egg-info/top_level.txt +0 -0
  118. {trntensor-0.25.2 → trntensor-0.27.0}/uv.lock +0 -0
@@ -0,0 +1,31 @@
1
+ ---
2
+ name: Bug report
3
+ about: Report a bug in trnfft
4
+ labels: bug
5
+ ---
6
+
7
+ ## Environment
8
+
9
+ - trnfft version:
10
+ - Python version:
11
+ - PyTorch version:
12
+ - Hardware: CPU / trn1 / trn2 / inf2
13
+ - OS:
14
+
15
+ ## Description
16
+
17
+ What happened?
18
+
19
+ ## Steps to reproduce
20
+
21
+ ```python
22
+ # Minimal code to reproduce
23
+ ```
24
+
25
+ ## Expected behavior
26
+
27
+ What should have happened?
28
+
29
+ ## Actual behavior
30
+
31
+ What happened instead? Include error messages/tracebacks if applicable.
@@ -0,0 +1,17 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest a new feature or enhancement
4
+ labels: enhancement
5
+ ---
6
+
7
+ ## Description
8
+
9
+ What feature would you like?
10
+
11
+ ## Motivation
12
+
13
+ Why is this needed? What problem does it solve?
14
+
15
+ ## Alternatives considered
16
+
17
+ Any other approaches you've thought about?
@@ -7,6 +7,131 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.27.0] — 2026-11-28
11
+
12
+ ### Added
13
+
14
+ - **MLIP edge and node ops: the rest of a MACE step as fused ops with
15
+ analytic backwards** (MLIP exemplar trnsci/trnsci#178, item 1). On the
16
+ MACE-MP-0b2 medium step on Trn2 at 216 atoms, about 92 of 118 ms went to
17
+ roughly 1,500 small aten launches outside the equivariant and graph
18
+ blocks.
19
+ - `spherical_harmonics(vectors, lmax=3)`: e3nn's real spherical harmonics
20
+ (basis, order and normalisation of `o3.SphericalHarmonics` for l ≤ 3).
21
+ The forward is one matmul of the degree ≤ 3 monomials against fixed
22
+ coefficients, and the backward is one matmul against their derivative
23
+ tables.
24
+ - `edge_chain(lengths, spec, r0)` with `edge_chain_spec(module=model)`:
25
+ the radial basis (Agnesi transform, Bessel basis, polynomial cutoff) and
26
+ every radial MLP that reads it, fused. It produces both layers'
27
+ `conv_tp` weights and edge densities `tanh(density_fn(·)²)`. The Agnesi
28
+ species constant is an input built once per neighbour list. Edges past
29
+ `r_max` contribute exactly zero, so padded edge buckets are safe.
30
+ - `equivariant_linear(x, spec, species=None)` with
31
+ `equivariant_linear_spec(module)`: an e3nn `o3.Linear` as one matmul per
32
+ irrep type (`W_l ⊗ I_{2l+1}`, probed once and checked exactly). The
33
+ one-hot `FullyConnectedTensorProduct` (MACE's `skip_tp`) becomes a
34
+ per-species map.
35
+ - Each op is one autograd node with an analytic backward, written in
36
+ differentiable aten, so double backward works. Against MACE at the six
37
+ MLIP exemplar captures, outputs match MACE fp32 to ≤ 4.6e-7 relative.
38
+ Input gradients for the real force-step cotangents are no further from
39
+ fp64 than MACE's own fp32 gradients.
40
+ - `set_region_backend("neuron")` (`TRNTENSOR_REGION_BACKEND`) runs the
41
+ forward and backward bodies of these ops as one
42
+ `torch.compile(dynamic=False)` graph per direction and call site.
43
+ `compiled_region(fn)` exposes the same wrapper.
44
+ - NKI kernels for `spherical_harmonics` and `edge_chain`, one launch per
45
+ direction. Edges are laid out partition-major (`[128, M·F]` views). The
46
+ radial MLPs run on the Tensor Engine with the weights resident in SBUF.
47
+ `sin` stays inside the Scalar Engine's accurate `[−π, π]` range. The
48
+ kernels are native `nki_op`s with `register_autograd`, or
49
+ `autograd.Function` on the XLA path and the simulator. They pass MLIR
50
+ verification for trn1 and trn2 (LNC 1 and 2). In `nki.simulate` they
51
+ match the fp64 PyTorch path to ≤ 2e-6 relative, and MACE at the
52
+ committed fixture. They are not yet validated on a device, so `"auto"`
53
+ leaves them off; `set_backend("nki")` or `TRNTENSOR_EDGE_NKI=1` selects
54
+ them. `tests/test_edge_neuron.py` holds the device checks and a timing
55
+ harness.
56
+ - New fixture `tests/fixtures/mace_mp0b2_edge.pt` (341 KiB), written by
57
+ the exemplar's `check_fused.py --trntensor-fixture` from the public
58
+ checkpoint.
59
+
60
+ ### Fixed
61
+
62
+ - **PSUM accumulation groups now open with a matmul write
63
+ (trnsci/trnsci#185).** The NKI kernels zeroed PSUM tiles with
64
+ `nl.zeros(..., buffer=nl.psum)` (a memset) and then accumulated into them
65
+ with `nisa.nc_matmul(..., accumulate=True)`. The `nc_matmul` docs make that
66
+ undefined behaviour on NeuronCore-v3 (Trn2): accumulating onto PSUM that a
67
+ non-matmul instruction initialised is not supported, and the first write
68
+ must use `accumulate=False`. Device results matched the references so far,
69
+ but they relied on that behaviour. All 20 sites now open each group with an
70
+ `accumulate=False` matmul: the matmul / batched-matmul, DF-MP2 energy,
71
+ AO→MO (4-index, Trn2, packed and blocked), DF exchange (half transform and
72
+ SYRK) and DF Coulomb `d` kernels peel the first K step of their
73
+ `nl.affine_range` loops into its own leg (`_psum_legs`), and the MACE
74
+ `conv_tp` backward and `symmetric_contraction` forward/backward kernels pass
75
+ `accumulate=(k > 0)` over their static loops. Those PSUM tiles are plain
76
+ `nl.ndarray`s now, so the redundant memsets are gone. Simulator outputs are
77
+ bitwise equal to 0.26.0 at the test shapes. A new static lint
78
+ (`tests/test_psum_accumulate_lint.py`) fails when a zeroed PSUM tile is a
79
+ matmul accumulation target, or when a tile is only ever accumulated into.
80
+
81
+ ## [0.26.0] — 2026-11-25
82
+
83
+ Validated on Trn2 (trn2.3xlarge, Neuron SDK 2.33.1, native TorchNeuron) — see trnsci/trnsci#35.
84
+
85
+ Headline: `trntensor.equivariant`, MACE-style equivariant contractions with registered backwards (#138, #139): `conv_tp` (the e3nn "uvu" tensor product, gradients for x, y and w) and `symmetric_contraction` (correlation ≤ 3, gradient for x). On Trn2 the NKI kernels match the fp64 host path to ≤ 2.2e-7 relative, forward, input gradients and double backward, so `"auto"` runs them for fp32 operands on the `neuron` device. The PyTorch-path `symmetric_contraction` backward is a few GEMMs instead of `index_add_` (#140).
86
+
87
+ ### Added
88
+
89
+ - **`trntensor.equivariant`: MACE-style equivariant contractions with
90
+ forward and input gradients** (#138, MLIP exemplar trnsci/trnsci#170).
91
+ These are the first trntensor ops with a registered backward.
92
+ - `conv_tp(x, y, w, spec)`: the e3nn "uvu" tensor product with per-edge
93
+ weights, the MLIP interaction. Gradients ∂x, ∂y, ∂w.
94
+ - `symmetric_contraction(x, species, spec)`: MACE's product basis,
95
+ correlation ≤ 3. Gradient ∂x.
96
+ - `conv_tp_spec` / `symmetric_contraction_spec` build the static spec
97
+ either from an e3nn / MACE module or from explicit irreps (or coupling
98
+ tensors and weights). e3nn and mace-torch stay optional, test-only
99
+ dependencies. `wigner_3j` and `wigner_D` reproduce e3nn 0.4.4's basis
100
+ and sign convention for l ≤ 3.
101
+ - The fused PyTorch path is a fixed handful of aten launches per call: 8
102
+ at MACE-MP layer 1 forward, against 34 for e3nn. Against the MACE-MP-0b2
103
+ medium captures it matches MACE to ≤ 3.6e-7 relative for every output and
104
+ input gradient on all six exemplar captures (16 / 64 / 216 atoms, two
105
+ geometries each).
106
+ - The NKI kernels run one launch per direction per layer. conv_tp keeps
107
+ edges on partitions; its Clebsch-Gordan blocks stay in SBUF and come out
108
+ of one Tensor Engine matmul, and the work is split over the GpSimd,
109
+ Scalar and Vector engines. symmetric_contraction runs as Tensor Engine
110
+ matmuls over a pruned symmetric-monomial basis, accumulating in PSUM.
111
+ - On the native TorchNeuron path the ops are `nki_op` custom ops with
112
+ `register_autograd`. On the XLA path and the simulator they are wrapped
113
+ in `torch.autograd.Function`.
114
+ - The kernels pass MLIR verification for trn1 and trn2 (LNC 1 and 2), and
115
+ match MACE in `nki.simulate`. On Trn2 (SDK 2.33.1, neuronx-cc 2.28,
116
+ native TorchNeuron, LNC=2) they match the fp64 host path to ≤ 2.2e-7
117
+ relative at 216 and 1728 atoms and every MACE-MP-0b2 capture to ≤ 2.9e-7
118
+ (bar 2e-5), forward, input gradients and double backward; reruns are
119
+ bitwise identical. `"auto"` therefore runs them for fp32 operands on the
120
+ `neuron` device (`TRNTENSOR_EQUIVARIANT_NKI=0` opts out); elsewhere it
121
+ runs the PyTorch path. Timings are in trntensor#139.
122
+ - The symmetric-contraction factor products run on the Vector Engine:
123
+ neuronx-cc 2.28 elides a PSUM → SBUF `tensor_copy` into a GpSimd
124
+ consumer and then fails with NCC_IBFD004.
125
+ - With `create_graph=True` (training on forces) the backward is built from
126
+ differentiable aten ops on the kernel operands, so double backward works
127
+ with the kernels on; first-order backward (forces) stays on the kernels.
128
+ - The PyTorch-path `symmetric_contraction` backward scatters the factors
129
+ as three GEMMs against a 0/1 factor-selection matrix, not `index_add_`
130
+ (#140). On Trn2 at 216 atoms the backward drops from 4485 to 5.1 ms
131
+ (layer 0) and from 1030 to 2.6 ms (layer 1).
132
+ - Device tests and a timing harness are in
133
+ `tests/test_equivariant_neuron.py`.
134
+
10
135
  ## [0.25.2] — 2026-11-10
11
136
 
12
137
  Validated on Trn2 (trn2.3xlarge, Neuron SDK 2.33.0, native TorchNeuron) — see trnsci/trnsci#35.
@@ -26,6 +151,18 @@ Headline: integer einsum on the neuron device is exact above 2^24, and int32/int
26
151
  views, which the device moves bit-exactly. On Trn2, `einsum("ij->ji", x,
27
152
  out=buf)` on an int32 (64, 96) tensor had 5928 of 6144 entries wrong, and
28
153
  `einsum("ij,jk->ik")` of `[[2^24 + 1, 2], [3, 4]]` with I gave 16777216.
154
+ ### Changed
155
+
156
+ - **Device conformance runs are signal-only (trnsci/trnsci#35).** Under
157
+ `--backend nki --conformance-device neuron`, `tests/test_conformance.py`
158
+ marks the known platform failures `xfail(strict=False)` by category at run
159
+ time (`DEVICE_KNOWN`, the trnsolver#146 pattern): complex SVD / solve on
160
+ device (#130, 9 cases) and device float64 at fp32 precision (#136, 1 case).
161
+ A case that starts passing shows as XPASS. CPU CI and `auto` / `pytorch`
162
+ runs are unchanged. A device run prints passed, xfailed and XPASS by
163
+ category and the NEW failures; `--conformance-json PATH` writes it as
164
+ JSON, and `scripts/conformance_expect.py` merges chunked runs (exit 1 on
165
+ NEW failures). Test: `tests/test_device_known.py`.
29
166
 
30
167
  ## [0.25.1] — 2026-11-07
31
168
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: trntensor
3
- Version: 0.25.2
3
+ Version: 0.27.0
4
4
  Summary: Tensor contractions for AWS Trainium via NKI
5
5
  Author-email: Scott Friedman <scttfrdmn@gmail.com>
6
6
  License-Expression: Apache-2.0
@@ -144,6 +144,11 @@ core, factors = trntensor.tucker_decompose(tensor, ranks=(5, 5, 5))
144
144
  | Chemistry | `df_exchange` / `df_coulomb` | Fused DF exchange (K) / Coulomb (J) from packed integrals |
145
145
  | Chemistry | `pack_tril` / `unpack_tril` | Packed (μ≥ν) three-centre integral layout |
146
146
  | Sharding | `ShardedTensor`, `scatter`, `gather` | Output- and reduce-parallel sharded contractions |
147
+ | Equivariant | `conv_tp` | e3nn "uvu" tensor product (MACE interaction), forward + ∂x/∂y/∂w |
148
+ | Equivariant | `symmetric_contraction` | MACE product basis (correlation ≤ 3), forward + ∂x |
149
+ | MLIP edge | `spherical_harmonics` | e3nn real spherical harmonics, l ≤ 3, forward + ∂v |
150
+ | MLIP edge | `edge_chain` | Fused radial basis + cutoff + radial MLPs (the `conv_tp` weights), forward + ∂r |
151
+ | MLIP node | `equivariant_linear` | e3nn `Linear` / one-hot skip tensor product as one matmul per irrep, forward + ∂x |
147
152
 
148
153
  ## Status
149
154
 
@@ -106,6 +106,11 @@ core, factors = trntensor.tucker_decompose(tensor, ranks=(5, 5, 5))
106
106
  | Chemistry | `df_exchange` / `df_coulomb` | Fused DF exchange (K) / Coulomb (J) from packed integrals |
107
107
  | Chemistry | `pack_tril` / `unpack_tril` | Packed (μ≥ν) three-centre integral layout |
108
108
  | Sharding | `ShardedTensor`, `scatter`, `gather` | Output- and reduce-parallel sharded contractions |
109
+ | Equivariant | `conv_tp` | e3nn "uvu" tensor product (MACE interaction), forward + ∂x/∂y/∂w |
110
+ | Equivariant | `symmetric_contraction` | MACE product basis (correlation ≤ 3), forward + ∂x |
111
+ | MLIP edge | `spherical_harmonics` | e3nn real spherical harmonics, l ≤ 3, forward + ∂v |
112
+ | MLIP edge | `edge_chain` | Fused radial basis + cutoff + radial MLPs (the `conv_tp` weights), forward + ∂r |
113
+ | MLIP node | `equivariant_linear` | e3nn `Linear` / one-hot skip tensor product as one matmul per irrep, forward + ∂x |
109
114
 
110
115
  ## Status
111
116
 
@@ -0,0 +1,177 @@
1
+ # Equivariant contractions
2
+
3
+ Fixed-shape kernels for the two contractions that dominate a MACE-style
4
+ machine-learned interatomic potential (MLIP exemplar,
5
+ [trnsci/trnsci#170](https://github.com/trnsci/trnsci/issues/170); contract
6
+ [#138](https://github.com/trnsci/trntensor/issues/138)). Conservative MLIPs
7
+ compute forces as F = −∂E/∂positions, so each op has a forward and a
8
+ registered input gradient.
9
+
10
+ | op | shares of a CPU energy + forces step (MACE-MP-0b2 medium, 216 atoms) |
11
+ |---|---|
12
+ | `conv_tp` (interaction tensor product) | 56% |
13
+ | `symmetric_contraction` (product basis) | 29% |
14
+
15
+ ## `conv_tp(x, y, w, spec) -> Tensor`
16
+
17
+ The e3nn `TensorProduct` with "uvu" instructions and per-edge weights. For
18
+ edge `e`, channel `u` and path `p = (l1 ⊗ l2 → l3, α_p)`:
19
+
20
+ ```
21
+ out_p[e, u, k] = α_p · w[e, p, u] · Σ_ij C^{l1 l2 l3}_ijk · x_{l1}[e, u, i] · y_{l2}[e, j]
22
+ ```
23
+
24
+ `C` are the real Wigner-3j symbols (e3nn basis and sign convention). Layouts
25
+ are e3nn's mul-major: an irreps block `mul × l` is `[mul, 2l+1]` row-major.
26
+ Gradients: `∂x`, `∂y`, `∂w`.
27
+
28
+ | | MACE-MP layer 0 | layer 1 |
29
+ |---|---|---|
30
+ | `x` | `[E, 128]` (128x0e) | `[E, 512]` (128x0e + 128x1o) |
31
+ | `y` | `[E, 16]` (0e + 1o + 2e + 3o) | `[E, 16]` |
32
+ | `w` | `[E, 512]`, 4 paths | `[E, 1280]`, 10 paths |
33
+ | out | `[E, 2048]` | `[E, 5120]` |
34
+
35
+ ### `conv_tp_spec(irreps_in1=None, irreps_in2=None, irreps_out=None, instructions=None, *, module=None, w3j=None, irrep_normalization="component", path_normalization="element") -> ConvTPSpec`
36
+
37
+ Built once per layer.
38
+
39
+ - `module=`: an e3nn `TensorProduct`, or a MACE interaction block (its
40
+ `conv_tp` is read). The irreps, instruction order (which is also the
41
+ weight order) and e3nn's normalisation (`path_weight`) are read from it.
42
+ - Explicit irreps: e3nn strings (`"128x0e+128x1o"`) or `[(mul, l), ...]`, and
43
+ instructions `(i1, i2, io)` (α from e3nn's "uvu" normalisation),
44
+ `(i1, i2, io, α)`, or e3nn's `(i1, i2, io, "uvu", True)`.
45
+ - The exemplar's capture dict is accepted wherever a spec is
46
+ (`ConvTPSpec.from_dict`, `spec.as_dict()`).
47
+
48
+ ```python
49
+ ins = [(0, 0, 0), (1, 1, 1), (0, 1, 2), (1, 0, 3), (1, 2, 4)]
50
+ ins += [(0, 2, 5), (1, 1, 6), (1, 3, 7), (0, 3, 8), (1, 2, 9)]
51
+ irreps_out = "128x0e+128x0e+128x1o+128x1o+128x1o+128x2e+128x2e+128x2e+128x3o+128x3o"
52
+ spec = trntensor.conv_tp_spec("128x0e+128x1o", "1x0e+1x1o+1x2e+1x3o", irreps_out, ins)
53
+ out = trntensor.conv_tp(x, y, w, spec) # [E, 5120]
54
+ # or from the model: trntensor.conv_tp_spec(module=model.interactions[1].conv_tp)
55
+ ```
56
+
57
+ ## `symmetric_contraction(x, species, spec) -> Tensor`
58
+
59
+ MACE's `SymmetricContraction`, correlation ν ≤ 3:
60
+
61
+ ```
62
+ out[n, c, m] = Σ_ν Σ_k W_ν[z_n, k, c] · Σ_{a_1..a_ν} U_ν[m, a_1..a_ν, k] · Π_j x[n, c, a_j]
63
+ ```
64
+
65
+ `x [N, C, 16]`, `species [N]` (int64 indices into the weight tables).
66
+ Returns `[N, Σ C·d_out]` in MACE's layout (output irreps in order, each
67
+ `[C, d_out]` row-major). Gradient: `∂x`.
68
+
69
+ ### `symmetric_contraction_spec(*, module=None, contractions=None) -> SymmetricContractionSpec`
70
+
71
+ - `module=`: a MACE `SymmetricContraction` or product block. Each
72
+ `Contraction`'s `U_matrix_ν` buffers and weights are read (`weights_max` is
73
+ ν = correlation, `weights[j]` is ν = correlation − 1 − j).
74
+ - `contractions=`: one mapping per output irrep with `d_out`, `correlation`,
75
+ `U` (`{ν: [d_out, 16, …, 16, K_ν]}`, dense or COO) and `W` (`{ν: [Z, K_ν, C]}`).
76
+
77
+ ## `wigner_3j(l1, l2, l3)`, `wigner_D(l, alpha, beta, gamma)`
78
+
79
+ e3nn-compatible real Wigner-3j symbols (`l ≤ 3`, checked against e3nn 0.4.4 to
80
+ 1e-15) and Wigner D matrices (Euler `Y(α) X(β) Y(γ)`). `C` is invariant under
81
+ `D` on all three indices; the tests use this for the equivariance checks.
82
+
83
+ ## Backends
84
+
85
+ | `set_backend` | what runs |
86
+ |---|---|
87
+ | `"pytorch"` | the fused PyTorch formulation on the operands' device |
88
+ | `"nki"` | the NKI kernels, one launch per direction per layer; float64 is computed in fp32 with a one-time warning |
89
+ | `"auto"` | the NKI kernels for fp32 operands on the `neuron` device (native TorchNeuron path); the fused PyTorch path everywhere else. `TRNTENSOR_EQUIVARIANT_NKI=0` keeps `"auto"` on the PyTorch path. float64 on the `neuron` device is computed on the host. |
90
+
91
+ `"auto"` uses the kernels on the device since their Trn2 validation
92
+ (trntensor#139). `TRNTENSOR_REQUIRE_NKI=1` raises instead of falling back.
93
+
94
+ ## Design
95
+
96
+ ### The fused PyTorch path
97
+
98
+ - **conv_tp.** One matmul `y @ cg` builds every per-edge coupling block
99
+ `G[e] ∈ R^{D1×K}` from a dense block-CG matrix (`[16, 4·40]` at layer 1,
100
+ α folded in). Here `D1 = Σ (2 l1 + 1)` (4 at layer 1) and `K = Σ_p (2 l3 + 1)` (40).
101
+ One batched product `x_cat @ G` follows, then one broadcast multiply by
102
+ `w` per *run* of paths. A run is a group of consecutive paths with the same
103
+ `2 l3 + 1` and consecutive output blocks; MACE-MP has 4 runs per layer. The
104
+ multiply writes straight into strided views of the output in e3nn's layout.
105
+ The forward is 7 aten launches at layer 0 and 8 at layer 1, the backward
106
+ about 29. e3nn's codegen is 34 forward and 144 forward + backward at layer 1.
107
+ The backward recomputes the intermediates rather than saving them, and it is
108
+ built from differentiable ops, so double backward (training on forces) works.
109
+ - **symmetric_contraction.** The coupling tensors are folded onto the
110
+ *symmetric monomial basis*: products `x_{a1} … x_{aν}` with `a1 ≤ … ≤ aν`
111
+ and a non-zero coupling, 410 of the 968 at layer 0 and 94 at layer 1. Per
112
+ row `(node, channel)`, `out = ((mono @ usym) ⊙ W[z_n, c]) @ S`. That is one
113
+ `[rows, 410] × [410, 202]` matmul at layer 0, where MACE runs
114
+ `[rows, 768] × [768, 816]` plus `bmm`.
115
+
116
+ ### The NKI kernels
117
+
118
+ **conv_tp**:
119
+
120
+ - Edges sit on the 128 partitions and channels on the free axis. Each operand
121
+ row is one contiguous DMA per tile of 128 edges.
122
+ - `G = y_tile @ cg` is one Tensor Engine matmul. The compact `cg`
123
+ (`[16, Q]`, `Q = Σ_p d1·d3` = 88 at layer 1) stays in SBUF for the whole kernel.
124
+ - Each column of `G` is a per-partition scalar. So every term of
125
+ `out_p[:, u, k] = Σ_i (x_i ⊙ w_p) · G[:, (p, i, k)]` is one `[128, U]`
126
+ instruction:
127
+ - the `x_i ⊙ w_p` products run on GpSimd;
128
+ - the first term of each `k` runs on the Scalar Engine;
129
+ - the accumulating terms run on the Vector Engine.
130
+ - e3nn's layouts are read and written through strided SBUF views.
131
+ - Per 128-edge tile that is 110 instructions forward at layer 1, and about
132
+ 30 KiB (forward) or 40 KiB (backward) of the 192 KiB per partition.
133
+ - The backward reduces the 128 channels for `∂G` with the Vector Engine's
134
+ fused free-axis reduction. `∂y = ∂G @ cgᵀ` is then a Tensor Engine
135
+ transpose and one matmul.
136
+
137
+ **symmetric_contraction**:
138
+
139
+ - Rows `(node, channel)` are on the free axis, 512 per block. The small axes
140
+ are on partitions: features, monomials, coupling columns `(irrep, m, ν, k)`
141
+ and outputs.
142
+ - Every contraction is a Tensor Engine matmul accumulating in PSUM:
143
+ - 0/1 selections that form the monomial factors;
144
+ - the folded couplings;
145
+ - the reduction over `(ν, k)`.
146
+ - All constants stay in SBUF. PSUM use is 7 of 8 banks.
147
+ - Species enter only as a host-side row gather of the folded weight table.
148
+
149
+ **Launches.** One kernel per direction per layer. Edge counts are padded to
150
+ coarse buckets (a multiple of 256; 10,392 and 10,378 edges both run at 11,264),
151
+ so the small changes in E between MD steps reuse one compiled kernel. No index
152
+ is compiled in.
153
+
154
+ **Autograd.** On the native TorchNeuron path, `trntensor::conv_tp` and
155
+ `trntensor::symcon` are `nki_op` custom ops with `register_autograd`. Their
156
+ backward ops are `trntensor::conv_tp_bwd` and `trntensor::symcon_bwd`. On the
157
+ XLA path and the CPU simulator, `torch.autograd.Function` wrappers run the
158
+ same kernels. The backward kernels are first order. When autograd records
159
+ the backward (`create_graph=True`, training on forces), the backward is
160
+ built from differentiable aten ops on the same padded operands instead, so
161
+ double backward works on every path; forces (first order) stay on the
162
+ kernels.
163
+
164
+ ## Tests
165
+
166
+ - `tests/test_equivariant.py` runs on CPU:
167
+ - against MACE's captured outputs and gradients (the exemplar's fixture);
168
+ - against the per-path reference;
169
+ - fp64 `gradcheck` and `gradgradcheck`;
170
+ - equivariance under random rotations;
171
+ - spec builders from explicit irreps, e3nn and MACE modules.
172
+ - `tests/test_equivariant_native.py` runs on CPU. It covers autograd and op
173
+ registration with emulated kernels.
174
+ - `tests/test_equivariant_nki.py` needs `nki`. It runs MLIR `verify()` for
175
+ trn1/trn2 at LNC 1 and 2, and `nki.simulate` against MACE.
176
+ - `tests/test_equivariant_neuron.py` runs on device. It checks correctness at
177
+ the 216- and 1728-atom shapes, checks captures, and has the timing harness.
@@ -1,9 +1,11 @@
1
1
  # API Reference
2
2
 
3
- trntensor's public API is organized into four modules:
3
+ trntensor's public API is organized into these modules:
4
4
 
5
5
  - **[einsum](einsum.md)** — `einsum`, `multi_einsum`
6
6
  - **[plan](plan.md)** — `plan_contraction`, `ContractionPlan`, `estimate_flops`
7
7
  - **[decompose](decompose.md)** — `cp_decompose`, `tucker_decompose`, and reconstructors
8
8
  - **[quantum](quantum.md)** — fused chemistry primitives (`mp2_energy`, `ao_to_mo_transform`, `df_exchange`, `df_coulomb`)
9
+ - **[equivariant](equivariant.md)** — MACE-style equivariant contractions (`conv_tp`, `symmetric_contraction`) with forward and input gradients
10
+ - **[mlip_edge](mlip_edge.md)** — the rest of a MACE step as fused ops with analytic backwards (`spherical_harmonics`, `edge_chain`, `equivariant_linear`) and compiled regions (`set_region_backend`)
9
11
  - **[nki](nki.md)** — backend dispatch (`set_backend`, `get_backend`, `HAS_NKI`)
@@ -0,0 +1,84 @@
1
+ # MLIP edge and node ops
2
+
3
+ The MACE-MP-0b2 medium energy + forces step on Trn2 (216 atoms, 10,392 edges)
4
+ took 118 ms with the equivariant contractions and the graph gather / segment
5
+ sum on trntensor and trnsparse kernels. About 92 ms of that was MACE's
6
+ remaining 1,503 aten ops, each launched separately
7
+ ([trnsci/trnsci#178](https://github.com/trnsci/trnsci/issues/178)). These
8
+ ops replace the largest groups. Each one is one autograd node with an
9
+ analytic backward, so forces (`-dE/dpositions`) still come from autograd.
10
+
11
+ | op | replaces (MACE / e3nn) | gradient |
12
+ |---|---|---|
13
+ | `spherical_harmonics(vectors, lmax=3)` | `o3.SphericalHarmonics(..., normalize=True, normalization="component")` | ∂vectors |
14
+ | `edge_chain(lengths, spec, r0)` | `RadialEmbeddingBlock` (Agnesi, Bessel, polynomial cutoff), every interaction's `conv_tp_weights` and `tanh(density_fn(·)²)` | ∂lengths |
15
+ | `equivariant_linear(x, spec, species=None)` | `o3.Linear`; the one-hot `FullyConnectedTensorProduct` (`skip_tp`) | ∂x |
16
+
17
+ ## `spherical_harmonics(vectors, lmax=3, normalize=True, normalization="component", eps=1e-12)`
18
+
19
+ This uses e3nn 0.4's real basis, component order and normalisation for
20
+ `l ≤ 3`. `normalize=True` divides by `max(|v|, eps)`, as
21
+ `torch.nn.functional.normalize` does. Every component is a polynomial of
22
+ degree `≤ l` in the unit vector, so the forward is one matmul of the
23
+ degree-1…3 monomials against a fixed `[19, 16]` coefficient matrix
24
+ (`sh_coefficients`). The backward is one matmul against the derivative
25
+ tables plus the projection of the normalisation.
26
+
27
+ ## `edge_chain_spec(...)` and `edge_chain(lengths, spec, r0=None)`
28
+
29
+ `edge_chain_spec(module=model)` reads a MACE model. It takes the radial
30
+ embedding and, per interaction, `conv_tp_weights` (head `tp_w{i}`) and
31
+ `density_fn` with `post="tanh_sq"` (head `density{i}`). Explicit
32
+ construction takes `r_max`, `num_basis`, `cutoff_p`, `agnesi=(a, q, p)`,
33
+ `apply_cutoff` and `EdgeMLP` heads. Each head holds effective matrices with
34
+ e3nn's `1/√fan_in` and `normalize2mom` constants folded in.
35
+
36
+ `edge_chain` returns one `[E, d_h]` tensor per head. The Agnesi species
37
+ constant `r0 = (R[z_s] + R[z_r]) / 2` depends only on the neighbour list.
38
+ MACE rebuilds it from integer gathers on every call; here it is an input,
39
+ `spec.agnesi_r0(z_sender, z_receiver)`, built once per neighbour list. An
40
+ edge at or past `r_max` contributes exactly zero, and so does its gradient.
41
+ Pad edge buckets with such edges.
42
+
43
+ ## `equivariant_linear_spec(module=None, *, elements=None, ...)` and `equivariant_linear(x, spec, species=None)`
44
+
45
+ The spec probes the module's dense map once in float64. It splits the map
46
+ per irrep type `(l, p)` into `K_l = W_l ⊗ I_{2l+1}` and checks the split
47
+ exactly. The op is then one matmul per irrep type and a concatenation, where
48
+ e3nn runs 62 aten ops for one 128x0e+…+128x3o linear. For the one-hot skip
49
+ tensor product, `elements` lists the species present; each node keeps its
50
+ own species' block. `mode="dense"` uses one matmul against the full matrix.
51
+
52
+ ## Backends
53
+
54
+ - **PyTorch path** (default everywhere). This is a short chain of aten ops
55
+ per direction. Against MACE-MP-0b2 at the six exemplar captures, outputs
56
+ match MACE fp32 to ≤ 4.6e-7 relative. Input gradients for the real
57
+ force-step cotangents are at most as far from fp64 as MACE's own fp32
58
+ gradients (`examples/mlip/check_fused.py`).
59
+ - **Compiled regions**: `set_region_backend("neuron")` (or
60
+ `TRNTENSOR_REGION_BACKEND`). The forward and the backward bodies each run
61
+ as one `torch.compile(dynamic=False)` graph per call site. Pad edge counts
62
+ to a bucket to avoid a recompile per geometry.
63
+ - **NKI kernels** for `spherical_harmonics` and `edge_chain`
64
+ (`trntensor/nki/_edge_kernels.py`), one launch per direction. Edges are
65
+ laid out partition-major, so each elementwise step is one instruction over
66
+ a `[128, J]` plane of edges. The radial MLPs run on the Tensor Engine with
67
+ the weights resident in SBUF and PSUM accumulation. `sin` runs as
68
+ `sin(π − w x)` to stay in the Scalar Engine's accurate `[−π, π]` range; the
69
+ host routes only specs where `max(w)·x ≤ 2π` (Agnesi transform). The
70
+ kernels pass MLIR verification for trn1 and trn2 (LNC 1 and 2) and match
71
+ the fp64 PyTorch path in `nki.simulate`. They are not yet validated on a
72
+ device, so `"auto"` does not route to them; use `set_backend("nki")` or
73
+ `TRNTENSOR_EDGE_NKI=1`.
74
+
75
+ ## Tests
76
+
77
+ - `tests/test_edge.py` (CPU): the MACE fixture `fixtures/mace_mp0b2_edge.pt`,
78
+ e3nn and MACE modules when installed, fp64 `gradcheck` / `gradgradcheck`,
79
+ equivariance, padding and compiled regions.
80
+ - `tests/test_edge_native.py` (CPU): registered ops, autograd, routing and
81
+ weight packing, with the kernels emulated by their contracts.
82
+ - `tests/test_edge_nki.py` (`nki`): MLIR verification and `nki.simulate`.
83
+ - `tests/test_edge_neuron.py` (device): correctness at 216 and 1728 atoms,
84
+ and a timing harness (`TRNTENSOR_EDGE_BENCH_JSON=…`).
@@ -27,6 +27,8 @@ nav:
27
27
  - Decompositions: api/decompose.md
28
28
  - Quantum primitives: api/quantum.md
29
29
  - Streaming DF integrals: api/stream.md
30
+ - Equivariant contractions: api/equivariant.md
31
+ - MLIP edge and node ops: api/mlip_edge.md
30
32
  - NKI dispatch: api/nki.md
31
33
  - Architecture: architecture.md
32
34
  - Benchmarks: benchmarks.md
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "trntensor"
7
- version = "0.25.2"
7
+ version = "0.27.0"
8
8
  description = "Tensor contractions for AWS Trainium via NKI"
9
9
  readme = "README.md"
10
10
  license = "Apache-2.0"
@@ -93,6 +93,7 @@ ignore = [
93
93
  # look unused to the linter, etc). Don't fight the kernel authoring loop.
94
94
  "trntensor/nki/_kernels.py" = ["F841", "B007"]
95
95
  "trntensor/nki/dispatch.py" = ["F841", "B007"]
96
+ "trntensor/nki/_equivariant_kernels.py" = ["F841", "B007"]
96
97
  "scripts/*" = ["F401"]
97
98
  "tests/*" = ["F401", "F811"]
98
99
 
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env python3
2
+ """Merge device conformance summaries and list the NEW failures.
3
+
4
+ A device conformance run (``pytest tests/test_conformance.py --backend nki
5
+ --conformance-device neuron``) marks known platform limits as
6
+ ``xfail(strict=False)`` with a ``[device-known:<category>]`` reason, and prints
7
+ a summary at the end. Runs on a Trainium box are split into chunks, so pass
8
+ ``--conformance-json PATH`` to each chunk and merge them here::
9
+
10
+ pytest tests/test_conformance.py --backend nki --conformance-device neuron \\
11
+ -k "<chunk>" --conformance-json chunk1.json
12
+ python scripts/conformance_expect.py chunk*.json
13
+
14
+ Prints passed, xfailed by category, XPASS by category (a known category that
15
+ now passes: a signal, not a failure) and the NEW failures. Exits 1 if there
16
+ are NEW failures, else 0.
17
+ """
18
+
19
+ from __future__ import annotations
20
+
21
+ import argparse
22
+ import json
23
+ import sys
24
+
25
+
26
+ def merge(paths):
27
+ out = {"passed": 0, "skipped": 0, "xfailed": {}, "xpassed": {}, "new_failures": []}
28
+ for p in paths:
29
+ with open(p) as fh:
30
+ s = json.load(fh)
31
+ out["passed"] += s["passed"]
32
+ out["skipped"] += s["skipped"]
33
+ for key in ("xfailed", "xpassed"):
34
+ for cat, ids in s[key].items():
35
+ out[key].setdefault(cat, []).extend(ids)
36
+ out["new_failures"].extend(s["new_failures"])
37
+ return out
38
+
39
+
40
+ def report(s, verbose=False):
41
+ lines = ["conformance expectations (device run)"]
42
+ lines.append(f" passed: {s['passed']} skipped: {s['skipped']}")
43
+ for key, label in (("xfailed", "xfailed"), ("xpassed", "XPASS (known category now passes)")):
44
+ lines.append(f" {label}: {sum(len(v) for v in s[key].values())}")
45
+ for cat, ids in sorted(s[key].items()):
46
+ lines.append(f" {cat}: {len(ids)}")
47
+ if verbose or key == "xpassed":
48
+ lines.extend(f" {i}" for i in ids)
49
+ lines.append(f" NEW failures: {len(s['new_failures'])}")
50
+ lines.extend(f" {i}" for i in s["new_failures"])
51
+ return "\n".join(lines)
52
+
53
+
54
+ def main(argv=None):
55
+ ap = argparse.ArgumentParser(description=__doc__.split("\n\n")[0])
56
+ ap.add_argument("json", nargs="+", help="--conformance-json files from device runs")
57
+ ap.add_argument("-v", "--verbose", action="store_true", help="list xfailed IDs too")
58
+ args = ap.parse_args(argv)
59
+ s = merge(args.json)
60
+ print(report(s, args.verbose))
61
+ return 1 if s["new_failures"] else 0
62
+
63
+
64
+ if __name__ == "__main__":
65
+ sys.exit(main())