# Bug report: Problems when using the MKL library to perform eigenvalue decomposition on the transverse field ising model

**URL:** <https://itensor.discourse.group/t/bug-report-problems-when-using-the-mkl-library-to-perform-eigenvalue-decomposition-on-the-transverse-field-ising-model/1805>\
**Category:** ITensor Julia Questions\
**Tags:** julia\
**Created:** [June 13, 2024, 2:59pm UTC](https://itensor.discourse.group/t/bug-report-problems-when-using-the-mkl-library-to-perform-eigenvalue-decomposition-on-the-transverse-field-ising-model/1805 "2024-06-13T14:59:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Huangzhiqiang](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/huangzhiqiang/32/576_2.png) [@Huangzhiqiang](https://itensor.discourse.group/u/Huangzhiqiang)\
**Post date:** [June 13, 2024, 2:59pm UTC](https://itensor.discourse.group/t/bug-report-problems-when-using-the-mkl-library-to-perform-eigenvalue-decomposition-on-the-transverse-field-ising-model/1805/1 "2024-06-13T14:59:22Z")

</div>

As the title says, when running the following code in Julia：

```julia
using ITensors, ITensorMPS, MKL
N = 12
g = 1.05
  sites = siteinds("S=1/2", N)
  os = OpSum()
  for j=1:N
    os += -4,"Sz",j,"Sz",j%N+1
    os += 2*g,"Sx",j;
  end
  H = MPO(os, sites)
  ITensors.disable_warn_order()
 H_full = contract(H);
 evt, Vt = eigen(H_full; ishermitian=true);

```

The program will give the wrong decomposition result, and norm(H\_full-Vt’_evt_Vt) ！≈0.  
I repeated the above error in computers using AMD 7840hs and 5900x.

---

<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:** [June 13, 2024, 3:01pm UTC](https://itensor.discourse.group/t/bug-report-problems-when-using-the-mkl-library-to-perform-eigenvalue-decomposition-on-the-transverse-field-ising-model/1805/2 "2024-06-13T15:01:18Z")

</div>

Does it work with another backend, like OpenBLAS?

---

<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:** [June 13, 2024, 3:01pm UTC](https://itensor.discourse.group/t/bug-report-problems-when-using-the-mkl-library-to-perform-eigenvalue-decomposition-on-the-transverse-field-ising-model/1805/3 "2024-06-13T15:01:48Z")

</div>

Also, how far off is it? What is the error?

---

<div class="post-metadata">

**Author:** ![Huangzhiqiang](https://yyz2.discourse-cdn.com/free1/user_avatar/itensor.discourse.group/huangzhiqiang/32/576_2.png) [@Huangzhiqiang](https://itensor.discourse.group/u/Huangzhiqiang)\
**Post date:** [June 13, 2024, 3:45pm UTC](https://itensor.discourse.group/t/bug-report-problems-when-using-the-mkl-library-to-perform-eigenvalue-decomposition-on-the-transverse-field-ising-model/1805/4 "2024-06-13T15:45:13Z")

</div>

The OpenBLAS works fine, the norm given by OpenBLAS is 1.2327681181461817e-12. The MKL gives 281.4977875674409.

---

<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:** [June 13, 2024, 4:05pm UTC](https://itensor.discourse.group/t/bug-report-problems-when-using-the-mkl-library-to-perform-eigenvalue-decomposition-on-the-transverse-field-ising-model/1805/5 "2024-06-13T16:05:19Z")

</div>

Interesting, thanks for the update. I’m not sure if there is much we can do about that since that sounds like a bug in MKL. You could convert that ITensor to a Julia Matrix, save it in a transferable file format (maybe with [HDF5.jl](https://github.com/JuliaIO/HDF5.jl) or as a [delimited file](https://docs.julialang.org/en/v1/stdlib/DelimitedFiles)), and report it as a bug to Julia’s MKL wrapper ([GitHub - JuliaLinearAlgebra/MKL.jl: Intel MKL linear algebra backend for Julia](https://github.com/JuliaLinearAlgebra/MKL.jl)) or raise it as an issue on Intel’s user forum: [Intel® oneAPI Math Kernel Library - Intel Community](https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/bd-p/oneapi-math-kernel-library).

You could also try other versions of MKL as described here: [GitHub - JuliaLinearAlgebra/MKL.jl: Intel MKL linear algebra backend for Julia](https://github.com/JuliaLinearAlgebra/MKL.jl?tab=readme-ov-file#note-mkl-on-intel-macs) to see if it is an issue particular to a certain version of MKL.

Finally, could you share the output of `versioninfo()` here so I can see what system and Julia version you are using?

---

<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:** [June 13, 2024, 4:08pm UTC](https://itensor.discourse.group/t/bug-report-problems-when-using-the-mkl-library-to-perform-eigenvalue-decomposition-on-the-transverse-field-ising-model/1805/6 "2024-06-13T16:08:56Z")

</div>

> [@Huangzhiqiang](#):
>
> `eigen(H_full; ishermitian=true)`

Does it change anything if you set `ishermitian=false`? That would call a different LAPACK routine so it would at least narrow down the issue a little bit.

Also, after you convert the ITensor to a Julia Matrix, you could try calling `LinearAlgebra.eigen` directly on that Julia Matrix (either wrapping it in `Symmetric`/`Hermitian` or not wrapping it to try out different LAPACK eigendecomposition backends), just to rule out the possibility that it is somehow related to the ITensor code wrapping the eigendecomposition.
