State vector retrieval

Is there any way I can retrieve a pre-measurment state vector as ket using Pennylane? It seems Strawberry Fields does allow an operation without measurement. For example:

state = eng.run(“tf”, cutoff_dim=cutoff, eval=False, batch_size=batch_size)
ket = state.ket()

But Pennylane wouldn’t allow me to run without specifying a measurement method. Any advice?

Hi @sophchoe! You could try the qml.state() return type:

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

@qml.qnode(dev)
def circuit():
    qml.Hadamard(wires=1)
    return qml.state()

Oh, I forgot to ask beforehand — are you performing a CV/photonics simulation in PL? Unfortunately in that case, returning qml.state() is not yet supported with the Strawberry Fields devices.

If you have the time, opening an issue on the PennyLane-SF GitHub repo with the requested feature would be greatly appreciated, and allow our development team to see the feature request! Otherwise, I will pass it on to the team :slight_smile:

Thank you, Josh. Yes, I am using a simulator and ran into problems with qml.state() although it is listed as one of the measurement options in PL documentation.

I will go to the GitHub repo right now.

Thank you for this feature request @sophchoe! It looks like something we should have. And thank you for opening the GitHub issue too.

If you would like to work on this feature let us know :smiley:

Catalina,

Thank you for your reply. If you guide me as to where to start, I would love to work on it.

I am working on classical and qnn hybrid network for credit card fraud detection (StrawberryFields + Keras) and have a crude code for classical and quantum hybrid auto-encoder model (Pennylane + Keras).

Thank you.

Hi @sophchoe. I’m glad you would like to work on this!

The first step would be to write on the GitHub issue that you would like to work on this, just in case to prevent double work from someone else.

The next step would be to go through the code where the issue happens and trying to understand how it works.

Once you have this you can try attempting a workaround or a solution. Taking small steps and testing the result is a good way to go forward.

I suggest that you also share any solution ideas that you might have with us on GitHub, so that you can have someone else take a look to see if it could be a good approach.

I hope this helps!

Also, the two projects you mention look great. Hopefully you can create a demo when you’re finished!

Hi @sophchoe, upon closer look it seems like this fix will not be straight forward because it will require:

  • Changes in PennyLane
  • Changes in the PennyLane-StrawberryFields plugin
  • Design decisions, i.e., the path to solving this is not straightforward

If you would like to work on a different issue there are several here that you can choose from.

Otherwise, have fun with your fraud detection and auto-encoder projects! :smiley:

Thank you, Catalina!

1 Like

Hi Catalina,

I have a working code (Jupyter Notebook) on the auto-encoder I mentioned about, using Keras and Pennylane. Since we can’t directly access the ket vectors from Pennylane yet, I made some modifications to the algorithm defined in the “Continuous Variable quantum neural networks” paper. I used the probability measurement method of cutoff dimension 3 to create output vectors of length 3 and using MSE to optimize the hybrid network.

Where is the best place for me to submit it?

Hi @sophchoe, this could be a good Demo. :smiley:

You can read the guidelines on how to submit it here.

The demo will then be posted here.

Please let me know if you have any further questions on this!

Hi @CatalinaAlbornoz, I would like to add this preprint paper to my demo codes. Can you guide me through the steps? Thanks!

https://github.com/sophchoe/Hybrid-Quantum-Classical-MNIST-Classfication-Model/blob/main/QNN.pdf

Hi @sophchoe, congratulations on your paper!

Would you like it to be added in the “paper” button that is in the demo’s card here? So replace this paper for this one?

Would you like this change to be done on your three demos or just on the one called Quantum-Classical MNIST Classification Model ?

Yes and yes. For all three demos.

Ok! No next steps from your side. We’ll make the update and hopefully it should be showing up on the page this week. I’ll let you know here when it’s up!

Thank you so much @CatalinaAlbornoz! Appreciate your help as usual!

Hi @sophchoe, it’s my pleasure!

Thanks to you for submitting these amazing demos. The changes have been made and you can now see them at the community demos page.

I hope you’re attending QHack! I’m sure you will enjoy it.

Yes @CatalinaAlbornoz , I saw about QHack today and will check it out.

I am running experiments of CV MNIST classifiers varying the number of qumodes and cutoff dimension. They work nicely, but my local Jupyter Notebook connection cut off randomly and I lost over 90 epoch results for 5, 6, 7, 8 qumodes. I will post on the same repository and let you know when I get experimental results.

I am modifying the Quavolutional neural network on your main demo page into a continuous variable version. I may have to do parameter updates manually, since the stride operation is not readily translatable to Keras. (Unless you have Keras Convolution plug-in features :grinning::grin:). I will write a paper and submit the code and paper when I’m done.

Thank you so much!!!

Hi @sophchoe, your work sounds very interesting.

Regarding the integration with Keras we have KerasLayer.

I’m not sure that it will do what you need but it might be worth taking a look.

I hope this helps!

Hi @CatalinaAlbornoz, below is a link to my GitHub page: Continuous Variable quantum MNIST classifiers.

The 7-qumode classifier experiment is still running on my MacBookAir, which will be completed in a week, I think.

Please let me know if you have any questions. Thanks.

PS. Can you direct me to the Keras plug in source code page?