Skip to content

Commit e8a419a

Browse files
committed
Created using Colab
1 parent 5dc4ed2 commit e8a419a

File tree

1 file changed

+202
-0
lines changed

1 file changed

+202
-0
lines changed
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {
6+
"id": "view-in-github",
7+
"colab_type": "text"
8+
},
9+
"source": [
10+
"<a href=\"https://colab.research.google.com/github/jadonsaurav/PythonBasic/blob/main/chapter_appendix-tools-for-deep-learning/jupyter.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
11+
]
12+
},
13+
{
14+
"cell_type": "markdown",
15+
"id": "31d9a4c9",
16+
"metadata": {
17+
"origin_pos": 0,
18+
"id": "31d9a4c9"
19+
},
20+
"source": [
21+
"# Using Jupyter Notebooks\n",
22+
":label:`sec_jupyter`\n",
23+
"\n",
24+
"\n",
25+
"This section describes how to edit and run the code\n",
26+
"in each section of this book\n",
27+
"using the Jupyter Notebook. Make sure you have\n",
28+
"installed Jupyter and downloaded the\n",
29+
"code as described in\n",
30+
":ref:`chap_installation`.\n",
31+
"If you want to know more about Jupyter see the excellent tutorial in\n",
32+
"their [documentation](https://jupyter.readthedocs.io/en/latest/).\n",
33+
"\n",
34+
"\n",
35+
"## Editing and Running the Code Locally\n",
36+
"\n",
37+
"Suppose that the local path of the book's code is `xx/yy/d2l-en/`. Use the shell to change the directory to this path (`cd xx/yy/d2l-en`) and run the command `jupyter notebook`. If your browser does not do this automatically, open http://localhost:8888 and you will see the interface of Jupyter and all the folders containing the code of the book, as shown in :numref:`fig_jupyter00`.\n",
38+
"\n",
39+
"![The folders containing the code of this book.](https://github.com/d2l-ai/d2l-en-colab/blob/master/img/jupyter00.png?raw=1)\n",
40+
":width:`600px`\n",
41+
":label:`fig_jupyter00`\n",
42+
"\n",
43+
"\n",
44+
"You can access the notebook files by clicking on the folder displayed on the webpage.\n",
45+
"They usually have the suffix \".ipynb\".\n",
46+
"For the sake of brevity, we create a temporary \"test.ipynb\" file.\n",
47+
"The content displayed after you click it is\n",
48+
"shown in :numref:`fig_jupyter01`.\n",
49+
"This notebook includes a markdown cell and a code cell. The content in the markdown cell includes \"This Is a Title\" and \"This is text.\".\n",
50+
"The code cell contains two lines of Python code.\n",
51+
"\n",
52+
"![Markdown and code cells in the \"text.ipynb\" file.](https://github.com/d2l-ai/d2l-en-colab/blob/master/img/jupyter01.png?raw=1)\n",
53+
":width:`600px`\n",
54+
":label:`fig_jupyter01`\n",
55+
"\n",
56+
"\n",
57+
"Double click on the markdown cell to enter edit mode.\n",
58+
"Add a new text string \"Hello world.\" at the end of the cell, as shown in :numref:`fig_jupyter02`.\n",
59+
"\n",
60+
"![Edit the markdown cell.](https://github.com/d2l-ai/d2l-en-colab/blob/master/img/jupyter02.png?raw=1)\n",
61+
":width:`600px`\n",
62+
":label:`fig_jupyter02`\n",
63+
"\n",
64+
"\n",
65+
"As demonstrated in :numref:`fig_jupyter03`,\n",
66+
"click \"Cell\" $\\rightarrow$ \"Run Cells\" in the menu bar to run the edited cell.\n",
67+
"\n",
68+
"![Run the cell.](https://github.com/d2l-ai/d2l-en-colab/blob/master/img/jupyter03.png?raw=1)\n",
69+
":width:`600px`\n",
70+
":label:`fig_jupyter03`\n",
71+
"\n",
72+
"After running, the markdown cell is shown in :numref:`fig_jupyter04`.\n",
73+
"\n",
74+
"![The markdown cell after running.](https://github.com/d2l-ai/d2l-en-colab/blob/master/img/jupyter04.png?raw=1)\n",
75+
":width:`600px`\n",
76+
":label:`fig_jupyter04`\n",
77+
"\n",
78+
"\n",
79+
"Next, click on the code cell. Multiply the elements by 2 after the last line of code, as shown in :numref:`fig_jupyter05`.\n",
80+
"\n",
81+
"![Edit the code cell.](https://github.com/d2l-ai/d2l-en-colab/blob/master/img/jupyter05.png?raw=1)\n",
82+
":width:`600px`\n",
83+
":label:`fig_jupyter05`\n",
84+
"\n",
85+
"\n",
86+
"You can also run the cell with a shortcut (\"Ctrl + Enter\" by default) and obtain the output result from :numref:`fig_jupyter06`.\n",
87+
"\n",
88+
"![Run the code cell to obtain the output.](https://github.com/d2l-ai/d2l-en-colab/blob/master/img/jupyter06.png?raw=1)\n",
89+
":width:`600px`\n",
90+
":label:`fig_jupyter06`\n",
91+
"\n",
92+
"\n",
93+
"When a notebook contains more cells, we can click \"Kernel\" $\\rightarrow$ \"Restart & Run All\" in the menu bar to run all the cells in the entire notebook. By clicking \"Help\" $\\rightarrow$ \"Edit Keyboard Shortcuts\" in the menu bar, you can edit the shortcuts according to your preferences.\n",
94+
"\n",
95+
"## Advanced Options\n",
96+
"\n",
97+
"Beyond local editing two things are quite important: editing the notebooks in the markdown format and running Jupyter remotely.\n",
98+
"The latter matters when we want to run the code on a faster server.\n",
99+
"The former matters since Jupyter's native ipynb format stores a lot of auxiliary data that is\n",
100+
"irrelevant to the content,\n",
101+
"mostly related to how and where the code is run.\n",
102+
"This is confusing for Git, making\n",
103+
"reviewing contributions very difficult.\n",
104+
"Fortunately there is an alternative---native editing in the markdown format.\n",
105+
"\n",
106+
"### Markdown Files in Jupyter\n",
107+
"\n",
108+
"If you wish to contribute to the content of this book, you need to modify the\n",
109+
"source file (md file, not ipynb file) on GitHub.\n",
110+
"Using the notedown plugin we\n",
111+
"can modify notebooks in the md format directly in Jupyter.\n",
112+
"\n",
113+
"\n",
114+
"First, install the notedown plugin, run the Jupyter Notebook, and load the plugin:\n",
115+
"\n",
116+
"```\n",
117+
"pip install d2l-notedown # You may need to uninstall the original notedown.\n",
118+
"jupyter notebook --NotebookApp.contents_manager_class='notedown.NotedownContentsManager'\n",
119+
"```\n",
120+
"\n",
121+
"You may also turn on the notedown plugin by default whenever you run the Jupyter Notebook.\n",
122+
"First, generate a Jupyter Notebook configuration file (if it has already been generated, you can skip this step).\n",
123+
"\n",
124+
"```\n",
125+
"jupyter notebook --generate-config\n",
126+
"```\n",
127+
"\n",
128+
"Then, add the following line to the end of the Jupyter Notebook configuration file (for Linux or macOS, usually in the path `~/.jupyter/jupyter_notebook_config.py`):\n",
129+
"\n",
130+
"```\n",
131+
"c.NotebookApp.contents_manager_class = 'notedown.NotedownContentsManager'\n",
132+
"```\n",
133+
"\n",
134+
"After that, you only need to run the `jupyter notebook` command to turn on the notedown plugin by default.\n",
135+
"\n",
136+
"### Running Jupyter Notebooks on a Remote Server\n",
137+
"\n",
138+
"Sometimes, you may want to run Jupyter notebooks on a remote server and access it through a browser on your local computer. If Linux or macOS is installed on your local machine (Windows can also support this function through third-party software such as PuTTY), you can use port forwarding:\n",
139+
"\n",
140+
"```\n",
141+
"ssh myserver -L 8888:localhost:8888\n",
142+
"```\n",
143+
"\n",
144+
"The above string `myserver` is the address of the remote server.\n",
145+
"Then we can use http://localhost:8888 to access the remote server `myserver` that runs Jupyter notebooks. We will detail on how to run Jupyter notebooks on AWS instances\n",
146+
"later in this appendix.\n",
147+
"\n",
148+
"### Timing\n",
149+
"\n",
150+
"We can use the `ExecuteTime` plugin to time the execution of each code cell in Jupyter notebooks.\n",
151+
"Use the following commands to install the plugin:\n",
152+
"\n",
153+
"```\n",
154+
"pip install jupyter_contrib_nbextensions\n",
155+
"jupyter contrib nbextension install --user\n",
156+
"jupyter nbextension enable execute_time/ExecuteTime\n",
157+
"```\n",
158+
"\n",
159+
"## Summary\n",
160+
"\n",
161+
"* Using the Jupyter Notebook tool, we can edit, run, and contribute to each section of the book.\n",
162+
"* We can run Jupyter notebooks on remote servers using port forwarding.\n",
163+
"\n",
164+
"\n",
165+
"## Exercises\n",
166+
"\n",
167+
"1. Edit and run the code in this book with the Jupyter Notebook on your local machine.\n",
168+
"1. Edit and run the code in this book with the Jupyter Notebook *remotely* via port forwarding.\n",
169+
"1. Compare the running time of the operations $\\mathbf{A}^\\top \\mathbf{B}$ and $\\mathbf{A} \\mathbf{B}$ for two square matrices in $\\mathbb{R}^{1024 \\times 1024}$. Which one is faster?\n",
170+
"\n",
171+
"\n",
172+
"[Discussions](https://discuss.d2l.ai/t/421)\n"
173+
]
174+
},
175+
{
176+
"cell_type": "code",
177+
"source": [],
178+
"metadata": {
179+
"id": "VksGkt3e4_Om"
180+
},
181+
"id": "VksGkt3e4_Om",
182+
"execution_count": null,
183+
"outputs": []
184+
}
185+
],
186+
"metadata": {
187+
"kernelspec": {
188+
"display_name": "Python 3",
189+
"name": "python3"
190+
},
191+
"language_info": {
192+
"name": "python"
193+
},
194+
"required_libs": [],
195+
"colab": {
196+
"provenance": [],
197+
"include_colab_link": true
198+
}
199+
},
200+
"nbformat": 4,
201+
"nbformat_minor": 5
202+
}

0 commit comments

Comments
 (0)