|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# Modeling - Part 1" |
| 8 | + ] |
| 9 | + }, |
| 10 | + { |
| 11 | + "cell_type": "markdown", |
| 12 | + "metadata": {}, |
| 13 | + "source": [ |
| 14 | + "In this tutorial, we will learn the basics of modeling quantum algorithms, using the Qmod language and its accompanied function library.\\\n", |
| 15 | + "We will learn to use functions, operators, quantum variables, and quantum types. " |
| 16 | + ] |
| 17 | + }, |
| 18 | + { |
| 19 | + "cell_type": "markdown", |
| 20 | + "metadata": {}, |
| 21 | + "source": [ |
| 22 | + "Let's learn through a simple example:" |
| 23 | + ] |
| 24 | + }, |
| 25 | + { |
| 26 | + "cell_type": "code", |
| 27 | + "execution_count": 3, |
| 28 | + "metadata": {}, |
| 29 | + "outputs": [], |
| 30 | + "source": [ |
| 31 | + "from classiq import *\n", |
| 32 | + "\n", |
| 33 | + "@qfunc\n", |
| 34 | + "def main(x: Output[QBit]) -> None:\n", |
| 35 | + " allocate(1,x)\n", |
| 36 | + " H(x)\n", |
| 37 | + "\n", |
| 38 | + "qmod = create_model(main)" |
| 39 | + ] |
| 40 | + }, |
| 41 | + { |
| 42 | + "cell_type": "markdown", |
| 43 | + "metadata": {}, |
| 44 | + "source": [ |
| 45 | + "The function `main` allocates 1 qubit to the quantum variable `x`, which is of type `QBit`. At this stage, `x` holds the default-upon-initialization state $|0\\rangle$.\\\n", |
| 46 | + "Then, the model applies the Hadamard gate `H` so that `x` should end in the state $\\frac{1}{\\sqrt{2}} (|0\\rangle + |1\\rangle)$." |
| 47 | + ] |
| 48 | + }, |
| 49 | + { |
| 50 | + "cell_type": "markdown", |
| 51 | + "metadata": {}, |
| 52 | + "source": [ |
| 53 | + "## Qmod Fundementals" |
| 54 | + ] |
| 55 | + }, |
| 56 | + { |
| 57 | + "cell_type": "markdown", |
| 58 | + "metadata": {}, |
| 59 | + "source": [ |
| 60 | + "This above simple model demonstrates several features that are essential in every Qmod code:" |
| 61 | + ] |
| 62 | + }, |
| 63 | + { |
| 64 | + "cell_type": "markdown", |
| 65 | + "metadata": {}, |
| 66 | + "source": [ |
| 67 | + "### The `@qfunc` decorator\n", |
| 68 | + "Qmod is a quantum computing language embeded into Python. The decorator `@qfunc` marks a Qmod function, so that the Qmod interpreter is called to handle it. The decorator is used in every quantum function definition.\n", |
| 69 | + "\n", |
| 70 | + "### The function `main`\n", |
| 71 | + "Any Qmod code that is intended to be synthesized into an executable quantum program must define a function `main`. The function `main` acts as the program's quantum entry point - it specifies the inputs and outputs of the quantum program, that is, its interface with the external classical execution logic.\n", |
| 72 | + "\n", |
| 73 | + "### The `Output` modifier\n", |
| 74 | + "All quantum variables that are to be measured must be declared using the `Output` modifier.\n", |
| 75 | + "The variable `x` declared in `main`'s definition is marked as an `Output`, meaning that it is to be measured...\n", |
| 76 | + "Function main cannot declare quantum arguments other than using the output modifier, since the classical execution logic cannot pass quantum states as arguments. " |
| 77 | + ] |
| 78 | + }, |
| 79 | + { |
| 80 | + "cell_type": "markdown", |
| 81 | + "metadata": {}, |
| 82 | + "source": [] |
| 83 | + }, |
| 84 | + { |
| 85 | + "cell_type": "markdown", |
| 86 | + "metadata": {}, |
| 87 | + "source": [] |
| 88 | + } |
| 89 | + ], |
| 90 | + "metadata": { |
| 91 | + "kernelspec": { |
| 92 | + "display_name": "external-user-venv-PaJZMdG0-py3.11", |
| 93 | + "language": "python", |
| 94 | + "name": "python3" |
| 95 | + }, |
| 96 | + "language_info": { |
| 97 | + "codemirror_mode": { |
| 98 | + "name": "ipython", |
| 99 | + "version": 3 |
| 100 | + }, |
| 101 | + "file_extension": ".py", |
| 102 | + "mimetype": "text/x-python", |
| 103 | + "name": "python", |
| 104 | + "nbconvert_exporter": "python", |
| 105 | + "pygments_lexer": "ipython3", |
| 106 | + "version": "3.11.6" |
| 107 | + } |
| 108 | + }, |
| 109 | + "nbformat": 4, |
| 110 | + "nbformat_minor": 2 |
| 111 | +} |
0 commit comments