Skip to content

[Experimental] Use jupyter-book 2.0 for building the lectures #363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix tags errors
  • Loading branch information
kp992 committed Jun 13, 2025
commit 01eef6bf8768f79c64a2a28b13b509dcfb3f968f
54 changes: 22 additions & 32 deletions lectures/debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ import matplotlib.pyplot as plt
Let's consider a simple (and rather contrived) example

```{code-cell} ipython
---
tags: [raises-exception]
---
:tags: raises-exception

def plot_log():
fig, ax = plt.subplots(2, 1)
x = np.linspace(1, 2, 10)
Expand All @@ -85,9 +84,8 @@ But let's pretend that we don't understand this for the moment.
We might suspect there's something wrong with `ax` but when we try to investigate this object, we get the following exception:

```{code-cell} python3
---
tags: [raises-exception]
---
:tags: raises-exception

ax
```

Expand All @@ -99,9 +97,8 @@ Let's try doing it a different way.
We run the first cell block again, generating the same error

```{code-cell} python3
---
tags: [raises-exception]
---
:tags: raises-exception

def plot_log():
fig, ax = plt.subplots(2, 1)
x = np.linspace(1, 2, 10)
Expand Down Expand Up @@ -178,9 +175,8 @@ The preceding approach is handy but sometimes insufficient.
Consider the following modified version of our function above

```{code-cell} python3
---
tags: [raises-exception]
---
:tags: raises-exception

def plot_log():
fig, ax = plt.subplots()
x = np.logspace(1, 2, 10)
Expand Down Expand Up @@ -283,7 +279,7 @@ In this section, we'll discuss different types of errors in Python and technique

### Errors in Python

We have seen `AttributeError` and `NameError` in {any}`our previous examples <debug_magic>`.
We have seen `AttributeError` and `NameError` in [our previous examples](#debug_magic).

In Python, there are two types of errors -- syntax errors and exceptions.

Expand All @@ -293,9 +289,8 @@ In Python, there are two types of errors -- syntax errors and exceptions.
Here's an example of a common error type

```{code-cell} python3
---
tags: [raises-exception]
---
:tags: raises-exception

def f:
```

Expand All @@ -304,36 +299,32 @@ Since illegal syntax cannot be executed, a syntax error terminates execution of
Here's a different kind of error, unrelated to syntax

```{code-cell} python3
---
tags: [raises-exception]
---
:tags: raises-exception

1 / 0
```

Here's another

```{code-cell} python3
---
tags: [raises-exception]
---
:tags: raises-exception

x1 = y1
```

And another

```{code-cell} python3
---
tags: [raises-exception]
---
:tags: raises-exception

'foo' + 6
```

And another

```{code-cell} python3
---
tags: [raises-exception]
---
:tags: raises-exception

X = []
x = X[0]
```
Expand Down Expand Up @@ -367,9 +358,8 @@ If we run this with an array of length one, the program will terminate and
print our error message

```{code-cell} python3
---
tags: [raises-exception]
---
:tags: raises-exception

var([1])
```

Expand Down Expand Up @@ -499,7 +489,7 @@ prices

Using `try` -- `except`, write a program to read in the contents of the file and sum the numbers, ignoring lines without numbers.

You can use the `open()` function we learnt {any}`before<iterators>` to open `numbers.txt`.
You can use the `open()` function we learnt [before](#iterators) to open `numbers.txt`.
```{exercise-end}
```

Expand Down
4 changes: 2 additions & 2 deletions lectures/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ Functions without a return statement automatically return the special Python obj
```{index} single: Python; keyword arguments
```

In a {ref}`previous lecture <python_by_example>`, you came across the statement
In a [previous lecture](python_by_example.md), you came across the statement

```{code-block} python3
:class: no-execute
Expand Down Expand Up @@ -203,7 +203,7 @@ f(2, a=4, b=5)

### The Flexibility of Python Functions

As we discussed in the {ref}`previous lecture <python_by_example>`, Python functions are very flexible.
As we discussed in the [previous lecture](python_by_example.md), Python functions are very flexible.

In particular

Expand Down
5 changes: 1 addition & 4 deletions lectures/matplotlib.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,9 @@ If you are interested, you can even create your own style sheets.
Parameters for your style sheets are stored in a dictionary-like variable `plt.rcParams`

```{code-cell} python3
---
tags: [hide-output]
---
:tags: hide-output

print(plt.rcParams.keys())

```

There are many parameters you could set for your style sheets.
Expand Down
16 changes: 8 additions & 8 deletions lectures/myst.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ project:
error_rules:
- rule: reference-syntax-valid
severity: ignore
exports:
- id: book-pdf
format: typst
template: https://github.com/rowanc1/typst-book.git
output: exports/quantecon-python-intro.pdf
downloads:
- id: book-pdf
title: Book (PDF)
# exports:
# - id: book-pdf
# format: typst
# template: https://github.com/rowanc1/typst-book.git
# output: exports/quantecon-lecture-python.pdf
# downloads:
# - id: book-pdf
# title: Book (PDF)
site:
parts:
footer: footer.md
Expand Down
5 changes: 2 additions & 3 deletions lectures/need_for_speed.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ We'll also discuss the following topics:
In addition to what's in Anaconda, this lecture will need

