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

def circuit():
    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:


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!