Cytnx icon indicating copy to clipboard operation
Cytnx copied to clipboard

conda install cytnx MKL problem.

Open Heliumky opened this issue 8 months ago • 11 comments

I followed the documentation to install Cytnx version 0.9.7. When I do not import the cytnx package, all NumPy-dependent code runs correctly, as shown below:

(cytnx) [jerrychen@cn7 2d_new]$ python3 test_bug.py (1.0000000000000004+0j)

However, after importing cytnx, the code triggers an Intel MKL-related error:

(cytnx) [jerrychen@cn7 2d_new]$ python3 test_bug.py

Intel oneMKL ERROR: Parameter 3 was incorrect on entry to ZHEEVD.

Intel oneMKL ERROR: Parameter 3 was incorrect on entry to ZHEEVD.

Intel oneMKL ERROR: Parameter 3 was incorrect on entry to ZHEEVD.

Intel oneMKL ERROR: Parameter 3 was incorrect on entry to ZHEEVD.

Intel oneMKL ERROR: Parameter 3 was incorrect on entry to ZHEEVD.

Intel oneMKL ERROR: Parameter 3 was incorrect on entry to ZHEEVD.

Intel oneMKL ERROR: Parameter 3 was incorrect on entry to ZHEEVD.

Intel oneMKL ERROR: Parameter 3 was incorrect on entry to ZHEEVD.

Intel oneMKL ERROR: Parameter 3 was incorrect on entry to ZHEEVD.

Intel oneMKL ERROR: Parameter 3 was incorrect on entry to ZHEEVD.

Intel oneMKL ERROR: Parameter 3 was incorrect on entry to ZHEEVD.

Intel oneMKL ERROR: Parameter 3 was incorrect on entry to ZHEEVD. Traceback (most recent call last): File "/data2/home/jerrychen/Jerry_work/2d_new/test_bug.py", line 130, in print(inner_MPS(psi0,psi0)) ^^^^^^^^^^^^^^^^^^^^ File "/data2/home/jerrychen/Jerry_work/2d_new/test_bug.py", line 12, in inner_MPS assert len(res) == 1 ^^^^^^^^^^^^^ AssertionError

Since GitHub does not allow attaching .py files directly, I have renamed the uploaded script with a .txt extension. Please kindly change the filename extension back to .py when testing.

Thank you very much for your help! test_bug.txt

Heliumky avatar Apr 28 '25 22:04 Heliumky

This might be related to #244 and #348

Cytnx defaults to MKL ilp64 interface but the one from conda uses lp64 interface, thus causing the trouble.

Maybe we should also ship lp64 version?

yingjerkao avatar Apr 29 '25 01:04 yingjerkao

Here is the code attached by the OP.

import sys
#import cytnx
import numpy as np
from ncon import ncon

def inner_MPS (mps1, mps2):
    assert len(mps1) == len(mps2)
    res = ncon([mps1[0], np.conj(mps2[0])], ((1,2,-1), (1,2,-2)))
    for i in range(1,len(mps1)):
        res = ncon([res,mps1[i],np.conj(mps2[i])], ((1,2), (1,3,-1), (2,3,-2)))
    res = res.reshape(-1)
    assert len(res) == 1
    return res[0]

def compress_MPS (mps, D=sys.maxsize, cutoff=0.):
    N = len(mps)
    #
    #        2 ---
    #            |
    #   R =      o
    #            |
    #        1 ---
    #
    Rs = [None for i in range(N+1)]
    Rs[-1] = np.array([1.]).reshape((1,1))
    for i in range(N-1, 0, -1):
        Rs[i] = ncon([Rs[i+1],mps[i],np.conjugate(mps[i])], ((1,2), (-1,3,1), (-2,3,2)))


    #
    #          2
    #          |
    #   rho =  o
    #          |
    #          1
    #
    rho = ncon([Rs[1],mps[0],np.conjugate(mps[0])], ((1,2), (-1,-2,1), (-3,-4,2)))
    rho = rho.reshape((rho.shape[1], rho.shape[3]))

    #         1
    #         |
    #    0 x--o-- 2
    #
    evals, U = np.linalg.eigh(rho)
    U = U.reshape((1,*U.shape))
    res = [U]

    #
    #        ---- 2
    #        |
    #   L =  |
    #        |
    #        ---- 1
    #
    L = np.array([1.]).reshape((1,1))
    for i in range(1,N):
        #
        #         2---(U)-- -2
        #         |    |
        #   L =  (L)   3
        #         |    |
        #         1---(A)--- -1
        #
        L = ncon([L,mps[i-1],np.conjugate(U)], ((1,2), (1,3,-1), (2,3,-2)))

        #
        #          -- -1
        #          |
        #   A =    |       -2
        #          |        |
        #         (L)--1--(mps)--- -3
        #
        A = ncon([L,mps[i]], ((1,-1), (1,-2,-3)))

        #
        #         -3 --(A)--2--
        #               |     |
        #              -4     |
        #   rho =            (R)
        #              -2     |
        #               |     |
        #         -1 --(A)--1--
        #
        rho = ncon([Rs[i+1],A,np.conjugate(A)], ((1,2), (-1,-2,1), (-3,-4,2)))
        d = rho.shape
        rho = rho.reshape((d[0]*d[1], d[2]*d[3]))

        #         1
        #         |
        #     0 --o-- 2
        #
        evals, U  = np.linalg.eigh(rho)
        # truncate by dimension
        DD = min(D, mps[i].shape[2])
        U = U[:,-DD:]
        evals = evals[-DD:]
        # truncate by cutoff
        iis = (evals > cutoff)
        U = U[:,iis]
        #
        U = U.reshape((d[2],d[3],U.shape[1]))
        res.append(U)
    return res

