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

Commit d160a88

Browse files
cesarzcbettinaheim
andauthored
Implement friendly URI option for Azure quantum machines (#294)
* Implemented friendly uri option in azure quantum. * Fixed tests. * Fixed tests after nerge conflict. Co-authored-by: bettinaheim <34236215+bettinaheim@users.noreply.github.com>
1 parent 0997916 commit d160a88

File tree

4 files changed

+45
-25
lines changed

4 files changed

+45
-25
lines changed

src/Azure/Azure.Quantum.Client/JobManagement/CloudJob.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public CloudJob(IWorkspace workspace, JobDetails jobDetails)
6060
/// <summary>
6161
/// Gets an URI to access the job.
6262
/// </summary>
63-
public Uri Uri => throw new NotImplementedException();
63+
public Uri Uri => GenerateUri();
6464

6565
/// <summary>
6666
/// Gets the workspace.
@@ -91,5 +91,16 @@ public async Task CancelAsync(CancellationToken cancellationToken = default)
9191
CloudJob job = (CloudJob)await this.Workspace.CancelJobAsync(this.Details.Id, cancellationToken);
9292
this.Details = job.Details;
9393
}
94+
95+
private Uri GenerateUri()
96+
{
97+
if (!(this.Workspace is Workspace cloudWorkspace))
98+
{
99+
throw new NotSupportedException($"{typeof(CloudJob)}'s Workspace is not of type {typeof(Workspace)} and does not have enough data to generate URI");
100+
}
101+
102+
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}";
103+
return new Uri(uriStr);
104+
}
94105
}
95106
}

src/Azure/Azure.Quantum.Client/JobManagement/Workspace.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ private Workspace(
114114
}
115115
}
116116

117+
public string ResourceGroupName { get => resourceGroupName; }
118+
119+
public string SubscriptionId { get => subscriptionId; }
120+
121+
public string WorkspaceName { get => workspaceName; }
122+
117123
/// <summary>
118124
/// Gets or sets the jobs client.
119125
/// Internal only.

src/Simulation/EntryPointDriver.Tests/Tests.fs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -471,8 +471,7 @@ let ``Shadows --shots`` () =
471471
given ["--shots"; "7"] |> yields "7"
472472
given (submitWithNothingTarget @ ["--shots"; "7"])
473473
|> yields "Warning: Option --shots is overridden by an entry point parameter name. Using default value 500.
474-
The friendly URI for viewing job results is not available yet. Showing the job ID instead.
475-
00000000-0000-0000-0000-0000000000000"
474+
https://www.example.com/00000000-0000-0000-0000-0000000000000"
476475

477476

478477
// Simulators
@@ -539,8 +538,7 @@ let ``Supports default custom simulator`` () =
539538
let ``Submit can submit a job`` () =
540539
let given = test 1
541540
given submitWithNothingTarget
542-
|> yields "The friendly URI for viewing job results is not available yet. Showing the job ID instead.
543-
00000000-0000-0000-0000-0000000000000"
541+
|> yields "https://www.example.com/00000000-0000-0000-0000-0000000000000"
544542

545543
[<Fact>]
546544
let ``Submit can show only the ID`` () =
@@ -551,8 +549,7 @@ let ``Submit can show only the ID`` () =
551549
let ``Submit uses default values`` () =
552550
let given = test 1
553551
given (submitWithNothingTarget @ ["--verbose"])
554-
|> yields "The friendly URI for viewing job results is not available yet. Showing the job ID instead.
555-
Subscription: mySubscription
552+
|> yields "Subscription: mySubscription
556553
Resource Group: myResourceGroup
557554
Workspace: myWorkspace
558555
Target: test.nothing
@@ -565,14 +562,13 @@ let ``Submit uses default values`` () =
565562
Dry Run: False
566563
Verbose: True
567564
568-
00000000-0000-0000-0000-0000000000000"
565+
https://www.example.com/00000000-0000-0000-0000-0000000000000"
569566

