Full Pennylane installation

For me this installed Pennylane and Cirq on a cloud Debian Linux server.


             python3 -m pip install pennylane                                      
             pip3 install pennylane-cirq  

Does anyone know what commands would do a complete installation of everything pennylane?

That is assuming git, pip and python have been installed.

Oops, missed the really big tab that said “install”, will get back about any success.

So here is a better question. After I have installed everything, how do I test the installation, other than running examples until something doesn’t work.

Here is my installation



pip3 install pennylane --upgrade                                       
pip3 install pennylane-cirq autograd "tensorflow>=1.13.2"              
pip3 install pennylane-sf pennylane-qiskit pennylane-cirq              
pip3 install pennylane-forest pennylane-qsharp                        
pip3 install torch==1.7.0+cpu torchvision==0.8.1+cpu torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html


Hi @jerteach,

Glad that it worked out!

Since you’re using pip, one way of checking that these packages were installed is by looking at the output of the pip freeze command and filtering for PennyLane:

pip freeze | grep PennyLane

Specifically, testing the installations of plugins could be done by running the test suites that are provided for PennyLane plugins by using pytest. Refer to the installation of required packages and a way of running the test suite in PennyLane.

Thanks @antalszava. I got this output after the command


pip3 freeze | grep PennyLane


PennyLane==0.12.0
PennyLane-Cirq==0.12.1
PennyLane-Forest==0.12.0
PennyLane-Qchem==0.12.0
PennyLane-qiskit==0.12.0
PennyLane-qsharp==0.8.0
PennyLane-SF==0.12.0

So it looks like things are installed. Not as much luck with

make test

but that is more probably to do with my system and “make” not being properly setup. I work best with examples, so that is my next step. I guess I will be looking for lots of examples. Any link suggestions or github links?

By the way if you know about https://gitpod.io/ that is how I am loading PennylaneAi in a browser capable docker.

This would be my gitpod link and it expects you to have a Github login

https://github.com/hpssjellis/my-examples-for-quantum-computing

takes a while to load from scratch (about 10 minutes). The next link is a snapshot that might load quicker but will not be fully up-to-date.

https://gitpod.io/#snapshot/d8c34cef-b46b-46be-b028-08cb7ffb493d

Hi @jerteach,

make test is a wrapper around running pytest tests from the root directory of the PennyLane repository. You can obtain the repo from GitHub with git clone https://github.com/PennyLaneAI/pennylane.git (perhaps already did this). Just went for a clean installation locally, and also had to install flaky with pip install flaky.

One thing to note here is that if you clone PennyLane, then you obtain the repository containing the most recent changes stored on the master branch. There might be changes that came after the latest release (which gets installed when running pip install pennylane). This is important, as the test suite will be testing the latest development version of PennyLane (hence you might experience differences when running the suite).


For sure! I would suggest looking at examples on our demonstrations page. There you find several examples organized into categories.

1 Like

Thanks again @antalszava. flaky was the key that made things work.

I think my setup is fine, your point about the slight difference between pip install pennylane and the Github of pennylane probably explains my 2 issues out of 7173

make test
python3 -m pytest tests --tb=native --no-flaky-report
====================================== test session starts =======================================
platform linux -- Python 3.7.4, pytest-6.1.2, py-1.9.0, pluggy-0.13.0
rootdir: /workspace/my-examples-for-quantum-computing/PENNYLANE/pennylane
plugins: mock-3.3.1, cov-2.10.1, flaky-3.7.0, pylama-7.7.1
collected 7173 items / 1 error / 1 skipped / 7171 selected   

So next the demos. I have another theoretical issue but I will post that elsewhere and tag you. It will probably take me 6 months or more but I would like to make a video series about PennylaneAI like what I have done for the Arduino PortentaH7 microcontroller.

Youtube Arduino PortentaH7 Playlist

3 Likes

@glassnotes
@antalszava

Haven’t even looked at the files yet, but I am having a fair bit of fun trying to get them all working. Demos loaded and for the most part work. I have a few demos to fix as Gitpod doesn’t seem to do relative folders well. I think I can fix most of the issues by fixing the paths to the data.

