# Run circuit N times in Q#

I use dotnet run command to run my .qs quantum circuit. Is there a way to run my circuit N times, and get results of each run (like the shots parameter in Qiskit) ?

Thank you.

• You could create a python or C# host program to further process data. However, there must be a dotnet command. Sep 7 '20 at 10:57

Quantum programs in Q# can include classical logic as well as low-level quantum instructions, such that you can directly include the "shot" concept from circuits in your Q# programs by using a for-loop.

@EntryPoint()
operation RunSeveralTimes(nTimes : Int) : Result[] {
mutable results = new Result[nTimes];
for (idx in 0..nTimes - 1) {
set results w/= idx <- DoSomething();
}
return results;
}


When running this program with dotnet run, you can now pass --n-times as a command-line argument to control how many times your DoSomething() operation gets called. Similarly, if you're using Q# in Jupyter Notebooks, you can use a command like %simulate RunSeveralTimes nTimes=50. From Python interoperability, you can pass nTimes as a keyword argument, e.g.: RunSeveralTimes.simulate(nTimes=50).

The Q# standard libraries also offer several functions and operations to make this sort of loop easier to write:

• Exactly what I wanted, thank you very much ! Sep 18 '20 at 19:28

As mentioned by Jonathcraft, it's possible to modify the host program. For example, set the driver of the Q# program to be C#, then call the Q# program multiple times with a for loop.