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

Create samples for QCI #823

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
220 changes: 220 additions & 0 deletions samples/azure-quantum/check-ghz/CheckGHZ-qci-qsharp.ipynb
@@ -0,0 +1,220 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Getting started with Integrated Hybrid Computing\n",
"In this sample, you will discover how to blend classical and quantum instructions in the same program, all fully processed by the quantum computing backend.\n",
"You can learn more about integrated hybrid computing at https://aka.ms/AQ/Hybrid/Docs\n",
"\n",
"## Connect to the Azure Quantum workspace\n",
"First, find the resource ID of your Azure Quantum workspace. You can copy/paste this from the top-right corner of your Quantum Workspace page in the Azure Portal.\n",
"\n",
"Next, you can run `%azure.connect` to connect to the workspace and display the list of provisioned targets that support execution of Q# programs. If you are prompted to login, be sure to use the same account you used to create your Azure Quantum workspace."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
"outputs_hidden": false,
"source_hidden": false
},
"nteract": {
"transient": {
"deleting": false
}
}
},
"outputs": [],
"source": [
"%azure.connect \"/subscriptions/subscriptionId/resourceGroups/resourceGroupName/providers/Microsoft.Quantum/Workspaces/workspaceName\" location=\"westus\""
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Select a target and opt-in to use integrated hybrid computing\n",
"First, we select the target the program is intended to be run on using the `%azure.target` command. This information is used by Q# compiler to check the program can be run on the specified target taking into consideration its capabilities.\n",
"\n",
"Since integrated hybrid computing is an opt-in feature, we run the `%azure.target-capability` command to opt into it.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%azure.target qci.simulator\n",
"%azure.target-capability AdaptiveExecution"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {
"nteract": {
"transient": {
"deleting": false
}
}
},
"source": [
"## Define the CheckGHZ operation\n",
"\n",
"This program prepares a Greenberger–Horne–Zeilinger (GHZ) state and counts the number of times qubit measurements are not perfectly correlated out of 10 attempts. Unlike in noiseless simulations, non-perfect correlations can occur when programs run on real quantum devices which are subject to the effects of noise.\n",
"\n",
"In the CheckGHZ() operation, we can see two capabilities of integrated hybrid computing being demonstrated:\n",
"1. **Branching** based on qubit measurements, which allows programs to execute different quantum operations or classical instructions depending on the results yielded by qubit measurements.\n",
"```Q#\n",
" if not (r0 == r1 and r1 == r2)\n",
"```\n",
"2. **Classical compute** performed in real time by the quantum machine itself.\n",
"```Q#\n",
" set mismatch += 1;\n",
"```\n",
"### ❕ Please note that you will see a warning displayed (QS5028)\n",
"It can be ignored for the purposes of this sample. It will be addressed in a subsequent release of the Quantum Development Kit."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"jupyter": {
"outputs_hidden": false,
"source_hidden": false
},
"microsoft": {},
"nteract": {
"transient": {
"deleting": false
}
}
},
"outputs": [],
"source": [
"open Microsoft.Quantum.Intrinsic;\n",
"open Microsoft.Quantum.Measurement;\n",
"\n",
"operation CheckGHZ() : Int {\n",
" use q = Qubit[3];\n",
" mutable mismatch = 0;\n",
" for _ in 1..10 {\n",
" // Prepare the GHZ state.\n",
" H(q[0]);\n",
" CNOT(q[0], q[1]);\n",
" CNOT(q[1], q[2]);\n",
"\n",
" // Measures and resets the 3 qubits\n",
" let (r0, r1, r2) = (MResetZ(q[0]), MResetZ(q[1]), MResetZ(q[2]));\n",
"\n",
" // Adjusts classical value based on qubit measurement results\n",
" if not (r0 == r1 and r1 == r2) {\n",
" set mismatch += 1;\n",
" }\n",
" }\n",
" return mismatch;\n",
"}"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Submit the program\n",
"If the job has not been completed after the client times out (300 seconds), you can query the status using `%azure.status` followed by querying the output using `%azure.output`.<br/>\n",
"\n",
"If the kernel was restarted after the program had been submitted, you will have to use `%azure.status <job_id>` to get the status of the job and `%azure.output <job_id>` to retrieve the results.<br/>\n",
"You can also check the status of the job under the **Job management** section on the left side menu of the portal.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%azure.execute CheckGHZ shots=50 timeout=300 poll=10"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%azure.status"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Understanding the results\n",
"Each item in the histogram represents the correlation mismatch count and the corresponding frequency the mismatch count was observed out of the number of shots that were run.<br/>\n",
"The histogram values can range from 0 (no correlation mismatch occurred) to 10 (all correlations checks were a mismatch)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%azure.output"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {
"nteract": {
"transient": {
"deleting": false
}
}
},
"source": [
"## ↗ Learning more about Integrated Hybrid Computing\n",
"Now that you have run this sample, you can further learn and experiment with other samples available in the gallery.\n",
"\n",
"To learn more, please refer to our [online documentation](https://aka.ms/AQ/Hybrid/Docs)."
]
}
],
"metadata": {
"kernel_info": {
"name": "iqsharp"
},
"kernelspec": {
"display_name": "Q#",
"language": "qsharp",
"name": "iqsharp"
},
"language_info": {
"file_extension": ".qs",
"mimetype": "text/x-qsharp",
"name": "qsharp",
"version": "0.27"
},
"nteract": {
"version": "nteract-front-end@1.0.0"
},
"vscode": {
"interpreter": {
"hash": "5928ddfb481d60843a3b943727ce04da7552e01006ad87377dd54780c5247bec"
}
}
},
"nbformat": 4,
"nbformat_minor": 0
}
5 changes: 5 additions & 0 deletions samples/azure-quantum/check-ghz/README.md
Expand Up @@ -16,3 +16,8 @@ products:
This sample illustrates how to blend classical and quantum instructions using a simple Q# program.

This sample is available in the notebook samples gallery in Azure Quantum workspaces in the Azure Portal. For an example of how to run these notebooks in Azure, see [this getting started guide](https://docs.microsoft.com/azure/quantum/get-started-jupyter-notebook?tabs=tabid-ionq).

## Manifest

- [CheckGHZ-quantinuum-qsharp.ipynb](./CheckGHZ-quantinuum-qsharp.ipynb): Azure Quantum notebook for running a program that blends classical and quantum on the Quantinuum simulator
- [CheckGHZ-qci-qsharp.ipynb](./CheckGHZ-qci-qsharp.ipynb): Azure Quantum notebook for running a program that blends classical and quantum on the QCI simulator
5 changes: 5 additions & 0 deletions samples/azure-quantum/three-qubit-repetition-code/README.md
Expand Up @@ -16,3 +16,8 @@ products:
This sample demonstrates how to create a 3 qubit repetition code that can be used to detect and correct bit flip errors.

It leverages integrated hybrid computing features to count the number of times a bit flip error occurred while the state of a qubit register is coherent.

## Manifest

- [TQRP-quantinuum-qsharp.ipynb](./TQRP-quantinuum-qsharp.ipynb): Azure Quantum notebook for running a 3-qubit repetition code on the Quantinuum simulator
- [TQRP-qci-qsharp.ipynb](./TQRP-qci-qsharp.ipynb): Azure Quantum notebook for running a 3-qubit repetition code on the QCI simulator