Consider the following code on which I want to run the resource estimator:
%%qsharp
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Diagnostics;
open Microsoft.Quantum.Math;
open Microsoft.Quantum.Arrays;
operation AlgoTest() : Unit {
let n=3; // Number of qubits
use q = Qubit[n];
mutable resultArray = [Zero, size = 3];
H(q[0]);
H(q[1]);
H(q[2]);
CNOT(q[0],q[1]);
for i in IndexRange(q) {
set resultArray w/= i <- M(q[i]);
// If I replace preceeding line by this one: compilation fails
// M(q[i]);
}
}
As indicated by the comment, calling "qsharp.azure.execute(AlgoTest)" after works, but if I replace the line set resultArray w/= i <- M(q[i]); by M(q[i]); it returns me the following error:
fail: Microsoft.Quantum.IQSharp.Snippets[0] QS0005 (/snippet_.qs:Microsoft.VisualStudio.LanguageServer.Protocol.Range): This expression has type Result and its value is implicitly ignored. Use "let _ = expr;" or "Ignore(expr);" to discard the value explicitly. /snippet_.qs(18,17): error QS0005: This expression has type Result and its value is implicitly ignored. Use "let _ = expr;" or "Ignore(expr);" to discard the value explicitly.
My understanding is that M(q[i]); is returning a value which is not stored (and for some reason Q# doesn't like it). The error suggests me to replace M(q[i]); by Ignore(M(q[i])); (and indeed in such case it works).
My question is: Would replacing M(q[i]); by Ignore(M(q[i])); indeed allow us to perform the correct resource estimate at the end of the day? Would it provide me with a resource estimate for an algorithm on which a layer of Hadamard has been implemented, followed by a CNOT between qubits 0 & 1, followed by a measurement in the $Z$ basis of all qubits? Or, for some reason, because of the command "Ignore" it will not do a resource estimation on this.
The documentation only says that the value of the measurement is ignored but does it have any influence on the resource estimate (such as the measurements are not taken into account in the estimate)?
The motivation behind my questions is to understand the philosophy of Q# on simple examples.