From e923ebc76bc63b8dc442f7bcd6c7c4d60202671f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Zaragoza=20Cort=C3=A9s?= Date: Sat, 19 Feb 2022 00:25:10 -0800 Subject: [PATCH 1/3] Fix to known QuantumProcessorTranslationException not being handled correctly (#949) * Add logging. * Add more logging. * Handle TargetInvocationException. --- .../EntryPointDriver/Azure/Azure.cs | 43 ++++++++++++++++--- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/src/Simulation/EntryPointDriver/Azure/Azure.cs b/src/Simulation/EntryPointDriver/Azure/Azure.cs index 0965e78f212..cf58e04a8c1 100644 --- a/src/Simulation/EntryPointDriver/Azure/Azure.cs +++ b/src/Simulation/EntryPointDriver/Azure/Azure.cs @@ -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; @@ -204,6 +205,32 @@ private static async Task SubmitQir( /// The exit code. private static async Task DisplayJobOrError(AzureSettings settings, Task 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); @@ -211,16 +238,20 @@ private static async Task DisplayJobOrError(AzureSettings settings, Task Date: Thu, 24 Feb 2022 16:24:58 -0800 Subject: [PATCH 2/3] Update wording for Azure submission errors --- src/Simulation/EntryPointDriver/Azure/Azure.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Simulation/EntryPointDriver/Azure/Azure.cs b/src/Simulation/EntryPointDriver/Azure/Azure.cs index cf58e04a8c1..21b0f931aa6 100644 --- a/src/Simulation/EntryPointDriver/Azure/Azure.cs +++ b/src/Simulation/EntryPointDriver/Azure/Azure.cs @@ -207,12 +207,12 @@ private static async Task DisplayJobOrError(AzureSettings settings, Task DisplayError( - "Something went wrong when submitting the program to the Azure Quantum service.", + "An error occurred when submitting 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.", + "Unable to translate the program for execution on the target quantum machine.", ex.Message); bool HandleTargetInvocationException(TargetInvocationException ex) From fd427928c001cd9a436e5201bf9ede3df2375a62 Mon Sep 17 00:00:00 2001 From: "Stefan J. Wernli" Date: Thu, 24 Feb 2022 22:27:18 -0800 Subject: [PATCH 3/3] Fix error string in test case --- src/Simulation/EntryPointDriver.Tests/Tests.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Simulation/EntryPointDriver.Tests/Tests.fs b/src/Simulation/EntryPointDriver.Tests/Tests.fs index 1e00e8bd15b..fdf5a447922 100644 --- a/src/Simulation/EntryPointDriver.Tests/Tests.fs +++ b/src/Simulation/EntryPointDriver.Tests/Tests.fs @@ -929,7 +929,7 @@ let ``Submit has required options`` () = let ``Submit catches exceptions`` () = let given = test "Returns Unit" given submitWithErrorTarget - |> failsWith "Something went wrong when submitting the program to the Azure Quantum service. + |> failsWith "An error occurred when submitting to the Azure Quantum service. This machine always has an error."