Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sample notebook #2075

Merged
merged 2 commits into from
Dec 19, 2024
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
8 changes: 6 additions & 2 deletions vscode/src/azure/workspaceActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,13 @@ export function getPythonCodeForWorkspace(
# should be configured and used for authentication. For more information, see
# https://learn.microsoft.com/en-us/azure/developer/python/sdk/authentication-overview

import azure.quantum
from azure.quantum import Workspace

workspace = azure.quantum.Workspace(
# If using an access key, replace the below with: Workspace.from_connection_string(connection_string)
# Or set the "AZURE_QUANTUM_CONNECTION_STRING" environment variable and just use: Workspace()
# See https://learn.microsoft.com/en-us/azure/quantum/how-to-connect-workspace for more details.

workspace = Workspace(
subscription_id = "${subscriptionId || "MY_SUBSCRIPTION_ID"}",
resource_group = "${resourceGroup || "MY_RESOURCE_GROUP"}",
name = "${name || "MY_WORKSPACE_NAME"}",
Expand Down
37 changes: 35 additions & 2 deletions vscode/src/notebookTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,14 @@ import matplotlib.pyplot as plt
import numpy as np
from collections import Counter

results = qsharp.run("RandomBit()", shots=1000)
# Use save_events to suppress the automatic printing of events for every shot
results = qsharp.run("RandomBit()", shots=1000, save_events=True)
billti marked this conversation as resolved.
Show resolved Hide resolved

# Sort the results so that the histogram labels appear in the correct order
# We only care about the result values, not the event data, so extract just the result
results = [entry["result"] for entry in results]
results.sort()

# Count the number of times each result appears
counts = Counter(results)

Expand All @@ -111,7 +116,35 @@ plt.title("RandomBit() Results")
plt.bar(xlabels, counts)
plt.xticks(xlabels, values)
plt.show()
`,
`,
},
{
kind: vscode.NotebookCellKind.Markup,
languageId: "markdown",
value: `## Q# widgets

You can also use the \`qsharp_widgets\` package to visualize data. Install with \`pip install qsharp-widgets\``,
},
{
kind: vscode.NotebookCellKind.Code,
languageId: "python",
value: `from qsharp_widgets import Histogram

Histogram(results)
`,
},
{
kind: vscode.NotebookCellKind.Code,
languageId: "python",
value: `from qsharp_widgets import EstimatesPanel

estimate = qsharp.estimate("RandomBit()", [
{"errorBudget": 0.333, "qubitParams": {"name": "qubit_gate_ns_e3"}},
{"errorBudget": 0.333, "qubitParams": {"name": "qubit_gate_us_e4"}},
{"errorBudget": 0.333, "qubitParams": {"name": "qubit_maj_ns_e6"}, "qecScheme": {"name": "floquet_code"}}
])
EstimatesPanel(estimate)
`,
},
swernli marked this conversation as resolved.
Show resolved Hide resolved
{
kind: vscode.NotebookCellKind.Markup,
Expand Down
Loading