Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 2d heisenberg example and add error for bad unit cell inputs #88

Merged
merged 4 commits into from
Oct 14, 2024

Conversation

ryanlevy
Copy link
Contributor

As reported in https://itensor.discourse.group/t/vumps-example-2d-heisenberg-model-interaction-term/2052?u=ryanlevy

The 2D heisenberg example misses some operators, which is fixed in this version. I've also included a warning to help users catch this in the future, happy to take suggestions on alternative "fixes"

@ryanlevy
Copy link
Contributor Author

I'm unable to replicate the errors from the CI at the moment (on 1.10.4), all tests pass locally for me

@mtfishman
Copy link
Member

It looks like it may be specific to Julia 1.11, it was just released and the CI started testing against that automatically.

@mtfishman
Copy link
Member

Here is a minimal code that reproduces the test failure in Julia 1.11:

using ITensors: ITensor, Index
i = Index(2)
a = reshape([ITensor(), ITensor(i)], 1, 2)
b = reshape([ITensor(2.0), ITensor(2.0, i)], 2, 1)
a * b

which leads to an error:

ERROR: StackOverflowError:
Stacktrace:
      [1] promote_result(::Type, ::Type, ::Type{NDTensors.EmptyNumber}, ::Type{Bool})
        @ Base ./promotion.jl:338
      [2] promote_type
        @ ./promotion.jl:318 [inlined]--- the above 2 lines are repeated 79982 more times ---

so it is related to performing matrix multiplication of matrices of ITensors where some of the ITensors are not initialized.

@mtfishman
Copy link
Member

It looks like there were a few missing promote_rule definitions for EmptyNumber, defining the following:

using NDTensors: EmptyNumber
Base.promote_rule(::Type{T}, ::Type{EmptyNumber}) where {T<:Number} = T
Base.promote_rule(::Type{Bool}, ::Type{EmptyNumber}) = Bool

seems to fix the issue. I'll make a PR to NDTensors.jl.

@mtfishman
Copy link
Member

Here are more minimal examples that error with stack overflows without those new definitions:

promote_type(Bool, EmptyNumber)
promote_type(EmptyNumber, Bool)

@ryanlevy
Copy link
Contributor Author

Thanks @mtfishman ! I can check things in InfiniteMPS once that's sorted (there looks like some deprecated Vararg calls I can open a PR for later)

@mtfishman
Copy link
Member

mtfishman commented Oct 12, 2024

ITensor/ITensors.jl#1541 is now merged, that should fix the test failures in Julia 1.11.

@mtfishman
Copy link
Member

Looks good, thanks Ryan! I'll merge once tests pass.

@mtfishman mtfishman merged commit fc1078a into ITensor:main Oct 14, 2024
6 checks passed
@mtfishman mtfishman changed the title Fix 2d heisenberg example and add warning Fix 2d heisenberg example and add error for bad unit cell inputs Oct 14, 2024
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.

2 participants