6
$\begingroup$

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!

$\endgroup$
5
$\begingroup$

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);
}
$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.