{ "cells": [ { "attachments": {}, "cell_type": "markdown", "id": "c74932e2", "metadata": {}, "source": [ "# How-to: retrieve results from backend" ] }, { "cell_type": "code", "execution_count": 1, "id": "f543c651", "metadata": {}, "outputs": [], "source": [ "from qiskit import transpile\n", "from qiskit.circuit.random import random_circuit\n", "\n", "from qiskit_braket_provider import AWSBraketProvider" ] }, { "attachments": {}, "cell_type": "markdown", "id": "e306df72", "metadata": {}, "source": [ "Let's create random circuit" ] }, { "cell_type": "code", "execution_count": 2, "id": "ddc70eea", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
                                 ┌───┐┌───────────────────┐           \n",
       "q_0: ──────────────────────────■─┤ Y ├┤ U2(6.0991,5.6116) ├───────────\n",
       "       ┌───────────────────┐   │ ├───┤└┬──────────────────┤           \n",
       "q_1: ──┤ R(4.3817,0.59173) ├───┼─┤ H ├─┤ R(4.7632,2.2276) ├───────────\n",
       "       └───────────────────┘   │ └─┬─┘ └──────────────────┘           \n",
       "q_2: ──────────────────────────■───┼────────────■────────────■────────\n",
       "     ┌───────────────────────┐     │            │            │   ┌───┐\n",
       "q_3: ┤0                      ├─────■────────────┼────────────┼───┤ H ├\n",
       "     │  {XX+YY}(6.13,4.7824) │            ┌─────┴──────┐   ┌─┴──┐└───┘\n",
       "q_4: ┤1                      ├────────────┤ Ry(4.0455) ├───┤ Sx ├─────\n",
       "     └───────────────────────┘            └────────────┘   └────┘     
" ], "text/plain": [ " ┌───┐┌───────────────────┐ \n", "q_0: ──────────────────────────■─┤ Y ├┤ U2(6.0991,5.6116) ├───────────\n", " ┌───────────────────┐ │ ├───┤└┬──────────────────┤ \n", "q_1: ──┤ R(4.3817,0.59173) ├───┼─┤ H ├─┤ R(4.7632,2.2276) ├───────────\n", " └───────────────────┘ │ └─┬─┘ └──────────────────┘ \n", "q_2: ──────────────────────────■───┼────────────■────────────■────────\n", " ┌───────────────────────┐ │ │ │ ┌───┐\n", "q_3: ┤0 ├─────■────────────┼────────────┼───┤ H ├\n", " │ {XX+YY}(6.13,4.7824) │ ┌─────┴──────┐ ┌─┴──┐└───┘\n", "q_4: ┤1 ├────────────┤ Ry(4.0455) ├───┤ Sx ├─────\n", " └───────────────────────┘ └────────────┘ └────┘ " ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "circuit = random_circuit(5, 3, seed=42)\n", "circuit.draw()" ] }, { "attachments": {}, "cell_type": "markdown", "id": "d96fb4ef", "metadata": {}, "source": [ "Get backend" ] }, { "cell_type": "code", "execution_count": 3, "id": "50522a02", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "BraketBackend[SV1]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "provider = AWSBraketProvider()\n", "backend = provider.get_backend(\"SV1\")\n", "backend" ] }, { "attachments": {}, "cell_type": "markdown", "id": "a9963aac", "metadata": {}, "source": [ "Transpile circuit against given backend" ] }, { "cell_type": "code", "execution_count": 4, "id": "efd93336", "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/html": [ "
global phase: 2.0774\n",
       "                                        ┌───────────┐     ┌────┐    ┌────────────┐                                                                                                                                           \n",
       "q_0 -> 0 ───────────────────────■───────┤ P(2.2423) ├─────┤ √X ├────┤ P(-1.7549) ├───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────\n",
       "         ┌──────────────┐       │       ├───────────┴┐┌───┴────┴───┐└────────────┘                ┌───┐┌─────────────┐ ┌────────────┐┌──────────────┐                                                                        \n",
       "q_1 -> 1 ┤ Rz(-0.14167) ├───────┼───────┤ Ry(2.4735) ├┤ Rz(2.9079) ├──────────────────────────────┤ X ├┤ Rz(-2.4203) ├─┤ Ry(2.2266) ├┤ Rz(-0.95318) ├────────────────────────────────────────────────────────────────────────\n",
       "         └──────────────┘       │       └────────────┘└────────────┘                              └─┬─┘└─────────────┘ └────────────┘└──────────────┘      ┌────────┐                                                        \n",
       "q_2 -> 2 ───────────────────────■───────────────────────────────────────────────────────────────────┼─────────■────────────────────────────────────────■───┤ P(π/4) ├─────────────■───────────────■──────────────────────────\n",
       "                         ┌─────────────┐    ┌───┐     ┌────────────┐    ┌───┐     ┌──────────────┐  │         │         ┌──────────┐    ┌────────┐     │   └────────┘             │               │                          \n",
       "q_3 -> 3 ────────────────┤ P(0.069993) ├────┤ X ├─────┤ Ry(-3.065) ├────┤ X ├─────┤ P(-0.069993) ├──■─────────┼─────────┤ Ry(-π/2) ├────┤ Rz(-π) ├─────┼──────────────────────────┼───────────────┼──────────────────────────\n",
       "                         └─┬─────────┬─┘    └─┬─┘     ├────────────┤    └─┬─┘     ├─────────────┬┘          ┌─┴─┐     ┌─┴──────────┴┐   └────────┘   ┌─┴─┐┌──────────┐┌────────┐┌─┴─┐┌─────────┐┌─┴─┐┌───────────┐┌─────────┐\n",
       "q_4 -> 4 ──────────────────┤ Ry(π/2) ├────────■───────┤ Ry(-3.065) ├──────■───────┤ Ry(0.45197) ├───────────┤ X ├─────┤ Ry(-2.0228) ├────────────────┤ X ├┤ Ry(-π/2) ├┤ Rz(-π) ├┤ X ├┤ P(-π/4) ├┤ X ├┤ Rz(-3π/4) ├┤ Ry(π/2) ├\n",
       "                           └─────────┘                └────────────┘              └─────────────┘           └───┘     └─────────────┘                └───┘└──────────┘└────────┘└───┘└─────────┘└───┘└───────────┘└─────────┘
" ], "text/plain": [ "global phase: 2.0774\n", " ┌───────────┐ ┌────┐ ┌────────────┐ \n", "q_0 -> 0 ───────────────────────■───────┤ P(2.2423) ├─────┤ √X ├────┤ P(-1.7549) ├───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────\n", " ┌──────────────┐ │ ├───────────┴┐┌───┴────┴───┐└────────────┘ ┌───┐┌─────────────┐ ┌────────────┐┌──────────────┐ \n", "q_1 -> 1 ┤ Rz(-0.14167) ├───────┼───────┤ Ry(2.4735) ├┤ Rz(2.9079) ├──────────────────────────────┤ X ├┤ Rz(-2.4203) ├─┤ Ry(2.2266) ├┤ Rz(-0.95318) ├────────────────────────────────────────────────────────────────────────\n", " └──────────────┘ │ └────────────┘└────────────┘ └─┬─┘└─────────────┘ └────────────┘└──────────────┘ ┌────────┐ \n", "q_2 -> 2 ───────────────────────■───────────────────────────────────────────────────────────────────┼─────────■────────────────────────────────────────■───┤ P(π/4) ├─────────────■───────────────■──────────────────────────\n", " ┌─────────────┐ ┌───┐ ┌────────────┐ ┌───┐ ┌──────────────┐ │ │ ┌──────────┐ ┌────────┐ │ └────────┘ │ │ \n", "q_3 -> 3 ────────────────┤ P(0.069993) ├────┤ X ├─────┤ Ry(-3.065) ├────┤ X ├─────┤ P(-0.069993) ├──■─────────┼─────────┤ Ry(-π/2) ├────┤ Rz(-π) ├─────┼──────────────────────────┼───────────────┼──────────────────────────\n", " └─┬─────────┬─┘ └─┬─┘ ├────────────┤ └─┬─┘ ├─────────────┬┘ ┌─┴─┐ ┌─┴──────────┴┐ └────────┘ ┌─┴─┐┌──────────┐┌────────┐┌─┴─┐┌─────────┐┌─┴─┐┌───────────┐┌─────────┐\n", "q_4 -> 4 ──────────────────┤ Ry(π/2) ├────────■───────┤ Ry(-3.065) ├──────■───────┤ Ry(0.45197) ├───────────┤ X ├─────┤ Ry(-2.0228) ├────────────────┤ X ├┤ Ry(-π/2) ├┤ Rz(-π) ├┤ X ├┤ P(-π/4) ├┤ X ├┤ Rz(-3π/4) ├┤ Ry(π/2) ├\n", " └─────────┘ └────────────┘ └─────────────┘ └───┘ └─────────────┘ └───┘└──────────┘└────────┘└───┘└─────────┘└───┘└───────────┘└─────────┘" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "transpiled_circuit = transpile(circuit, backend=backend, seed_transpiler=42)\n", "transpiled_circuit.draw(idle_wires=False, fold=-1)" ] }, { "attachments": {}, "cell_type": "markdown", "id": "fa7d65c1", "metadata": {}, "source": [ "Run circuit" ] }, { "cell_type": "code", "execution_count": 5, "id": "fc6aa158", "metadata": {}, "outputs": [], "source": [ "job = backend.run(transpiled_circuit, shots=10)" ] }, { "cell_type": "code", "execution_count": 6, "id": "a4ea3a45", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'Task id b171d67b-e8c4-4ec6-b548-1b6e8f7c6c38'" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "f\"Task id {job.job_id().split('/')[-1]}\"" ] }, { "attachments": {}, "cell_type": "markdown", "id": "83222235", "metadata": {}, "source": [ "Retrieve job by id from backend" ] }, { "cell_type": "code", "execution_count": 8, "id": "f65cd41c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "retrieved_job = backend.retrieve_job(task_id=job.job_id())\n", "retrieved_job" ] }, { "cell_type": "code", "execution_count": 9, "id": "652bf407", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'00001': 4, '01011': 1, '01000': 1, '00011': 3, '01001': 1}" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "retrieved_job.result().get_counts()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.10" } }, "nbformat": 4, "nbformat_minor": 5 }