7

I am attempting to run a series of tests on a Q# program I'm running on the local simulator, but I'm not seeing any way to use >1 shot and collect the results of those shots at once, as in essentially every other quantum language/system I've seen. Is this not a feature at all in the Q#/Azure Quantum system? Thank you!

1 Answers1

5

Thanks for your question! If you're interested in running multiple shots of a quantum operation, Q# allow for doing that with conventional programming techniques such as a for loop:

open Microsoft.Quantum.Arrays;
open Microsoft.Quantum.Measurement;

operation SampleRandomBit() : Result { using (q = Qubit()) { return MResetX(q); } }

operation SampleManyRandomBits(nBits : Int) : Result[] { mutable results = EmptyArray<Result>(); for (_ in 1..nBits) { set results += [SampleRandomBit()]; } return results; }

The Q# standard library also provides some convenience operations for repeating operations in this way, such as DrawMany or EstimateFrequency:

open Microsoft.Quantum.Characterization;

operation SampleManyRandomBits(nBits : Int) : Result[] { return DrawMany(SampleRandomBit, nBits, ()); }

operation EstimateHeadsProbability(nShots : Int) : Double { return EstimateFrequency(ApplyToEach(H, _), Measure([PauliZ], _), 1, nShots); }

Chris Granade
  • 1,088
  • 7
  • 10