If anyone can point to files that may have more complex issues that would save me some time. All files marked with “x-” are not yet working. I should be able to fix all the data pointing issues.

Nov 18th updated: deleted the one that are now working


x-pytorch_noise.py
x-qonn.py
x-tutorial_QGAN.py
x-tutorial_ensemble_multi_qpu.py
x-tutorial_noisy_circuit_optimization.py
x-tutorial_pasqal.py
x-tutorial_plugins_hybrid.py
x-tutorial_quantum_metrology.py
x-tutorial_quantum_transfer_learning.py
x-tutorial_vqe_parallel.py
x-quantum_neural_net.py

All the above “X-” files are at my Github at pennylaneai/qml-demos

The full browser Docker Gitpod is at (takes a while to load and you need a Github login)

https://gitpod.io/#github.com/hpssjellis/my-examples-for-quantum-computing

Hi @jerteach, what is the specific issue you are encountering with the files?

LOL. They don’t work.

I thought most of the issues would be loading the data, but most of the “X-” files don’t seem to load data. I need to run them again on my Gitpod and start reading the error reports. Just so many files.

Something that is coming up is

x-tutorial_ensemble_multi_qpu.py#L166-L167

.

.

Something I should be able to fix is:

x-tutorial_pasqal.py#L58

.

.

Something I would really like to see running is (As I have used transfer learning a fair bit):

x-tutorial_quantum_transfer_learning.py

Hi @jerteach,

One thing I notice is that a couple of the ones in that list use Forest (pytorch_noise, vqe_parallel ensemble_multi_qpu). These demos need the QVM and quil compiler running in the background (see instructions here, in a yellow box).

For the rest, have you tried setting up an environment directly from the requirements file of the demo repository? Beyond that, are there any error messages that you can share to help debug?

1 Like

LOL, that was probably not a good file for me to miss. Thanks for pointing it out. I am getting most of the demos working and that file should help with a few more. Thank you.

No problem! Feel free to reach out if you have any further questions.

I managed to generate an errors.txt file and fixed one more of the non-working demos. Here is a link to the file. It is large, but nicely organized by each non-working file with:

**************
**************
File.py
**************

Then all the errors. Ignore the CUDA errors as the cloud docker does not host CUDA

https://github.com/hpssjellis/my-examples-for-quantum-computing/blob/main/pennylaneai/qml-demos/z-myErrors.txt

I now think most of the errors are incorrect version pip files. I will be checking those.

I did manage to fix

x-tutorial_pasqal.py

using these commands

python3 -m pip install --user six==1.13.0
pip3 install qsimcirq

@glassnotes

My Github is at https://github.com/hpssjellis/my-examples-for-quantum-computing

I am doing much better with the installation. I only have 4 not working demos


x-pytorch_noise.py

x-tutorial_ensemble_multi_qpu.py

x-tutorial_quantum_transfer_learning.py

x-tutorial_vqe_parallel.py


My .gitpod.yml file (what gets auto installed)


image:
  file: .gitpod.Dockerfile
  
ports:
  - port: 6080
    onOpen: ignore 

  
tasks:
  - init:    pip3 install --upgrade pip                                             &&
             pip3 install tensorflow                                                &&
             pip3 install tensorflowjs                                              &&
             pip3 install netron                                                    &&
             pip3 install tensorflow-quantum                                        &&
             pip3 install matplotlib                                                &&
             git clone https://github.com/tensorflow/quantum.git                    &&
             pip3 install pennylane --upgrade                                       &&
             pip3 install pennylane-cirq autograd "tensorflow>=1.13.2"              &&
             pip3 install pytest-mock flaky  nlopt   dask[delayed]                  &&
             pip3 install  toml  scipy qulacs pillow  numpy                         &&
             pip3 install pennylane-sf pennylane-qiskit pennylane-cirq pytest-cov   &&
             pip3 install pennylane-forest pennylane-qsharp pytest pennylane-qchem  &&
             pip3 install torch==1.7.0+cpu torchvision==0.8.1+cpu torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html  &&
             pip3 install six==1.13.0 qsimcirq sympy==1.5.1 pyquil==2.21 antlr4-python3-runtime==4.8
             
             

