Skip to main content

Pytket extension and Pennylane plugin.

Project description

pytket-pennylane

Slack Stack Exchange

Pytket extension and PennyLane plugin which allows pytket backends and compilation to be used as a PennyLane device.

Pytket is a quantum SDK python package which provides state of the art compilation for quantum circuits and a unified interface for execution on a number of "backends" (devices and simulators). PennyLane is a package for differentiable programming of quantum computer, which also provides a way to execute circuits on a variety of "devices". This package allows users to easily leverage the differentiablecircuits of PennyLane combined with the compilation available in Pytket.

The package is available for python 3.10, 3.11 and 3.12, and can be installed by cloning and installing from source, or via pip:

pip install pytket-pennylane

API documentation is here.

See the PennyLane documentation and Pytket documentation to get an intro to PennyLane and Pytket.

To use the integration once installed, initialise your pytket backend (in this example, an AerBackend which uses Qiskit Aer), and construct a PennyLane PytketDevice using this backend:

import pennylane as qml
from pytket.extensions.qiskit import AerBackend

# initialise pytket backend
pytket_backend = AerBackend()

# construct PennyLane device
dev = qml.device(
    "pytket.pytketdevice",
    wires=2,
    pytket_backend=pytket_backend,
    shots=1000
)

# define a PennyLane Qnode with this device
@qml.qnode(dev)
def my_quantum_function(x, y):
    qml.RZ(x, wires=0)
    qml.RX(y, wires=1)
    return qml.expval(qml.PauliZ(0) @ qml.PauliZ(1))

# call the node
print(my_quantum_function(0.1, 0.2))

The example above uses the Pytket default compilation pass for the backend, you can change the optimisation level of the default backend pass (0, 1 or 2) by setting the optimisation_level parameter:

dev = qml.device(
    "pytket.pytketdevice",
    wires=2,
    pytket_backend=pytket_backend,
    optimisation_level=2,
    shots=1000
)

You can also use any Pytket compilation pass using the compilation_pass parameter, which is used instead of the default pass:

from pytket.passes import PauliSimp, SequencePass

# use a Chemistry optimised pass before the backend's default pass

custom_pass = SequencePass([PauliSimp(), pytket_backend.default_compilation_pass()])

dev = qml.device(
    "pytket.pytketdevice",
    wires=2,
    pytket_backend=pytket_backend,
    compilation_pass=custom_pass,
    shots=1000
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytket_pennylane-0.20.0-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file pytket_pennylane-0.20.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytket_pennylane-0.20.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ea71a43a2cbba67367b2b0091eefb3925b520a3d0dec34cc7469205d89072e3c
MD5 008c3d51da187cfeabe8b12de9315767
BLAKE2b-256 6949b4a698178262d176a3e6c10547d934430a7a6a6a8738656a0ea93b840fd3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page