Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.

Commit 2b8117f

Browse files
rlanzafameTom-van-Woudenbergtshiya731
authored
Sphinx thebe from GitHub (#39)
* Update requirements.txt * Update _config.yml to fix the Sympy reference * Update 01.ipynb Add some markdowns to align the errors and debugging section to MUDE corresponding part * Update sympy.ipynb please ignore the first pull request, which changed the config.yml. config is completely fine and i just forget to add the reference. after adding the reference it should be completely fine to show the reference part. * Update _config.yml (#13) * Update _config.yml to fix the Sympy reference * Update 01.ipynb Add some markdowns to align the errors and debugging section to MUDE corresponding part * Update sympy.ipynb please ignore the first pull request, which changed the config.yml. config is completely fine and i just forget to add the reference. after adding the reference it should be completely fine to show the reference part. * Update _config.yml to make it the original * First branch (#14) * Update _config.yml (#17) * Update 01.ipynb (#18) * Fix figures (#19) * fix figures * fix 04 * MyST * myst_try * fix by MyST * simple bug fix (#25) * fix bugs for book6 * fix typo in chapter 5 * matrix operator fix wrong matrix operator in chapter 5 * matrix operator fix * H5p test(only changed Exercise 1.2.2) (#22) * exercise transition * test * update readme * create docs subdir and add old stuff * describe quiz convention * apply quiz convention * book1_exercises_updata * remove-input * remove-input * remove_input --------- Co-authored-by: Robert Lanzafame <R.C.Lanzafame@tudelft.nl> * Chapter2 h5p (#27) * h5p--chapter2 * add notes to h5p * chapter1- typo fix (#28) * Chapter5 h5p (#29) * chapter5-h5p * exercise2 * bug form remove * reportbug-setup * intro comments and filename formatting * intro text: adjust additional resources info * update feedback instructions * toolbox-calculator update * fix intro * better name * get sphinx-thebe from github --------- Co-authored-by: Tom van Woudenberg <t.r.vanwoudenberg@tudelft.nl> Co-authored-by: tshiya731 <tshiya05@gmail.com> Co-authored-by: tshiya731 <152382463+tshiya731@users.noreply.github.com>
1 parent ae7295a commit 2b8117f

File tree

30 files changed

+406
-3442
lines changed

30 files changed

+406
-3442
lines changed

README.md

Lines changed: 3 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -27,78 +27,13 @@ The course is organized as follows:
2727
- Each chapter contains at least two parts: theory and exercises. For this edition on the chapter on `numpy` contains more than one Exercise section, but this may change in the future.
2828
- The "In a Nutshell" chapters do not contain any interactive elements.
2929

30-
## Interactive Python Elements
31-
32-
As of Summer 2023, this course uses two methods for providing students the ability to run Python in their internet browser: an IPython console (JupyterLite and Pyodide) and a 3rd party cloud kernel to run a `*.ipynb` file (Binder and Colab). The IPython console is provided in the associated repositor `TUDelft-CITG/learn-python-calculator`. There is also a package that is loaded into the notebooks and IPython console to check student answers, which can be found in `TUDelft-CITG/learn-python-package`.
33-
34-
We decided that with the in-browser Python capabilities, there is no longer a requirement to provide separate notebooks for students to run locally (and consequently, no need to install any software!). However, since it is nice to be able to run the cells in the theory and exercise pages, links to open each page with a working Python kernel via Binder and Colab are included (the rocket icon {fa}`rocket` at the top right). Colab initializes much faster and more reliably, but due to GDPR concerns with Google products, Binder is offerred as an alternative. Neither platform will save modifications to the notebook, unless they are downloaded or imported individually.
35-
36-
An overview of the interactive elements by Chapter:
37-
38-
- Exercises in Chapters 1 and 2 are evaluated using JupyterQuiz only; no execution of Python code is required
39-
- Exercises in Chapters 3, 4 and 6 use a JupyterLite REPL; the answer-checking package is used here
40-
- Exercises in Chapter 5 use a mix of JupyterQuiz and a JupyterLite REPL; the answer-checking package is used here
41-
- Exercises in Chapter 7 use a JupyterLite REPL (separate web page); the answer-checking package is *not* used here
42-
43-
### IPython Console
44-
45-
An HTML link is created and can be customized to initialize the console fora particular page.
46-
47-
To use the IPython console with a bit of front-end setup, use this [link](https://tudelft-citg.github.io/learn-python-calculator/repl/index.html?toolbar=1&kernel=python&code=print(%27You%20may%20begin!%27)), which adds the following to the URL: `?toolbar=1&kernel=python&code=print(%27You%20may%20begin!%27)`.
48-
49-
The example below chooses the kernel, imports pandas and the answer-checker and gives a message to begin.
50-
51-
````md
52-
```{admonition} Open the Python Calculator for this page
53-
:class: tip, dropdown
54-
Click this <a href="https://tudelft-citg.github.io/learn-python-calculator/repl/index.html?toolbar=1&kernel=python&code=import pandas as pd; import data.check_answers as check; print('You may begin!')" target="_blank">link</a> and wait until the message "<tt>You may begin!</tt>" is printed to start evaluating code. More information about this tool can be found [here](calculator).
55-
56-
Remember that all pages in this course can also be opened as an interactive notebook via Binder or Colab using the {fa}rocket icon above (read more about it [here](nb-links)).
57-
```
58-
````
59-
60-
### Jupyter notebooks
61-
62-
Notebooks are set up using built-in features of Jupyter Book and links to Binder and Colab are provided. This automatically uses the notebook to generate the page, and the following cell needs to be added to the notebooks (remember to make it a hidden cell in the Jupyter Book so that it does not display on the website):
63-
```
64-
# ##-On Google colab uncomment and run the following code
65-
# ## to install and import the function that will be used to check your answers.
66-
# !pip install learn-python-ceg-test
67-
68-
# ##-On Binder just uncomment and run the following line
69-
# import learn_python_ceg_test.check_answers as check
70-
```
71-
72-
### Decision-making notes
73-
74-
This section summarizes some key information that led up to the final decision of whether (and how) to include a Python kernel directly in the Jupyter Book (i.e., an interactive page directly in the book) for the Summer 2023 version, which was not trivial. These tools change quickly, so the information may already be out of date or irrelevant.
75-
76-
Remember that JupyterLite provides a Jupyter-like interface (Lab, classic notebook, REPL/console) and can be used with one of two kernels: Xeus or Pyodide. The biggest implication for us seems to be that Xeus does not allow dynamic import of packages at runtime (conda-forge only), whereas Pyodide does (via pip). On the other hand, Xeus allows pre-loading packages, whereas Pyodide does not. Future development may combine these two kernels, so it is only a matter of time until something breaks. Stay tuned...
77-
78-
Option 1:
79-
- JupyterLite REPL to create iPython console in a frame on the page, supported by a Xeus kernel
80-
- Allows conda forge packages (no pip) installed during the build process (not dynamically installed via frontend)
81-
- Can specify code to run on init but it is visible as the first cell command (no hiding of code)
82-
- conda forge package only visible in error traceback (important for answer-checking)
83-
84-
Option 1.5: same as Option 1 with a notebook, but must include the nb as a separate file in the book repo
85-
86-
Option 2:
87-
- Binder (creates an image) and Colab creates a nb interface on google server (not same container as binder)
88-
- displays page as nb with live kernel
89-
- can use pip (conda-forge not sure)
90-
- cannot hide cells (this is JB only, and all cells need to run and be not hidden)
91-
- all cells are active
92-
- need to hide cell in JB for colab pip install (not remove) and run this cell when using nb in colab
93-
94-
Option 3: JupyterLite kernel with Thebe to support an interactive Jupyter notebook page. We did not pursue this because it's not fully implemented yet via Jupyter Book (javascript stuff). Although Thebe is functional with a Binder kernel, in our opinion this is too slow and unreliable.
95-
96-
In the end, there was a problem with getting `matplotlib` to import when JupyterLite was included in the book build (see [Issue #35](https://github.com/TUDelft-CITG/learn-python/issues/35)). We also realized that it is possible (and much easier!) to create a separate JupyterLite website that uses Lab, classic nb or REPL via GitHub pages (see the [JupyterLite](https://jupyterlite.readthedocs.io/en/latest/) demos), which was a good alternative to complicated workflows and buggy kernel installations required for building the kernel directly into the book.
30+
This book is
9731

9832
## Acknowledgments
9933

100-
Financial support for this project was provided through an open education grant from the Educational Management Team for the Civil Engineering and Geosciences Faculty at Delft. The content was first developed for Summer 2022 by Sandra Verhagen and a team of TA's in Jupyter notebooks that were auto-graded in Vocareum. For Summer 2023 a second round of funding was optained to update the content and adapt it to an entirely open and self-paced course without enrollement via a Jupyter Book, led by Robert Lanzafame. Special thanks goes to Miguel Mendoza Lugo who adapted the notebooks into the Jupyter Book format and implemented the interactive features, as well as Ahmed Farahat, who helped create the fun new visual features that make understanding the material easier in the Jupyter Book platform, as well as the In a Nutshell summaries.
34+
Financial support for this project was provided through an open education grant from the Educational Management Team for the Civil Engineering and Geosciences Faculty at Delft. The content was first developed for Summer 2022 by Sandra Verhagen and a team of TA's in Jupyter notebooks that were auto-graded in Vocareum. For Summer 2023 a second round of funding was optained to update the content and adapt it to an entirely open and self-paced course without enrollement via a Jupyter Book, led by Robert Lanzafame. Special thanks goes to Miguel Mendoza Lugo who adapted the notebooks into the Jupyter Book format and implemented the interactive features, as well as Ahmed Farahat, who helped create the fun new visual features that make understanding the material easier in the Jupyter Book platform, as well as the In a Nutshell summaries. Guilherme Ferreira Sêco de Alvarenga made improvements to the content and set up the interactive Python feature via [TeachBooks](teachbooks.io) tools. Shiya Tang improved the contents and converted exercises from JupyterQuiz to H5p.
10135

10236
This Book is maintained and developed by staff of the Faculty of Civil Engineering and Geosciences of TU Delft, the Netherlands.
10337

10438
<img src="https://raw.githubusercontent.com/TUDelft-CITG/learn-python/mike/book/figures/TUDelft_logo_cmyk.png" width=170 style="float: right;"/>
39+

book/01/Exercises/01.ipynb

Lines changed: 73 additions & 1158 deletions
Large diffs are not rendered by default.

book/01/Exercises/bug_report.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

book/02/Exercises/01.ipynb

Lines changed: 107 additions & 1699 deletions
Large diffs are not rendered by default.

book/02/Exercises/bug_report.md

Lines changed: 0 additions & 10 deletions
This file was deleted.

book/03/Exercises/01.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
":class: tip, dropdown\n",
5757
"Click this <a href=\"https://tudelft-citg.github.io/learn-python-calculator/repl/index.html?toolbar=1&kernel=python&code=import pandas as pd; import data.check_answers as check; print('You may begin!')\" target=\"_blank\">link</a> and wait until the message \"<tt>You may begin!</tt>\" is printed to start evaluating code. More information about this tool can be found [here](calculator). \n",
5858
"\n",
59-
"Remember that all pages in this course can also be opened as an interactive notebook via Binder or Colab using the {fa}rocket icon above (read more about it [here](nb-links)).\n",
59+
"Remember that most pages in this course can also be run interactively using the {fa}rocket icon above (read more about it [here](toolbox)).\n",
6060
"`````"
6161
]
6262
},

book/03/Exercises/bug_report.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

book/03/Theory/01.ipynb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,13 @@
818818
"print(f'2 to the 3rd power is {power_of_2}')"
819819
]
820820
},
821+
{
822+
"cell_type": "markdown",
823+
"metadata": {},
824+
"source": [
825+
"Want to learn more about erros? Check the MUDE notebook for more detailed information about errors! <a href=\"https://mude.citg.tudelft.nl/2024/book/external/learn-python/book/09/error_types.html\"><i>MUDE</i></a> — <i>Week 1.6: Errors</i> - <i>Error Types</i> "
826+
]
827+
},
821828
{
822829
"attachments": {},
823830
"cell_type": "markdown",
@@ -961,6 +968,13 @@
961968
"print('The sum of the elements of the list A is {}.'.format(sumA_fixed(A)))"
962969
]
963970
},
971+
{
972+
"cell_type": "markdown",
973+
"metadata": {},
974+
"source": [
975+
"<b><code>print</code></b> is simple and direct, and ideal for small scripts or quick troubleshooting, helping you quickly observe the state of your program. However, it is insufficient for more complex or systematic debugging needs. There are more debugging tools as Traceback, Raising Errors, Handling Errors, and Assertations. You can know more debugging tools by checking <a href=\"https://mude.citg.tudelft.nl/2024/book/external/learn-python/book/09/traceback.html\"><i>MUDE</i></a> — <i>The Python Traceback</i>, <i>The Python Traceback</i>, <i>Raising Errors</i>, <i>Handling Errors</i> and <i>Assertations</i>."
976+
]
977+
},
964978
{
965979
"attachments": {},
966980
"cell_type": "markdown",
@@ -982,7 +996,8 @@
982996
"* https://realpython.com/working-with-files-in-python/\n",
983997
"* Think Python (2nd ed.) - Section 14 \n",
984998
"* Official Python Documentation - https://docs.python.org/3/library/debug.html\n",
985-
"* Think Python (2nd ed.) - Appendix A and all (sub-)sections"
999+
"* Think Python (2nd ed.) - Appendix A and all (sub-)sections\n",
1000+
"* MUDE - Week 1.6: Errors"
9861001
]
9871002
},
9881003
{

book/04/Exercises/bug_report.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

book/04/Theory/01.ipynb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,11 @@
125125
"source": [
126126
"Hmmmm, that's strange... we altered only one list but both were changed in the end! Why would that happen? Welp, the two reasons behind that are $1)$ what a variable actually <b>is</b>; and, $2)$ what the $=$ operator actually does. In short, variables are just links to the spatial location where objects are stored. By reassigning the value of a variable, you're just changing this link.<br><br>So, first, when you create 2 lists, <b><code>var1 = [1, 2, 3]</code></b> and <b><code>var2 = [555, 777, 888]</code></b>, you create two different objects: <b><code>var1</code></b>, a variable referring to the list <b><code>[1, 2, 3]</code></b>; and <b><code>var2</code></b>, a variable referring to the list <b><code>[555, 777, 888]</code></b>. Then, with the line <b><code>var1 = var2</code></b> you don't actually change the content of <b><code>var1</code></b> — you just make it refer to the list <b><code>[555, 777, 888]</code></b>! Thus, by changing one element of <b><code>var2</code></b> you will be able to see changes in <b><code>var1</code></b> as well since they both refer to the same object in memory! Here's a sketch of the described situation:\n",
127127
"\n",
128-
"![image.png](https://raw.githubusercontent.com/mike-mendoza/Bivariate_NPBN_workshop_files/main/files_pyhton_book_test/01.png) \n",
128+
"```{image} 01.png\n",
129+
":alt: rectangle\n",
130+
":width: 800px\n",
131+
":align: center\n",
132+
"```\n",
129133
"\n",
130134
"You can also see this by using the <b><code>id()</code></b> function. It returns the unique id assigned to the object, thus one object will return the same id every time. However, a copy of that object with the same value but stored in a different place will return a different id. In addition, the <b><code>is</code></b> operator compares the identity of two variables and returns <b><code>True</code></b> if they reference the same object!\n"
131135
]
@@ -325,7 +329,11 @@
325329
"source": [
326330
"And here's a small illustration of what happened:\n",
327331
"\n",
328-
"![image.png](https://raw.githubusercontent.com/mike-mendoza/Bivariate_NPBN_workshop_files/main/files_pyhton_book_test/02.png)\n",
332+
"```{image} 02.png\n",
333+
":alt: rectangle\n",
334+
":width: 800px\n",
335+
":align: center\n",
336+
"```\n",
329337
"\n",
330338
"So, as you can see — this confusion is not a big deal for immutable objects. However, it should still be explained what you should do in this situation with the mutable objects. How could you assign values of one list to another list? First, you can just write a for loop and copy the lower level data, which is immutable, with the <b><code>=</code></b> operator.\n",
331339
"\n",

0 commit comments

Comments
 (0)