microsoft/qdk
Publicmirrored fromhttps://github.com/microsoft/qdkAvailable
samples/notebooks/project.ipynb
89lines · modecode
| 1 | { |
| 2 | "cells": [ |
| 3 | { |
| 4 | "cell_type": "markdown", |
| 5 | "metadata": {}, |
| 6 | "source": [ |
| 7 | "Initialize Q# with a project root. This will look for a `qsharp.json` at the specified directory and compile the Q# sources included by the manifest." |
| 8 | ] |
| 9 | }, |
| 10 | { |
| 11 | "cell_type": "code", |
| 12 | "execution_count": null, |
| 13 | "id": "1e8e4faa", |
| 14 | "metadata": {}, |
| 15 | "outputs": [], |
| 16 | "source": [ |
| 17 | "import qsharp\n", |
| 18 | "\n", |
| 19 | "qsharp.init(project_root='./test_project')\n" |
| 20 | ] |
| 21 | }, |
| 22 | { |
| 23 | "cell_type": "markdown", |
| 24 | "id": "0a107432", |
| 25 | "metadata": {}, |
| 26 | "source": [ |
| 27 | "Now we can reference the compiled sources." |
| 28 | ] |
| 29 | }, |
| 30 | { |
| 31 | "cell_type": "code", |
| 32 | "execution_count": null, |
| 33 | "id": "9df62352", |
| 34 | "metadata": { |
| 35 | "vscode": { |
| 36 | "languageId": "qsharp" |
| 37 | } |
| 38 | }, |
| 39 | "outputs": [], |
| 40 | "source": [ |
| 41 | "%%qsharp\n", |
| 42 | "\n", |
| 43 | "Sample.Main()\n" |
| 44 | ] |
| 45 | }, |
| 46 | { |
| 47 | "cell_type": "markdown", |
| 48 | "id": "5fad86c4", |
| 49 | "metadata": {}, |
| 50 | "source": [ |
| 51 | "The callables from the project are also available under `qsharp.code` and can be called or imported from Python." |
| 52 | ] |
| 53 | }, |
| 54 | { |
| 55 | "cell_type": "code", |
| 56 | "execution_count": null, |
| 57 | "id": "423b6fc4", |
| 58 | "metadata": {}, |
| 59 | "outputs": [], |
| 60 | "source": [ |
| 61 | "from qsharp.code.Sample import Main\n", |
| 62 | "\n", |
| 63 | "res = Main()\n", |
| 64 | "print(f\"Got return value from Q# code: {res}\")" |
| 65 | ] |
| 66 | } |
| 67 | ], |
| 68 | "metadata": { |
| 69 | "kernelspec": { |
| 70 | "display_name": "Python 3", |
| 71 | "language": "python", |
| 72 | "name": "python3" |
| 73 | }, |
| 74 | "language_info": { |
| 75 | "codemirror_mode": { |
| 76 | "name": "ipython", |
| 77 | "version": 3 |
| 78 | }, |
| 79 | "file_extension": ".py", |
| 80 | "mimetype": "text/x-python", |
| 81 | "name": "python", |
| 82 | "nbconvert_exporter": "python", |
| 83 | "pygments_lexer": "ipython3", |
| 84 | "version": "3.11.11" |
| 85 | } |
| 86 | }, |
| 87 | "nbformat": 4, |
| 88 | "nbformat_minor": 5 |
| 89 | } |
| 90 | |