in Standard/src/Diagnostics/Emulation/AllowOperationCalls.cs [50:79]
bool IsSelf(ICallable callable) =>
callable.FullName == "Microsoft.Quantum.Diagnostics.AllowAtMostNCallsCA";
// Record whether or not the condition checked by this allow
// has failed, so that we can property unwind in the endOperation
// handler below.
var failed = false;
Handlers[Key].Push(Simulator.RegisterOperationHandlers(
startOperation: (callable, data) =>
{
if (IsSelf(callable)) return;
callStack = callStack.Push(callable.FullName);
if (callable.FullName == op.FullName)
{
callSites = callSites.Add(callStack);
if (callSites.Count > nTimes)
{
Simulator?.MaybeDisplayDiagnostic(new CallSites
{
Sites = callSites,
Subject = op.FullName
});
failed = true;
throw new ExecutionFailException(
$"Operation {op.FullName} was called more than the allowed {nTimes} times:\n{message}"
);
}
}
},