Skip to content

PennyLane

PennyLane is an open-source software platform for differentiable quantum computing, with the first version published on GitHub in 2018. Developed in Toronto by Xanadu, PennyLane allows users to design quantum circuits and execute them on various simulators and quantum hardware. The platform is designed to facilitate the simulation, optimization, and learning of hybrid quantum algorithms that combine classical and quantum processing.

Features

PennyLane offers several features to facilitate research and development in the field of differentiable quantum computing.

Unified Quantum Interface

PennyLane provides a unified interface that allows users to design quantum circuits and execute them on different quantum simulators and hardware. The platform supports several popular quantum simulators, such as Qiskit, CirQ, Strawberry Fields, and QuTip. PennyLane also supports several quantum hardware platforms, including quantum devices from Xanadu, IBM, Rigetti, and IonQ.

Calcul Québec has developed the PennyLane-CalculQuebec plugin, which uses the PennyLane interface to design and execute quantum circuits on MonarQ.

Integration with Machine Learning Libraries

PennyLane integrates seamlessly with popular machine learning libraries such as TensorFlow and PyTorch, allowing you to use machine learning tools to build hybrid quantum machine learning models and optimize quantum circuits.

Quantum Circuit Optimization

By using differentiable optimization techniques and combining classical and quantum differentiation methods, PennyLane optimizes the parameters of quantum circuits to solve various problems.

Visualization Tools

PennyLane provides visualization tools to facilitate understanding of how quantum circuits operate.

Community and Development

PennyLane is an open-source project with an active community of developers and users. The project is constantly updated with new features and improvements, and everyone can contribute to the platform's development.

Using PennyLane with MonarQ

MonarQ is designed to be programmed with Snowflurry, a software library programmed in Julia and developed by Anyon Systems. However, thanks to the PennyLane-CalculQuebec plugin, PennyLane circuits can be created using Snowflurry in the backend. This allows circuits to be executed on MonarQ while benefiting from the features and development environment offered by PennyLane. See the PennyLane-CalculQuebec documentation for installation and usage guides.

A quantum transpiler is also available from PennyLane to optimize its circuits for MonarQ.

Creating the Virtual Environment

Let's create a Python virtual environment to use PennyLane.

module load python/3.11
virtualenv --no-download --clear ~/ENV && source ~/ENV/bin/activate
pip install --no-index --upgrade pip
pip install --no-index pennylane==X.Y.Z
python -c "import pennylane"
where X.Y.Z is the desired version.

You can also write the last three commands above into a pennylane-reqs.txt file and call the file within a session with the commands:

module load python/3.11
pip install --no-index -r pennylane-reqs.txt

Running PennyLane on a Cluster

script.sh
#!/bin/bash
#SBATCH --account=def-someuser # Enter your account name
#SBATCH --time=00:15:00        # Modify as needed
#SBATCH --cpus-per-task=1      # Modify as needed
#SBATCH --mem-per-cpu=1G       # Modify as needed

# Load module dependencies.
module load StdEnv/2023 gcc python/3.11

# Generate the virtual environment in $SLURM_TMPDIR.
virtualenv --no-download ${SLURM_TMPDIR}/env
source ${SLURM_TMPDIR}/env/bin/activate

# Install PennyLane and its dependencies.
pip install --no-index --upgrade pip
pip install --no-index --requirement ~/pennylane_requirements.txt

# Run your PennyLane program.
python pennylane_example.py
You can then submit your job to the scheduler.

Usage Example: Bell States

Let's start by creating the virtual environment, as described above.

Next, we will generate the first Bell state using PennyLane.

import pennylane as qml

# Define the quantum circuit to generate the first Bell state
def bell_circuit():
    qml.Hadamard(wires=0)
    qml.CNOT(wires=[0, 1])

# Define the quantum circuit simulator
dev = qml.device('default.qubit', wires=2)

# Define the quantum circuit as a QNode function
@qml.qnode(dev)
def generate_bell_state():
    bell_circuit()
    return qml.state()

# Generate and display the first Bell state
bell_state_0 = generate_bell_state()
print("First Bell state :", bell_state_0)
First Bell state :[0.70710678+0.j 0.        +0.j 0.        +0.j 0.70710678+0.j]

References