Pennylane QML code to run on quantum hardware instead of local

Does anyone know of some documentation that illustrates the integration between Pennylane and Strawberyfields to get code from Pennylane that quantum embeds data and does some clustering, but runs on quantum hardware instead of locally?


Hi @BillWisotsky!

Our tutorial on plugins and hybrid computation will be very helpful!

Note that StrawberryFields requires the use of continuous-variable gates.

If you want to use other hardware such as IBM’s, IonQ’s, or other hardware available on Amazon Braket, you can use our plugins. You will need to install the apropiate plugin and follow the examples available for each one. For instance, here are the docs for the pennylane-qiskit plugin, where you can find usage examples, and here is a tutorial for using PennyLane with AWS Braket.

Please let me know if you have any standing questions about this!

Thanks very much for this. Is the strawberryfields.Fock a simulator also? Could I just substitute one of the real quantum hardware devices in its place?

Also, are there online instructor led courses that I could register for that would touch on starting with a dataset, embedding the datastep, running a kind of QML model on the dataset in a simulation and the. In real quantum hardware?

I have been though the demos and understand parts of everything, but a full beginning to end scenario and i having trouble finding or at least putting together.

Thanks very much. Trying to learn as much of this as possible after years of classical computer data science.

Hi @BillWisotsky!

Yes, strawberryfields.fock is a simulator.

This tutorial teaches how to run a program on our X8 device. It’s important to note that this device only supports gaussian gates so you can’t execute a Kerr gate on it for instance.

If you prefer the video format then be sure to check out this video on how to run a program on our X8 device on Xanadu Cloud.

We also have a series of video tutorials which cover many of the topics you would like to learn about.

This tutorial teaches an end-to-end example on quantum machine learning. It’s done on a simulator but you can install the pennylane-qiskit plugin, change the device to one of IBM’s devices, and run it on IBM’s hardware instead.

Please let me know if you have any further questions! We would love to hear about any material that you’re not finding or any trouble that you’re having.

This is great thanks so much!!

I have been going through all the links you sent and have been successful at getting them to run. The part I am not having some issues with is putting things together. The machine learning sample is amazing and makes complete sense. However, the problem I have is making it realistic, from beginning to end. Such as, here is a dataset with 1000 rows of data with 5 predictors and a binary response. I read up on and took a look at the samples of different methods of encoding data. How do you know which method should be used?? And then after it gets encoded what are the steps of putting into a machine learning sample like the one you provided at I come from a long history of classical predictive analytics with classical datasets. Would love to understand and be able to make the transition of using a classical dataset in a quantum machine learning model and running it both on simulator and real quantum hardware. Are they any samples that exist that show this process from beginning to end. The closest I found was an iris sample, but that didn’t seem to be generalizable to other datasets.

I think a great idea would be to publish a sample from beginning to end, where users could substitute other datasets in place of the same dataset.

Thanks again for all the help you have provided thus far.

Hi @BillWisotsky, I’m glad it’s going well so far!

I agree that having a ‘plug and play’ example would be great. I will note it down as something we might want to build in the near future. Thank you for suggesting it.

Embedding data is one very big question in quantum machine learning and it’s one of the steps that currently generate very big overheads. You can learn about quantum embedding from this section of our quantum glossary.

Aside from the two examples described there I also recommend using AngleEmbedding, which can sometimes be easier to understand. You can also find more embedding templates in the PennyLane documentation.

The main reason why you would choose one over the other is because of the kind of data you have. If you have binary data then BasisEmbedding is well suited for that. If your data are real numbers between 0 and 2pi then AngleEmbedding is a great choice. If your data can be pre-processed to fit into one of these cases then that’s a good thing you can do too.

If you’re using continuous-variable circuits then you might want to use displacement embedding or squeezing embedding.

The QAOAEmbedding includes both the data embedding and also the ansatz, so it can be more tricky to understand but it can also be very useful once you do.

If you have more information about the kind of data that you have then I can suggest one or another method for embedding.

I hope this helps!

Thanks so much for this information. I will read through what I haven’t already. Basically the data would fall into a couple of different types. Basically the IVs would be either continuous data or categorical and the DV could be continuous, binary or multinomial.

I am trying to put together some use cases to present to my company interfacing our software (SAS) with quantum machine learning and comparing the results of classical models with quantum. If results are similar using a quantum simulator, then test against real quantum hardware.

The ultimate goal would be to present this internally to try to justify the exploration of quantum as something we could use with real data on realproblems, making it somewhat easy to implement.

If you want to discuss further I would love to set up a time for a teams meeting. I have a lot of ideas.


Wow, this sounds great @BillWisotsky!

If it’s ok with you I would prefer to keep the technical conversation here so that others can benefit from the answers too. However I would love to hear your ideas so please send me a DM via Slack and we can discuss meeting details. I can also help set up a business meeting with our Business Development Lead, who would be very excited to meet you.

Regarding your data, if your variables are continuous, categorical, or multinomial they can surely be transformed into real numbers between 0-2pi so angle encoding would work well. Binary data works with Base Embedding or Angle Embedding so I would say that Angle Embedding would be a safe choice for all of you data types. However you will have to pre-process each of your datasets differently according to the kind of data they contain.

If you’re working with labelled data it’s also important to take a look at the labels because this will determine the kind of measurement that you will need to perform.

I hope this is helpful!

OK Understood. I would be very interested in talking to someone further. One thing I have notice and have had some trouble with is that it seems like, but I might be wrong, that PennyLane is the coding interface that can run code on a a variety of devices. I can create all sorts of gates and run them on IBM hardware which I was successful at doing, pennylane simulators, and strawberryfields simulators and hardware. From PennyLane to IBM the transition is pretty seamless. However, running things on strawberry fields seem like a lot of rework. I know the technologies are different, but was wondering if there was some lookuptable that if you want to use a RY gate, then in strawberryfields it would be " ?? ". Does something like this exist?

Hi @BillWisotsky, please send me a DM via Slack so we can talk further.

Unfortunately there’s no lookup-table between the qubit based model and the continuous-variable model. We do have a table that compares the two models in our StrawberryFields website though. As you can see in this table you can find a parallel between the different concepts, but there’s no direct translation from one to the other.

Our fault-tolerant architecture (you can learn more about it at is based on GKP qubits. This means that it will be very easy to program them on PennyLane and execute them without needing any translation. So if you’re looking into working directly with the continuous-variable model then StrawberryFields is the right tool for you. Otherwise it’s better to focus on PennyLane, which gives you the necessary tools to run your programs on the hardware from several different providers.