{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "44722111fdaf" }, "source": [ "# Getting started with Honeywell and Cirq on Azure Quantum\n", "
\n",
" ![]() | \n",
" \n",
" ![]() | \n",
" \n",
" ![]() | \n",
" \n",
" ![]() | \n",
"
0: ───H───@───M('b')───\n", " │ │\n", "1: ───────X───M────────" ], "text/plain": [ "0: ───H───@───M('b')───\n", " │ │\n", "1: ───────X───M────────" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import cirq\n", "\n", "q0, q1 = cirq.LineQubit.range(2)\n", "circuit = cirq.Circuit(\n", " cirq.H(q0), # Hadamard\n", " cirq.CNOT(q0, q1), # CNOT\n", " cirq.measure(q0, q1, key='b'), # Measure both qubits into classical register \"b\"\n", ")\n", "circuit" ] }, { "cell_type": "markdown", "metadata": { "id": "fc61d090b25b" }, "source": [ "You can now run the program via the Azure Quantum service and get the result. The following cell will submit a job that runs the circuit with 100 repetitions, wait until the job is completed and return the results." ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "id": "ed8cc1e2a22b" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "......." ] } ], "source": [ "result = service.run(program=circuit, repetitions=100)" ] }, { "cell_type": "markdown", "metadata": { "id": "f2ccb7c043c4" }, "source": [ "This returns a `cirq.Result` object. Note that the API validator only returns zeros." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "id": "710784ea4e12" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "b=0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n" ] } ], "source": [ "print(result)" ] }, { "cell_type": "markdown", "metadata": { "id": "60b2570d3341" }, "source": [ "## Asynchronous workflow using Jobs\n", "\n", "For long-running circuits, it can be useful to run them asynchronously. The `service.create_job` method returns a `Job`, which you can use to get the results after the job has run successfully." ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "id": "122d8679e03a" }, "outputs": [], "source": [ "job = service.create_job(program=circuit, repetitions=100)" ] }, { "cell_type": "markdown", "metadata": { "id": "b7315b371f77" }, "source": [ "To check on the job status, use `job.status()`:" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "id": "a92c9d72435b" }, "outputs": [ { "data": { "text/plain": [ "'Waiting'" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "job.status()" ] }, { "cell_type": "markdown", "metadata": { "id": "a5c2cebc3a51" }, "source": [ "To wait for the job to be done and get the results, use the blocking call `job.results()`:" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "id": "6dfec987654e" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ ".......{'m_b': ['00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00', '00']}\n" ] } ], "source": [ "result = job.results()\n", "print(result)" ] }, { "cell_type": "markdown", "metadata": { "id": "d3d658b2d172" }, "source": [ "This returns a dictionary of lists. The dictionary keys are the name of the classical register prepended with `\"m_\"`, and the values are a list of bit strings that are measured for each repetition. Since here, in the `cirq` program measures the results for both qubits 0 and 1 into a register `\"b\"`, you can access the list of measurement results for those qubits with key `\"m_b\"`. Since here you ran the program with 100 repetitions, the length of the list should be 100:" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "id": "bec675a56769" }, "outputs": [ { "data": { "text/plain": [ "100" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(result[\"m_b\"])" ] } ], "metadata": { "colab": { "name": "getting_started_honeywell.ipynb", "toc_visible": true }, "kernelspec": { "display_name": "Python 3", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 0 }