Lightning qubit import error


ImportError Traceback (most recent call last)
Cell In[1], line 7
3 from pennylane import numpy as np
6 n_qubits = 2
----> 7 dev = qml.device(“lightning.qubit”, wires=n_qubits+1)
9 @qml.qnode(dev, )
10 def circuit(weights, x):
12 qml.AmplitudeEmbedding(x, wires=range(n_qubits), normalize=True)

File ~/.conda/envs/cent7/2020.11-py38/tqc/lib/python3.9/site-packages/pennylane/devices/device_constructor.py:280, in device(name, *args, **kwargs)
274 raise qml.DeviceError(
275 f"The {name} plugin requires PennyLane versions {required_versions}, "
276 f"however PennyLane version {qml.version()} is installed."
277 )
279 # Construct the device
→ 280 dev = plugin_device_class(*args, **options)
282 # Once the device is constructed, we set its custom expansion function if
283 # any custom decompositions were specified.
284 if custom_decomps is not None:

File ~/.conda/envs/cent7/2020.11-py38/tqc/lib/python3.9/site-packages/pennylane_lightning/lightning_qubit/lightning_qubit.py:504, in LightningQubit.init(self, wires, c_dtype, shots, seed, mcmc, kernel_name, num_burnin, batch_obs)
491 def init( # pylint: disable=too-many-arguments
492 self,
493 wires,
(…)
501 batch_obs=False,
502 ):
503 if not self._CPP_BINARY_AVAILABLE:
→ 504 raise ImportError(
505 "Pre-compiled binaries for lightning.qubit are not available. "
506 "To manually compile from source, follow the instructions at "
507 “https://docs.pennylane.ai/projects/lightning/en/stable/dev/installation.html.
508 )
510 super().init(wires=wires, shots=shots)
512 if isinstance(wires, int):

ImportError: Pre-compiled binaries for lightning.qubit are not available. To manually compile from source, follow the instructions at Installation — Lightning 0.39.0 documentation.

It was working when I have pennylane=0.28.0, but after upgrading to 0.38.0, it stopped working.

Name: PennyLane
Version: 0.38.0
Summary: PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
Home-page: https://github.com/PennyLaneAI/pennylane
Author: 
Author-email: 
License: Apache License 2.0
Location: /home/bhatia87/.conda/envs/cent7/2020.11-py38/xyz2/lib/python3.10/site-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, packaging, pennylane-lightning, requests, rustworkx, scipy, toml, typing-extensions
Required-by: PennyLane_Lightning

Platform info:           Linux-3.10.0-1160.108.1.el7.x86_64-x86_64-with-glibc2.17
Python version:          3.10.14
Numpy version:           1.23.5
Scipy version:           1.10.0
Installed devices:
- lightning.qubit (PennyLane_Lightning-0.38.0)
- default.clifford (PennyLane-0.38.0)
- default.gaussian (PennyLane-0.38.0)
- default.mixed (PennyLane-0.38.0)
- default.qubit (PennyLane-0.38.0)
- default.qubit.autograd (PennyLane-0.38.0)
- default.qubit.jax (PennyLane-0.38.0)
- default.qubit.legacy (PennyLane-0.38.0)
- default.qubit.tf (PennyLane-0.38.0)
- default.qubit.torch (PennyLane-0.38.0)
- default.qutrit (PennyLane-0.38.0)
- default.qutrit.mixed (PennyLane-0.38.0)
- default.tensor (PennyLane-0.38.0)
- null.qubit (PennyLane-0.38.0)

Hi @Amandeep ,

Could you please create a new virtual environment with Python>=3.10, and just pip install pennylane? You don’t need to install anything else.

Let me know if you need help on creating the environment.

Name: PennyLane
Version: 0.39.0
Summary: PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
Home-page: GitHub - PennyLaneAI/pennylane: PennyLane is a cross-platform Python library for quantum computing, quantum machine learning, and quantum chemistry. Train a quantum computer the same way as a neural network.
Author:
Author-email:
License: Apache License 2.0
Location: /home/bhatia87/.conda/envs/cent7/2020.11-py38/tqc/lib/python3.10/site-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, packaging, pennylane-lightning, requests, rustworkx, scipy, toml, typing-extensions
Required-by: PennyLane_Lightning

