Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 37 additions & 6 deletions src/Simulation/EntryPointDriver/Azure/Azure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Immutable;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.Azure.Quantum;
using Microsoft.Azure.Quantum.Exceptions;
Expand Down Expand Up @@ -204,23 +205,53 @@ private static async Task<int> SubmitQir(
/// <returns>The exit code.</returns>
private static async Task<int> DisplayJobOrError(AzureSettings settings, Task<IQuantumMachineJob> job)
{
void DisplayAzureQuantumException(AzureQuantumException ex) =>
DisplayError(
"Something went wrong when submitting the program to the Azure Quantum service.",
ex.Message);

void DisplayQuantumProcessorTranslationException(QuantumProcessorTranslationException ex) =>
DisplayError(
"Something went wrong when performing translation to the intermediate representation used by the target quantum machine.",
ex.Message);

bool HandleTargetInvocationException(TargetInvocationException ex)
{
if (ex.InnerException is AzureQuantumException azureQuantumEx)
{
DisplayAzureQuantumException(azureQuantumEx);
return true;
}
else if (ex.InnerException is QuantumProcessorTranslationException quantumProcessorTranslationEx)
{
DisplayQuantumProcessorTranslationException(quantumProcessorTranslationEx);
return true;
}

return false;
}

try
{
DisplayJob(await job, settings.Output);
return 0;
}
catch (AzureQuantumException ex)
{
DisplayError(
"Something went wrong when submitting the program to the Azure Quantum service.",
ex.Message);
DisplayAzureQuantumException(ex);
return 1;
}
catch (QuantumProcessorTranslationException ex)
{
DisplayError(
"Something went wrong when performing translation to the intermediate representation used by the target quantum machine.",
ex.Message);
DisplayQuantumProcessorTranslationException(ex);
return 1;
}
catch (TargetInvocationException ex)
{
if (!HandleTargetInvocationException(ex))
{
throw;
}
return 1;
}
}
Expand Down