Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
simonsavitt committed Mar 18, 2024
1 parent a8f0d02 commit 74bf24e
Show file tree
Hide file tree
Showing 10 changed files with 1,427 additions and 1 deletion.
284 changes: 284 additions & 0 deletions jupyter notebooks/.ipynb_checkpoints/JupyterAI-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,284 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "50bc448b-1d39-4eda-8945-58f1f868b2d9",
"metadata": {
"id": "50bc448b-1d39-4eda-8945-58f1f868b2d9"
},
"source": [
"# JupyterAI Tutorial\n",
"\n",
"### Installing JupyterAI"
]
},
{
"cell_type": "markdown",
"id": "1805fbe1-2c8b-4eb7-ab07-0e77cbc5ac8f",
"metadata": {},
"source": [
"Take a look at the [Installation](https://jupyter-ai.readthedocs.io/en/latest/users/index.html#installation) section/"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "11e80ca1-7246-4d49-ba06-17600d7bf473",
"metadata": {
"id": "11e80ca1-7246-4d49-ba06-17600d7bf473",
"outputId": "b8f2bcb1-cee1-462d-cc16-27bb6f4c6d63"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"jupyter_ai module already installed.\n"
]
}
],
"source": [
"# Check if JupyterAI module is already installed\n",
"import os\n",
"\n",
"if os.system(\"import jupyter_ai\") == 0:\n",
" !pip install jupyter_ai\n",
"else:\n",
" print(\"jupyter_ai module already installed.\")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "c0d947fc-b662-4f3f-901b-72d623348e69",
"metadata": {
"id": "c0d947fc-b662-4f3f-901b-72d623348e69",
"outputId": "c7379ceb-20a6-4073-f014-b9354d8a712c",
"scrolled": true
},
"outputs": [],
"source": [
"# Load JupyterAI extension\n",
"%load_ext jupyter_ai"
]
},
{
"cell_type": "markdown",
"id": "611d508f-4666-4772-9b00-e58e61b20ba6",
"metadata": {
"id": "611d508f-4666-4772-9b00-e58e61b20ba6"
},
"source": [
"To add one of the supported AI backends, obtain your api key.\n",
"\n",
"`%env PROVIDER_API_KEY=YOUR_API_KEY_HERE`\n",
"\n",
"NOTE: Replace 'PROVIDER_API_KEY' with the credential key's name, and replace 'YOUR_API_KEY_HERE' with the key."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "19876707-27aa-42e5-b699-b4b4cf5b65a8",
"metadata": {
"id": "19876707-27aa-42e5-b699-b4b4cf5b65a8",
"outputId": "99d9babc-cd80-4827-9eaf-1711d03ecd01",
"scrolled": true
},
"outputs": [],
"source": [
"# ChatGPT\n",
"if os.system(\"import openai\") == 0:\n",
" !pip install openai\n",
"else:\n",
" print(\"openai module already installed.\")\n",
"# https://platform.openai.com/api-keys\n",
"# %env OPENAI_API_KEY = token\n",
"%env OPENAI_API_KEY = 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"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0944af0e-0ce8-4370-9c75-a2aae0e3eba5",
"metadata": {},
"outputs": [],
"source": [
"%%ai chatgpt\n",
"\n",
"Hello! What version of ChatGPT am I using?"
]
},
{
"cell_type": "markdown",
"id": "ce7998de-1da7-496c-9bfa-5d76c3554b12",
"metadata": {
"id": "ce7998de-1da7-496c-9bfa-5d76c3554b12",
"jp-MarkdownHeadingCollapsed": true
},
"source": [
"We can change the [formatting](https://jupyter-ai.readthedocs.io/en/latest/users/index.html#formatting-the-output) using arguments.\n",
"\n",
"The `-f code` argument produces output as a code cell below the input cell so you can copy and paste it, with the message `AI generated code inserted below` ⬇."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "391cb3a8-268b-4102-8225-a5ca340825d3",
"metadata": {
"id": "391cb3a8-268b-4102-8225-a5ca340825d3",
"outputId": "68f4dc21-32ee-463e-9de3-88bd68e8c5c3"
},
"outputs": [],
"source": [
"%%ai chatgpt -f code\n",
"\n",
"generate an empy qiskit project"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1412a1b8-5592-4f04-aebf-98d90208d74c",
"metadata": {},
"outputs": [],
"source": [
"# Generate an empty qiskit project"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "53ea8d04-ef0f-4448-96f1-19104e0dc75d",
"metadata": {
"id": "53ea8d04-ef0f-4448-96f1-19104e0dc75d",
"outputId": "9ed7ba83-da0a-43d1-e766-3e74dd382c1e"
},
"outputs": [],
"source": [
"from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister\n",
"\n",
"# Create a quantum circuit with 3 qubits and 3 classical bits\n",
"qc = QuantumCircuit(3, 3)\n",
"\n",
"# Draw the circuit\n",
"qc.draw(output = 'mpl')"
]
},
{
"cell_type": "markdown",
"id": "28d15894-8f57-4d10-b35a-d76e723f6c10",
"metadata": {
"id": "28d15894-8f57-4d10-b35a-d76e723f6c10"
},
"source": [
"A circuit is a list of instructions bound to some registers.\n",
"The registers to be included in the circuit.\n",
"\n",
"QuantumCircuit(regs = QuantumRegister(i), ClassicalRegister(j), name = \"myCircuit\" )\n",
"\n",
"``QuantumCircuit(QuantumRegister(4))``\n",
" * ``QuantumCircuit(QuantumRegister(4), ClassicalRegister(3))``\n",
" * ``QuantumCircuit(QuantumRegister(4, 'qr0'), QuantumRegister(2, 'qr1'))``\n",
"\n",
"If a list of ``int``, the amount of qubits and/or classical bits to include in\n",
" the circuit. It can either be a single int for just the number of quantum bits,\n",
" or 2 ints for the number of quantum bits and classical bits, respectively.\n",
"\n",
" For example:\n",
"\n",
" * ``QuantumCircuit(4) # A QuantumCircuit with 4 qubits``\n",
" * ``QuantumCircuit(4, 3) # A QuantumCircuit with 4 qubits and 3 classical bits``"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "33d0b63b-e0ee-48a9-bebf-c09cd780205f",
"metadata": {
"id": "33d0b63b-e0ee-48a9-bebf-c09cd780205f"
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "88153ff3-c944-4bc6-a1e1-dcbd3586a90b",
"metadata": {
"id": "88153ff3-c944-4bc6-a1e1-dcbd3586a90b"
},
"outputs": [],
"source": [
"Construct a simple Bell state circuit.\n",
"\n",
" .. plot::\n",
" :include-source:\n",
"\n",
" from qiskit import QuantumCircuit\n",
"\n",
" qc = QuantumCircuit(2, 2)\n",
" qc.h(0)\n",
" qc.cx(0, 1)\n",
" qc.measure([0, 1], [0, 1])\n",
" qc.draw('mpl')\n",
"\n",
" Construct a 5-qubit GHZ circuit.\n",
"\n",
" .. code-block::\n",
"\n",
" from qiskit import QuantumCircuit\n",
"\n",
" qc = QuantumCircuit(5)\n",
" qc.h(0)\n",
" qc.cx(0, range(1, 5))\n",
" qc.measure_all()\n"
]
},
{
"cell_type": "markdown",
"id": "55a4f854-9a68-46cf-954a-c037b65ecc53",
"metadata": {
"id": "55a4f854-9a68-46cf-954a-c037b65ecc53"
},
"source": [
"jupyter lab --AiExtension.default_api_keys={'OPENAI_API_KEY': 'sk-abcd'}"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "052d5df8-e40d-47aa-acff-1879173ce26d",
"metadata": {
"id": "052d5df8-e40d-47aa-acff-1879173ce26d"
},
"outputs": [],
"source": []
}
],
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.12.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit 74bf24e

Please sign in to comment.