570567
[<Fact>]
571568
let ``Submit uses default values with default target`` () =
572569
let given = testWithTarget "test.nothing" 1
573570
given (submitWithoutTarget @ ["--verbose"])
574-
|> yields "The friendly URI for viewing job results is not available yet. Showing the job ID instead.
575-
Subscription: mySubscription
571+
|> yields "Subscription: mySubscription
576572
Resource Group: myResourceGroup
577573
Workspace: myWorkspace
578574
Target: test.nothing
@@ -585,7 +581,7 @@ let ``Submit uses default values with default target`` () =
585581
Dry Run: False
586582
Verbose: True
587583
588-
00000000-0000-0000-0000-0000000000000"
584+
https://www.example.com/00000000-0000-0000-0000-0000000000000"
589585

590586
[<Fact>]
591587
let ``Submit allows overriding default values`` () =
@@ -603,8 +599,7 @@ let ``Submit allows overriding default values`` () =
603599
"--shots"
604600
"750"
605601
])
606-
|> yields "The friendly URI for viewing job results is not available yet. Showing the job ID instead.
607-
Subscription: mySubscription
602+
|> yields "Subscription: mySubscription
608603
Resource Group: myResourceGroup
609604
Workspace: myWorkspace
610605
Target: test.nothing
@@ -617,7 +612,7 @@ let ``Submit allows overriding default values`` () =
617612
Dry Run: False
618613
Verbose: True
619614
620-
00000000-0000-0000-0000-0000000000000"
615+
https://www.example.com/00000000-0000-0000-0000-0000000000000"
621616

622617
[<Fact>]
623618
let ``Submit allows overriding default values with default target`` () =
@@ -635,8 +630,7 @@ let ``Submit allows overriding default values with default target`` () =
635630
"--shots"
636631
"750"
637632
])
638-
|> yields "The friendly URI for viewing job results is not available yet. Showing the job ID instead.
639-
Subscription: mySubscription
633+
|> yields "Subscription: mySubscription
640634
Resource Group: myResourceGroup
641635
Workspace: myWorkspace
642636
Target: test.nothing
@@ -649,14 +643,13 @@ let ``Submit allows overriding default values with default target`` () =
649643
Dry Run: False
650644
Verbose: True
651645
652-
00000000-0000-0000-0000-0000000000000"
646+
https://www.example.com/00000000-0000-0000-0000-0000000000000"
653647

654648
[<Fact>]
655649
let ``Submit requires a positive number of shots`` () =
656650
let given = test 1
657651
given (submitWithNothingTarget @ ["--shots"; "1"])
658-
|> yields "The friendly URI for viewing job results is not available yet. Showing the job ID instead.
659-
00000000-0000-0000-0000-0000000000000"
652+
|> yields "https://www.example.com/00000000-0000-0000-0000-0000000000000"
660653
given (submitWithNothingTarget @ ["--shots"; "0"]) |> fails
661654
given (submitWithNothingTarget @ ["--shots"; "-1"]) |> fails
662655

@@ -691,8 +684,7 @@ let ``Submit has required options`` () =
691684
for args in powerSet allArgs do
692685
given (commandName :: List.concat args)
693686
|> if List.length args = List.length allArgs
694-
then yields "The friendly URI for viewing job results is not available yet. Showing the job ID instead.
695-
00000000-0000-0000-0000-0000000000000"
687+
then yields "https://www.example.com/00000000-0000-0000-0000-0000000000000"
696688
else fails
697689

698690
[<Fact>]

src/Simulation/EntryPointDriver/Azure.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,21 @@ private static void DisplayJob(IQuantumMachineJob job, OutputFormat format)
121121
switch (format)
122122
{
123123
case OutputFormat.FriendlyUri:
124-
// TODO:
125-
DisplayWithColor(ConsoleColor.Yellow, Console.Error,
126-
"The friendly URI for viewing job results is not available yet. Showing the job ID instead.");
127-
Console.WriteLine(job.Id);
124+
try
125+
{
126+
Console.WriteLine(job.Uri);
127+
}
128+
catch (Exception ex)
129+
{
130+
DisplayWithColor(
131+
ConsoleColor.Yellow,
132+
Console.Error,
133+
$"The friendly URI for viewing job results could not be obtained.{System.Environment.NewLine}" +
134+
$"Error details: {ex.Message}" +
135+
$"Showing the job ID instead.");
136+
137+
Console.WriteLine(job.Id);
138+
}
128139
break;
129140
case OutputFormat.Id:
130141
Console.WriteLine(job.Id);

0 commit comments

Comments
 (0)