Skip to content

Support broadcasting on operators and dot on graded named arrays#233

Merged
mtfishman merged 1 commit into
mainfrom
mf/operator-broadcast-dynamic-rank
Jun 18, 2026
Merged

Support broadcasting on operators and dot on graded named arrays#233
mtfishman merged 1 commit into
mainfrom
mf/operator-broadcast-dynamic-rank

Conversation

@mtfishman

@mtfishman mtfishman commented Jun 18, 2026

Copy link
Copy Markdown
Member

Summary

Lets operator-backed and graded-backed named arrays go through linear algebra without falling into the generic AbstractArray paths, which assume a statically known ndims or use scalar indexing.

Base.broadcastable on AbstractNamedDimsOperator peels an operator to its state, so broadcasting and the array operations that lower to it (+, -, scalar multiplication) run on the underlying state. Without it they threw TypeError: expected Int64, got Type{Any} when the operator's parent is dynamically ranked, as it is when backed by an ITensor. The result is a bare state, dropping the operator wrapper, matching *.

dot becomes the full contraction (conj(a1) * a2)[], which aligns the legs by name and reduces through the contraction backend. The generic definition scalar-indexes, which graded arrays reject.

Together these let ITensorNetworksNext run belief propagation with operator-valued messages, where message normalization and the convergence check exercise both paths.

@codecov

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.38%. Comparing base (5da084a) to head (de6890b).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #233      +/-   ##
==========================================
+ Coverage   72.97%   73.38%   +0.40%     
==========================================
  Files          20       20              
  Lines        1051     1052       +1     
==========================================
+ Hits          767      772       +5     
+ Misses        284      280       -4     
Flag Coverage Δ
docs 26.28% <0.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mtfishman mtfishman force-pushed the mf/operator-broadcast-dynamic-rank branch from d0d1f0d to a69afbd Compare June 18, 2026 16:56
@mtfishman mtfishman changed the title Define +, -, and scalar multiplication for named operators Peel named operators to their state when broadcasting Jun 18, 2026
@mtfishman mtfishman force-pushed the mf/operator-broadcast-dynamic-rank branch from a69afbd to ec4e417 Compare June 18, 2026 16:56
Lets operator-backed and graded-backed named arrays go through linear algebra without
falling into the generic `AbstractArray` paths, which assume a statically known
`ndims` or use scalar indexing.

`Base.broadcastable` on `AbstractNamedDimsOperator` peels an operator to its `state`,
so broadcasting and the array operations that lower to it (`+`, `-`, scalar
multiplication) run on the underlying state. Without it they threw `TypeError:
expected Int64, got Type{Any}` when the operator's parent is dynamically ranked, as it
is when backed by an `ITensor`. The result is a bare state, dropping the operator
wrapper, matching `*`.

`dot` becomes the full contraction `(conj(a1) * a2)[]`, which aligns the legs by name
and reduces through the contraction backend. The generic definition scalar-indexes,
which graded arrays reject.

Together these let ITensorNetworksNext run belief propagation with operator-valued
messages, where message normalization and the convergence check exercise both paths.
@mtfishman mtfishman force-pushed the mf/operator-broadcast-dynamic-rank branch from ec4e417 to de6890b Compare June 18, 2026 17:49
@mtfishman mtfishman changed the title Peel named operators to their state when broadcasting Support broadcasting on operators and dot on graded named arrays Jun 18, 2026
@mtfishman mtfishman merged commit 5a01577 into main Jun 18, 2026
22 checks passed
@mtfishman mtfishman deleted the mf/operator-broadcast-dynamic-rank branch June 18, 2026 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant