Repository navigation
Conversation
`_instantiate_operators` ran all of the work of the `MPOHamiltonian` constructors inside `map(collect(local_operators)) do term ... end`. Below that `map` call, type inference applies its recursion limit to every nested `map` over a vector whose element type is not concrete, such as `map(dual, S.spaces)` in `dual(::SumSpace)`. The limited results are not cached, so each function between the two `map` calls is inferred again at every call site (JuliaLang/julia#64862). A comprehension gives the same result without a `map` frame at the root. First call of `InfiniteMPOHamiltonian([P, P], (1, 2) => h, (2, 3) => h)` from that issue: | Julia | before | after | |---------------|------------------|------------------| | 1.10.13 | 10.7 s, 4.5 GiB | 9.4 s, 3.5 GiB | | 1.13.3 | 36.0 s, 16.7 GiB | 16.8 s, 7.6 GiB | | 1.14.0-alpha2 | 29.5 s, 16.4 GiB | 14.7 s, 7.9 GiB | Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Put inference barriers around the calls in `_instantiate_operators` that receive the untyped representatives, and reorder the inverse `swap!` contraction so that `τ'` is not the first `@plansor` tensor. That ordering threw `UndefVarError: τ` (QuantumKitHub/TensorKit.jl#622), and since it was an undefined global it also made the whole method infer abstractly. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Group the representatives in `_instantiate_operators` by operator type, so that each group is a concretely typed vector. This removes the abstract inference that the inference barriers worked around, so those barriers are removed. Proportional operators of different types (e.g. a real and a complex copy of the same operator) no longer share a decomposition. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # src/operators/mpohamiltonian.jl
Codecov Report✅ All modified and coverable lines are covered by tests.
🚀 New features to boost your workflow:
|
Without it, `instantiate_operator` is inferred inside the comprehension of `_instantiate_operators`. For a nearest-neighbour `FiniteMPOHamiltonian` that takes minutes on Julia 1.12 (SU(2) Heisenberg chain of 12 sites: 302 s, with the barrier 29 s) and about twice as long on 1.13.3 (41 s vs 20 s). The infinite case is unaffected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This builds on #556 and contains its commits, so it should be merged after #556. Only the commits "Store the representatives in concretely typed vectors" and "Restore the inference barrier on
instantiate_operator" are new here.#556 puts inference barriers around the calls that use the
representativesof_instantiate_operators. This PR fixes the cause instead: the representatives are grouped by operator type, so each group is stored in a concretely typed vector.FiniteMPO(O)already infers concretely, soBase.promote_op(FiniteMPO, typeof(O))gives the element type of each group. With that, the barriers on_proportionalityand on rescaling the last tensor are removed. The barrier oninstantiate_operatorstays, because the finite case needs it (see below).Behaviour change: proportional operators are now only merged when they have the same type. For example, a real and a complex copy of the same operator no longer share a decomposition, and so no longer share virtual channels. Both are still built correctly; the bond dimension can just be larger in that case. No existing test covers it. This is why the change is in a separate PR.
On Julia 1.13.3, building the SU(2) Heisenberg
InfiniteMPOHamiltonianin a fresh process, from a single A/B run (the second column is without any barrier):swap!)With the barrier on
instantiate_operatorkept, the infinite first call was 15.8 s.That barrier matters for finite chains. First
FiniteMPOHamiltonian(fill(P, 12), (i, i + 1) => h for i in 1:11)for the same SU(2) Heisenberg term, with TensorKit 0.17.4, in a fresh process, both variants run at the same time:instantiate_operator)For the infinite Hamiltonian both variants took 19–27 s. On main, the same finite construction takes 320 s on 1.12 (see #556).
Locally, the
mpo/finite,hamiltonianandoperatorstest files pass with the barrier restored, andalgorithms/changebondspassed before.🤖 Generated with Claude Code