in utilities/Microsoft.Quantum.Katas/KataMagic.cs [161:204]
public virtual bool Simulate(OperationInfo test, OperationInfo userAnswer, IChannel channel)
{
var skeletonAnswer = FindSkeletonAnswer(test, userAnswer);
if (skeletonAnswer == null)
{
channel.Stderr($"Invalid task: {userAnswer.FullName}");
return false;
}
try
{
var qsim = CreateSimulator();
qsim.DisableExceptionPrinting();
qsim.DisableLogToConsole();
qsim.OnLog += channel.Stdout;
qsim.OnDisplayableDiagnostic += channel.Display;
// Register all solutions to previously executed tasks (including the current one)
foreach (KeyValuePair<OperationInfo, OperationInfo> answer in AllAnswers) {
Logger.LogDebug($"Registering {answer.Key.FullName}");
qsim.Register(answer.Key.RoslynType, answer.Value.RoslynType, typeof(ICallable));
}
var value = test.RunAsync(qsim, null).Result;
if (qsim is IDisposable dis) { dis.Dispose(); }
return true;
}
catch (AggregateException agg)
{
foreach (var e in agg.InnerExceptions) { channel.Stderr(e.Message); }
channel.Stderr($"Try again!");
return false;
}
catch (Exception e)
{
channel.Stderr(e.Message);
channel.Stderr($"Try again!");
return false;
}
}