Platform info: Linux-3.10.0-1160.108.1.el7.x86_64-x86_64-with-glibc2.17
Python version: 3.10.15
Numpy version: 1.26.4
Scipy version: 1.14.1
Installed devices:

  • default.clifford (PennyLane-0.39.0)
  • default.gaussian (PennyLane-0.39.0)
  • default.mixed (PennyLane-0.39.0)
  • default.qubit (PennyLane-0.39.0)
  • default.qutrit (PennyLane-0.39.0)
  • default.qutrit.mixed (PennyLane-0.39.0)
  • default.tensor (PennyLane-0.39.0)
  • null.qubit (PennyLane-0.39.0)
  • reference.qubit (PennyLane-0.39.0)
  • lightning.qubit (PennyLane_Lightning-0.39.0)
    dev = qml.device(“lightning.qubit”, wires=num_qubits+1)

@qml.qnode(dev)
def circuit( weights,x):
index=0
qml.AmplitudeEmbedding(x, wires=range(num_qubits), normalize=True)

for t in range(2):
    for i in range(1):
        for i in range(num_qubits):
            qml.RY(weights[index], wires=i)
            index += 1
            qml.RX(weights[index], wires=i)
            index += 1
     

        for i in range(num_qubits - 1):
            qml.CNOT(wires=[i, i + 1])

After creating new environment with python=3.10. Lightning qubit not working. ImportError: Pre-compiled binaries for lightning.qubit are not available. To manually compile from source, follow the instructions at Installation — Lightning 0.39.0 documentation.

As I am using 10 qubits, and depth of circuit is also moe, how can I expedite computation of QFIM.

Hi @Amandeep ,

If you don’t need to work locally you could try using Google Colab or qBraid. In Google Colab all you need is to write !pip install pennylane in the first cell (including the exclamation mark).

Edit: the two options below may not work because we require a minimum glibc library of 2.28 (ie RHEL 8 compatible and newer). Yours is glibc 2.17 (RHEL 7). So I would strongly suggest going for the options mentioned above.

If you need to work locally here are two options to solve your issue with lightning. If option 1 doesn’t work you can try option 2. If none of them work please share your output for qml.about() and your full error traceback.

Option 1: Virtual environment with Conda

You can create a virtual environment with Conda and install PennyLane as follows:

  1. Install Miniconda following the instructions here.
  2. Open your terminal (Mac) or command line (Windows).
  3. Create a new Conda environment with: conda create --name <name_of_your_environment> python=3.10
  4. Activate the environment with: conda activate <name_of_your_environment>
  5. Install PennyLane with: python -m pip install pennylane
  6. Install other useful packages with: python -m pip install jupyter matplotlib

Note that you will be installing 3 packages here: PennyLane, Jupyter, and Matplotlib. Also, note that where it says <name_of_your_environment> you can choose any name that you want.

Option 2: Virtual environment with venv

You can create a virtual environment with venv and install PennyLane as follows (Mac & Windows):

  1. Download Python 3.10 or newer here.
  2. Double-click on the .pkg file (Mac) or .exe file (Windows).
  3. Double-click on the Install Certificates.command file. It will open a terminal/command
    line window. You can close it after it says “process completed”.
  4. Open your terminal/command line.
  5. Create the directory for your virtual environment with: mkdir ~/.virtualenvs
  6. Create a new virtual environment with:
    python3.X -m venv ~/.virtualenvs/new_venv
    where X is the version of Python you installed. E.g. if you installed Python 3.10 then start with python3.10
    You can change new_venv to whatever name you want for your environment.
  7. Activate the environment with:
    source ~/.virtualenvs/new_venv/bin/activate
  8. Install PennyLane with: python -m pip install pennylane
  9. Install other useful packages such as Jupyter and Matplotlib with:
    python -m pip install jupyter matplotlib
  10. Write jupyter notebook in your terminal/command line and you will be ready to
    create programs using PennyLane.
    Every time you want to use PennyLane make sure to open a new terminal/command line, activate the environment with step 7, and open a Jupyter notebook with step 10.

Let me know if this works for you.