def random_MPS(N, phydim, seed, vdim=1, dtype=np.complex128):
    mps = []
    np.random.seed(seed)
    is_complex = np.issubdtype(dtype, np.complexfloating)
    for i in range(N):
        if i == 0:
            arr = np.random.rand(1, phydim, vdim).astype(dtype)
        elif i == N-1:
            arr = np.random.rand(vdim, phydim, 1).astype(dtype)
        else:
            arr = np.random.rand(vdim, phydim, vdim).astype(dtype)
        if is_complex:
            if i == 0:
                arr += 1j * np.random.rand(1, phydim, vdim).astype(dtype)
            elif i == N-1:
                arr += 1j * np.random.rand(vdim, phydim, 1).astype(dtype)
            else:
                arr += 1j * np.random.rand(vdim, phydim, vdim).astype(dtype)

        mps.append(arr)

    return mps

psi0 = random_MPS (12, 2, 15)
psi0 = compress_MPS (psi0, cutoff=1e-18)
print(inner_MPS(psi0,psi0))

IvanaGyro avatar Apr 29 '25 02:04 IvanaGyro

I checked the numpy version in my current cytnx environment, and it seems that it is linked to OpenBLAS rather than MKL. One strange point I noticed is that when installing Cytnx 0.9.7 via conda install -c kaihsinwu cytnx=0.9.7, the numpy that comes along is actually the OpenBLAS version, not the MKL version.

When I follow the instructions from the tenpy documentation to initially install the MKL version of numpy with conda install "libblas=*=*mkl" and then proceed to install cytnx, I noticed that cytnx replaces the previously installed numpy with a version that is dependent on cytnx. You can find the instructions I followed here:

https://tenpy.readthedocs.io/en/latest/install/conda.html

The key infomations of numpy shows below:

(cytnx) [jerrychen@cn7 ~]$ python Python 3.11.12 | packaged by conda-forge | (main, Apr 10 2025, 22:23:25) [GCC 13.3.0] on linux Type "help", "copyright", "credits" or "license" for more information.

import numpy as np np.show_config()

"Machine Information": { "host": { "cpu": "x86_64", "family": "x86_64", "endian": "little", "system": "linux" }, "build": { "cpu": "x86_64", "family": "x86_64", "endian": "little", "system": "linux" } }, "Build Dependencies": { "blas": { "name": "blas", "found": true, "version": "3.9.0", "detection method": "pkgconfig", "include directory": "/data2/home/jerrychen/anaconda3/envs/cytnx/include", "lib directory": "/data2/home/jerrychen/anaconda3/envs/cytnx/lib", "openblas configuration": "unknown", "pc file directory": "/data2/home/jerrychen/anaconda3/envs/cytnx/lib/pkgconfig" }, "lapack": { "name": "dep140567732183440", "found": true, "version": "1.26.4", "detection method": "internal", "include directory": "unknown", "lib directory": "unknown", "openblas configuration": "unknown", "pc file directory": "unknown" } }, "Python Information": { "path": "/data2/home/jerrychen/anaconda3/envs/cytnx/bin/python", "version": "3.11" },

Heliumky avatar Apr 29 '25 04:04 Heliumky

