unitaryfund / pennylane-qrack

The PennyLane-Qrack plugin integrates the Qrack quantum computing framework with PennyLane's quantum machine learning capabilities.
https://pennylane-qrack.readthedocs.io/
Apache License 2.0
3 stars 0 forks source link

Install Qrack from source on build #3

Closed WrathfulSpatula closed 1 month ago

WrathfulSpatula commented 1 month ago

In theory, Qrack has a perfectly "sane and rational" set of various supported methods by which users can install it; in practice, this a large cognitive load on users who just want the Python package from PyPi. Hence, this PR adds an automatic Qrack source checkout and build for the Catalyst device, such that no manual installation of Qrack by the user is necessary to install the Catalyst Qrack device package from PyPi.

cosenal commented 1 month ago

I tried running pip install -e . on this branch and I got the following error:

-- Found OpenCL: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/System/Library/Frameworks/OpenCL.framework (found version "1.2")
    -- Configuring done (2.6s)
    -- Generating done (0.0s)
    -- Build files have been written to: /Users/cosenal/Coding/unitaryfund/pennylane-qrack/_skbuild/macosx-14.0-arm64-3.11/cmake-build
    [ 50%] Building CXX object CMakeFiles/qrack_device.dir/pennylane_qrack/qrack_device.cpp.o
    /Users/cosenal/Coding/unitaryfund/pennylane-qrack/pennylane_qrack/qrack_device.cpp:4:10: fatal error: 'QuantumDevice.hpp' file not found
    #include <QuantumDevice.hpp>
             ^~~~~~~~~~~~~~~~~~~
    1 error generated.
    make[2]: *** [CMakeFiles/qrack_device.dir/pennylane_qrack/qrack_device.cpp.o] Error 1
    make[1]: *** [CMakeFiles/qrack_device.dir/all] Error 2
    make: *** [all] Error 2
    Traceback (most recent call last):
      File "/opt/miniconda3/envs/pennylane-qrack/lib/python3.11/site-packages/skbuild/setuptools_wrap.py", line 674, in setup
        cmkr.make(make_args, install_target=cmake_install_target, env=env)
      File "/opt/miniconda3/envs/pennylane-qrack/lib/python3.11/site-packages/skbuild/cmaker.py", line 697, in make
        self.make_impl(clargs=clargs, config=config, source_dir=source_dir, install_target=install_target, env=env)
      File "/opt/miniconda3/envs/pennylane-qrack/lib/python3.11/site-packages/skbuild/cmaker.py", line 742, in make_impl
        raise SKBuildError(msg)

    An error occurred while building with CMake.
      Command:
        /usr/local/bin/cmake --build . --target install --config Release --
      Install target:
        install
      Source directory:
        /Users/cosenal/Coding/unitaryfund/pennylane-qrack
      Working directory:
        /Users/cosenal/Coding/unitaryfund/pennylane-qrack/_skbuild/macosx-14.0-arm64-3.11/cmake-build
    Please check the install target is valid and see CMake's output for more information.

    [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
WrathfulSpatula commented 1 month ago

I tried running pip install -e . on this branch and I got the following error:...

Likely, the issue is that, before packaging, you need to run these two commands, first, to pull in Qrack and Catalyst:

git submodule init
git submodule update

When the source package builds, the necessary files will end up copied over directly into the source package, so PyPi install doesn't need the submodules. Just a "packaging environment" does.

WrathfulSpatula commented 1 month ago

Sorry for the "noise" in the diff from running black, but it shouldn't happen when we run it again.

cosenal commented 1 month ago

I tried running pip install -e . on this branch and I got the following error:...

Likely, the issue is that, before packaging, you need to run these two commands, first, to pull in Qrack and Catalyst:

git submodule init
git submodule update

When the source package builds, the necessary files will end up copied over directly into the source package, so PyPi install doesn't need the submodules. Just a "packaging environment" does.

For that, don't we need to add qrack url in https://github.com/unitaryfund/pennylane-qrack/blob/qrack_source_install/.gitmodules ?

WrathfulSpatula commented 1 month ago

...For that, don't we need to add qrack url in https://github.com/unitaryfund/pennylane-qrack/blob/qrack_source_install/.gitmodules ?

I think the answer is actually, "It's optional," because the command line tools didn't do it automatically in this case, while the submodule was successfully added, but I just made it explicit in .gitmodules.

WrathfulSpatula commented 1 month ago

@cosenal To the point of your comment elsewhere, you asked about examples we could run to show the package works, and I actually ran into an issue with even static linkage of the Qrack library when I attempted to run the tutorial_qft.py file in the PennyLaneAI/qml repository. I've now spent about a full working day trying to include Qrack as a submodule: it's not easy to do this at all, with scikit-build and setuptools. Hence, most of the point of this PR is moot, although it's good to review formatting.

Everyone be aware, you will have to install Qrack separately, currently. On the bright side, the Python package installation will complain that the qrack library can't be found to link, which should be understood by users with basic computer science savvy. However, let me add explicit instructions to the README! I really wish I could eliminate every point of friction for users, but this is becoming a disproportionate level-of-effort to work around a build process that is theoretically already standardized and working.