Using qiskit feature map in pennylane

I would like to use the PauliFeatureMap from qiskit in the context of kernel algorithms, while being powered by pennylane’s automatic differentiation. Does anyone know if we can translate the feature map from qiskit into pennylane’s framework? i looked into qml.from_qiskit(), but I had troubles because the feature map depends on inputs (the circuit is not fixed). On the other hand, maybe it would be easier to code the feature map directly in pennylane, but I liked the flexibility of the qiskit implementation.

What are your suggestions? Thanks a lot!
Oriel

Hey @Oriel!

Does anyone know if we can translate the feature map from qiskit into pennylane’s framework?

This should be possible however I had a go at using PauliFeatureMap with qml.from_qiskit() today and couldn’t get things to work. I’ve passed this onto the team who works on the PennyLane-Qiskit plugin and will update you if we get it working.

i looked into qml.from_qiskit(), but I had troubles because the feature map depends on inputs (the circuit is not fixed)

The qml.from_qiskit() function should in principle allow you to easily add-in differentiability, see the example below for a simple circuit:

from qiskit import QuantumCircuit
from qiskit.circuit import Parameter
import pennylane as qml

dev = qml.device("default.qubit", wires=2)

theta = Parameter("theta")
qc = QuantumCircuit(2)
qc.rx(theta, [0])
qc.cx(0, 1)

@qml.qnode(dev)
def loaded_circuit(x):
    qml.from_qiskit(qc)({theta: x})
    return qml.expval(qml.PauliZ(0))

However, this seemed to error when adapting for PauliFeatureMap.

On the other hand, maybe it would be easier to code the feature map directly in pennylane

I think this may be the way to go for now.

Thanks Tom, yes i rewrote the class in pennylane.

1 Like