Installation and dependencies

Dependencies

PennyLane requires the following libraries be installed:

as well as the following Python packages:

The following Python packages are optional:

If you currently do not have Python 3 installed, we recommend Anaconda for Python 3, a distributed version of Python packaged for scientific computation.

Interface dependencies

For development of the TensorFlow and PyTorch interfaces, there are additional requirements:

  • PyTorch interface: pytorch >= 1.1

  • TensorFlow interface: tensorflow >= 1.15

    Note that any version of TensorFlow supporting eager execution mode is supported, however there are slight differences between the eager API in TensorFlow 1.X versus 2.X.

    Make sure that all modifications and tests involving the TensorFlow interface work for both TensorFlow 1.X and 2.X!

    This includes:

    • If tf.__version__[0] == "1", running tf.enable_eager_execution() before execution.

    • Only using the tf.GradientTape context for gradient computation.

QChem dependencies

Finally, for development of the QChem package, the following dependencies are required:

  • OpenFermion >= 0.10

  • pySCF and OpenFermion-PySCF >= 0.4

  • Psi4 and OpenFermion-Psi4 >= 0.4 (optional but recommended to run the full test suite)

    The easiest way to install Psi4 is via Ananconda:

    conda install psi4 psi4-rt -c psi4
    
  • Open Babel (optional but recommended to run the full test suite)

    Open Babel can be installed using apt if on Ubuntu/Debian:

    sudo apt install openbabel
    

    or using Anaconda:

    conda install -c conda-forge openbabel
    

Installation

For development purposes, it is recommended to install PennyLane source code using development mode:

git clone https://github.com/PennyLaneAI/pennylane
cd pennylane
pip install -e .

If also developing for the QChem package, this will need to installed as well:

pip install -e qchem

The -e flag ensures that edits to the source code will be reflected when importing PennyLane in Python.

Note

Due to the use of entry points to install plugins, changes to PennyLane device class locations or shortnames requires pip install -e . to be re-run in the plugin repository for the changes to take effect.

Docker

Build a PennyLane Docker image

Docker support exists for building using CPU and GPU (Nvidia CUDA 11.1+) images.

Note

Docker builds using “make” will work on Linux and MacOS only. For MS Windows you can use WSL. They are currently not supported on the Apple M1 chip (ARM64).

Build a basic PennyLane image

  • To build a basic PennyLane image without any additional interfaces (Torch, TensorFlow, or Jax) or plugins (qiskit, amazon-braket, cirq, forest), run the following:

    make -f docker/Makefile build-base
    

Build a PennyLane image with a specific interface

  • To build a PennyLane image using a specific interface (Torch, TensorFlow or Jax), run the following:

    make -f docker/Makefile build-interface interface-name=tensorflow
    
  • To build a PennyLane image using a specific interface (Torch, TensorFlow or Jax) with GPU support, run the following:

    make -f docker/Makefile build-interface-gpu interface-name=tensorflow
    

Build a PennyLane image with a plugin

  • To build a PennyLane image using a specific plugin (qiskit, amazon-braket, cirq, forest, etc), run the following:

    make -f docker/Makefile build-plugin plugin-name=qiskit
    

Build a PennyLane-Qchem image

  • You can also build an image with the PennyLane Qchem package and its dependencies. Use the following commands:

    make -f docker/Makefile build-qchem
    
  • To check all available interfaces, run the following:

    make -f docker/Makefile available-interfaces
    
  • To check all available plugins, run the following:

    make -f docker/Makefile available-plugins