Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit e923ebc

Browse files
cesarzcswernli
authored andcommitted
Fix to known QuantumProcessorTranslationException not being handled correctly (#949)
* Add logging. * Add more logging. * Handle TargetInvocationException.
1 parent 2be25d3 commit e923ebc

File tree

1 file changed

+37
-6
lines changed
  • src/Simulation/EntryPointDriver/Azure

1 file changed

+37
-6
lines changed

src/Simulation/EntryPointDriver/Azure/Azure.cs

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Immutable;
6+
using System.Reflection;
67
using System.Threading.Tasks;
78
using Microsoft.Azure.Quantum;
89
using Microsoft.Azure.Quantum.Exceptions;
@@ -204,23 +205,53 @@ private static async Task<int> SubmitQir(
204205
/// <returns>The exit code.</returns>
205206
private static async Task<int> DisplayJobOrError(AzureSettings settings, Task<IQuantumMachineJob> job)
206207
{
208+
void DisplayAzureQuantumException(AzureQuantumException ex) =>
209+
DisplayError(
210+
"Something went wrong when submitting the program to the Azure Quantum service.",
211+
ex.Message);
212+
213+
void DisplayQuantumProcessorTranslationException(QuantumProcessorTranslationException ex) =>
214+
DisplayError(
215+
"Something went wrong when performing translation to the intermediate representation used by the target quantum machine.",
216+
ex.Message);
217+
218+
bool HandleTargetInvocationException(TargetInvocationException ex)
219+
{
220+
if (ex.InnerException is AzureQuantumException azureQuantumEx)
221+
{
222+
DisplayAzureQuantumException(azureQuantumEx);
223+
return true;
224+
}
225+
else if (ex.InnerException is QuantumProcessorTranslationException quantumProcessorTranslationEx)
226+
{
227+
DisplayQuantumProcessorTranslationException(quantumProcessorTranslationEx);
228+
return true;
229+
}
230+
231+
return false;
232+
}
233+
207234
try
208235
{
209236
DisplayJob(await job, settings.Output);
210237
return 0;
211238
}
212239
catch (AzureQuantumException ex)
213240
{
214-
DisplayError(
215-
"Something went wrong when submitting the program to the Azure Quantum service.",
216-
ex.Message);
241+
DisplayAzureQuantumException(ex);
217242
return 1;
218243
}
219244
catch (QuantumProcessorTranslationException ex)
220245
{
221-
DisplayError(
222-
"Something went wrong when performing translation to the intermediate representation used by the target quantum machine.",
223-
ex.Message);
246+
DisplayQuantumProcessorTranslationException(ex);
247+
return 1;
248+
}
249+
catch (TargetInvocationException ex)
250+
{
251+
if (!HandleTargetInvocationException(ex))
252+
{
253+
throw;
254+
}
224255
return 1;
225256
}
226257
}

0 commit comments

Comments
 (0)