# State vector retrieval

**URL:** <https://discuss.pennylane.ai/t/state-vector-retrieval/1367>\
**Category:** PennyLane Help\
**Created:** [September 20, 2021, 11:07pm UTC](https://discuss.pennylane.ai/t/state-vector-retrieval/1367 "2021-09-20T23:07:48Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![sophchoe](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@sophchoe](https://discuss.pennylane.ai/u/sophchoe)\
**Post date:** [September 20, 2021, 11:07pm UTC](https://discuss.pennylane.ai/t/state-vector-retrieval/1367/1 "2021-09-20T23:07:48Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![josh](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/josh/32/100_2.png) [@josh](https://discuss.pennylane.ai/u/josh)\
**Post date:** [September 21, 2021, 7:05am UTC](https://discuss.pennylane.ai/t/state-vector-retrieval/1367/2 "2021-09-21T07:05:24Z")

</div>

Hi @sophchoe! You could try the [`qml.state()`](https://pennylane.readthedocs.io/en/stable/code/api/pennylane.state.html) return type:

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

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

```

---

<div class="post-metadata">

**Author:** ![josh](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/josh/32/100_2.png) [@josh](https://discuss.pennylane.ai/u/josh)\
**Post date:** [September 21, 2021, 7:09am UTC](https://discuss.pennylane.ai/t/state-vector-retrieval/1367/3 "2021-09-21T07:09:30Z")

</div>

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](https://github.com/PennyLaneAI/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 🙂

---

<div class="post-metadata">

**Author:** ![sophchoe](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@sophchoe](https://discuss.pennylane.ai/u/sophchoe)\
**Post date:** [September 21, 2021, 7:00pm UTC](https://discuss.pennylane.ai/t/state-vector-retrieval/1367/4 "2021-09-21T19:00:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)\
**Post date:** [September 21, 2021, 8:27pm UTC](https://discuss.pennylane.ai/t/state-vector-retrieval/1367/5 "2021-09-21T20:27:40Z")

</div>

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 😃

---

<div class="post-metadata">

**Author:** ![sophchoe](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@sophchoe](https://discuss.pennylane.ai/u/sophchoe)\
**Post date:** [September 22, 2021, 3:32am UTC](https://discuss.pennylane.ai/t/state-vector-retrieval/1367/6 "2021-09-22T03:32:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)\
**Post date:** [September 23, 2021, 2:53am UTC](https://discuss.pennylane.ai/t/state-vector-retrieval/1367/7 "2021-09-23T02:53:09Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)\
**Post date:** [September 23, 2021, 12:41pm UTC](https://discuss.pennylane.ai/t/state-vector-retrieval/1367/8 "2021-09-23T12:41:25Z")

</div>

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](https://github.com/PennyLaneAI/pennylane/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) that you can choose from.

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

---

<div class="post-metadata">

**Author:** ![sophchoe](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@sophchoe](https://discuss.pennylane.ai/u/sophchoe)\
**Post date:** [September 23, 2021, 3:56pm UTC](https://discuss.pennylane.ai/t/state-vector-retrieval/1367/9 "2021-09-23T15:56:03Z")

</div>

Thank you, Catalina!

---

<div class="post-metadata">

**Author:** ![sophchoe](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@sophchoe](https://discuss.pennylane.ai/u/sophchoe)\
**Post date:** [September 24, 2021, 12:08am UTC](https://discuss.pennylane.ai/t/state-vector-retrieval/1367/10 "2021-09-24T00:08:02Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)\
**Post date:** [September 24, 2021, 1:52pm UTC](https://discuss.pennylane.ai/t/state-vector-retrieval/1367/11 "2021-09-24T13:52:26Z")

</div>

Hi @sophchoe, this could be a good Demo. 😃

You can read the guidelines on how to submit it [here](https://pennylane.ai/qml/demos_submission.html).

The demo will then be posted [here](https://pennylane.ai/qml/demos_community.html).

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

---

<div class="post-metadata">

**Author:** ![sophchoe](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@sophchoe](https://discuss.pennylane.ai/u/sophchoe)\
**Post date:** [January 25, 2022, 7:17pm UTC](https://discuss.pennylane.ai/t/state-vector-retrieval/1367/12 "2022-01-25T19:17:30Z")

</div>

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](https://github.com/sophchoe/Hybrid-Quantum-Classical-MNIST-Classfication-Model/blob/main/QNN.pdf)

---

<div class="post-metadata">

**Author:** ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)\
**Post date:** [January 25, 2022, 9:05pm UTC](https://discuss.pennylane.ai/t/state-vector-retrieval/1367/13 "2022-01-25T21:05:24Z")

</div>

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](https://pennylane.ai/qml/demos_community.html)? So replace [this paper](https://arxiv.org/pdf/1806.06871v1.pdf) for [this one](https://github.com/sophchoe/Hybrid-Quantum-Classical-MNIST-Classfication-Model/blob/main/QNN.pdf)?

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

---

<div class="post-metadata">

**Author:** ![sophchoe](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@sophchoe](https://discuss.pennylane.ai/u/sophchoe)\
**Post date:** [January 25, 2022, 10:35pm UTC](https://discuss.pennylane.ai/t/state-vector-retrieval/1367/14 "2022-01-25T22:35:54Z")

</div>

Yes and yes. For all three demos.

---

<div class="post-metadata">

**Author:** ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)\
**Post date:** [January 25, 2022, 11:31pm UTC](https://discuss.pennylane.ai/t/state-vector-retrieval/1367/15 "2022-01-25T23:31:32Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![sophchoe](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@sophchoe](https://discuss.pennylane.ai/u/sophchoe)\
**Post date:** [January 26, 2022, 8:03pm UTC](https://discuss.pennylane.ai/t/state-vector-retrieval/1367/16 "2022-01-26T20:03:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)\
**Post date:** [January 27, 2022, 10:45pm UTC](https://discuss.pennylane.ai/t/state-vector-retrieval/1367/17 "2022-01-27T22:45:57Z")

</div>

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](https://pennylane.ai/qml/demos_community.html).

I hope you’re attending [QHack](https://qhack.ai/)! I’m sure you will enjoy it.

---

<div class="post-metadata">

**Author:** ![sophchoe](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@sophchoe](https://discuss.pennylane.ai/u/sophchoe)\
**Post date:** [January 27, 2022, 11:32pm UTC](https://discuss.pennylane.ai/t/state-vector-retrieval/1367/18 "2022-01-27T23:32:23Z")

</div>

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 😀😁). I will write a paper and submit the code and paper when I’m done.

Thank you so much!!!

---

<div class="post-metadata">

**Author:** ![CatalinaAlbornoz](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/catalinaalbornoz/32/1196_2.png) [@CatalinaAlbornoz](https://discuss.pennylane.ai/u/CatalinaAlbornoz)\
**Post date:** [January 28, 2022, 7:04pm UTC](https://discuss.pennylane.ai/t/state-vector-retrieval/1367/19 "2022-01-28T19:04:19Z")

</div>

Hi @sophchoe, your work sounds very interesting.

Regarding the integration with Keras we have [KerasLayer](https://pennylane.readthedocs.io/en/stable/code/api/pennylane.qnn.KerasLayer.html).

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

I hope this helps!

---

<div class="post-metadata">

**Author:** ![sophchoe](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@sophchoe](https://discuss.pennylane.ai/u/sophchoe)\
**Post date:** [March 14, 2022, 8:17pm UTC](https://discuss.pennylane.ai/t/state-vector-retrieval/1367/20 "2022-03-14T20:17:03Z")

</div>

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

> **[GitHub - sophchoe/Continous-Variable-Quantum-MNIST-Classifiers: Classical and...](https://github.com/sophchoe/Continous-Variable-Quantum-MNIST-Classifiers)**
>
> Classical and quantum hybrid circuit for classifying MNIST - GitHub - sophchoe/Continous-Variable-Quantum-MNIST-Classifiers: Classical and quantum hybrid circuit for classifying MNIST

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?

[Next page](https://discuss.pennylane.ai/t/state-vector-retrieval/1367.md?page=2)