And my short errors are


*********************
*********************
Running Python file: x-pytorch_noise
*********************

2020-11-21 02:41:09.978901: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcudart.so.10.1'; dlerror: libcudart.so.10.1: cannot open shared object file: No such file or directory
2020-11-21 02:41:09.978989: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Traceback (most recent call last):
  File "x-pytorch_noise.py", line 60, in <module>
    dev = qml.device("forest.qvm", device="2q", noisy=True)
  File "/workspace/.pip-modules/lib/python3.7/site-packages/pennylane/__init__.py", line 187, in device
    plugin_device_class = plugin_devices[name].load()
  File "/workspace/.pip-modules/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2446, in load
    self.require(*args, **kwargs)
  File "/workspace/.pip-modules/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2469, in require
    items = working_set.resolve(reqs, env, installer, extras=self.extras)
  File "/workspace/.pip-modules/lib/python3.7/site-packages/pkg_resources/__init__.py", line 775, in resolve
    raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.ContextualVersionConflict: (antlr4-python3-runtime 4.8 (/workspace/.pip-modules/lib/python3.7/site-packages), Requirement.parse('antlr4-python3-runtime<4.8,>=4.7.2'), {'pyquil'})

*********************
*********************
Running Python file: x-tutorial_ensemble_multi_qpu
*********************

2020-11-21 02:41:21.833860: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcudart.so.10.1'; dlerror: libcudart.so.10.1: cannot open shared object file: No such file or directory
2020-11-21 02:41:21.833951: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Traceback (most recent call last):
  File "x-tutorial_ensemble_multi_qpu.py", line 166, in <module>
    dev0 = qml.device("forest.qvm", device="4q-qvm")
  File "/workspace/.pip-modules/lib/python3.7/site-packages/pennylane/__init__.py", line 187, in device
    plugin_device_class = plugin_devices[name].load()
  File "/workspace/.pip-modules/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2446, in load
    self.require(*args, **kwargs)
  File "/workspace/.pip-modules/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2469, in require
    items = working_set.resolve(reqs, env, installer, extras=self.extras)
  File "/workspace/.pip-modules/lib/python3.7/site-packages/pkg_resources/__init__.py", line 775, in resolve
    raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.ContextualVersionConflict: (antlr4-python3-runtime 4.8 (/workspace/.pip-modules/lib/python3.7/site-packages), Requirement.parse('antlr4-python3-runtime<4.8,>=4.7.2'), {'pyquil'})

*********************
*********************
Running Python file: x-tutorial_quantum_transfer_learning
*********************

2020-11-21 02:41:34.765270: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcudart.so.10.1'; dlerror: libcudart.so.10.1: cannot open shared object file: No such file or directory
2020-11-21 02:41:34.765375: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Traceback (most recent call last):
  File "x-tutorial_quantum_transfer_learning.py", line 215, in <module>
    for x in ["train", "val"]
  File "x-tutorial_quantum_transfer_learning.py", line 215, in <dictcomp>
    for x in ["train", "val"]
  File "/workspace/.pip-modules/lib/python3.7/site-packages/torchvision/datasets/folder.py", line 229, in __init__
    is_valid_file=is_valid_file)
  File "/workspace/.pip-modules/lib/python3.7/site-packages/torchvision/datasets/folder.py", line 108, in __init__
    classes, class_to_idx = self._find_classes(self.root)
  File "/workspace/.pip-modules/lib/python3.7/site-packages/torchvision/datasets/folder.py", line 137, in _find_classes
    classes = [d.name for d in os.scandir(dir) if d.is_dir()]
FileNotFoundError: [Errno 2] No such file or directory: '../_data/hymenoptera_data/train'

