|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# [WIP] Execution Tutorial" |
| 8 | + ] |
| 9 | + }, |
| 10 | + { |
| 11 | + "cell_type": "markdown", |
| 12 | + "metadata": {}, |
| 13 | + "source": [ |
| 14 | + "A typical workflow with classiq ends with the execution of a quantum program on a chosen simulator or hardware (and post-processing the results).\n", |
| 15 | + "\n", |
| 16 | + "\n", |
| 17 | + "Another typical workflow, called _hybrid execution_ is based not on the execution of a single quantum program, but on iterative executions of quantum progarams that are tuned between iterations according to some classical logic (see for example the [VQE algorithm](https://en.wikipedia.org/wiki/Variational_quantum_eigensolver)).\n", |
| 18 | + "\n", |
| 19 | + "In this tutorial, we will cover the required knowledge for both usecases:\n", |
| 20 | + "- Specifying the quantum backend (hardware or simulator) on which to run, and the `n_shots` number of times to run.\n", |
| 21 | + "- use `ExecutionSession` as a context manager for the execution:\n", |
| 22 | + " - Choosing between `sample` (measurement aling the z-axis) and `estimate` as the execution primitive.\n", |
| 23 | + " - Creating parametric circuits and executing them for different parameter-values.\n", |
| 24 | + " - Using batch-execution to obtain multiple results in a single command.\n", |
| 25 | + "\n" |
| 26 | + ] |
| 27 | + }, |
| 28 | + { |
| 29 | + "cell_type": "markdown", |
| 30 | + "metadata": {}, |
| 31 | + "source": [ |
| 32 | + "## Specifying Backend and Number of Shots\n", |
| 33 | + "\n", |
| 34 | + "Let's look into the following quantum model:" |
| 35 | + ] |
| 36 | + }, |
| 37 | + { |
| 38 | + "cell_type": "code", |
| 39 | + "execution_count": 1, |
| 40 | + "metadata": {}, |
| 41 | + "outputs": [ |
| 42 | + { |
| 43 | + "name": "stdout", |
| 44 | + "output_type": "stream", |
| 45 | + "text": [ |
| 46 | + "Opening: https://platform.classiq.io/circuit/2t8Hqj0F0Ixb67vJRXiGzQLjy0G?version=0.68.0\n" |
| 47 | + ] |
| 48 | + } |
| 49 | + ], |
| 50 | + "source": [ |
| 51 | + "from classiq import *\n", |
| 52 | + "\n", |
| 53 | + "@qfunc\n", |
| 54 | + "def main(x: Output[QBit]):\n", |
| 55 | + " allocate(1, x)\n", |
| 56 | + " RX(3.14, x)\n", |
| 57 | + "\n", |
| 58 | + "\n", |
| 59 | + "qmod = create_model(main)\n", |
| 60 | + "qprog = synthesize(qmod)" |
| 61 | + ] |
| 62 | + }, |
| 63 | + { |
| 64 | + "cell_type": "markdown", |
| 65 | + "metadata": {}, |
| 66 | + "source": [ |
| 67 | + "[***] show how to specify BE and n_shots, both in IDE and in code." |
| 68 | + ] |
| 69 | + }, |
| 70 | + { |
| 71 | + "cell_type": "markdown", |
| 72 | + "metadata": {}, |
| 73 | + "source": [ |
| 74 | + "## Using Execution Session as a Context Manager\n" |
| 75 | + ] |
| 76 | + }, |
| 77 | + { |
| 78 | + "cell_type": "markdown", |
| 79 | + "metadata": {}, |
| 80 | + "source": [ |
| 81 | + "[***] add subsections according to details in the first section.\n", |
| 82 | + "use Nadav's notebook and the user guide as resources." |
| 83 | + ] |
| 84 | + }, |
| 85 | + { |
| 86 | + "cell_type": "markdown", |
| 87 | + "metadata": {}, |
| 88 | + "source": [ |
| 89 | + "## [Internal]" |
| 90 | + ] |
| 91 | + }, |
| 92 | + { |
| 93 | + "cell_type": "code", |
| 94 | + "execution_count": null, |
| 95 | + "metadata": {}, |
| 96 | + "outputs": [], |
| 97 | + "source": [ |
| 98 | + "@qfunc\n", |
| 99 | + "def main(x: Output[QBit], t: CReal, w: CReal):\n", |
| 100 | + " allocate(1, x)\n", |
| 101 | + " RX(t, x)\n", |
| 102 | + " RZ(w, x)\n", |
| 103 | + "\n", |
| 104 | + "\n", |
| 105 | + "qmod = create_model(main)\n", |
| 106 | + "qprog = synthesize(qmod)\n", |
| 107 | + "# execution_session = ExecutionSession(qprog)" |
| 108 | + ] |
| 109 | + } |
| 110 | + ], |
| 111 | + "metadata": { |
| 112 | + "kernelspec": { |
| 113 | + "display_name": "external-user-venv-PaJZMdG0-py3.11", |
| 114 | + "language": "python", |
| 115 | + "name": "python3" |
| 116 | + }, |
| 117 | + "language_info": { |
| 118 | + "codemirror_mode": { |
| 119 | + "name": "ipython", |
| 120 | + "version": 3 |
| 121 | + }, |
| 122 | + "file_extension": ".py", |
| 123 | + "mimetype": "text/x-python", |
| 124 | + "name": "python", |
| 125 | + "nbconvert_exporter": "python", |
| 126 | + "pygments_lexer": "ipython3", |
| 127 | + "version": "3.11.6" |
| 128 | + } |
| 129 | + }, |
| 130 | + "nbformat": 4, |
| 131 | + "nbformat_minor": 2 |
| 132 | +} |
0 commit comments