# Extracting Singular Values of an entanglement cut within a Quantum Number Block

**URL:** <https://itensor.discourse.group/t/extracting-singular-values-of-an-entanglement-cut-within-a-quantum-number-block/2084>\
**Category:** ITensor Julia Questions\
**Tags:** entanglement, mps\
**Created:** [October 24, 2024, 5:28am UTC](https://itensor.discourse.group/t/extracting-singular-values-of-an-entanglement-cut-within-a-quantum-number-block/2084 "2024-10-24T05:28:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![amoghanakru](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@amoghanakru](https://itensor.discourse.group/u/amoghanakru)\
**Post date:** [October 24, 2024, 5:28am UTC](https://itensor.discourse.group/t/extracting-singular-values-of-an-entanglement-cut-within-a-quantum-number-block/2084/1 "2024-10-24T05:28:10Z")

</div>

Hi, I want to ask a question that is sort of a follow-up/continuation of this question: [How to realize momentum Entanglement spectrum in ITensor.jl - #3 by kevinh](https://itensor.discourse.group/t/how-to-realize-momentum-entanglement-spectrum-in-itensor-jl/750/3). The goal of that question (which is my goal as well) is to compute, given an entanglement cut of a QN-conserving wavefunction, the pairs/tuples of Schmidt eigenvalues and the quantum numbers.

If I compute the SVD of a QN-conserving MPS `psi` like so:

```auto
psi = orthogonalize(psi, b)
  U, S, V = svd(psi[b], (linkind(psi, b - 1), siteind(psi, b)))

```

the object S is an ITensor whose entries (singular values) can be accessed with `S[n,n]` for `n in 1:size(S)[1]`. The eigenbasis of the singular value matrix is block diagonal in the quantum number basis, and the code above produces an `S` that does contain the QN information. For example, if we display `S` in the terminal, the output is

```auto
ITensor ord=2
Dim 1: (dim=181|id=976|"Link,u") <Out>
 1: QN(("A",1),("B",32)) => 6
 2: QN(("A",1),("B",31)) => 13
 ...
 13: QN(("A",-1),("B",-32)) => 6
Dim 2: (dim=181|id=747|"Link,v") <Out>
 1: QN(("A",-1),("B",-32)) => 6
 2: QN(("A",-1),("B",-31)) => 13
 ...
 13: QN(("A",1),("B",32)) => 6

```

where “A”, “B” are two quantum numbers. Doing `println(S)` actually prints (along with the above code) the matrix entries corresponding to singular value matrix, in Blocks corresponding to the QN sectors:

```auto
NDTensors.DiagBlockSparse{Float64, Vector{Float64}, 2}
 181×181
Block(1, 1)
 [1:6, 1:6]
 0.00028918907365869354 0.0 0.0 0.0 0.0 0.0
 0.0 7.634975754941061e-5 0.0 0.0 0.0 0.0
 0.0 0.0 6.501313181278113e-5 0.0 0.0 0.0
 0.0 0.0 0.0 1.5586653810441255e-5 0.0 0.0
 0.0 0.0 0.0 0.0 8.979528300027936e-6 0.0
 0.0 0.0 0.0 0.0 0.0 2.2726487218800084e-6
#other blocks to follow

```

From the print output, I can of course recover the singular values within a QN block of my choice. However, this is messy, and I would much rather have a way to input a given QN sector (like ((“A”,1),(“B”,32))) and recover the corresponding block of the SVD matrix (which in my example is a square matrix only because the left/right bond dimensions are equal). I unfortunately couldn’t see how to do this sort of operation by digging through the ITensors.jl code (and through related questions on this forum), and I would definitely appreciate any direction.

Thanks very much,

Amogh

---

<div class="post-metadata">

**Author:** ![mtfishman](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/mtfishman/32/11_2.png) [@mtfishman](https://itensor.discourse.group/u/mtfishman)\
**Post date:** [October 24, 2024, 1:55pm UTC](https://itensor.discourse.group/t/extracting-singular-values-of-an-entanglement-cut-within-a-quantum-number-block/2084/2 "2024-10-24T13:55:51Z")

</div>

I think this is the best way to do that right now:

```julia
using ITensors: Block, Index, QN, commonind, dag, random_itensor, space
using LinearAlgebra: svd

i = Index([QN(0) => 2, QN(1) => 3], "i")
j = Index([QN(0) => 2, QN(1) => 3], "j")
A = random_itensor(i, dag(j))
U, S, V = svd(A, i)
u = commonind(S, U)
v = commonind(S, V)
b1 = findfirst(b -> first(b) == QN(1), space(u))
b2 = findfirst(b -> first(b) == QN(1), space(v))
S[Block(b1, b2)]

```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/itensor/original/1X/d3072b13e047cd06df7f3981547c0917d940dfa4.png) [@system](https://itensor.discourse.group/u/system)\
**Post date:** [November 3, 2024, 1:56pm UTC](https://itensor.discourse.group/t/extracting-singular-values-of-an-entanglement-cut-within-a-quantum-number-block/2084/3 "2024-11-03T13:56:01Z")

</div>

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.
