Lightning Qubit device

The lightning.qubit device uses a custom-built backend to perform fast linear algebra calculations for simulating quantum state-vector evolution.

A lightning.qubit device can be loaded using:

import pennylane as qml
dev = qml.device("lightning.qubit", wires=2)

Check out the Lightning-Qubit installation guide for more information.

Supported operations and observables

Supported operations:

BasisState

Prepares a single computational basis state.

CNOT

The controlled-NOT operator

ControlledPhaseShift

A qubit controlled phase shift.

ControlledQubitUnitary

Apply an arbitrary fixed unitary to wires with control from the control_wires.

CPhase

alias of ControlledPhaseShift

CRot

The controlled-Rot operator

CRX

The controlled-RX operator

CRY

The controlled-RY operator

CRZ

The controlled-RZ operator

CSWAP

The controlled-swap operator

CY

The controlled-Y operator

CZ

The controlled-Z operator

DiagonalQubitUnitary

Apply an arbitrary diagonal unitary matrix with a dimension that is a power of two.

DoubleExcitation

Double excitation rotation.

DoubleExcitationMinus

Double excitation rotation with negative phase-shift outside the rotation subspace.

DoubleExcitationPlus

Double excitation rotation with positive phase-shift outside the rotation subspace.

ECR

An echoed RZX(pi/2) gate.

Hadamard

The Hadamard operator

Identity

The Identity operator

IsingXX

Ising XX coupling gate

IsingXY

Ising (XX + YY) coupling gate

IsingYY

Ising YY coupling gate

IsingZZ

Ising ZZ coupling gate

ISWAP

The i-swap operator

MultiControlledX

Apply a Pauli X gate controlled on an arbitrary computational basis state.

MultiRZ

Arbitrary multi Z rotation.

OrbitalRotation

Spin-adapted spatial orbital rotation.

PauliX

The Pauli X operator

PauliY

The Pauli Y operator

PauliZ

The Pauli Z operator

PhaseShift

Arbitrary single qubit local phase shift

PSWAP

Phase SWAP gate

QFT

Apply a quantum Fourier transform (QFT).

QubitCarry

Apply the QubitCarry operation to four input wires.

QubitStateVector

QubitSum

Apply a QubitSum operation on three input wires.

QubitUnitary

Apply an arbitrary unitary matrix with a dimension that is a power of two.

Rot

Arbitrary single qubit rotation

RX

The single qubit X rotation

RY

The single qubit Y rotation

RZ

The single qubit Z rotation

S

The single-qubit phase gate

SingleExcitation

Single excitation rotation.

SingleExcitationMinus

Single excitation rotation with negative phase-shift outside the rotation subspace.

SingleExcitationPlus

Single excitation rotation with positive phase-shift outside the rotation subspace.

SISWAP

The square root of i-swap operator.

SQISW

alias of SISWAP

SWAP

The swap operator

SX

The single-qubit Square-Root X operator.

T

The single-qubit T gate

Toffoli

Toffoli (controlled-controlled-X) gate.

Supported observables:

Exp

A symbolic operator representing the exponential of a operator.

Hadamard

The Hadamard operator

Hamiltonian

alias of LinearCombination

Hermitian

An arbitrary Hermitian observable.

Identity

The Identity operator

PauliX

The Pauli X operator

PauliY

The Pauli Y operator

PauliZ

The Pauli Z operator

Prod

Symbolic operator representing the product of operators.

Projector

Observable corresponding to the state projector \(P=\ket{\phi}\bra{\phi}\).

SparseHamiltonian

A Hamiltonian represented directly as a sparse matrix in Compressed Sparse Row (CSR) format.

SProd

Arithmetic operator representing the scalar product of an operator with the given scalar.

Sum

Symbolic operator representing the sum of operators.

Parallel adjoint differentiation support:

The lightning.qubit device directly supports the adjoint differentiation method, and enables parallelization over the requested observables (Linux/MacOS support only).

To enable parallel differentiation over observables, ensure the OMP_NUM_THREADS environment variable is set before starting your Python session, or if already started, before importing packages:

# Option 1: Before starting Python
export OMP_NUM_THREADS=4
python <your_file>.py
# Option 2: Before importing packages
import os
os.environ["OMP_NUM_THREADS"] = 4
import pennylane as qml

Assuming you request multiple expectation values from a QNode, this should automatically parallelize the computation over the requested number of threads. You should ensure that the number of threads does not exceed the available physical cores on your machine.

If you are computing a large number of expectation values, or if you are using a large number of wires on your device, it may be best to limit the number of expectation value calculations to at-most OMP_NUM_THREADS concurrent executions. This will help save memory, at the cost of additional compute time. To enable this, initialize a lightning.qubit device with the batch_obs=True keyword argument, as:

# Before importing packages
import os
os.environ["OMP_NUM_THREADS"] = 4
import pennylane as qml
dev = qml.device("lightning.qubit", wires=2, batch_obs=True)

Markov Chain Monte Carlo sampling support:

The lightning.qubit device allows users to use the Markov Chain Monte Carlo (MCMC) sampling method to generate approximate samples. To enable the MCMC sampling method for sample generation, initialize a lightning.qubit device with the mcmc=True keyword argument, as:

import pennylane as qml
dev = qml.device("lightning.qubit", wires=2, shots=1000, mcmc=True)

By default, the kernel_name is "Local" and num_burnin is 100. The local kernel conducts a bit-flip local transition between states. The local kernel generates a random qubit site and then generates a random number to determine the new bit at that qubit site.

The lightning.qubit device also supports a "NonZeroRandom" kernel. This kernel randomly transits between states that have nonzero probability. It can be enabled by initializing the device as:

import pennylane as qml
dev = qml.device("lightning.qubit", wires=2, shots=1000, mcmc=True, kernel_name="NonZeroRandom", num_burnin=200)