# Post selection problem

**URL:** <https://discuss.pennylane.ai/t/post-selection-problem/1104>\
**Category:** Strawberry Fields\
**Created:** [June 8, 2021, 5:25pm UTC](https://discuss.pennylane.ai/t/post-selection-problem/1104 "2021-06-08T17:25:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ron\_Ruimy](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/ron_ruimy/32/567_2.png) [@Ron\_Ruimy](https://discuss.pennylane.ai/u/Ron_Ruimy)\
**Post date:** [June 8, 2021, 5:25pm UTC](https://discuss.pennylane.ai/t/post-selection-problem/1104/1 "2021-06-08T17:25:12Z")

</div>

Hey I want to implement single qubit gates on the X8 hardware, first I’m trying to do so in SF.  
The Idea is to generate the entangled modes using the S2 gate and then by post selecting 0/1 on the idler modes stay with a legitimate state in the signal mode (when I encode my qubit data using two modes in the singal modes with 1 photon in them)

I use the line:  
ops.MeasureFock(select=(0/1)) | q[2]

To post select 0/1 photons and it works fine in SF (will it also work on the X8?) How do I get a table like “results.samples” that include only the desired post selected results?

In the X8 platform there is also a problem Im facing, even in very simple codes such as:

import strawberryfields as sf  
from strawberryfields import ops  
from strawberryfields import RemoteEngine  
from collections import Counter

### Definitions

prog = sf.Program(8, name=“remote\_job1”)

with prog.context as q:

```
ops.S2gate(1.0) | (q[0], q[4])

ops.Rgate(-np.pi/2) | q[1]
ops.BSgate(np.pi/4,np.pi/2) | (q[0], q[1])
ops.Rgate(-np.pi/2) | q[1]

ops.MeasureFock() | q

```

##Get results##  
eng = RemoteEngine(“X8”)  
results = eng.run(prog, shots=20)  
print(results.samples)

I get the error “There can be no operations before the S2gates.”  
But clearly in the code trhere is no operation happening before the S2gates, what is the source of that?

Thank you in advance 🙂

---

<div class="post-metadata">

**Author:** ![Nicolas\_Quesada](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/nicolas_quesada/32/118_2.png) [@Nicolas\_Quesada](https://discuss.pennylane.ai/u/Nicolas_Quesada)\
**Post date:** [June 9, 2021, 1:12pm UTC](https://discuss.pennylane.ai/t/post-selection-problem/1104/2 "2021-06-09T13:12:22Z")

</div>

Hi @Ron_Ruimy — Welcome to the forum. As for your first question,

> To post select 0/1 photons and it works fine in SF (will it also work on the X8?) How do I get a table like “results.samples” that include only the desired post selected results?

The hardware does not currently allow for post selection. If you simulate the results using the `gaussian` backend you will have to filter the results yourself after obtaining all the samples.

As for your second question, I believe you might want to compile your program using the `Xunitary` compiler before sending it to a remote engine.

---

<div class="post-metadata">

**Author:** ![Tom\_Lubowe](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/tom_lubowe/32/542_2.png) [@Tom\_Lubowe](https://discuss.pennylane.ai/u/Tom_Lubowe)\
**Post date:** [June 10, 2021, 4:28pm UTC](https://discuss.pennylane.ai/t/post-selection-problem/1104/3 "2021-06-10T16:28:20Z")

</div>

Hi @Ron_Ruimy after looking into this further, leveraging `Xcov` will actually kick out the right error message which says: the applied unitary on modes 0-3 must be identical to the unitary applied to modes 4-7.

We suggest taking a look at the `operation` decorator which can help make this easier. Found [here](https://strawberryfields.readthedocs.io/en/stable/code/api/strawberryfields.utils.operation.html)

---

<div class="post-metadata">

**Author:** ![Ron\_Ruimy](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/ron_ruimy/32/567_2.png) [@Ron\_Ruimy](https://discuss.pennylane.ai/u/Ron_Ruimy)\
**Post date:** [June 14, 2021, 11:49am UTC](https://discuss.pennylane.ai/t/post-selection-problem/1104/4 "2021-06-14T11:49:55Z")

</div>

I tried using the Xcov compiler and really this new error message pops out  
However applying the same unitary gates on modes 0-3 and 4-7 destroys what I want to achieve. Since I want to generate qubit states on modes 0-3 and “post select” on modes 4-7

say I want to create the initial state 1010 on modes 0-3 what I’m doing is applying two modes squeezing on 0+4 and 2+6, then at the end when I measure everything I will keep only the results where modes 2+6 are measured with 1 photon (and then I can understand in retro respective that I had the correct initial condition on modes 0-3), isn’t doing something like this possible on the X8?

---

<div class="post-metadata">

**Author:** ![Tom\_Bromley](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/tom_bromley/32/129_2.png) [@Tom\_Bromley](https://discuss.pennylane.ai/u/Tom_Bromley)\
**Post date:** [June 14, 2021, 8:07pm UTC](https://discuss.pennylane.ai/t/post-selection-problem/1104/5 "2021-06-14T20:07:06Z")

</div>

Hey @Ron_Ruimy!

> However applying the same unitary gates on modes 0-3 and 4-7 destroys what I want to achieve.

Unfortunately this is a current limitation of the X8 chip. You can get more details on the device [here](https://strawberryfields.ai/photonics/demos/tutorial_X8.html#device-details). Generally you can think of the device as performing a type of [Gaussian boson sampling](https://strawberryfields.ai/photonics/concepts/gbs.html) - it is not currently general purpose but there may be some interesting [problems](https://strawberryfields.ai/photonics/applications.html) that can be encoded.

Have you tried running your code on simulator?
