# Feed-forward on IBM HW failure

**URL:** <https://discuss.pennylane.ai/t/feed-forward-on-ibm-hw-failure/3931>\
**Category:** PennyLane Help\
**Created:** [January 21, 2024, 2:08am UTC](https://discuss.pennylane.ai/t/feed-forward-on-ibm-hw-failure/3931 "2024-01-21T02:08:03Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![Jan\_Balewski](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/jan_balewski/32/2220_2.png) [@Jan\_Balewski](https://discuss.pennylane.ai/u/Jan_Balewski)\
**Post date:** [February 2, 2024, 6:07pm UTC](https://discuss.pennylane.ai/t/feed-forward-on-ibm-hw-failure/3931/10 "2024-02-02T18:07:38Z")

</div>

Hi Tom,  
you were close. Below is the code which implements plan B - I used ancilla as random generator, combined with your implicit loop mapping hw to index in pL[.]. The results are as expected. It is 1 circuit with 8k shots, rather than 8k circuits with 1 shot (as I wanted it). Will it run on a real HW ?- I’ll investigate it next.  
I think this thread is long enough - so I’ll stop posting here

You suggested I learn Catalyst. Perhaps you can point me to a tutorial showing it works for a non-trivial feed-forward circuit executed on a real HW from any cloud vendor?

Thanks  
Jan

```auto
dev = qml.device("default.qubit",wires=4,shots=8000)

@qml.qnode(dev)
def f5():
    ninp=3
    qout=ninp
    mL=[None for i in range(ninp)] # locks memory
    for i in range(ninp):  
        qml.Hadamard(i)
        mL[i]=qml.measure(i)        
    hw=sum(mL)
    pL=np.array([0.5, 0.7, 0., 1.])
    angL=np.arccos(1-2*pL)
    [qml.cond(hw ==i, qml.RX)(angL[i],qout) for i in range(ninp+1)]
    return qml.sample()

print(qml.draw(f5)())
samples = f5()
counts = qml.counts(wires=[0, 1, 2, 3])._samples_to_counts(samples)
pprint(counts)

```

Output:

```auto

0: ──H──┤↗├─────────────────────────────────────────────────────────┤ Sample
1: ──────║───H──┤↗├─────────────────────────────────────────────────┤ Sample
2: ──────║───────║───H──┤↗├─────────────────────────────────────────┤ Sample
3: ──────║───────║───────║───RX(1.57)──RX(1.98)──RX(0.00)──RX(3.14)─┤ Sample
         ╚═══════║═══════║═══╬═════════╬═════════╬═════════╣ Sample
                 ╚═══════║═══╬═════════╬═════════╬═════════╣ Sample
                         ╚═══╩═════════╩═════════╩═════════╝ Sample
{'0000': 497,
 '0001': 522,
 '0010': 322,
 '0011': 690,
 '0100': 308,
 '0101': 708,
 '0110': 994,
 '1000': 316,
 '1001': 694,
 '1010': 1016,
 '1100': 948,
 '1111': 985}

```

Analysis of the output for requested probability vs. hw : ` pL=[0.5, 0.7, 0., 1.]`

- hw=0 has one input ‘000’ should have appended 1 with 50% prob - it is the case:

```auto
'0000': 497,
'0001': 522, --> p=0.5

```

- hw=1 has 3 inputs: 001, 010, 110, all should have attached ‘1’ with prob 0.7 - it is the case

```auto
 '0010': 322,
 '0011': 690, -->p=0.7
 '0100': 308,
 '0101': 708, -->p=0.7
 '1000': 316,
 '1001': 694, -->p=0.7

```

- hw=2 has inputs 011, 101, 110, should never have ‘1’ attached, correct, this are only strings I see

```auto
 '0110': 994,
 '1010': 1016,
 '1100': 948,

```

- hw=3 has one input 111 should always have attached 1, correct, I see only  
'`1111': 985` → p=1.0

---

_[View the full topic](https://discuss.pennylane.ai/t/feed-forward-on-ibm-hw-failure/3931)._
