Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
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
13 changes: 12 additions & 1 deletion src/Azure/Azure.Quantum.Client/JobManagement/CloudJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public CloudJob(IWorkspace workspace, JobDetails jobDetails)
/// <summary>
/// Gets an URI to access the job.
/// </summary>
public Uri Uri => throw new NotImplementedException();
public Uri Uri => GenerateUri();

/// <summary>
/// Gets the workspace.
Expand Down Expand Up @@ -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);
}
}
}
6 changes: 6 additions & 0 deletions src/Azure/Azure.Quantum.Client/JobManagement/Workspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ private Workspace(
}
}

public string ResourceGroupName { get => resourceGroupName; }

public string SubscriptionId { get => subscriptionId; }

public string WorkspaceName { get => workspaceName; }

/// <summary>
/// Gets or sets the jobs client.
/// Internal only.
Expand Down
32 changes: 12 additions & 20 deletions src/Simulation/EntryPointDriver.Tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"

[<Fact>]
let ``Submit can show only the ID`` () =
Expand All @@ -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
Expand All @@ -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"

[<Fact>]
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
Expand All @@ -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"

[<Fact>]
let ``Submit allows overriding default values`` () =
Expand All @@ -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
Expand All @@ -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"

[<Fact>]
let ``Submit allows overriding default values with default target`` () =
Expand All @@ -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
Expand All @@ -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"

[<Fact>]
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

Expand Down Expand Up @@ -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

[<Fact>]
Expand Down
19 changes: 15 additions & 4 deletions src/Simulation/EntryPointDriver/Azure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down