```{code-cell} ipython
---
tags: [hide-output]
---
:tags: hide-output

!pip install quantecon
```

Expand Down
53 changes: 22 additions & 31 deletions lectures/numpy.md
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,8 @@ a + b
Here is a visual representation of this broadcasting operation:

```{code-cell} python3
---
tags: [hide-input]
---
:tags: hide-input

# Adapted and modified based on the code in the book written by Jake VanderPlas (see https://jakevdp.github.io/PythonDataScienceHandbook/06.00-figure-code.html#Broadcasting)
# Originally from astroML: see http://www.astroml.org/book_figures/appendix/fig_broadcast_visual.html

Expand Down Expand Up @@ -643,9 +642,8 @@ a + b
Here is a visual representation of this broadcasting operation:

```{code-cell} python3
---
tags: [hide-input]
---
:tags: hide-input


fig = plt.figure(figsize=(5, 1), facecolor='w')
ax = plt.axes([0, 0, 1, 1], xticks=[], yticks=[], frameon=False)
Expand Down Expand Up @@ -725,9 +723,8 @@ a + b
Here is a visual representation of this broadcasting operation:

```{code-cell} python3
---
tags: [hide-input]
---
:tags: hide-input


# Draw a figure and axis with no boundary
fig = plt.figure(figsize=(5, 1), facecolor='w')
Expand Down Expand Up @@ -781,9 +778,8 @@ While broadcasting is very useful, it can sometimes seem confusing.
For example, let's try adding `a -> (3, 2)` and `b -> (3,)`.

```{code-cell} python3
---
tags: [raises-exception]
---
:tags: raises-exception

a = np.array(
[[1, 2],
[4, 5],
Expand All @@ -799,9 +795,8 @@ The `ValueError` tells us that operands could not be broadcast together.
Here is a visual representation to show why this broadcasting cannot be executed:

```{code-cell} python3
---
tags: [hide-input]
---
:tags: hide-input

# Draw a figure and axis with no boundary
fig = plt.figure(figsize=(3, 1.3), facecolor='w')
ax = plt.axes([0, 0, 1, 1], xticks=[], yticks=[], frameon=False)
Expand Down Expand Up @@ -901,9 +896,8 @@ a + b
- We can see that they do not match each other after the first two steps. Thus, a `ValueError` will be raised

```{code-cell} python3
---
tags: [raises-exception]
---
:tags: raises-exception

a = np.array(
[[[1, 2, 3],
[2, 3, 4]],
Expand Down Expand Up @@ -1595,9 +1589,8 @@ A = x / y
Here is the output

```{code-cell} python3
---
tags: [hide-output]
---
:tags: hide-output

print(A)
```

Expand All @@ -1608,7 +1601,8 @@ For this part of the exercise you can use the `tic`/`toc` functions from the `qu
Let's make sure this library is installed.

```{code-cell} python3
:tags: [hide-output]
:tags: hide-output

!pip install quantecon
```

Expand All @@ -1628,9 +1622,8 @@ qe.toc()
Here is the output

```{code-cell} python3
---
tags: [hide-output]
---
:tags: hide-output

print(B)
```

Expand Down Expand Up @@ -1659,9 +1652,8 @@ for i in range(n):
Compare the results to check your answer

```{code-cell} python3
---
tags: [hide-output]
---
:tags: hide-output

print(C)
```

Expand Down Expand Up @@ -1695,9 +1687,8 @@ Note that the `for` loop takes much longer than the broadcasting operation.
Compare the results to check your answer

```{code-cell} python3
---
tags: [hide-output]
---
:tags: hide-output

print(D)
```

Expand Down
7 changes: 3 additions & 4 deletions lectures/oop_intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,8 @@ On the other hand, between two numbers it means ordinary addition
Consider the following expression

```{code-cell} python3
---
tags: [raises-exception]
---
:tags: raises-exception

'300' + 400
```

Expand Down Expand Up @@ -342,7 +341,7 @@ and write clear Pythonic code.
:label: oop_intro_ex1
```

We have met the {any}`boolean data type <boolean>` previously.
We have met the [boolean data type](python_essentials.md#boolean) previously.

Using what we have learnt in this lecture, print a list of methods of the
boolean object `True`.
Expand Down
7 changes: 3 additions & 4 deletions lectures/parallelization.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ kernelspec:
In addition to what's in Anaconda, this lecture will need the following libraries:

```{code-cell} ipython
---
tags: [hide-output]
---
:tags: hide-output

!pip install quantecon
```

Expand Down Expand Up @@ -177,7 +176,7 @@ To get some basis for comparison for the last example, let's try the same
thing with Numba.

In fact there is an easy way to do this, since Numba can also be used to
create custom {ref}`ufuncs <ufuncs>` with the [@vectorize](http://numba.pydata.org/numba-doc/dev/user/vectorize.html) decorator.
create custom {ref}`ufuncs <ufuncs>` with the [`@vectorize`](http://numba.pydata.org/numba-doc/dev/user/vectorize.html) decorator.

```{code-cell} python3
from numba import vectorize
Expand Down
Loading