PennyLane-Qulacs Plugin

Release

0.32.0

The PennyLane-Qulacs plugin integrates the Qulacs quantum computing framework with PennyLane’s quantum machine learning capabilities.

PennyLane is a cross-platform Python library for quantum machine learning, automatic differentiation, and optimization of hybrid quantum-classical computations.

Qulacs is a software library for quantum computing, written in C++ and with GPU support.

Once PennyLane-Qulacs is installed, the provided Qulacs devices can be accessed straight away in PennyLane, without the need to import any additional packages.

Devices

Currently, PennyLane-Qulacs provides one Qulacs device for PennyLane:


Benchmarks

We ran a 100 executions of 4 layer quantum neural network strongly entangling layer and compared the runtimes between CPU and GPU.

https://raw.githubusercontent.com/soudy/pennylane-qulacs/master/images/qnn_cpu_vs_gpu.png

https://raw.githubusercontent.com/soudy/pennylane-qulacs/master/images/qulacs_table.png

Tutorials

Check out these demos to see the PennyLane-Qulacs plugin in action:


You can use any of the qubit based demos from the PennyLane documentation, for example the tutorial on qubit rotation, and simply replace 'default.qubit' with the 'qulacs.simulator' device:

dev = qml.device('qulacs.simulator', wires=XXX)

Installation

This plugin requires Python version 3.6 or above, as well as PennyLane and Qulacs. Installation of this plugin, as well as all dependencies, can be done using pip:

$ pip install pennylane-qulacs["cpu"]

Note that you need to include whether to install the CPU version (pennylane-qulacs["cpu"]) or the GPU version (pennylane-qulacs["gpu"]) of Qulacs for it to be installed correctly. Otherwise Qulacs will need to be installed independently:

pip install qulacs pennylane-qulacs

Alternatively, you can install PennyLane-Qulacs from the source code by navigating to the top directory and running:

$ python setup.py install

Note

Qulacs supports parallelized executions via OpenMP. To set the number of threads to use during simulations you need to update the environment variable OMP_NUM_THREADS. It can be set using the UNIX command:

export OMP_NUM_THREADS = 8

where 8 can be replaced by the number of threads that you wish to use. By default Qulacs uses all available threads. To restore the default behaviour, simply remove the environment variable. It can be done using the UNIX command:

unset OMP_NUM_THREADS

See the OpenMP documentation page for OMP_NUM_THREADS or here for more details on how to use environment variables.

Dependencies

PennyLane-Qulacs requires the following libraries be installed:

as well as the following Python packages:

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

Tests

To test that the PennyLane-Qulacs plugin is working correctly you can run

$ make test

in the source folder.

Documentation

To build the HTML documentation, go to the top-level directory and run:

$ make docs

The documentation can then be found in the doc/_build/html/ directory.

Support

If you are having issues, please let us know by posting the issue on our Github issue tracker, or by asking a question in the forum.

The Simulator device

You can instantiate the qulacs device in PennyLane as follows:

import pennylane as qml

dev = qml.device('qulacs.simulator', wires=2)

This device can then be used just like other devices for the definition and evaluation of QNodes within PennyLane. A simple quantum function that returns the expectation value of a measurement and depends on three classical input parameters would look like:

@qml.qnode(dev)
def circuit(x, y, z):
    qml.RZ(z, wires=[0])
    qml.RY(y, wires=[0])
    qml.RX(x, wires=[0])
    qml.CNOT(wires=[0, 1])
    return qml.expval(qml.PauliZ(wires=1))

You can then execute the circuit like any other function to get the quantum mechanical expectation value.

circuit(0.2, 0.1, 0.3)

Device options

To run the qulacs device simulations on a GPU, set the custom qpu argument to True when creating the device.

dev = qml.device('qulacs.simulator', wires=2, gpu=True)

Note

For GPU support, you need to have the qulacs-gpu version installed, including its dependencies. Check the Qulacs documentation for details.

If you create the device with gpu=True but you do not have qulacs-gpu installed you will get an error GPU not supported with installed version of Qulacs..

Supported operations

The qulacs.simulator device supports all PennyLane operations and observables:

pennylane-qulacs

This section contains the API documentation for the PennyLane-Qulacs plugin.

Warning

Unless you are a PennyLane plugin developer, you likely do not need to use these classes and functions directly.

See the overview page for more details using the available Qulacs devices with PennyLane.

Top level Pennylane-qulacs plugin