@Heliumky Per offline discussion, could you provide the outputs of these two command on both your workable and not workable device/environment? They show what BLAS libs are actually linked by NumPy and Cyntx.

ldd $(python -c "import numpy._core._multiarray_umath as m; print(m.__file__)") \
  | awk '/=>/ {
      orig = $1 " => " $3;
      cmd = "realpath " $3;
      cmd | getline real;
      close(cmd);
      print orig "  (real: " real ")"
    }'
ldd $(python -c "import cytnx; print(cytnx.cytnx.__file__)") \
  | awk '/=>/ {
      orig = $1 " => " $3;
      cmd = "realpath " $3;
      cmd | getline real;
      close(cmd);
      print orig "  (real: " real ")"
    }'

IvanaGyro avatar Apr 30 '25 09:04 IvanaGyro

I can reproduce the problem when NumPy links against BLIS and Cytnx links against the MKL Single Dynamic Library.

Here is the output of the minimal code to reproduce the problem when importing NumPy first.

import numpy as np
import cytnx

A = np.array([[1., -3.j], [3.j, 2.]], dtype=np.complex128)
print(np.linalg.matrix_rank(A, hermitian=True))

output:

cytnx/__init__.py:14: UserWarning: numpy and/or scipy are imported before cytnx. Please make sure it support ILP64.
  warnings.warn("numpy and/or scipy are imported before cytnx. Please make sure it support ILP64.")
2

And here is the code and the output when importing Cytnx first.

import cytnx
import numpy as np

A = np.array([[1., -3.j], [3.j, 2.]], dtype=np.complex128)
print(np.linalg.matrix_rank(A, hermitian=True))

output:

Intel MKL ERROR: Parameter 3 was incorrect on entry to ZHEEVD.
1

If Cytnx links against OpenBLAS instead (NumPy still links against BLIS), there is no error and the outputs are correct regardless of the order of the import statements.

IvanaGyro avatar Apr 30 '25 09:04 IvanaGyro

We need a smarter method to detect the validity of BLAS runtime. Currently, Cytnx only prints an warning when NumPy is imported before Cytnx. This is not a detection and is not enough either. Misalignment of BLAS runtime between Cytnx and other libraries using BLAS breaks other libraries and causes wrong calculation results even when Cytnx is imported first as the example in the previous comment.

Here is how NumPy detects the validity of BLAS runtime now. Obviously, it's not enough because it doesn't catch the case in the previous comment. However, we can adapt the similar strategy to do the detection.

https://github.com/numpy/numpy/blob/470c458aacda6ecd5207c7442cbe720833194c60/numpy/init.py#L430-L454

IvanaGyro avatar Apr 30 '25 13:04 IvanaGyro

@Heliumky For make your script workable in your environment, please check which BLAS library that your NumPy actually links against. I think Cytnx, both version 0.9.7 and 1.0.1, ships the acceptable MKL variant on conda now.

IvanaGyro avatar Apr 30 '25 13:04 IvanaGyro

@IvanaGyro Thanks for your helping, I found the tamporary way to solve the partial bug( but still have the bugs) that I reverse the ordering of import cytnx and numpy, and ignoring the warm information in the unworked machine:

  warnings.warn("numpy and/or scipy are imported before cytnx. Please make sure it support ILP64.")

Thanks for your minized the test_bug.txt. In the unworked machine, I also try the small script as:

import cytnx
import numpy as np

A = np.array([[1,0],[0,1]])
eigval, eigvec = np.linalg.eigh(A)
print(eigval)

firstly run, it outputs:

Intel oneMKL ERROR: Parameter 3 was incorrect on entry to DSYEVD.
[-2.00000000e+000 -4.39018811e+293]

secondly run, it outputs:

Intel oneMKL ERROR: Parameter 3 was incorrect on entry to DSYEVD.
[-2.00000000e+00  1.34302774e-05]

The eigval of A are [1,1] obviously.

I run the command

import cytnx
cytnx.__cpp_flags__

Output:

'-I/home/jerrychen/anaconda3/include -DUNI_HPTT -fopenmp '

running

cytnx.__cpp_linkflags__

Output:

'/opt/intel/oneapi/mkl/2025.0/lib/libmkl_rt.so -lm -ldl -lm -ldl -Wl,-rpath,/opt/intel/oneapi/mkl/2025.0/lib '

keep running

import numpy as np
np.show_config()

