Skip to content

Add project convenience for symmetry-restricted arrays and TensorMap support#203

Merged
mtfishman merged 3 commits into
mainfrom
mf/projectto-tensormap
Jul 2, 2026
Merged

Add project convenience for symmetry-restricted arrays and TensorMap support#203
mtfishman merged 3 commits into
mainfrom
mf/projectto-tensormap

Conversation

@mtfishman

@mtfishman mtfishman commented Jul 2, 2026

Copy link
Copy Markdown
Member

Summary

Adds project, an owned convenience over the existing project_map hook for building a symmetry-restricted array from a dense one. The three-argument form takes an explicit codomain/domain split and the two-argument form takes a flat list of axes (an empty domain), both forwarding to project_map, and checked_project is the verified counterpart of checked_project_map. This mirrors the zeros/zeros_map pairing, where the unsuffixed name is the convenience that also accepts the codomain/domain split.

Also adds the TensorMap path in the TensorKit extension so project can build a TensorMap from a dense array: similar_map allocates a same-device buffer whose block storage type follows the dense prototype, projectto! fills the symmetry-allowed blocks through project_symmetric! and discards the rest, and checked_projectto! verifies the projection by densifying the result and reusing the dense path's elementwise isapprox(src, dest) check, so it keeps one InexactError/kwargs contract across backends.

The named-index project for AbstractITensor is added in ITensor/ITensorBase.jl#208.

…support

Adds `project`, an owned convenience over the existing `project_map` hook
for building a symmetry-restricted array from a dense one. The
three-argument form takes an explicit codomain/domain split and the
two-argument form takes a flat list of axes (an empty domain), both
forwarding to `project_map`. `checked_project` is the verified counterpart
of `checked_project_map`. This mirrors the `zeros`/`zeros_map` pairing,
where the unsuffixed name is the convenience that also accepts the
codomain/domain split.

Also adds the `TensorMap` path in the TensorKit extension so `project` can
build a `TensorMap` from a dense array: `similar_map` allocates a
same-device buffer whose block storage type follows the dense prototype,
`projectto!` fills the symmetry-allowed blocks through `project_symmetric!`
and discards the rest, and `checked_projectto!` verifies the projection by
norm, since a dense array and a `TensorMap` are not comparable elementwise
and projection onto the symmetric blocks preserves the norm exactly when
nothing is discarded.
@codecov

codecov Bot commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.47368% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.90%. Comparing base (ddf4dd7) to head (fdfeb56).

Files with missing lines Patch % Lines
ext/TensorAlgebraTensorKitExt.jl 84.61% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #203      +/-   ##
==========================================
- Coverage   84.03%   83.90%   -0.13%     
==========================================
  Files          24       24              
  Lines         739      758      +19     
==========================================
+ Hits          621      636      +15     
- Misses        118      122       +4     
Flag Coverage Δ
docs 24.69% <0.00%> (-0.67%) ⬇️

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.

The two `similar_map` methods for a dense prototype with space axes had
identical bodies and existed only to pin the elementary space type `S` from
whichever of codomain/domain is non-empty. Factor the body into a
`similar_tensormap` helper that takes `S` explicitly, matching the
`_map_homspace` helper and the two-entries-per-constructor pattern used for
the map constructors.
Densify the `TensorMap` destination with `convert(Array, ...)` and reuse the
dense path's `isapprox(src, dest)` check in `checked_projectto!` instead of the
norm-based shortcut, so the check keeps one `InexactError`/`kwargs` contract
across backends rather than diverging toward TensorKit's residual-norm
`tol`/`ArgumentError` check.
@mtfishman mtfishman marked this pull request as ready for review July 2, 2026 21:15
@mtfishman mtfishman enabled auto-merge (squash) July 2, 2026 21:15
@mtfishman mtfishman merged commit 48ea23e into main Jul 2, 2026
30 of 31 checks passed
@mtfishman mtfishman deleted the mf/projectto-tensormap branch July 2, 2026 21:40
mtfishman added a commit to ITensor/ITensorBase.jl that referenced this pull request Jul 2, 2026
## Summary

Adds methods extending `TensorAlgebra.project` and
`TensorAlgebra.checked_project` (added in
ITensor/TensorAlgebra.jl#203) that build a named
tensor from a dense array and the indices to attach. The three-argument
form takes a codomain/domain split (an operator), and the two-argument
form takes a flat list of indices (a state, i.e. an empty domain). The
index axes select the backend, so the same call builds an `Array` on
dense indices, a block-sparse array on graded indices, and a `TensorMap`
on TensorKit spaces. The named entry strips to the unnamed array plus
axes, lowers to `TensorAlgebra.project`, and reattaches the names.

This is the named-index projection primitive for building symmetric
operators and states from a dense basis matrix: `project(Sz, (i',),
(i,))` for an operator, `project(v, (i,))` for a state.
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