oreilly-qc / oreilly-qc.github.io

Code samples for Programming Quantum Computers, from O'Reilly Media
130 stars 59 forks source link

Unused variable in Spy Hunter (Example 2-4) #52

Closed emipc closed 2 weeks ago

emipc commented 2 weeks ago

The spy_had variable in the Example 2-4 Quantum random spy hunter seems to have no effect on the program's behavior as it is always set to 0. It might be redundant and can be removed.

emipc commented 2 weeks ago

Looks like it's only 0 in the book, but the value is 1 in the repo. Closing this issue.

emipc commented 2 weeks ago

I'd like to reopen this issue because I don't see the purpose of this variable. It has a static value used in conditionals, which doesn't seem valuable.

machinelevel commented 2 weeks ago

Hi Emi, the spy_had variable is there on purpose, to allow you to easily select which basis the spy performs their interception attempt in. If the spy's choice matches Alice's choice, then the spy wins, intercepting a perfect copy of the stolen bit, and avoids detection. If the spy guesses wrong, then they intercept a random bit, and pass a random bit to Bob, making it likely they'll be detected.

emipc commented 2 weeks ago

Thanks for the response, Eric! I clearly missed that point. I might need to read the chapter again 🙂