I pick up the important info from Output:

  "Build Dependencies": {
    "blas": {
      "name": "blas",
      "found": true,
      "version": "3.9.0",
      "detection method": "pkgconfig",
      "include directory": "/home/jerrychen/anaconda3/envs/cytnx/include",
      "lib directory": "/home/jerrychen/anaconda3/envs/cytnx/lib",
      "openblas configuration": "unknown",
      "pc file directory": "/home/jerrychen/anaconda3/envs/cytnx/lib/pkgconfig"
    },
    "lapack": {
      "name": "lapack",
      "found": true,
      "version": "3.9.0",
      "detection method": "pkgconfig",
      "include directory": "/home/jerrychen/anaconda3/envs/cytnx/include",
      "lib directory": "/home/jerrychen/anaconda3/envs/cytnx/lib",
      "openblas configuration": "unknown",
      "pc file directory": "/home/jerrychen/anaconda3/envs/cytnx/lib/pkgconfig"
    }
  },

running

ldd $(python -c "import numpy._core._multiarray_umath as m; print(m.__file__)") \
  | awk '/=>/ {
      orig = $1 " => " $3;
      cmd = "realpath " $3;
      cmd | getline real;
      close(cmd);
      print orig "  (real: " real ")"
    }'

Output:

libcblas.so.3 => /home/jerrychen/anaconda3/envs/cytnx/lib/python3.11/site-packages/numpy/_core/../../../../libcblas.so.3  (real: /home/jerrychen/anaconda3/envs/cytnx/lib/libmkl_rt.so.2)
libstdc++.so.6 => /home/jerrychen/anaconda3/envs/cytnx/lib/python3.11/site-packages/numpy/_core/../../../../libstdc++.so.6  (real: /home/jerrychen/anaconda3/envs/cytnx/lib/libstdc++.so.6.0.33)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6  (real: /usr/lib/x86_64-linux-gnu/libm.so.6)
libgcc_s.so.1 => /home/jerrychen/anaconda3/envs/cytnx/lib/python3.11/site-packages/numpy/_core/../../../../libgcc_s.so.1  (real: /home/jerrychen/anaconda3/envs/cytnx/lib/libgcc_s.so.1)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6  (real: /usr/lib/x86_64-linux-gnu/libc.so.6)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2  (real: /usr/lib/x86_64-linux-gnu/libdl.so.2)

running

ldd $(python -c "import cytnx; print(cytnx.cytnx.__file__)") \
  | awk '/=>/ {
      orig = $1 " => " $3;
      cmd = "realpath " $3;
      cmd | getline real;
      close(cmd);
      print orig "  (real: " real ")"
    }'

output

libpython3.11.so.1.0 => not  (real: /home/jerrychen/Downloads/QTTHydrogen-main/onebody/hydrogen/2d_new/not)
libmkl_rt.so.2 => /opt/intel/oneapi/mkl/2025.0/lib/libmkl_rt.so.2  (real: /opt/intel/oneapi/mkl/2025.0/lib/libmkl_rt.so.2)
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6  (real: /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.33)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6  (real: /usr/lib/x86_64-linux-gnu/libm.so.6)
libgomp.so.1 => /lib/x86_64-linux-gnu/libgomp.so.1  (real: /usr/lib/x86_64-linux-gnu/libgomp.so.1.0.0)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1  (real: /usr/lib/x86_64-linux-gnu/libgcc_s.so.1)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6  (real: /usr/lib/x86_64-linux-gnu/libc.so.6)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2  (real: /usr/lib/x86_64-linux-gnu/libdl.so.2)

In the worked machine: run:

np.config()

output:

Build Dependencies:
  blas:
    detection method: pkgconfig
    found: true
    include directory: /usr/local/include
    lib directory: /usr/local/lib
    name: openblas64
    openblas configuration: USE_64BITINT=1 DYNAMIC_ARCH=1 DYNAMIC_OLDER= NO_CBLAS=
      NO_LAPACK= NO_LAPACKE= NO_AFFINITY=1 USE_OPENMP= HASWELL MAX_THREADS=2
    pc file directory: /usr/local/lib/pkgconfig
    version: 0.3.23.dev
  lapack:
    detection method: internal
    found: true
    include directory: unknown
    lib directory: unknown
    name: dep140680530736656
    openblas configuration: unknown
    pc file directory: unknown
    version: 1.26.1
Compilers:
  c:
    commands: cc
    linker: ld.bfd
    name: gcc
    version: 10.2.1
  c++:
    commands: c++
    linker: ld.bfd
    name: gcc
    version: 10.2.1
  cython:
    commands: cython
    linker: cython
    name: cython
    version: 3.0.3

