Skip to content

[ENHANCEMENT] Defined loginner(::ITensor, ::ITensor) methods#1714

Open
sotashimozono wants to merge 5 commits intoITensor:mainfrom
sotashimozono:feature/loginner
Open

[ENHANCEMENT] Defined loginner(::ITensor, ::ITensor) methods#1714
sotashimozono wants to merge 5 commits intoITensor:mainfrom
sotashimozono:feature/loginner

Conversation

@sotashimozono
Copy link

@sotashimozono sotashimozono commented Mar 9, 2026

Description

I implemented loginner and logdot methods.
Fixes #1552

In the previous implementation for MPS/MPO, the contraction order was well-defined, and we utilized a specialized method to compute the inner product in the logarithmic scale.

For general ITensor objects, however, the optimal contraction sequence is not uniquely determined. Therefore, I have implemented a straightforward fallback as follows:

inner(y::ITensor, x::ITensor) = (dag(y) * x)[]
loginner(A::ITensor, B::ITensor) = log(complex(inner(A, B)))

example code:

i = Index(2)
j = Index(2)
A = random_itensor(ElType, i', j', i, j)
x = random_itensor(ElType, i, j)
y = random_itensor(ElType, i, j)


val2 = inner(x, y)
val3 = inner(x', A, y)

@assert loginner(x, y)  log(complex(val2))
@assert logdot(x, y)  log(complex(val2))

How Has This Been Tested?

I added testcode in test_itensor.jl

Checklist:

  • My code follows the style guidelines of this project. Please run the ITensorFormatter in the base directory of the repository (~/.julia/dev/ITensors) to format your code according to our style guidelines.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that verify the behavior of the changes I made.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • Any dependent changes have been merged and published in downstream modules.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2026

Your PR no longer requires formatting changes. Thank you for your contribution!

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.

[ITensors] [ENHANCEMENT] Define loginner(::ITensor, ::ITensor)

1 participant