# How can I mesure a register of qubits and grab the index of the qubit with the highest probability in Q#?

I have an array of qubits, with indices to represent each such that if we have 3 qubits, we have 0, 1, 2 representing each. From here I would like to measure the probability of our qubits after running it through some gates. How can I grab these probabilities and spit out one of the indices based on which has the highest probability?

Cheers!

• In general, this is impossible to do via the No-Cloning Theorem, as you can't learn the probability of a measurement from a single copy of that state. May I ask more about the context to help understand your question better? Thanks! Aug 6 '20 at 19:43
• How does DumpRegister() work? By No-Cloning Theorem we shouldn't be able to utilize this right? In essence I would like to use DumpRegister but instead of getting visual results, I pick the one with the highest probability and utilize its index value. Context is related to the Durr Hoyer library, specifically QESA, in the last part of the algorithm we must measure the first register, and the qubit with highest probability, where each qubit represents an index, is your min... Utilizing MeasureInteger() is giving back what I believe is Little endian decoding, though this is not what I am after, Aug 6 '20 at 21:24
• I'm assuming you mean grab the qubit with the highest probability of reading 1? If so, you could repeatedly measure the qubits and select the one with the highest proportion (though this would be probabilistic). The DumpRegister method could also work, but you'd need an external program to identify the highest probability qubit Aug 7 '20 at 0:05
• Oh that is a nice idea actually, I could simply preserve the state of my register, and measure each qubit storing it in a list, then comparing to each other to find the highest probability. I am looking for a probabilistic outcome so I think this would work out. Aug 7 '20 at 2:59
• @Mridul: To clarify, simulators need not obey the no-cloning theorem, making it possible to get useful diagnostics when running on a simulator. DumpRegister doesn't violate the no-cloning theorem those diagnostics are displayed directly, and not used to condition the execution of a Q# program. Put differently, a Q# program can't ever "notice" a call to DumpMachine or DumpRegister, such that they can be safely replaced by no-ops on machines where that's not possible. Aug 7 '20 at 19:58

counts = Int[NumberOfQubits]