What does "Error '00' mean?

I’m running PF.5.1. My code runs. I get the printed output:

the success probability is 0.2524

which is roughly what I expected but then above that I see a red stripe above my user output with the message Error '00'. My answer isn’t accepted and I have no idea what it is trying to tell me.

My code is:

@qml.qnode(dev)
def circuit(bomb: bool = False):
    qp.H(0)
    if bomb:
        # If I get a 1, the bomb explodes. I continue with 0
        qp.measure(wires=0, postselect=0)
    qp.H(0)
    # If I measure a 1, then it's definitely not a bomb.
    # This measurement isn't really necessary.
    qp.measure(wires=0)
    return qp.counts(wires = 0)

result = circuit(True)
prob_success = result.get('1', 0) / n_shots
print('the success probability is', prob_success)

I’d love to know both what is wrong with my code and what this cryptic error means.

Hi @fyellin , welcome to the forum! We’re excited that you’re here.

As a hint, circuit should not have an input i.e., running circuit() should yield the desired result.

Error '00' indicates that we are expecting an output key called 00 but cannot find it.

More broadly, the task is looking for the counts of two different measurements: m_bomb and m_det.

I hope these tips help!

Best wishes,

David

I did eventually figure out that that’s what the error message had to mean. It does seem strange that the puzzle not only wants you to get the right answer, but wants you to get it the correct method.

I’m now struggling with Part 2. The obvious solution is in the inconclusive case, just run the test again. The bomb will go off 75% of the time, but I’ll know there’s a bomb 25% + 25%/4 = 31.25% of the time. There is nothing I can do with the qubit after the detector measurement. The qubit is definitively |0> or |1>.

I could rotate the qubit so that I was measuring it halfway between |+> and |0>, but that would give me both false positives and false negatives.

When I run the following code:

@qp.qnode(dev)
def circuit():
    # |0> -> |+>
    qp.H(0)

    # No bomb.  q0 unchanged.
    # Bomb |0> Bomb doesn't explode. q0 = |0>
    # Bomb |1> Bomb explodes. q0 = |1>  But we throw away this case!
    m_bomb = qp.measure(wires=0, postselect=0)

    # Bomb:      |0> => |+>
    # No bomb:   |+> => |0>
    qp.H(0)

    # Bomb:      Measurement.  50%  |0> + 50% |1>
    # No bomb:   Measurement.  100% |0>
    # Measurement of |1> unambiguously indicates a bomb
    # Measurement of |0> is ambigous.  
    m_det_1 = qp.measure(wires=0, reset=True)

    # Run the same test again in the ambiguous case, having reset the qubit.
    qp.cond(m_det_1 == 0, qp.H)(0)
    m_bomb_2 = qp.measure(wires=0)
    qp.cond(m_det_1 == 0, qp.H)(0)
    m_det_2 = qp.measure(wires=0)

    return qp.counts([m_bomb, m_det_1]), qp.counts([m_bomb_2, m_det_2])


results1, results2 = circuit()
prob_suc = (results1['01'] + results2['01']) / n_shots
print("The success probability is", prob_suc)

I get the right answer, but get the error message “Error: Your quantum circuit isn’t quite right.” Not helpful at all. I wished the text gave me some indication of what it wanted, rather than letting me know I’ve got the wrong right answer.

Hi @fyellin , thanks for your question. Glad to see that you are progressing with that topic!

It is a harder topic because it is more open-ended, so it’s natural to encounter problems. The prompt also leaves a little unexplained.

For PF.5.1., we discarded all instances when the first detector provided an inconclusive result. Now, we are trying to recover useful information when that happens with qp.cond.

Firstly, resetting the qubit in m_det_1 is not advisable because the outcome is guaranteed to be |0\rangle. Secondly, regarding the language, our convention at the first detector is: |1\rangle if there is a bomb there. Thirdly, just like in PF.5.1, you have a circuit with post-selection. You might want to try that in the second part :wink:

I hope this helps!

Yes. I had managed to finish the puzzle. I am stubborn that way.

I realized that I was doing something that didn’t affect correctness but was unnecessary. Removing it make the grader happy.

Outstanding work, @fyellin ! Keep going!

Out of curiosity, is there anything in particular you are learning PennyLane for?