PennyLaneAI / pennylane-qulacs

The PennyLane-Qulacs plugin integrates the Qulacs quantum computing framework with PennyLane's quantum machine learning capabilities.
https://docs.pennylane.ai/projects/qulacs
Apache License 2.0
27 stars 16 forks source link

Unable to install Pennylane-Qulacs GPU: follow-up #63

Open JustinS6626 opened 5 months ago

JustinS6626 commented 5 months ago

This is related to my previous post on this topic : https://github.com/PennyLaneAI/pennylane-qulacs/issues/62#issue-2197685954

I forgot to mention before that I had succeeded in installing Qulacs-GPU on its own, so I am wondering, when I am installing pennylane-qulacs-gpu, is there a way to get the installation process to recognize the existing installation of Qulacs-GPU so that it doen't try to install it over again?

josh146 commented 5 months ago

Hey @JustinS6626, are you installing pennylane-qulacs into the same Python environment as the run that already had Qulacs GPU installed?

JustinS6626 commented 5 months ago

Hey @JustinS6626, are you installing pennylane-qulacs into the same Python environment as the run that already had Qulacs GPU installed?

Thanks for getting back to me again! Yes, that's what I did. Should I do something else instead?

isaacdevlugt commented 5 months ago

Just posting this for the paper trail: https://discuss.pennylane.ai/t/unable-to-install-pennylane-qulacs-gpu-verson/4319/2

JustinS6626 commented 5 months ago

It looks like it could be an issue in the installation script. Is there anything you can do about that?

isaacdevlugt commented 5 months ago

Indeed, I tried installing this on Collab and got this:

!pip install pennylane qulacs pennylane-qulacs["gpu"]
Building wheels for collected packages: qulacs-gpu
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> See above for output.

  note: This error originates from a subprocess, and is likely not a problem with pip.
  Building wheel for qulacs-gpu (setup.py) ... error
  ERROR: Failed building wheel for qulacs-gpu
  Running setup.py clean for qulacs-gpu
Failed to build qulacs-gpu
ERROR: Could not build wheels for qulacs-gpu, which is required to install pyproject.toml-based projects

However, as the traceback suggests, this doesn't seem to be a pennylane-qulacs plugin issue; there's an issue with qulacs-gpu. I see this issue here: https://github.com/qulacs/qulacs/issues/623. I think it's best to follow that (we will, as well). If there's a fix, we'll make sure to upgrade the dependency, make sure everything works with the plugin, etc.

JustinS6626 commented 5 months ago

Thanks again for getting back to me! Using the workaround mentioned on the qulacs github, I managed to install qulacs-gpu on its own from source, but now when I try to install pennylane-qulacs-gpu, pip doesn't recognize the existing qulacs-gpu installation and tries to install qulacs-gpu again. When I run the pip install command, is there an argument that I can use to stop it from trying to install qulacs-gpu again as well?

isaacdevlugt commented 5 months ago

Hey @JustinS6626, I recommend cloning the pennylane-qulacs repo and modifying the requirements to something like this (see here for more details about installing from github: https://stackoverflow.com/questions/16584552/how-to-state-in-requirements-txt-a-direct-github-source):

pennylane>=0.32
Qulacs @ git+https://github.com/qulacs/qulacs@<branch name with the fix you mentioned>
numpy~=1.16

Then you can pip install your local clone like this (make sure you're in the root directory of your pennylane-qulacs clone, and have a dedicated virtual environment!):

pip install -e .

Let me know if this works :)

JustinS6626 commented 5 months ago

The workaround was actually not a fix to one of the branches itself, but rather a manual installation command mentioned in the related issue https://github.com/qulacs/qulacs/issues/623. The solution given is to run USE_GPU=Yes pip install --no-build-isolation ., which works for me since I have sudo access. Based on that, is there a way to tell pip to skip the qulacs-gpu installation, or to tell it where the existing installation is on my machine so that it doesn't try to install qulacs-gpu again?

JustinS6626 commented 5 months ago

On a related note, I was wondering, is qulacs the fastest simulator supported by Pennylane for use with machine learning, or would I be better off using pennylane-lightning?

isaacdevlugt commented 5 months ago

Based on that, is there a way to tell pip to skip the qulacs-gpu installation, or to tell it where the existing installation is on my machine so that it doesn't try to install qulacs-gpu again?

When you pip install pennylane-qulacs, you can use the --no-dependencies flag to ignore the dependencies (see here: https://stackoverflow.com/questions/12759761/pip-force-install-ignoring-dependencies). Does that work for you?

isaacdevlugt commented 5 months ago

On a related note, I was wondering, is qulacs the fastest simulator supported by Pennylane for use with machine learning, or would I be better off using pennylane-lightning?

Between the qulacs plugin and lightning, we definitely put more points into supporting lightning ⚡. I would expect it to be faster, but let us know otherwise! You can also try out Catalyst (our quantum-flavoured JIT compiler): https://docs.pennylane.ai/projects/catalyst/en/stable/index.html

JustinS6626 commented 5 months ago

Thank you very much for getting back to me!

I tried running

sudo pip3.11 install --upgrade --no-dependencies pennylane-qulacs["gpu"]

and got

Requirement already satisfied: pennylane-qulacs[gpu] in /usr/local/lib/python3.11/dist-packages (0.33.0.dev0)

However, when I tried

import pennylane as qml
dev = qml.device('qulacs.gpu', wires=2)

I got

Traceback (most recent call last):
  File "/usr/lib/python3.11/idlelib/run.py", line 578, in runcode
    exec(code, self.locals)
  File "<pyshell#1>", line 1, in <module>
  File "/usr/local/lib/python3.11/dist-packages/pennylane/__init__.py", line 398, in device
    raise DeviceError(f"Device {name} does not exist. Make sure the required plugin is installed.")
pennylane._device.DeviceError: Device qulacs.gpu does not exist. Make sure the required plugin is installed.

What else do I need to do to make sure the plugin is recognized?

I will look into Catalyst as well, however, my overall model is written in Pytorch and not JAX. Is there an efficient way to integrate compatibility without having to overhaul my code?

isaacdevlugt commented 5 months ago

Interesting... I'm not sure how to fix this 😅. I will probably need to hand this off to someone more knowledgeable than myself.

If your code is written in PyTorch, is there a reason why the qulacs plugin is more appealing than what standard pennylane has to offer?