Skip to content

Commit

Permalink
added jupyter notebook guide and rearrange order (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
rcarrata authored Apr 17, 2024
1 parent b51f51c commit 962a4b9
Show file tree
Hide file tree
Showing 14 changed files with 180 additions and 4 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion content/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
// ** xref:02-02-diy-creating-project.adoc[2.2 (DIY) Creating your project and pipeline server]
** xref:02-03-auto-created-workbench.adoc[2.3 Pre-Created workbench]
// ** xref:02-03-diy-creating-workbench.adoc[2.3 (DIY) Creating your workbench]
** xref:02-04-validating-env.adoc[2.4 Validating the environment]
** xref:02-04-first-jupyter-notebook.adoc[2.4 Your first Jupyter Notebook]
** xref:02-05-validating-env.adoc[2.5 Validating the environment]
* 3. Working with an LLM
** xref:03-01-notebook-based-llm.adoc[3.1 Notebook-Based LLM Example]
Expand Down
63 changes: 63 additions & 0 deletions content/modules/ROOT/pages/02-04-first-jupyter-notebook.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
= Running code in a notebook
include::_attributes.adoc[]

NOTE: If you're already at ease with Jupyter Notebooks, you can skip to the next section.

A notebook is an environment where you have _cells_ that can display formatted text or code.

This is an empty cell:

[.bordershadow]
image::02/02-05-cell.png[Jupyter Cell]

This is a cell with some code:

[.bordershadow]
image::02/02-05-cell_code.png[Jupyter Cell Code]

Code cells contain Python code that you can run interactively. You can modify the code and then run it. The code does not run on your computer or in the browser, but directly in the environment that you are connected to, *{rhoai}* in our case.

You can run a code cell from the notebook interface or from the keyboard:

* *From the user interface:* Select the cell (by clicking inside the cell or to the left side of the cell) and then click *Run* from the toolbar.
+
[.bordershadow]
image::02/02-05-run_button.png[Jupyter Run]
* *From the keyboard:* Press `CTRL`+`ENTER` to run a cell or press `SHIFT`+`ENTER` to run the cell and automatically select the next one.
After you run a cell, you can see the result of its code as well as information about when the cell was run, as shown in this example:

[.bordershadow]
image::02/02-05-cell_run.png[Jupyter run cell]

When you save a notebook, the code and the results are saved. You can reopen the notebook to look at the results without having to run the program again, while still having access to the code.

Notebooks are so named because they are like a physical _notebook_: you can take notes about your experiments (which you will do), along with the code itself, including any parameters that you set. You can see the output of the experiment inline (this is the result from a cell after it's run), along with all the notes that you want to take (to do that, from the menu switch the cell type from `Code` to `Markup`).

== Try It

Now that you know the basics, give it a try!

=== Procedure

In your workbench:

. In the left hand navigation menu, navigate to the folder called: `parasol-insurance/lab-materials/02`

. Open the notebook called `02-04-first-jupyter-notebook.ipynb`

. Experiment by, for example, running the existing cells, adding more cells and creating functions.
+
You can do what you want - it's your environment and there is no risk of breaking anything or impacting other users. This environment isolation is also a great advantage brought by {rhoai}.
. Optionally, create a new notebook in which the code cells are run by using a Python 3 kernel:
.. Create a new notebook by either selecting *File ->New ->Notebook* or by clicking the Python 3 tile in the Notebook section of the launcher window:
+
[.bordershadow]
image::02/02-05-new_notebook.png[alt text]

You can use different kernels, with different languages or versions, to run in your notebook.

.Additional resource

* If you want to learn more about notebooks, go to https://jupyter.org/[the Jupyter site,window=_blank].
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ In your workbench:

. In the left hand navigation menu, navigate to the folder called: `parasol-insurance/lab-materials/02`

. Open the notebook called `02-04-validating.ipynb`
. Open the notebook called `02-05-validating.ipynb`

. If you have never executed Cells in a Jupyter Notebook before, here is what you need to do:

.. Click on the **Restart kernel and Run all Cells** link:
+
[.bordershadow]
image::02/02-04-restart-and-run.png[]
image::02/02-05-restart-and-run.png[]
.. Click **Restart** :
+
[.bordershadow]
image::02/02-04-restart-kernel.png[]
image::02/02-05-restart-kernel.png[]
+
. Running these cells will confirm that all the lab-required services are responding.

Expand Down
112 changes: 112 additions & 0 deletions lab-materials/02/02-04-first-jupyter-notebook.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "991808d0-7d79-47f2-b8cc-764fe86a6156",
"metadata": {
"tags": []
},
"source": [
"# Your First Jupyter Notebook\n",
"\n",
"NOTE: **If you are already familiar with Jupyter Notebook**, and you understand how to edit and run cells, and how to use other Jupyter features, you can skip this notebook and continue to the next one.\n",
"\n",
"## What are Jupyter notebooks?\n",
"\n",
"This is a [Jupyter](https://jupyter.org/) notebook. You need to know only a few things to get started.\n",
"\n",
"* Jupyter notebooks are made up of _cells_ that can contain prose, executable code, or interactive UI elements. This cell is a prose cell.\n",
"\n",
"* You can edit and execute cells. To edit a cell, double-click until the frame around it is highlighted. To execute a cell (whether you've edited it or not), click the play button at the top of the file window or select the cell and then press SHIFT+ENTER.\n",
"\n",
" <figure>\n",
" <img src=\"../../content/modules/ROOT/assets/images/02/02-04-play-button.png\" alt='missing' width=\"300\" >\n",
" <figure/>\n",
" \n",
" Jupyter executes the code in the cell, records the code output, and advances to the next cell. \n",
"\n",
"* While a cell is executing, an asterisk shows in the margin, for example: `In: [*]`. After a cell completes executing, the asterisk is replaced with a sequence number.\n",
"\n",
"\n",
"Let's try it out now! Try executing the next cell"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3b4dc1f1-8d6e-4869-ade8-cafc22baa817",
"metadata": {},
"outputs": [],
"source": [
"def print_some_text(entered_text):\n",
" print(\"This is what you entered: \\n\" + entered_text)\n",
" \n",
"my_text = \"This cell is for code. You can execute code by clicking on the play button above or hitting SHIFT+ENTER.\"\n",
"\n",
"print_some_text(my_text)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "70c9ed5e-60e1-42dd-b9c3-87fcfc79493e",
"metadata": {},
"outputs": [],
"source": [
"new_text = \"Next, let's see how you would write narrative text or documentation.\"\n",
"\n",
"# previously defined functions from another cell are still accessible.\n",
"print_some_text(new_text)"
]
},
{
"cell_type": "markdown",
"id": "92bc6513-dbe5-4128-9399-d4d3ab9be845",
"metadata": {},
"source": [
"## This is a markdown cell\n",
"### Chapter 1\n",
"You can use **markdown formatting** to enter your text.\n",
"\n",
"*Double-click* on a cell to modify it.\n",
"\n",
"[Markdown reference](https://www.markdownguide.org/basic-syntax/)"
]
},
{
"cell_type": "markdown",
"id": "edaf739c-ff87-457b-914e-5d74428fa8ed",
"metadata": {},
"source": [
"## More Information\n",
"\n",
"For more information about Jupyter, click the **Help menu** in the Jupyter window's menu bar.\n",
"\n",
"<figure>\n",
" <img src=\"../../content/modules/ROOT/assets/images/02/02-04-help-menu.png\" alt='missing' width=\"300\" >\n",
"<figure/>"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.9",
"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.9.16"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
File renamed without changes.

0 comments on commit 962a4b9

Please sign in to comment.