*********************
*********************
Running Python file: z-tutorial_vqe_parallel
*********************

2020-11-21 02:41:47.537153: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcudart.so.10.1'; dlerror: libcudart.so.10.1: cannot open shared object file: No such file or directory
2020-11-21 02:41:47.537252: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Traceback (most recent call last):
  File "z-tutorial_vqe_parallel.py", line 123, in <module>
    dev1 = [qml.device("forest.qvm", device="4q-qvm") for _ in range(8)]
  File "z-tutorial_vqe_parallel.py", line 123, in <listcomp>
    dev1 = [qml.device("forest.qvm", device="4q-qvm") for _ in range(8)]
  File "/workspace/.pip-modules/lib/python3.7/site-packages/pennylane/__init__.py", line 187, in device
    plugin_device_class = plugin_devices[name].load()
  File "/workspace/.pip-modules/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2446, in load
    self.require(*args, **kwargs)
  File "/workspace/.pip-modules/lib/python3.7/site-packages/pkg_resources/__init__.py", line 2469, in require
    items = working_set.resolve(reqs, env, installer, extras=self.extras)
  File "/workspace/.pip-modules/lib/python3.7/site-packages/pkg_resources/__init__.py", line 775, in resolve
    raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.ContextualVersionConflict: (antlr4-python3-runtime 4.8 (/workspace/.pip-modules/lib/python3.7/site-packages), Requirement.parse('antlr4-python3-runtime<4.8,>=4.7.2'), {'pyquil'})


Note: some other demo needed antlr4-python3-runtime==4.8 and switching it to 4.7.2 does not solve all the issues.

I will probably figure it out, but if anyone can see anything obvious to them, that would be helpful.

Hi @jerteach,

The issue with the transfer learning one seems to just be that it cannot find the data at the specified path.

As for the other 3, they are the three that use Pennylane-Forest / pyquil, and antlr4-python3-runtime is one of the requirements of pyquil, but not the PennyLane demos. This may be something we have to look into on our end, if there is a mismatch between a dependency of one of our demos with what is required by pyquil.

I notice though that the yml file is explicitly installing that library rather than letting pip handle it; did you encounter the same issues without installing it manually? Also, are you able to build them all locally in an environment made directly from the requirements.txt file?

One demo needs antlr4-python3-runtime==4.8, but tutorial_vqe_parallel needs antlr4-python3-runtime==4.7.2. I just went with the newer one and could probably make a bash file to install the older one as appropriate.

I think I got most of the requirements.txt file but may have missed a few. I use https://gitpod.io/ so my installation is online and I access it through the browser so it is not really local.

You have given me some good ideas I will see what I can do with the last few files. However I am already overloaded with the amount of code I have to go through so I am not really concerned about the last few files.

Reminder, all I want to do is make a really simple Keras layers Quantum trained model so that I can export a Tensorflow Keras model to use on microcontrollers. Already taking a much deeper dive than I really need to.

I tagged you in another thread about actual Quantum Access Quantum Computer Access?

Good catch with that. That was an easy fix using wget and unzip. Thank you.

Hi @jerteach,

Good catch with that. That was an easy fix using wget and unzip. Thank you.

Great! No problem.

I think I got most of the requirements.txt file but may have missed a few.

A quick way to install everything automatically from the requirements file is pip install -r requirements.txt.

One demo needs antlr4-python3-runtime==4.8, but tutorial_vqe_parallel needs antlr4-python3-runtime==4.7.2.

Thanks so much for pointing this out! I’ll make an issue for this on our Github and we’ll look into it. Is tutorial_vqe_parallel the only demo that needs 4.7.2, or is it all three of the ones that use pyquil?

Wow, that is one of those “I wish I had known that earlier” things that I probably should remember. I might completely change my .gitpod.yml file.

Hmmmm. that did not solve the 3 files that were broken for me, and did break 3 more files ( qonn.py, quantum_neural_net.py, tutorial_plugins_hybrid.py) that I had working, but does show some potential for upgrading easily, I think I will keep that .yml file as a backup.