diff --git a/src/Azure/Azure.Quantum.Client/JobManagement/CloudJob.cs b/src/Azure/Azure.Quantum.Client/JobManagement/CloudJob.cs index 746de8c57b1..bfc879eb9d2 100644 --- a/src/Azure/Azure.Quantum.Client/JobManagement/CloudJob.cs +++ b/src/Azure/Azure.Quantum.Client/JobManagement/CloudJob.cs @@ -60,7 +60,7 @@ public CloudJob(IWorkspace workspace, JobDetails jobDetails) /// /// Gets an URI to access the job. /// - public Uri Uri => throw new NotImplementedException(); + public Uri Uri => GenerateUri(); /// /// Gets the workspace. @@ -91,5 +91,16 @@ public async Task CancelAsync(CancellationToken cancellationToken = default) CloudJob job = (CloudJob)await this.Workspace.CancelJobAsync(this.Details.Id, cancellationToken); this.Details = job.Details; } + + private Uri GenerateUri() + { + if (!(this.Workspace is Workspace cloudWorkspace)) + { + throw new NotSupportedException($"{typeof(CloudJob)}'s Workspace is not of type {typeof(Workspace)} and does not have enough data to generate URI"); + } + + var uriStr = $"https://ms.portal.azure.com/#@microsoft.onmicrosoft.com/resource/subscriptions/{cloudWorkspace.SubscriptionId}/resourceGroups/{cloudWorkspace.ResourceGroupName}/providers/Microsoft.Quantum/Workspaces/{cloudWorkspace.WorkspaceName}/job_management?microsoft_azure_quantum_jobid={Id}"; + return new Uri(uriStr); + } } } diff --git a/src/Azure/Azure.Quantum.Client/JobManagement/Workspace.cs b/src/Azure/Azure.Quantum.Client/JobManagement/Workspace.cs index c123010c18b..f37ed454817 100644 --- a/src/Azure/Azure.Quantum.Client/JobManagement/Workspace.cs +++ b/src/Azure/Azure.Quantum.Client/JobManagement/Workspace.cs @@ -114,6 +114,12 @@ private Workspace( } } + public string ResourceGroupName { get => resourceGroupName; } + + public string SubscriptionId { get => subscriptionId; } + + public string WorkspaceName { get => workspaceName; } + /// /// Gets or sets the jobs client. /// Internal only. diff --git a/src/Simulation/EntryPointDriver.Tests/Tests.fs b/src/Simulation/EntryPointDriver.Tests/Tests.fs index 0059809c97b..7206cf9f44e 100644 --- a/src/Simulation/EntryPointDriver.Tests/Tests.fs +++ b/src/Simulation/EntryPointDriver.Tests/Tests.fs @@ -471,8 +471,7 @@ let ``Shadows --shots`` () = given ["--shots"; "7"] |> yields "7" given (submitWithNothingTarget @ ["--shots"; "7"]) |> yields "Warning: Option --shots is overridden by an entry point parameter name. Using default value 500. - The friendly URI for viewing job results is not available yet. Showing the job ID instead. - 00000000-0000-0000-0000-0000000000000" + https://www.example.com/00000000-0000-0000-0000-0000000000000" // Simulators @@ -539,8 +538,7 @@ let ``Supports default custom simulator`` () = let ``Submit can submit a job`` () = let given = test 1 given submitWithNothingTarget - |> yields "The friendly URI for viewing job results is not available yet. Showing the job ID instead. - 00000000-0000-0000-0000-0000000000000" + |> yields "https://www.example.com/00000000-0000-0000-0000-0000000000000" [] let ``Submit can show only the ID`` () = @@ -551,8 +549,7 @@ let ``Submit can show only the ID`` () = let ``Submit uses default values`` () = let given = test 1 given (submitWithNothingTarget @ ["--verbose"]) - |> yields "The friendly URI for viewing job results is not available yet. Showing the job ID instead. - Subscription: mySubscription + |> yields "Subscription: mySubscription Resource Group: myResourceGroup Workspace: myWorkspace Target: test.nothing @@ -565,14 +562,13 @@ let ``Submit uses default values`` () = Dry Run: False Verbose: True - 00000000-0000-0000-0000-0000000000000" + https://www.example.com/00000000-0000-0000-0000-0000000000000" [] let ``Submit uses default values with default target`` () = let given = testWithTarget "test.nothing" 1 given (submitWithoutTarget @ ["--verbose"]) - |> yields "The friendly URI for viewing job results is not available yet. Showing the job ID instead. - Subscription: mySubscription + |> yields "Subscription: mySubscription Resource Group: myResourceGroup Workspace: myWorkspace Target: test.nothing @@ -585,7 +581,7 @@ let ``Submit uses default values with default target`` () = Dry Run: False Verbose: True - 00000000-0000-0000-0000-0000000000000" + https://www.example.com/00000000-0000-0000-0000-0000000000000" [] let ``Submit allows overriding default values`` () = @@ -603,8 +599,7 @@ let ``Submit allows overriding default values`` () = "--shots" "750" ]) - |> yields "The friendly URI for viewing job results is not available yet. Showing the job ID instead. - Subscription: mySubscription + |> yields "Subscription: mySubscription Resource Group: myResourceGroup Workspace: myWorkspace Target: test.nothing @@ -617,7 +612,7 @@ let ``Submit allows overriding default values`` () = Dry Run: False Verbose: True - 00000000-0000-0000-0000-0000000000000" + https://www.example.com/00000000-0000-0000-0000-0000000000000" [] let ``Submit allows overriding default values with default target`` () = @@ -635,8 +630,7 @@ let ``Submit allows overriding default values with default target`` () = "--shots" "750" ]) - |> yields "The friendly URI for viewing job results is not available yet. Showing the job ID instead. - Subscription: mySubscription + |> yields "Subscription: mySubscription Resource Group: myResourceGroup Workspace: myWorkspace Target: test.nothing @@ -649,14 +643,13 @@ let ``Submit allows overriding default values with default target`` () = Dry Run: False Verbose: True - 00000000-0000-0000-0000-0000000000000" + https://www.example.com/00000000-0000-0000-0000-0000000000000" [] let ``Submit requires a positive number of shots`` () = let given = test 1 given (submitWithNothingTarget @ ["--shots"; "1"]) - |> yields "The friendly URI for viewing job results is not available yet. Showing the job ID instead. - 00000000-0000-0000-0000-0000000000000" + |> yields "https://www.example.com/00000000-0000-0000-0000-0000000000000" given (submitWithNothingTarget @ ["--shots"; "0"]) |> fails given (submitWithNothingTarget @ ["--shots"; "-1"]) |> fails @@ -691,8 +684,7 @@ let ``Submit has required options`` () = for args in powerSet allArgs do given (commandName :: List.concat args) |> if List.length args = List.length allArgs - then yields "The friendly URI for viewing job results is not available yet. Showing the job ID instead. - 00000000-0000-0000-0000-0000000000000" + then yields "https://www.example.com/00000000-0000-0000-0000-0000000000000" else fails [] diff --git a/src/Simulation/EntryPointDriver/Azure.cs b/src/Simulation/EntryPointDriver/Azure.cs index 2f53a878836..541e939b1b0 100644 --- a/src/Simulation/EntryPointDriver/Azure.cs +++ b/src/Simulation/EntryPointDriver/Azure.cs @@ -121,10 +121,21 @@ private static void DisplayJob(IQuantumMachineJob job, OutputFormat format) switch (format) { case OutputFormat.FriendlyUri: - // TODO: - DisplayWithColor(ConsoleColor.Yellow, Console.Error, - "The friendly URI for viewing job results is not available yet. Showing the job ID instead."); - Console.WriteLine(job.Id); + try + { + Console.WriteLine(job.Uri); + } + catch (Exception ex) + { + DisplayWithColor( + ConsoleColor.Yellow, + Console.Error, + $"The friendly URI for viewing job results could not be obtained.{System.Environment.NewLine}" + + $"Error details: {ex.Message}" + + $"Showing the job ID instead."); + + Console.WriteLine(job.Id); + } break; case OutputFormat.Id: Console.WriteLine(job.Id);