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

1 Like

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.

1 Like

Thanks Tom, yes i rewrote the class in pennylane.

2 Likes

Hi @Oriel,

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.

Hi @CatalinaAlbornoz,

Thanks for your response.

I ended up creating my own circuits for the variational forms and feature maps.

Thank you for letting us know @syedfarhan!

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.

Let me know what you think!

Sure, would love to contribute but am caught up with projects at the moment. Would definitely try contributing in the future.

1 Like

No problem @syedfarhan! We’ll be here when you’re ready to contribute.

Hello Tom, when printing this circuit I get a Converter does not exist.

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))

x = [0.7]
print(qml.draw_mpl(loaded_circuit(x)))

Thank you.

Hey @kevinkawchak , could you please share the full error output and the package versions you’re using? :slight_smile:
You can use this icon
image
right above where you write your reply to embed code in your post.