The Numpy-Wavefunction device¶
forest.numpy_wavefunction device provides an interface between PennyLane
and the pyQuil
As the NumPy wavefunction simulator allows access and manipulation of the underlying
quantum state vector,
forest.numpy_wavefunction is able to support the full
suite of PennyLane and Quil quantum operations and observables.
Since the NumPy wavefunction simulator is written entirely in NumPy, no external Quil compiler is required.
forest.numpy_wavefunction is initialized with
that the exact analytic expectation value is to be returned.
If the number of trials or shots provided to the
instead non-zero, a spectral decomposition is performed and a Bernoulli distribution
is constructed and sampled. This allows the
forest.numpy_wavefunction device to
‘approximate’ the effect of sampling the expectation value.
You can instantiate the device in PennyLane as follows:
import pennylane as qml dev_numpy = qml.device('forest.numpy_wavefunction', 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 and variance of a measurement and depends on three classical input parameters would look like:
@qml.qnode(dev_numpy) def circuit(x, y, z): qml.RZ(z, wires=) qml.RY(y, wires=) qml.RX(x, wires=) qml.CNOT(wires=[0, 1]) return qml.expval(qml.PauliZ(0)), var(qml.PauliZ(1))
You can then execute the circuit like any other function to get the quantum mechanical expectation value and variance:
>>> circuit(0.2, 0.1, 0.3) array([0.97517033, 0.04904283])
All Forest devices support all PennyLane operations and observables, with
the exception of the PennyLane
QubitStateVector state preparation operation.
In addition, PennyLane-Forest provides the following PyQuil-specific operations for PennyLane.
These are all importable from
These operations include:
CHPASE(phi, q, wires) Controlled-phase gate.