basnijholt / pfapack

Efficient numerical computation of the Pfaffian for dense and banded skew-symmetric matrices
https://arxiv.org/abs/1102.3440
Other
14 stars 6 forks source link

Unable to find `libcpfapack.so` #7

Open awstasiuk opened 2 years ago

awstasiuk commented 2 years ago

I cannot import the C bindings. I have the latest C++ build tools installed and installed the package via conda as suggested. Here is the error message

FileNotFoundError: Could not find module 'libcpfapack.so' (or one of its dependencies). Try using the full path with constructor syntax.

I'd prefer to clone and manually install the repo regardless, can I generate this library myself?

basnijholt commented 2 years ago

Are you sure you are using the correct conda environment? Perhaps your PATH is incorrect.

Anyhow, to build yourself, you could look at https://github.com/conda-forge/pfapack-feedstock/blob/main/recipe/build.sh for inspiration.

awstasiuk commented 2 years ago

Can you provide any insight to what I might need in my PATH? I am installing into a virtual environment in a fresh installation of miniconda, and it fails. Additional instructions would be greatly appreciated.

awstasiuk commented 2 years ago

I am convinced that the conda installation does not include C-bindings. I have tried generating them myself using the original c_interface library on Wimmer's personal website, however its been 6+ years since working with C and I've been unable to produce a working library.

libcpfapack.so does not exist anywhere in my miniconda3 directory, nor do any other C source files needed to generate it. Any insight would be greatly appreciated.

basnijholt commented 2 years ago

If I download the file from https://anaconda.org/conda-forge/pfapack/files I do see libcpfapack.so.

I tried:

conda install -y pfapack

then python:

import numpy as np
import numpy.linalg
import numpy.matlib
from pfapack.ctypes import pfaffian as cpfaffian
from pfapack import pfaffian as pf  # noqa isort:skip
for method in ("P", "H"):
    # first real matrices
    A = numpy.matlib.rand(100, 100)
    A = A - A.T
    pf_a = cpfaffian(A, uplo="L", method=method)
    pf_a2 = cpfaffian(A, uplo="L", avoid_overflow=True, method=method)
    np.testing.assert_almost_equal(pf_a / pf_a2, 1)
    np.testing.assert_almost_equal(pf_a / pf.pfaffian(A), 1)
    # then complex matrices
    A = numpy.matlib.rand(100, 100) + 1.0j * numpy.matlib.rand(100, 100)
    A = A - A.T
    pf_a = cpfaffian(A, uplo="L", method=method)
    pf_a2 = cpfaffian(A, uplo="L", avoid_overflow=True, method=method)
    np.testing.assert_almost_equal(pf_a / pf_a2, 1)
    np.testing.assert_almost_equal(pf_a / pf.pfaffian(A), 1)

And this seems to just work fine for me.

Unfortunately, I currently have no time to debug your problem.

mikeyh30 commented 1 year ago

I'm not familiar with conda packaging or C, but is libcpfapack.so only available for linux and OSX, and not for Windows?

It looks like https://github.com/conda-forge/pfapack-feedstock/blob/main/recipe/bld.bat doesn't call any C compiler, and no .so files are included in the Windows builds in https://anaconda.org/conda-forge/pfapack/files