run

cytnx.__cpp_flags__

output

'-I/home/jerrychen/anaconda3/envs/cytnx/include -DUNI_HPTT -fvisibility-inlines-hidden -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /home/jerrychen/anaconda3/envs/cytnx/include -fdebug-prefix-map=/usr/share/miniconda3/envs/test/conda-bld/cytnx_1714963947811/work=/usr/local/src/conda/cytnx-0.9.7 -fdebug-prefix-map=/home/jerrychen/anaconda3/envs/cytnx=/usr/local/src/conda-prefix -fvisibility-inlines-hidden -fmessage-length=0 -march=nocona -mtune=haswell -ftree-vectorize -fPIC -fstack-protector-strong -fno-plt -O2 -ffunction-sections -pipe -isystem /home/jerrychen/anaconda3/envs/cytnx/include -fdebug-prefix-map=/usr/share/miniconda3/envs/test/conda-bld/cytnx_1714963947811/work=/usr/local/src/conda/cytnx-0.9.7 -fdebug-prefix-map=/home/jerrychen/anaconda3/envs/cytnx=/usr/local/src/conda-prefix -DVERSION_INFO=\\"0.9.7\\" -fopenmp '

run

cytnx.__cpp_linkflags__

output

'/home/jerrychen/anaconda3/envs/cytnx/lib/libmkl_rt.so -lpthread -lm -ldl -lpthread -lm -ldl -Wl,-rpath,/home/jerrychen/anaconda3/envs/cytnx/lib /home/jerrychen/anaconda3/envs/cytnx/lib/python3.10/site-packages/cytnx/hptt/lib/libhptt.a'

run

ldd $(python -c "import numpy._core._multiarray_umath as m; print(m.__file__)") \
  | awk '/=>/ {
      orig = $1 " => " $3;
      cmd = "realpath " $3;
      cmd | getline real;
      close(cmd);
      print orig "  (real: " real ")"
    }'

output

libopenblas64_p-r0-0cf96a72.3.23.dev.so => /home/jerrychen/.local/lib/python3.10/site-packages/numpy/core/../../numpy.libs/libopenblas64_p-r0-0cf96a72.3.23.dev.so  (real: /home/jerrychen/.local/lib/python3.10/site-packages/numpy.libs/libopenblas64_p-r0-0cf96a72.3.23.dev.so)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6  (real: /usr/lib/x86_64-linux-gnu/libm.so.6)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1  (real: /usr/lib/x86_64-linux-gnu/libgcc_s.so.1)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6  (real: /usr/lib/x86_64-linux-gnu/libc.so.6)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0  (real: /usr/lib/x86_64-linux-gnu/libpthread.so.0)
libgfortran-040039e1.so.5.0.0 => /home/jerrychen/.local/lib/python3.10/site-packages/numpy/core/../../numpy.libs/libgfortran-040039e1.so.5.0.0  (real: /home/jerrychen/.local/lib/python3.10/site-packages/numpy.libs/libgfortran-040039e1.so.5.0.0)
libquadmath-96973f99.so.0.0.0 => /home/jerrychen/.local/lib/python3.10/site-packages/numpy/core/../../numpy.libs/libquadmath-96973f99.so.0.0.0  (real: /home/jerrychen/.local/lib/python3.10/site-packages/numpy.libs/libquadmath-96973f99.so.0.0.0)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1  (real: /usr/lib/x86_64-linux-gnu/libz.so.1.2.11)

run

ldd $(python -c "import cytnx; print(cytnx.cytnx.__file__)") \
  | awk '/=>/ {
      orig = $1 " => " $3;
      cmd = "realpath " $3;
      cmd | getline real;
      close(cmd);
      print orig "  (real: " real ")"
    }'

output

