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.
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
Thanks for bringing up this topic. Even I’ve been looking for FeatureMaps and Variational Circuits from qiskit in Pennylane (PauliFeatureMap, RealAmplitudes, EfficientSU2, etc.).
It would be of great help if you could share the class that you rewrote in pennylane. Thanks!
Hi @syedfarhan, can you provide some more detail on what is the functionality that you’re looking for?
For the RealAmplitudes and EfficientSU2 cases in particular you can take a look at the PennyLane templates. They provide very good usage flexibility so you may be able to tailor one of the templates to do what you need.
Please let us know if you need guidance onto how to use the templates.
If you think it’s a feature that others might want to use, it would be really cool if you could contribute this to PennyLane. We can guide you on how to contribute (if you need it) or you can read our development guidelines.
If you don’t want to contribute this to PennyLane directly but want to share your code here that may also help other people.