libpython3.10.so.1.0 => /home/jerrychen/anaconda3/envs/cytnx/lib/python3.10/site-packages/cytnx/../../../libpython3.10.so.1.0  (real: /home/jerrychen/anaconda3/envs/cytnx/lib/libpython3.10.so.1.0)
libmkl_rt.so.2 => /home/jerrychen/anaconda3/envs/cytnx/lib/python3.10/site-packages/cytnx/../../../libmkl_rt.so.2  (real: /home/jerrychen/anaconda3/envs/cytnx/lib/libmkl_rt.so.2)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0  (real: /usr/lib/x86_64-linux-gnu/libpthread.so.0)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6  (real: /usr/lib/x86_64-linux-gnu/libm.so.6)
libgomp.so.1 => /home/jerrychen/anaconda3/envs/cytnx/lib/python3.10/site-packages/cytnx/../../../libgomp.so.1  (real: /home/jerrychen/anaconda3/envs/cytnx/lib/libomp.so)
libstdc++.so.6 => /home/jerrychen/anaconda3/envs/cytnx/lib/python3.10/site-packages/cytnx/../../../libstdc++.so.6  (real: /home/jerrychen/anaconda3/envs/cytnx/lib/libstdc++.so.6.0.33)
libgcc_s.so.1 => /home/jerrychen/anaconda3/envs/cytnx/lib/python3.10/site-packages/cytnx/../../../libgcc_s.so.1  (real: /home/jerrychen/anaconda3/envs/cytnx/lib/libgcc_s.so.1)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6  (real: /usr/lib/x86_64-linux-gnu/libc.so.6)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2  (real: /usr/lib/x86_64-linux-gnu/libdl.so.2)
libutil.so.1 => /lib/x86_64-linux-gnu/libutil.so.1  (real: /usr/lib/x86_64-linux-gnu/libutil.so.1)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1  (real: /usr/lib/x86_64-linux-gnu/librt.so.1)

Finally, I run my small script

(cytnx) jerrychen@jerrychen-X550VX:~$ python3 test.py 
[1. 1.]

Thank you again.

Heliumky avatar Apr 30 '25 13:04 Heliumky

For you unworkable machine, it seems that MKL 2024.2.2 is not compatible with MKL 2025 even if they are both MKL... And the other problem is that CMake doesn't adopt the MKL installed in your conda environment, instead, it linked to your system MKL.

For you workable machine, somehow it works even NumPy links against OpenBLAS and Cytnx links MKL. Did you get different outputs when reversing the import statements on your workable machine?

IvanaGyro avatar Apr 30 '25 14:04 IvanaGyro

To make CMake use the MKL library installed in your conda environment, try

conda install cxx-compiler cmake

and

  1. Remove build/ folder
  2. cmake --preset mkl-cpu
  3. cmake --build --preset mkl-cpu

IvanaGyro avatar Apr 30 '25 15:04 IvanaGyro

I’ve found a reliable way to resolve the issue.

First, I followed the official documentation to install cytnx using conda.

Second, I used pip3 uninstall numpy to remove only the NumPy package. This avoids the problem with conda remove numpy, which would otherwise uninstall all packages that depend on numpy, including cytnx.

Third, I reinstalled numpy using pip3 install numpy. After that, running np.show_config() confirms that numpy is properly configured.

  },
  "Build Dependencies": {
    "blas": {
      "name": "scipy-openblas",
      "found": true,
      "version": "0.3.28",
      "detection method": "pkgconfig",
      "include directory": "/opt/_internal/cpython-3.11.10/lib/python3.11/site-packages/scipy_openblas64/include",
      "lib directory": "/opt/_internal/cpython-3.11.10/lib/python3.11/site-packages/scipy_openblas64/lib",
      "openblas configuration": "OpenBLAS 0.3.28  USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell MAX_THREADS=64",
      "pc file directory": "/project/.openblas"
    },
    "lapack": {
      "name": "scipy-openblas",
      "found": true,
      "version": "0.3.28",
      "detection method": "pkgconfig",
      "include directory": "/opt/_internal/cpython-3.11.10/lib/python3.11/site-packages/scipy_openblas64/include",
      "lib directory": "/opt/_internal/cpython-3.11.10/lib/python3.11/site-packages/scipy_openblas64/lib",
      "openblas configuration": "OpenBLAS 0.3.28  USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell MAX_THREADS=64",
      "pc file directory": "/project/.openblas"
    }
  }

With this setup, my program now runs smoothly. Thank you for your helping.

Heliumky avatar May 05 '25 07:05 Heliumky

I suggest we ship binaries with mkl_lp64 instead of mkl_ilp64 by default. Users can decide to compile the ilp64 version if that is real necessary.

yingjerkao avatar May 24 '25 06:05 yingjerkao

This should be resolved in #601

yingjerkao avatar Aug 19 '25 02:08 yingjerkao

I suggest we detect the validity of BLAS at runtime like what numpy does. We may add a testcase like this

A = np.array([[1., -3.j], [3.j, 2.]], dtype=np.complex128)
print(np.linalg.matrix_rank(A, hermitian=True))

but a Cytnx version.

IvanaGyro avatar Aug 19 '25 05:08 IvanaGyro