diff --git a/.github/workflows/build-ipynb.yml b/.github/workflows/build-ipynb.yml
new file mode 100644
index 00000000..2c87367f
--- /dev/null
+++ b/.github/workflows/build-ipynb.yml
@@ -0,0 +1,85 @@
+name: Build ipynb [using QuantEcon/mystmd]
+on:
+ push:
+ branches: [jb2]
+ pull_request:
+ workflow_dispatch:
+jobs:
+ build-ipynb:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+
+ - uses: actions/setup-node@v4
+ with:
+ node-version: 22.x
+
+ - name: Install Python
+ uses: actions/setup-python@v5
+ with:
+ python-version: '3.12'
+ cache: 'pip'
+ cache-dependency-path: 'myst_requirements.txt'
+
+ - name: Install execution requirements
+ run: python -m pip install -r myst_requirements.txt
+
+ - name: Clone QuantEcon/mystmd (myst-to-ipynb branch)
+ run: |
+ git clone --depth 1 --branch myst-to-ipynb https://github.com/QuantEcon/mystmd.git /tmp/mystmd
+
+ - name: Build mystmd from source
+ working-directory: /tmp/mystmd
+ run: |
+ npm install
+ npx turbo run build
+
+ - name: Build HTML with custom mystmd
+ working-directory: ./lectures
+ run: /tmp/mystmd/packages/mystmd/dist/myst.cjs build --html
+
+ - name: Build ipynb exports with custom mystmd
+ working-directory: ./lectures
+ run: /tmp/mystmd/packages/mystmd/dist/myst.cjs build --ipynb
+
+ - name: Audit notebooks for MyST syntax leaks
+ working-directory: ./lectures
+ run: |
+ python3 -c "
+ import json, glob, re, sys
+ PATTERNS = [
+ (r'^\s*:::', 'directive fence'),
+ (r'\{math\}\`', 'math role'),
+ (r'^\+\+\+', 'block marker'),
+ (r'\{doc\}\`', 'doc role'),
+ (r'\{index\}', 'index directive'),
+ (r'\`\`\`\{', 'fenced directive'),
+ (r'^\([a-z_][a-z0-9_-]*\)=\$', 'target label'),
+ ]
+ issues = 0
+ for nb_path in sorted(glob.glob('exports/*.ipynb')):
+ with open(nb_path) as f:
+ nb = json.load(f)
+ for i, cell in enumerate(nb.get('cells', []), 1):
+ if cell.get('cell_type') != 'markdown':
+ continue
+ source = ''.join(cell.get('source', []))
+ for line in source.split('\n'):
+ for pat, desc in PATTERNS:
+ if re.search(pat, line.strip()):
+ print(f'{nb_path} cell {i}: [{desc}] {line.strip()[:80]}')
+ issues += 1
+ if issues:
+ print(f'\n{issues} MyST syntax leaks found!')
+ sys.exit(1)
+ else:
+ print(f'All {len(glob.glob(\"exports/*.ipynb\"))} notebooks clean.')
+ "
+
+ - name: Upload ipynb exports
+ uses: actions/upload-artifact@v4
+ with:
+ name: ipynb-exports
+ path: './lectures/exports/'
+
+
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 27dc37d6..4b53ac07 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -5,80 +5,49 @@ jobs:
runs-on: "runs-on=${{ github.run_id }}/family=g4dn.2xlarge/image=quantecon_ubuntu2404/disk=large"
steps:
- uses: actions/checkout@v6
+
+ - name: Setup GitHub Pages
+ uses: actions/configure-pages@v3
+
+ - name: Cache Notebook Execution
+ uses: actions/cache@v3
+ id: cache-execution
with:
- fetch-depth: 0 # Fetch full git history for changelog feature
- - name: Setup Anaconda
- uses: conda-incubator/setup-miniconda@v3
+ path: ./lectures/_build/execute
+ key: ${{ runner.os }}-execute-cache-${{ hashFiles('lectures/**/*.md') }}
+
+ - uses: actions/setup-node@v4
with:
- auto-update-conda: true
- auto-activate-base: true
- miniconda-version: 'latest'
- python-version: "3.13"
- environment-file: environment.yml
- activate-environment: quantecon
- - name: Check nvidia Drivers
- shell: bash -l {0}
- run: nvidia-smi
- - name: Install JAX and Numpyro
- shell: bash -l {0}
- run: |
- pip install -U "jax[cuda13]"
- pip install numpyro
- python scripts/test-jax-install.py
- - name: Install latex dependencies
- run: |
- sudo apt-get -qq update
- sudo apt-get install -y \
- texlive-latex-recommended \
- texlive-latex-extra \
- texlive-fonts-recommended \
- texlive-fonts-extra \
- texlive-xetex \
- latexmk \
- xindy \
- dvipng \
- cm-super
- - name: Display Conda Environment Versions
- shell: bash -l {0}
- run: conda list
- - name: Display Pip Versions
- shell: bash -l {0}
- run: pip list
- - name: Download "build" folder (cache)
- uses: dawidd6/action-download-artifact@v12
+ node-version: 18.x
+
+ - name: Install Python
+ if: steps.cache-execution.outputs.cache-hit != 'true'
+ uses: actions/setup-python@v5
with:
- workflow: cache.yml
- branch: main
- name: build-cache
- path: _build
- # Build Assets (Download Notebooks and PDF via LaTeX)
- - name: Build Download Notebooks (sphinx-tojupyter)
- shell: bash -l {0}
- run: |
- jb build lectures --path-output ./ --builder=custom --custom-builder=jupyter -n -W --keep-going
- mkdir -p _build/html/_notebooks
- cp -u _build/jupyter/*.ipynb _build/html/_notebooks
- - name: Build PDF from LaTeX
- shell: bash -l {0}
- run: |
- jb build lectures --builder pdflatex --path-output ./ -n -W --keep-going
- mkdir _build/html/_pdf
- cp -u _build/latex/*.pdf _build/html/_pdf
- # Final Build of HTML
+ python-version: '3.12'
+ cache: 'pip'
+ cache-dependency-path: 'myst_requirements.txt'
+
+ - name: Install execution requirements
+ if: steps.cache-execution.outputs.cache-hit != 'true'
+ run: python -m pip install -r myst_requirements.txt
+
+ - name: Install jupyter book 2.0
+ run: pip install "jupyter-book>=2.0.0a0"
+
- name: Build HTML
- shell: bash -l {0}
- run: |
- jb build lectures --path-output ./ -n -W --keep-going
- - name: Upload Execution Reports
+ working-directory: ./lectures
+ run: jupyter book build --html --execute
+
+ - name: Upload build output
uses: actions/upload-artifact@v6
- if: failure()
with:
- name: execution-reports
- path: _build/html/reports
+ path: './lectures/_build/html'
+
- name: Preview Deploy to Netlify
uses: nwtgck/actions-netlify@v3
with:
- publish-dir: '_build/html/'
+ publish-dir: './lectures/_build/html'
production-branch: main
github-token: ${{ secrets.GITHUB_TOKEN }}
deploy-message: "Preview Deploy from GitHub Actions"
diff --git a/.gitignore b/.gitignore
index d8655893..769ed503 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,6 +11,7 @@ lectures/sine_wave.py
lectures/mathfoo.py
lectures/mod.py
lectures/test.py
+lectures/exports/
lectures/foo.py
lectures/*.txt
-lectures/*.csv
\ No newline at end of file
+lectures/*.csv
diff --git a/lectures/_static/ccbysa.png b/lectures/_static/ccbysa.png
new file mode 100644
index 00000000..87707329
Binary files /dev/null and b/lectures/_static/ccbysa.png differ
diff --git a/lectures/about_py.md b/lectures/about_py.md
index 96e8f1a1..dacb1642 100644
--- a/lectures/about_py.md
+++ b/lectures/about_py.md
@@ -7,19 +7,18 @@ kernelspec:
display_name: Python 3
language: python
name: python3
+exports:
+ - format: ipynb
+ markdown: commonmark
+ images: attachment
+ output: exports/about_py.ipynb
+downloads:
+ - file: ./about_py.md
+ title: Markdown (md)
+ - file: exports/about_py.ipynb
+ title: IPython (.ipynb)
---
-(about_py)=
-```{raw} jupyter
-
-```
-
-```{index} single: python
-```
# About These Lectures
@@ -100,8 +99,7 @@ This is important because it
### Common Uses
-{index}`Python ` is a general-purpose language used
-in almost all application domains, including
+Python is a general-purpose language used in almost all application domains, including
* AI and computer science
* other scientific computing
@@ -158,8 +156,6 @@ Python is flexible and pragmatic, supporting multiple programming styles (proced
### Syntax and Design
-```{index} single: Python; syntax and design
-```
One reason for Python's popularity is its simple and elegant design.
@@ -268,8 +264,6 @@ These lectures will explain how.
## Scientific Programming with Python
-```{index} single: scientific programming
-```
We have already discussed the importance of Python for AI, machine learning and data science
@@ -290,9 +284,6 @@ This section briefly showcases some examples of Python for general scientific pr
### NumPy
-```{index} single: scientific programming; numeric
-```
-
One of the most important parts of scientific computing is working with data.
Data is often stored in matrices, vectors and arrays.
@@ -395,8 +386,6 @@ Later we'll discuss SciPy in more detail.
### Graphics
-```{index} single: Matplotlib
-```
A major strength of Python is data visualization.
@@ -409,13 +398,13 @@ The most popular and comprehensive Python library for creating figures and graph
Example 2D plot with embedded LaTeX annotations
```{figure} /_static/lecture_specific/about_py/qs.png
-:scale: 75
+:width: 75%
```
Example contour plot
```{figure} /_static/lecture_specific/about_py/bn_density1.png
-:scale: 70
+:width: 70%
```
Example 3D plot
@@ -449,8 +438,6 @@ For example, we are interesting in studying
Python has many libraries for studying networks and graphs.
-```{index} single: NetworkX
-```
One well-known example is [NetworkX](https://networkx.org/).
diff --git a/lectures/debugging.md b/lectures/debugging.md
index a9356866..36707dba 100644
--- a/lectures/debugging.md
+++ b/lectures/debugging.md
@@ -7,22 +7,20 @@ kernelspec:
display_name: Python 3
language: python
name: python3
+exports:
+ - format: ipynb
+ markdown: commonmark
+ images: attachment
+ output: exports/debugging.ipynb
+downloads:
+ - file: ./debugging.md
+ title: Markdown (md)
+ - file: exports/debugging.ipynb
+ title: IPython (.ipynb)
---
-(debugging)=
-```{raw} jupyter
-
-```
-
# Debugging and Handling Errors
-```{index} single: Debugging
-```
-
```{epigraph}
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by definition,
@@ -45,9 +43,6 @@ In this lecture, we will discuss how to debug our programs and improve error han
## Debugging
-```{index} single: Debugging
-```
-
Debugging tools for Python vary across platforms, IDEs and editors.
For example, a [visual debugger](https://jupyterlab.readthedocs.io/en/stable/user/debugger.html) is available in JupyterLab.
@@ -67,9 +62,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)
@@ -94,9 +88,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
```
@@ -108,9 +101,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)
@@ -187,9 +179,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)
@@ -259,8 +250,6 @@ The full list of magics is [here](https://ipython.readthedocs.io/en/stable/inter
## Handling Errors
-```{index} single: Python; Handling Errors
-```
Sometimes it's possible to anticipate bugs and errors as we're writing code.
@@ -292,19 +281,16 @@ 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 `.
+We have seen `AttributeError` and `NameError` in [our previous examples](#debug_magic).
In Python, there are two types of errors -- syntax errors and exceptions.
-```{index} single: Python; Exceptions
-```
Here's an example of a common error type
```{code-cell} python3
----
-tags: [raises-exception]
----
+:tags: raises-exception
+
def f:
```
@@ -313,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]
```
@@ -355,8 +337,6 @@ In Python, these errors are called *exceptions*.
### Assertions
-```{index} single: Python; Assertions
-```
Sometimes errors can be avoided by checking whether your program runs as expected.
@@ -376,9 +356,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])
```
@@ -389,8 +368,6 @@ The advantage is that we can
### Handling Errors During Runtime
-```{index} single: Python; Runtime Errors
-```
The approach used above is a bit limited, because it always leads to
termination.
@@ -508,7 +485,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` to open `numbers.txt`.
+You can use the `open()` function we learnt [before](#iterators) to open `numbers.txt`.
```{exercise-end}
```
diff --git a/lectures/foo.py b/lectures/foo.py
new file mode 100644
index 00000000..14cce625
--- /dev/null
+++ b/lectures/foo.py
@@ -0,0 +1,2 @@
+
+print("foobar")
diff --git a/lectures/footer.md b/lectures/footer.md
new file mode 100644
index 00000000..e7473522
--- /dev/null
+++ b/lectures/footer.md
@@ -0,0 +1,6 @@
+::::{figure} _static/ccbysa.png
+:alt: CC-BY-SA-4.0
+:height: 36
+:align: left
+[Creative Commons License](https://creativecommons.org/licenses/by-sa/4.0) – This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International.
+::::
\ No newline at end of file
diff --git a/lectures/functions.md b/lectures/functions.md
index 65b3b2fc..71577440 100644
--- a/lectures/functions.md
+++ b/lectures/functions.md
@@ -7,21 +7,20 @@ kernelspec:
display_name: Python 3
language: python
name: python3
+exports:
+ - format: ipynb
+ markdown: commonmark
+ images: attachment
+ output: exports/functions.ipynb
+downloads:
+ - file: ./functions.md
+ title: Markdown (md)
+ - file: exports/functions.ipynb
+ title: IPython (.ipynb)
---
-(functions)=
-```{raw} jupyter
-
-```
-
# Functions
-```{index} single: Python; User-defined functions
-```
## Overview
@@ -82,7 +81,7 @@ The full list of Python built-ins is [here](https://docs.python.org/3/library/fu
If the built-in functions don't cover what we need, we either need to import
functions or create our own.
-Examples of importing and using functions were given in the {doc}`previous lecture `
+Examples of importing and using functions were given in the [previous lecture](python_by_example.md)
Here's another one, which tests whether a given year is a leap year:
@@ -167,10 +166,8 @@ Functions without a return statement automatically return the special Python obj
(pos_args)=
### Keyword Arguments
-```{index} single: Python; keyword arguments
-```
-In a {ref}`previous lecture `, you came across the statement
+In a [previous lecture](python_by_example.md), you came across the statement
```{code-block} python3
:class: no-execute
@@ -212,7 +209,7 @@ f(2, a=4, b=5)
### The Flexibility of Python Functions
-As we discussed in the {ref}`previous lecture `, Python functions are very flexible.
+As we discussed in the [previous lecture](python_by_example.md), Python functions are very flexible.
In particular
@@ -226,8 +223,6 @@ a function in the following sections.
### One-Line Functions: `lambda`
-```{index} single: Python; lambda functions
-```
The `lambda` keyword is used to create simple functions on one line.
@@ -272,13 +267,13 @@ User-defined functions are important for improving the clarity of your code by
(Writing the same thing twice is [almost always a bad idea](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself))
-We will say more about this {doc}`later `.
+We will say more about this [later](writing_good_code.md).
## Applications
### Random Draws
-Consider again this code from the {doc}`previous lecture `
+Consider again this code from the [previous lecture](python_by_example.md)
```{code-cell} python3
ts_length = 100
@@ -301,7 +296,6 @@ We will break this program into two parts:
This is accomplished in the next program
-(funcloopprog)=
```{code-cell} python3
def generate_data(n):
ϵ_values = []
@@ -321,8 +315,6 @@ The net result is that the name `data` is *bound* to the list `ϵ_values` return
### Adding Conditions
-```{index} single: Python; Conditions
-```
Our function `generate_data()` is rather limited.
@@ -330,7 +322,6 @@ Let's make it slightly more useful by giving it the ability to return either sta
This is achieved in the next piece of code.
-(funcloopprog2)=
```{code-cell} python3
def generate_data(n, generator_type):
ϵ_values = []
@@ -362,7 +353,6 @@ For example, we can get rid of the conditionals all together by just passing the
To understand this, consider the following version.
-(test_program_6)=
```{code-cell} python3
def generate_data(n, generator_type):
ϵ_values = []
@@ -407,8 +397,6 @@ function*---as we did above.
(recursive_functions)=
## Recursive Function Calls (Advanced)
-```{index} single: Python; Recursion
-```
This is an advanced topic that you should feel free to skip.
@@ -458,7 +446,6 @@ This example is somewhat contrived, since the first (iterative) solution would u
We'll meet less contrived applications of recursion later on.
-(factorial_exercise)=
## Exercises
```{exercise-start}
diff --git a/lectures/getting_started.md b/lectures/getting_started.md
index 62a5c53c..214880eb 100644
--- a/lectures/getting_started.md
+++ b/lectures/getting_started.md
@@ -7,35 +7,20 @@ kernelspec:
display_name: Python 3
language: python
name: python3
+exports:
+ - format: ipynb
+ markdown: commonmark
+ images: attachment
+ output: exports/getting_started.ipynb
+downloads:
+ - file: ./getting_started.md
+ title: Markdown (md)
+ - file: exports/getting_started.ipynb
+ title: IPython (.ipynb)
---
-(getting_started)=
-```{raw} jupyter
-
-```
-
-
-
-
-
-
# Getting Started
-```{index} single: Python
-```
## Overview
@@ -104,8 +89,6 @@ Anaconda also comes with a package management system to organize your code libra
(install_anaconda)=
### Installing Anaconda
-```{index} single: Python; Anaconda
-```
To install Anaconda, [download](https://www.anaconda.com/download) the binary and follow the instructions.
@@ -128,16 +111,7 @@ As a practice run, please execute the following
For more information on conda, type conda help in a terminal.
(ipython_notebook)=
-## {index}`Jupyter Notebooks `
-
-```{index} single: Python; IPython
-```
-
-```{index} single: IPython
-```
-
-```{index} single: Jupyter
-```
+## Jupyter Notebook
[Jupyter](https://jupyter.org/) notebooks are one of the many possible ways to interact with Python and the scientific libraries.
@@ -166,8 +140,6 @@ These lectures are designed for executing in Jupyter notebooks.
### Starting the Jupyter Notebook
-```{index} single: Jupyter Notebook; Setup
-```
Once you have installed Anaconda, you can start the Jupyter notebook.
@@ -212,8 +184,6 @@ The notebook displays an *active cell*, into which you can type Python commands.
### Notebook Basics
-```{index} single: Jupyter Notebook; Basics
-```
Let's start with how to edit code and run simple programs.
@@ -328,8 +298,6 @@ In this way, the Tab key helps remind you of what's available and also saves you
(gs_help)=
#### On-Line Help
-```{index} single: Jupyter Notebook; Help
-```
To get help on `np.random.randn`, we can execute `np.random.randn?`.
@@ -366,8 +334,6 @@ Now we `Shift+Enter` to produce this
### Debugging Code
-```{index} single: Jupyter Notebook; Debugging
-```
Debugging is the process of identifying and removing errors from a program.
@@ -376,7 +342,7 @@ You will spend a lot of time debugging code, so it is important to [learn how to
If you are using a newer version of Jupyter, you should see a bug icon on the right end of the toolbar.
```{figure} /_static/lecture_specific/getting_started/debug.png
-:scale: 50%
+:width: 80%
:figclass: auto
```
@@ -402,11 +368,6 @@ You can explore more functionality of the debugger in the [Jupyter documentation
### Sharing Notebooks
-```{index} single: Jupyter Notebook; Sharing
-```
-
-```{index} single: Jupyter Notebook; nbviewer
-```
Notebook files are just text files structured in [JSON](https://en.wikipedia.org/wiki/JSON) and typically ending with `.ipynb`.
@@ -439,10 +400,6 @@ to comments and votes by the community.
## Installing Libraries
-(gs_qe)=
-```{index} single: QuantEcon
-```
-
Most of the libraries we need come in Anaconda.
Other libraries can be installed with `pip` or `conda`.
@@ -520,10 +477,8 @@ following questions:
1. how should you execute it?
1. How should you modify or edit it?
-#### Option 1: {index}`JupyterLab `
+#### Option 1: JupyterLab
-```{index} single: JupyterLab
-```
[JupyterLab](https://github.com/jupyterlab/jupyterlab) is an integrated development environment built on top of Jupyter notebooks.
diff --git a/lectures/intro.md b/lectures/intro.md
index 440a2a1b..e6d2938e 100644
--- a/lectures/intro.md
+++ b/lectures/intro.md
@@ -7,6 +7,16 @@ kernelspec:
display_name: Python 3
language: python
name: python3
+exports:
+ - format: ipynb
+ markdown: commonmark
+ images: attachment
+ output: exports/intro.ipynb
+downloads:
+ - file: ./intro.md
+ title: Markdown (md)
+ - file: exports/intro.ipynb
+ title: IPython (.ipynb)
---
# Python Programming for Economics and Finance
diff --git a/lectures/jax_intro.md b/lectures/jax_intro.md
index adf3b80c..f5d59c7f 100644
--- a/lectures/jax_intro.md
+++ b/lectures/jax_intro.md
@@ -9,6 +9,16 @@ kernelspec:
display_name: Python 3 (ipykernel)
language: python
name: python3
+exports:
+ - format: ipynb
+ markdown: commonmark
+ images: attachment
+ output: exports/jax_intro.ipynb
+downloads:
+ - file: ./jax_intro.md
+ title: Markdown (md)
+ - file: exports/jax_intro.ipynb
+ title: IPython (.ipynb)
---
# JAX
@@ -784,8 +794,7 @@ We defer further exploration of automatic differentiation with JAX until {doc}`j
:label: jax_intro_ex2
```
-In the Exercise section of {doc}`our lecture on Numba `, we {ref}`used Monte
-Carlo to price a European call option `.
+In the Exercise section of {doc}`our lecture on Numba `, we {ref}`used Monte Carlo to price a European call option `.
The code was accelerated by Numba-based multithreading.
diff --git a/lectures/matplotlib.md b/lectures/matplotlib.md
index 4f860d22..b39e45a1 100644
--- a/lectures/matplotlib.md
+++ b/lectures/matplotlib.md
@@ -7,21 +7,20 @@ kernelspec:
display_name: Python 3
language: python
name: python3
+exports:
+ - format: ipynb
+ markdown: commonmark
+ images: attachment
+ output: exports/matplotlib.ipynb
+downloads:
+ - file: ./matplotlib.md
+ title: Markdown (md)
+ - file: exports/matplotlib.ipynb
+ title: IPython (.ipynb)
---
-(matplotlib)=
-```{raw} jupyter
-
-```
-
-# {index}`Matplotlib `
+# Matplotlib
-```{index} single: Python; Matplotlib
-```
## Overview
@@ -49,8 +48,6 @@ But first, let's discuss the difference.
## The APIs
-```{index} single: Matplotlib; Simple API
-```
### The MATLAB-style API
@@ -147,8 +144,6 @@ We mention just a few.
### Multiple Plots on One Axis
-```{index} single: Matplotlib; Multiple Plots on One Axis
-```
It's straightforward to generate multiple plots on the same axes.
@@ -171,9 +166,6 @@ plt.show()
### Multiple Subplots
-```{index} single: Matplotlib; Subplots
-```
-
Sometimes we want multiple subplots in one figure.
Here's an example that generates 6 histograms
@@ -193,8 +185,6 @@ plt.show()
### 3D Plots
-```{index} single: Matplotlib; 3D Plots
-```
Matplotlib does a nice job of 3D plots --- here is one example
@@ -352,12 +342,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.
@@ -462,9 +449,8 @@ Place all the curves in the same figure.
The output should look like this
-```{image} /_static/lecture_specific/matplotlib/matplotlib_ex1.png
-:scale: 130
-:align: center
+```{figure} /_static/lecture_specific/matplotlib/matplotlib_ex1.png
+:width: 100%
```
```{exercise-end}
diff --git a/lectures/myst.yml b/lectures/myst.yml
new file mode 100644
index 00000000..8a5bbce5
--- /dev/null
+++ b/lectures/myst.yml
@@ -0,0 +1,89 @@
+version: 1
+project:
+ title: Python Programming for Economics and Finance
+ authors:
+ - name: Thomas J. Sargent
+ affiliations:
+ - Professor of Economics, New York University.
+ - Senior Fellow, Hoover Institution, Stanford, CA.
+ url: http://www.tomsargent.com
+ - name: John Stachurski
+ affiliations:
+ - Professor, Research School of Economics, ANU.
+ - Instructor for Ph.D. Advanced Macroeconomics, University of Minnesota.
+ url: https://johnstachurski.net
+ email: john.stachurski@gmail.com
+ github: https://github.com/QuantEcon/lecture-python-programming.myst
+ toc:
+ - file: intro.md
+ - title: Introduction to Python
+ children:
+ - file: about_py.md
+ - file: getting_started.md
+ - file: python_by_example.md
+ - file: functions.md
+ - file: python_essentials.md
+ - file: oop_intro.md
+ - file: names.md
+ - file: python_oop.md
+ - file: workspace.md
+ - title: The Scientific Libraries
+ children:
+ - file: need_for_speed.md
+ - file: numpy.md
+ - file: matplotlib.md
+ - file: scipy.md
+ - title: Working with Data
+ children:
+ - file: pandas.md
+ - file: pandas_panel.md
+ - title: High Performance Computing
+ children:
+ - file: numba.md
+ - file: jax_intro.md
+ - file: numpy_vs_numba_vs_jax.md
+ - title: More Python Programming
+ children:
+ - file: writing_good_code.md
+ - file: workspace.md
+ - file: python_advanced_features.md
+ - file: debugging.md
+ - file: sympy.md
+ - title: Other
+ children:
+ - file: troubleshooting.md
+ - file: status.md
+ references:
+ intermediate: https://python.quantecon.org/
+ pyprog: https://python-programming.quantecon.org/
+ intro: https://intro.quantecon.org/
+ dle: https://quantecon.github.io/lecture-dle/
+ dps: https://quantecon.github.io/lecture-dps/
+ eqm: https://quantecon.github.io/lecture-eqm/
+ stats: https://quantecon.github.io/lecture-stats/
+ tools: https://quantecon.github.io/lecture-tools-techniques/
+ dynam: https://quantecon.github.io/lecture-dynamics/
+ numbering:
+ titles: true
+ headings: true
+ heading_1: false
+ figure:
+ template: Fig. %s
+ settings:
+ output_stderr: remove
+ output_matplotlib_strings: remove
+ 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-lecture-python.pdf
+ # downloads:
+ # - id: book-pdf
+ # title: Book (PDF)
+site:
+ parts:
+ footer: footer.md
+ template: https://github.com/QuantEcon/quantecon-theme/archive/refs/heads/main.zip
diff --git a/lectures/names.md b/lectures/names.md
index 3ce66b14..2cfd75d7 100644
--- a/lectures/names.md
+++ b/lectures/names.md
@@ -7,17 +7,18 @@ kernelspec:
display_name: Python 3
language: python
name: python3
+exports:
+ - format: ipynb
+ markdown: commonmark
+ images: attachment
+ output: exports/names.ipynb
+downloads:
+ - file: ./names.md
+ title: Markdown (md)
+ - file: exports/names.ipynb
+ title: IPython (.ipynb)
---
-(oop_names)=
-```{raw} jupyter
-
-```
-
# Names and Namespaces
## Overview
@@ -34,8 +35,6 @@ understanding of how names work in Python.
(var_names)=
## Variable Names in Python
-```{index} single: Python; Variable Names
-```
Consider the Python statement
@@ -96,9 +95,6 @@ You can [read more on garbage collection](https://rushter.com/blog/python-garbag
## Namespaces
-```{index} single: Python; Namespaces
-```
-
Recall from the preceding discussion that the statement
```{code-cell} python3
@@ -211,8 +207,6 @@ math.__name__
## Interactive Sessions
-```{index} single: Python; Interpreter
-```
In Python, **all** code executed by the interpreter runs in some module.
@@ -265,8 +259,6 @@ import numpy as np
## The Global Namespace
-```{index} single: Python; Namespace (Global)
-```
Python documentation often makes reference to the "global namespace".
@@ -294,8 +286,6 @@ In this case it's `__main__`, so the namespace of `__main__` again becomes the g
## Local Namespaces
-```{index} single: Python; Namespace (Local)
-```
Important fact: When we call a function, the interpreter creates a *local namespace* for that function, and registers the variables in that namespace.
@@ -326,8 +316,6 @@ You can see the local namespace of `f` before it is destroyed.
## The `__builtins__` Namespace
-```{index} single: Python; Namespace (__builtins__)
-```
We have been using various built-in functions, such as `max(), dir(), str(), list(), len(), range(), type()`, etc.
@@ -366,8 +354,6 @@ The next section explains how this works ...
## Name Resolution
-```{index} single: Python; Namespace (Resolution)
-```
Namespaces are great because they help us organize variable names.
@@ -479,7 +465,7 @@ Note that the global `a` was not affected by the local `a`.
(mutable_vs_immutable)=
-### {index}`Mutable ` Versus {index}`Immutable ` Parameters
+### Mutable Versus Immutable Parameters
This is a good time to say a little more about mutable vs immutable objects.
diff --git a/lectures/need_for_speed.md b/lectures/need_for_speed.md
index ef4f23ad..f8de8dc0 100644
--- a/lectures/need_for_speed.md
+++ b/lectures/need_for_speed.md
@@ -7,17 +7,18 @@ kernelspec:
display_name: Python 3
language: python
name: python3
+exports:
+ - format: ipynb
+ markdown: commonmark
+ images: attachment
+ output: exports/need_for_speed.ipynb
+downloads:
+ - file: ./need_for_speed.md
+ title: Markdown (md)
+ - file: exports/need_for_speed.ipynb
+ title: IPython (.ipynb)
---
-(speed)=
-```{raw} jupyter
-
-```
-
# Python for Scientific Computing
```{epigraph}
@@ -51,9 +52,8 @@ In this introductory lecture, we'll 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
```
@@ -160,8 +160,6 @@ Why is this the case?
#### Dynamic typing
-```{index} single: Dynamic Typing
-```
Consider this Python operation
@@ -202,8 +200,6 @@ overhead becomes a large overhead.
#### Static types
-```{index} single: Static Types
-```
Compiled languages avoid these overheads with explicit, static types.
@@ -298,8 +294,6 @@ This task is best left to specialized compilers!
Certain Python libraries have outstanding capabilities for parallelizing scientific code -- we'll discuss this more as we go along.
-
-
## Accelerating Python
In this section we look at three related techniques for accelerating Python
@@ -311,10 +305,7 @@ Later we'll look at specific libraries and how they implement these ideas.
-### {index}`Vectorization `
-
-```{index} single: Python; Vectorization
-```
+### Vectorization
One method for avoiding memory traffic and type checking is [array
programming](https://en.wikipedia.org/wiki/Array_programming).
@@ -414,7 +405,6 @@ parallelized machine code.
-
## Parallelization
The growth of CPU clock speed (i.e., the speed at which a single chain of logic
@@ -508,7 +498,7 @@ GPUs were originally designed for rendering graphics, which requires performing
the same operation on many pixels simultaneously.
```{figure} /_static/lecture_specific/need_for_speed/geforce.png
-:scale: 40
+:width: 40%
```
Scientists and engineers realized that this same architecture --- many simple
@@ -554,7 +544,7 @@ automatically detect and use available GPUs with minimal code changes.
For larger-scale problems, servers containing multiple GPUs (often 4-8 GPUs per server) are increasingly common.
```{figure} /_static/lecture_specific/need_for_speed/dgx.png
-:scale: 40
+:width: 40%
```
diff --git a/lectures/newfile.txt b/lectures/newfile.txt
new file mode 100644
index 00000000..119fdd30
--- /dev/null
+++ b/lectures/newfile.txt
@@ -0,0 +1,2 @@
+Testing
+Testing again
\ No newline at end of file
diff --git a/lectures/numba.md b/lectures/numba.md
index b6a3cccb..8acb1664 100644
--- a/lectures/numba.md
+++ b/lectures/numba.md
@@ -9,17 +9,18 @@ kernelspec:
display_name: Python 3 (ipykernel)
language: python
name: python3
+exports:
+ - format: ipynb
+ markdown: commonmark
+ images: attachment
+ output: exports/numba.ipynb
+downloads:
+ - file: ./numba.md
+ title: Markdown (md)
+ - file: exports/numba.ipynb
+ title: IPython (.ipynb)
---
-(speed)=
-```{raw} jupyter
-
-```
-
# Numba
In addition to what's in Anaconda, this lecture will need the following libraries:
@@ -31,7 +32,7 @@ In addition to what's in Anaconda, this lecture will need the following librarie
```
Please also make sure that you have the latest version of Anaconda, since old
-versions are a {doc}`common source of errors `.
+versions are a [common source of errors](troubleshooting.md).
Let's start with some imports:
@@ -45,7 +46,7 @@ import matplotlib.pyplot as plt
## Overview
-In an {doc}`earlier lecture ` we learned about vectorization, which is one method to improve speed and efficiency in numerical work.
+In an [earlier lecture](need_for_speed.md) we learned about vectorization, which is one method to improve speed and efficiency in numerical work.
Vectorization involves sending array processing
operations in batch to efficient low-level code.
@@ -72,10 +73,8 @@ Beyond speed gains from compilation, Numba is specifically designed for numerica
This lecture introduces the main ideas.
(numba_link)=
-## {index}`Compiling Functions `
+## Compiling Functions
-```{index} single: Python; Numba
-```
As stated above, Numba's primary use is compiling functions to fast native
machine code during runtime.
@@ -170,7 +169,7 @@ Numba attempts to generate fast machine code using the infrastructure provided b
It does this by inferring type information on the fly.
-(See our {doc}`earlier lecture ` on scientific computing for a discussion of types.)
+(See our [earlier lecture](need_for_speed.md) on scientific computing for a discussion of types.)
The basic idea is this:
@@ -202,7 +201,7 @@ qm_numba = jit(qm)
In practice this would typically be done using an alternative *decorator* syntax.
-(We discuss decorators in a {doc}`separate lecture ` but you can skip the details at this stage.)
+(We discuss decorators in a [separate lecture](python_advanced_features.md) but you can skip the details at this stage.)
Let's see how this is done.
@@ -301,7 +300,7 @@ If a class is successfully compiled, then its methods act as JIT-compiled
functions.
To give one example, let's consider the class for analyzing the Solow growth model we
-created in {doc}`this lecture `.
+created in [this lecture](python_oop.md).
To compile this class we use the `@jitclass` decorator:
@@ -660,8 +659,7 @@ Suppose that the volatility of returns on an asset can be in one of two regimes
The transition probabilities across states are as follows
-```{image} /_static/lecture_specific/sci_libs/nfs_ex1.png
-:align: center
+```{figure} /_static/lecture_specific/sci_libs/nfs_ex1.png
```
For example, let the period length be one day, and suppose the current state is high.
diff --git a/lectures/numbers.txt b/lectures/numbers.txt
new file mode 100644
index 00000000..5a6193d8
--- /dev/null
+++ b/lectures/numbers.txt
@@ -0,0 +1,6 @@
+prices
+3
+8
+
+7
+21
diff --git a/lectures/numpy.md b/lectures/numpy.md
index ecb6a294..6552db27 100644
--- a/lectures/numpy.md
+++ b/lectures/numpy.md
@@ -7,21 +7,20 @@ kernelspec:
display_name: Python 3
language: python
name: python3
+exports:
+ - format: ipynb
+ markdown: commonmark
+ images: attachment
+ output: exports/numpy.ipynb
+downloads:
+ - file: ./numpy.md
+ title: Markdown (md)
+ - file: exports/numpy.ipynb
+ title: IPython (.ipynb)
---
-(np)=
-```{raw} jupyter
-
-```
-
-# {index}`NumPy `
-```{index} single: Python; NumPy
-```
+# NumPy
```{epigraph}
"Let's be clear: the work of science has nothing whatever to do with consensus. Consensus is the business of politics. Science, on the contrary, requires only one investigator who happens to be right, which means that he or she has results that are verifiable by reference to the real world. In science consensus is irrelevant. What is relevant is reproducible results." -- Michael Crichton
@@ -68,8 +67,6 @@ from matplotlib import cm
(numpy_array)=
## NumPy Arrays
-```{index} single: NumPy; Arrays
-```
The essential problem that NumPy solves is fast array processing.
@@ -121,8 +118,6 @@ type(a[0])
(numpy_shape_dim)=
### Shape and Dimension
-```{index} single: NumPy; Arrays (Shape and Dimension)
-```
Consider the following assignment
@@ -160,8 +155,6 @@ in `z = np.zeros((2, 2))`.
(creating_arrays)=
### Creating Arrays
-```{index} single: NumPy; Arrays (Creating)
-```
As we've seen, the `np.zeros` function creates an array of zeros.
@@ -221,8 +214,6 @@ To read in the array data from a text file containing numeric data use `np.loadt
### Array Indexing
-```{index} single: NumPy; Arrays (Indexing)
-```
For a flat array, indexing is the same as Python sequences:
@@ -313,8 +304,6 @@ z
### Array Methods
-```{index} single: NumPy; Arrays (Methods)
-```
Arrays have useful methods, all of which are carefully optimized
@@ -382,8 +371,6 @@ z.searchsorted(2.2)
## Arithmetic Operations
-```{index} single: NumPy; Arithmetic Operations
-```
The operators `+`, `-`, `*`, `/` and `**` all act *elementwise* on arrays
@@ -431,11 +418,6 @@ In particular, `A * B` is *not* the matrix product, it is an element-wise produc
## Matrix Multiplication
-```{index} single: NumPy; Matrix Multiplication
-```
-
-```{index} single: NumPy; Matrix Multiplication
-```
We use the `@` symbol for matrix multiplication, as follows:
@@ -459,8 +441,6 @@ Since we are post-multiplying, the tuple is treated as a column vector.
(broadcasting)=
## Broadcasting
-```{index} single: NumPy; Broadcasting
-```
(This section extends an excellent discussion of broadcasting provided by [Jake VanderPlas](https://jakevdp.github.io/PythonDataScienceHandbook/02.05-computation-on-arrays-broadcasting.html).)
@@ -499,9 +479,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 https://www.astroml.org/book_figures/appendix/fig_broadcast_visual.html
@@ -628,9 +607,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)
@@ -697,9 +675,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')
@@ -753,9 +730,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],
@@ -771,9 +747,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)
@@ -877,7 +852,7 @@ a
What's happened is that we have changed `a` by changing `b`.
The name `b` is bound to `a` and becomes just another reference to the
-array (the Python assignment model is described in more detail {doc}`later in the course `).
+array the Python assignment model is described in more detail [later in the course](python_advanced_features.md).
Hence, it has equal rights to make changes to that array.
@@ -926,8 +901,6 @@ Let's look at some other useful features of NumPy.
### Universal Functions
-```{index} single: NumPy; Vectorized Functions
-```
NumPy provides versions of the standard functions `log`, `exp`, `sin`, etc. that act *element-wise* on arrays
@@ -994,8 +967,6 @@ However, this approach doesn't always obtain the same speed as a more carefully
### Comparisons
-```{index} single: NumPy; Comparisons
-```
As a rule, comparisons on arrays are done element-wise
@@ -1069,15 +1040,9 @@ np.linalg.det(A) # Compute the determinant
np.linalg.inv(A) # Compute the inverse
```
-```{index} single: SciPy
-```
-
-```{index} single: Python; SciPy
-```
-
Much of this functionality is also available in [SciPy](https://scipy.org/), a collection of modules that are built on top of NumPy.
-We'll cover the SciPy versions in more detail {doc}`soon `.
+We'll cover the SciPy versions in more detail [soon](scipy.md).
For a comprehensive list of what's available in NumPy see [this documentation](https://numpy.org/doc/stable/reference/routines.html).
@@ -1107,7 +1072,7 @@ Now, let's look at the output of the htop system monitor on our machine while
this code is running:
```{figure} /_static/lecture_specific/parallelization/htop_parallel_npmat.png
-:scale: 80
+:width: 80%
```
We can see that 4 of the 8 CPUs are running at full speed.
@@ -1117,8 +1082,6 @@ distributes them to different threads.
-
-
## Exercises
@@ -1420,9 +1383,8 @@ A = x / y
Here is the output
```{code-cell} python3
----
-tags: [hide-output]
----
+:tags: hide-output
+
print(A)
```
@@ -1433,7 +1395,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
```
@@ -1452,9 +1415,8 @@ with qe.Timer("Broadcasting operation"):
Here is the output
```{code-cell} python3
----
-tags: [hide-output]
----
+:tags: hide-output
+
print(B)
```
@@ -1483,9 +1445,8 @@ for i in range(n):
Compare the results to check your answer
```{code-cell} python3
----
-tags: [hide-output]
----
+:tags: hide-output
+
print(C)
```
@@ -1518,9 +1479,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)
```
diff --git a/lectures/numpy_vs_numba_vs_jax.md b/lectures/numpy_vs_numba_vs_jax.md
index aa9c85a9..984c09fb 100644
--- a/lectures/numpy_vs_numba_vs_jax.md
+++ b/lectures/numpy_vs_numba_vs_jax.md
@@ -7,17 +7,19 @@ kernelspec:
display_name: Python 3
language: python
name: python3
+exports:
+ - format: ipynb
+ markdown: commonmark
+ images: attachment
+ output: exports/numpy_vs_numba_vs_jax.ipynb
+downloads:
+ - file: ./numpy_vs_numba_vs_jax.md
+ title: Markdown (md)
+ - file: exports/numpy_vs_numba_vs_jax.ipynb
+ title: IPython (.ipynb)
---
(parallel)=
-```{raw} jupyter
-
-```
-
# NumPy vs Numba vs JAX
In the preceding lectures, we've discussed three core libraries for scientific
diff --git a/lectures/oop_intro.md b/lectures/oop_intro.md
index 21787a1d..aa911c29 100644
--- a/lectures/oop_intro.md
+++ b/lectures/oop_intro.md
@@ -7,17 +7,18 @@ kernelspec:
display_name: Python 3
language: python
name: python3
+exports:
+ - format: ipynb
+ markdown: commonmark
+ images: attachment
+ output: exports/oop_intro.ipynb
+downloads:
+ - file: ./oop_intro.md
+ title: Markdown (md)
+ - file: exports/oop_intro.ipynb
+ title: IPython (.ipynb)
---
-(oop_intro)=
-```{raw} jupyter
-
-```
-
# OOP I: Objects and Methods
## Overview
@@ -68,8 +69,6 @@ We'll make use of the following third party library
## Objects
-```{index} single: Python; Objects
-```
In Python, an *object* is a collection of data and instructions held in computer memory that consists of
@@ -83,8 +82,6 @@ These concepts are defined and discussed sequentially below.
(type)=
### Type
-```{index} single: Python; Type
-```
Python provides for different types of objects, to accommodate different categories of data.
@@ -117,9 +114,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
```
@@ -144,8 +140,6 @@ int('300') + 400 # To add as numbers, change the string to an integer
(identity)=
### Identity
-```{index} single: Python; Identity
-```
In Python, each object has a unique identifier, which helps Python (and us) keep track of the object.
@@ -167,8 +161,6 @@ The identity of an object is in fact just the address of the object in memory.
### Object Content: Data and Attributes
-```{index} single: Python; Content
-```
If we set `x = 42` then we create an object of type `int` that contains
the data `42`.
@@ -203,8 +195,6 @@ These attributes are important, so let's discuss them in-depth.
(methods)=
### Methods
-```{index} single: Python; Methods
-```
Methods are *functions that are bundled with objects*.
@@ -297,7 +287,7 @@ If Python is object oriented, why don't we use `x.len()`?
The answer is related to the fact that Python aims for readability and consistent style.
In Python, it is common for users to build custom objects --- we discuss how to
-do this {doc}`later `.
+do this [later](python_oop.md).
It's quite common for users to add methods to their that measure the length of
the object, suitably defined.
@@ -352,7 +342,7 @@ and write clear Pythonic code.
:label: oop_intro_ex1
```
-We have met the {any}`boolean data type ` 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`.
diff --git a/lectures/output.txt b/lectures/output.txt
new file mode 100644
index 00000000..66a30a78
--- /dev/null
+++ b/lectures/output.txt
@@ -0,0 +1,3 @@
+Line 0: Testing
+
+Line 1: Testing again
diff --git a/lectures/output2.txt b/lectures/output2.txt
new file mode 100644
index 00000000..7696e417
--- /dev/null
+++ b/lectures/output2.txt
@@ -0,0 +1,5 @@
+Line 0: Testing
+
+Line 1: Testing again
+
+This is the end of the file
\ No newline at end of file
diff --git a/lectures/pandas.md b/lectures/pandas.md
index 3d2c809d..aaec0bd8 100644
--- a/lectures/pandas.md
+++ b/lectures/pandas.md
@@ -9,21 +9,19 @@ kernelspec:
display_name: Python 3 (ipykernel)
language: python
name: python3
+exports:
+ - format: ipynb
+ markdown: commonmark
+ images: attachment
+ output: exports/pandas.ipynb
+downloads:
+ - file: ./pandas.md
+ title: Markdown (md)
+ - file: exports/pandas.ipynb
+ title: IPython (.ipynb)
---
-(pd)=
-```{raw} jupyter
-
-```
-
-# {index}`Pandas `
-
-```{index} single: Python; Pandas
-```
+# Pandas
In addition to what’s in Anaconda, this lecture will need the following libraries:
@@ -44,7 +42,7 @@ of fields such as data science and machine learning.
Here's a popularity comparison over time against Matlab and STATA courtesy of Stack Overflow Trends
```{figure} /_static/lecture_specific/pandas/pandas_vs_rest.png
-:scale: 100
+:width: 100%
```
Just as [NumPy](https://numpy.org/) provides the basic array data type plus core array operations, pandas
@@ -80,8 +78,6 @@ A `DataFrame` is a two-dimensional object for storing related columns of data.
## Series
-```{index} single: Pandas; Series
-```
Let's start with Series.
@@ -143,8 +139,6 @@ s
## DataFrames
-```{index} single: Pandas; DataFrames
-```
While a `Series` is a single column of data, a `DataFrame` is several columns, one for each variable.
@@ -494,8 +488,6 @@ plt.show()
## On-Line Data Sources
-```{index} single: Data Sources
-```
Python makes it straightforward to query online databases programmatically.
@@ -511,10 +503,8 @@ This can be done with a variety of methods.
We start with a relatively low-level method and then return to pandas.
-### Accessing Data with {index}`requests `
+### Accessing Data with requests
-```{index} single: Python; requests
-```
One option is to use [requests](https://requests.readthedocs.io/en/latest/), a standard Python library for requesting data over the Internet.
@@ -590,7 +580,7 @@ Note that pandas offers many other file type alternatives.
Pandas has [a wide variety](https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html) of top-level methods that we can use to read, excel, json, parquet or plug straight into a database server.
-### Using {index}`wbgapi ` and {index}`yfinance ` to Access Data
+### Using wbgapi and yfinance to Access Data
The [wbgapi](https://pypi.org/project/wbgapi/) python library can be used to fetch data from the many databases published by the World Bank.
@@ -682,9 +672,8 @@ ticker = read_data(ticker_list)
Complete the program to plot the result as a bar graph like this one:
-```{image} /_static/lecture_specific/pandas/pandas_share_prices.png
-:scale: 80
-:align: center
+```{figure} /_static/lecture_specific/pandas/pandas_share_prices.png
+:width: 80%
```
```{exercise-end}
@@ -749,9 +738,8 @@ indices_list = {'^GSPC': 'S&P 500',
Complete the program to show summary statistics and plot the result as a time series graph like this one:
-```{image} /_static/lecture_specific/pandas/pandas_indices_pctchange.png
-:scale: 80
-:align: center
+```{figure} /_static/lecture_specific/pandas/pandas_indices_pctchange.png
+:width: 80%
```
```{exercise-end}
diff --git a/lectures/pandas_panel.md b/lectures/pandas_panel.md
index 8bb6b29e..6a783509 100644
--- a/lectures/pandas_panel.md
+++ b/lectures/pandas_panel.md
@@ -9,21 +9,19 @@ kernelspec:
display_name: Python 3 (ipykernel)
language: python
name: python3
+exports:
+ - format: ipynb
+ markdown: commonmark
+ images: attachment
+ output: exports/pandas_panel.ipynb
+downloads:
+ - file: ./pandas_panel.md
+ title: Markdown (md)
+ - file: exports/pandas_panel.ipynb
+ title: IPython (.ipynb)
---
-```{raw} jupyter
-
-```
-
-(ppd)=
-# {index}`Pandas for Panel Data `
-
-```{index} single: Python; Pandas
-```
+# Pandas for Panel Data
In addition to what’s in Anaconda, this lecture will need the following libraries:
@@ -43,7 +41,7 @@ sns.set_theme()
## Overview
-In an {doc}`earlier lecture on pandas `, we looked at working with simple data sets.
+In an [earlier lecture on pandas](pandas.md), we looked at working with simple data sets.
Econometricians often need to work with more complex data sets, such as panels.
diff --git a/lectures/python_advanced_features.md b/lectures/python_advanced_features.md
index 9d2cb574..a10ae49b 100644
--- a/lectures/python_advanced_features.md
+++ b/lectures/python_advanced_features.md
@@ -7,17 +7,18 @@ kernelspec:
display_name: Python 3
language: python
name: python3
+exports:
+ - format: ipynb
+ markdown: commonmark
+ images: attachment
+ output: exports/python_advanced_features.ipynb
+downloads:
+ - file: ./python_advanced_features.md
+ title: Markdown (md)
+ - file: exports/python_advanced_features.ipynb
+ title: IPython (.ipynb)
---
-(python_advanced_features)=
-```{raw} jupyter
-
-```
-
# More Language Features
## Overview
@@ -33,8 +34,6 @@ A variety of topics are treated in the lecture, including iterators, decorators
## Iterables and Iterators
-```{index} single: Python; Iteration
-```
We've {ref}`already said something ` about iterating in Python.
@@ -43,8 +42,6 @@ Now let's look more closely at how it all works, focusing in Python's implementa
(iterators)=
### Iterators
-```{index} single: Python; Iterators
-```
Iterators are a uniform interface to stepping through elements in a collection.
@@ -54,7 +51,7 @@ Formally, an *iterator* is an object with a `__next__` method.
For example, file objects are iterators .
-To see this, let's have another look at the {ref}`US cities data `,
+To see this, let's have another look at the {ref}`US cities data `,
which is written to the present working directory in the following cell
```{code-cell} ipython
@@ -132,8 +129,6 @@ next(nikkei_data)
### Iterators in For Loops
-```{index} single: Python; Iterators
-```
All iterators can be placed to the right of the `in` keyword in `for` loop statements.
@@ -171,8 +166,6 @@ This continues until a `StopIteration` error occurs.
### Iterables
-```{index} single: Python; Iterables
-```
You already know that we can put a Python list to the right of `in` in a `for` loop
@@ -191,9 +184,8 @@ type(x)
```
```{code-cell} python3
----
-tags: [raises-exception]
----
+:tags: raises-exception
+
next(x)
```
@@ -224,9 +216,8 @@ next(y)
```
```{code-cell} python3
----
-tags: [raises-exception]
----
+:tags: raises-exception
+
next(y)
```
@@ -235,9 +226,8 @@ Many other objects are iterable, such as dictionaries and tuples.
Of course, not all objects are iterable
```{code-cell} python3
----
-tags: [raises-exception]
----
+:tags: raises-exception
+
iter(42)
```
@@ -248,9 +238,6 @@ To conclude our discussion of `for` loops
### Iterators and built-ins
-```{index} single: Python; Iterators
-```
-
Some built-in functions that act on sequences also work with iterables
* `max()`, `min()`, `sum()`, `all()`, `any()`
@@ -280,9 +267,8 @@ max(y)
```
```{code-cell} python3
----
-tags: [raises-exception]
----
+:tags: raises-exception
+
max(y)
```
@@ -461,12 +447,6 @@ The difference is that functions with `*args` will be able to take *positional a
## Decorators and Descriptors
-```{index} single: Python; Decorators
-```
-
-```{index} single: Python; Descriptors
-```
-
Let's look at some special syntax elements that are routinely used by Python developers.
You might not need the following concepts immediately, but you will see them
@@ -476,8 +456,6 @@ Hence you need to understand them at some stage of your Python education.
### Decorators
-```{index} single: Python; Decorators
-```
Decorators are a bit of syntactic sugar that, while easily avoided, have turned out to be popular.
@@ -578,8 +556,6 @@ At the same time, the test logic is written only once.
#### Enter Decorators
-```{index} single: Python; Decorators
-```
The last version of our code is still not ideal.
@@ -634,8 +610,6 @@ In the opinion of many people, this makes the decorator syntax a significant imp
(descriptors)=
### Descriptors
-```{index} single: Python; Descriptors
-```
Descriptors solve a common problem regarding management of variables.
@@ -748,11 +722,6 @@ method is triggered --- in this case `set_miles`.
#### Decorators and Properties
-```{index} single: Python; Decorators
-```
-
-```{index} single: Python; Properties
-```
These days its very common to see the `property` function used via a decorator.
@@ -792,9 +761,6 @@ For further information you can refer to the [descriptor documentation](https://
(paf_generators)=
## Generators
-```{index} single: Python; Generators
-```
-
A generator is a kind of iterator (i.e., it works with a `next` function).
We will study two ways to build generators: generator expressions and generator functions.
@@ -857,8 +823,6 @@ sum(x * x for x in range(10))
### Generator Functions
-```{index} single: Python; Generator Functions
-```
The most flexible way to create generator objects is to use generator functions.
@@ -901,9 +865,8 @@ next(gen)
```
```{code-cell} python3
----
-tags: [raises-exception]
----
+:tags: raises-exception
+
next(gen)
```
@@ -966,9 +929,8 @@ next(gen)
```
```{code-cell} python3
----
-tags: [raises-exception]
----
+:tags: raises-exception
+
next(gen)
```
@@ -1024,9 +986,8 @@ This uses lots of memory and is very slow.
If we make `n` even bigger then this happens
```{code-cell} python3
----
-tags: [raises-exception]
----
+:tags: raises-exception
+
n = 100000000
draws = [random.uniform(0, 1) < 0.5 for i in range(n)]
```
diff --git a/lectures/python_by_example.md b/lectures/python_by_example.md
index 531340c9..66a8fc2d 100644
--- a/lectures/python_by_example.md
+++ b/lectures/python_by_example.md
@@ -7,21 +7,21 @@ kernelspec:
display_name: Python 3
language: python
name: python3
+exports:
+ - format: ipynb
+ markdown: commonmark
+ images: attachment
+ output: exports/python_by_example.ipynb
+downloads:
+ - file: ./python_by_example.md
+ title: Markdown (md)
+ - file: exports/python_by_example.ipynb
+ title: IPython (.ipynb)
---
-(python_by_example)=
-```{raw} jupyter
-
-```
# An Introductory Example
-```{index} single: Python; Introductory Example
-```
## Overview
@@ -33,7 +33,7 @@ The objective is to introduce you to basic Python syntax and data structures.
Deeper concepts will be covered in later lectures.
-You should have read the {doc}`lecture ` on getting started with Python before beginning this one.
+You should have read the [lecture](getting_started.md) on getting started with Python before beginning this one.
## The Task: Plotting a White Noise Process
@@ -44,7 +44,7 @@ process $\epsilon_0, \epsilon_1, \ldots, \epsilon_T$, where each draw $\epsilon_
In other words, we want to generate figures that look something like this:
```{figure} /_static/lecture_specific/python_by_example/test_program_1_updated.png
-:scale: 120
+:width: 120%
```
(Here $t$ is on the horizontal axis and $\epsilon_t$ is on the
@@ -75,7 +75,7 @@ Let's break this program down and see how it works.
The first two lines of the program import functionality from external code
libraries.
-The first line imports {doc}`NumPy `, a favorite Python package for tasks like
+The first line imports [NumPy](numpy.md), a favorite Python package for tasks like
* working with arrays (vectors and matrices)
* common mathematical functions like `cos` and `sqrt`
@@ -107,8 +107,6 @@ to import additional functionality.
#### Packages
-```{index} single: Python; Packages
-```
As stated above, NumPy is a Python package.
@@ -132,8 +130,6 @@ print(np.__file__)
#### Subpackages
-```{index} single: Python; Subpackages
-```
Consider the line `ϵ_values = np.random.randn(100)`.
@@ -201,8 +197,8 @@ But they do help us illustrate some important Python syntax and semantics in a f
Here's a version that illustrates `for` loops and Python lists.
-(firstloopprog)=
```{code-cell} python3
+:name: firstloopprog
ts_length = 100
ϵ_values = [] # empty list
@@ -227,8 +223,6 @@ Let's study some parts of this program in more detail.
(lists_ref)=
### Lists
-```{index} single: Python; Lists
-```
Consider the statement `ϵ_values = []`, which creates an empty list.
@@ -258,7 +252,7 @@ x
Here `append()` is what's called a **method**, which is a function "attached to" an object---in this case, the list `x`.
-We'll learn all about methods {doc}`later on `, but just to give you some idea,
+We'll learn all about methods [later on](oop_intro.md), but just to give you some idea,
* Python objects such as lists, strings, etc. all have methods that are used to manipulate data contained in the object.
* String objects have [string methods](https://docs.python.org/3/library/stdtypes.html#string-methods), list objects have [list methods](https://docs.python.org/3/tutorial/datastructures.html#more-on-lists), etc.
@@ -289,10 +283,8 @@ x[1] # second element of x
### The For Loop
-```{index} single: Python; For loop
-```
-Now let's consider the `for` loop from {ref}`the program above `, which was
+Now let's consider the `for` loop from {ref}`the program above `, which was
```{code-cell} python3
for i in range(ts_length):
@@ -333,8 +325,6 @@ The Python interpreter performs the following:
### A Comment on Indentation
-```{index} single: Python; Indentation
-```
In discussing the `for` loop, we explained that the code blocks being looped over are delimited by indentation.
@@ -359,14 +349,11 @@ On the other hand, it takes a bit of care to get right, so please remember:
### While Loops
-```{index} single: Python; While loop
-```
The `for` loop is the most common technique for iteration in Python.
-But, for the purpose of illustration, let's modify {ref}`the program above ` to use a `while` loop instead.
+But, for the purpose of illustration, let's modify {ref}`the program above ` to use a `while` loop instead.
-(whileloopprog)=
```{code-cell} python3
ts_length = 100
ϵ_values = []
diff --git a/lectures/python_essentials.md b/lectures/python_essentials.md
index 8589b06e..9d2f28b5 100644
--- a/lectures/python_essentials.md
+++ b/lectures/python_essentials.md
@@ -7,17 +7,18 @@ kernelspec:
display_name: Python 3
language: python
name: python3
+exports:
+ - format: ipynb
+ markdown: commonmark
+ images: attachment
+ output: exports/python_essentials.ipynb
+downloads:
+ - file: ./python_essentials.md
+ title: Markdown (md)
+ - file: exports/python_essentials.ipynb
+ title: IPython (.ipynb)
---
-(python_done_right)=
-```{raw} jupyter
-
-```
-
# Python Essentials
## Overview
@@ -30,8 +31,6 @@ This approach is less exciting but helps clear up some details.
## Data Types
-```{index} single: Python; Data Types
-```
Computer programs typically keep track of a range of data types.
@@ -130,8 +129,6 @@ Python has several basic types for storing collections of (possibly heterogeneou
We've {ref}`already discussed lists `.
-```{index} single: Python; Tuples
-```
A related data type is **tuples**, which are "immutable" lists
@@ -160,9 +157,8 @@ x
But tuples are not
```{code-cell} python3
----
-tags: [raises-exception]
----
+:tags: raises-exception
+
x = (1, 2)
x[0] = 10
```
@@ -187,8 +183,6 @@ Tuple unpacking is convenient and we'll use it often.
#### Slice Notation
-```{index} single: Python; Slicing
-```
To access multiple elements of a sequence (a list, a tuple or a string), you can use Python's slice
notation.
@@ -233,12 +227,6 @@ s[-3:] # Select the last three elements
#### Sets and Dictionaries
-```{index} single: Python; Sets
-```
-
-```{index} single: Python; Dictionaries
-```
-
Two other container types we should mention before moving on are [sets](https://docs.python.org/3/tutorial/datastructures.html#sets) and [dictionaries](https://docs.python.org/3/tutorial/datastructures.html#dictionaries).
Dictionaries are much like lists, except that the items are named instead of
@@ -283,9 +271,6 @@ s3
## Input and Output
-```{index} single: Python; IO
-```
-
Let's briefly review reading and writing to text files, starting with writing
```{code-cell} python3
@@ -407,9 +392,6 @@ that you could experiment with.
### Paths
-```{index} single: Python; Paths
-```
-
Note that if `newfile.txt` is not in the present working directory then this call to `open()` fails.
In this case, you can shift the file to the pwd or specify the [full path](https://en.wikipedia.org/wiki/Path_%28computing%29) to the file
@@ -423,9 +405,6 @@ f = open('insert_full_path_to_file/newfile.txt', 'r')
(iterating_version_1)=
## Iterating
-```{index} single: Python; Iteration
-```
-
One of the most important tasks in computing is stepping through a
sequence of data and performing a given action.
@@ -438,8 +417,9 @@ Many Python objects are "iterable", in the sense that they can be looped over.
To give an example, let's write the file us_cities.txt, which lists US cities and their population, to the present working directory.
-(us_cities_data)=
```{code-cell} ipython
+:name: us_cities_data
+
%%writefile us_cities.txt
new york: 8244910
los angeles: 3819702
@@ -537,8 +517,6 @@ for index, letter in enumerate(letter_list):
(list_comprehensions)=
### List Comprehensions
-```{index} single: Python; List comprehension
-```
We can also simplify the code for generating the list of random draws considerably by using something called a *list comprehension*.
@@ -568,8 +546,6 @@ doubles
### Comparisons
-```{index} single: Python; Comparison
-```
Many different kinds of expressions evaluate to one of the Boolean values (i.e., `True` or `False`).
@@ -630,9 +606,6 @@ The rule is:
### Combining Expressions
-```{index} single: Python; Logical Expressions
-```
-
We can combine expressions using `and`, `or` and `not`.
These are the standard logical connectives (conjunction, disjunction and denial)
@@ -686,8 +659,6 @@ documentation can make the code easier to understand and maintain.
### Python Style Guidelines: PEP8
-```{index} single: Python; PEP8
-```
You can find Python programming philosophy by typing `import this` at the prompt.
@@ -697,7 +668,7 @@ We've all heard the saying about consistency and little minds.
In programming, as in mathematics, the opposite is true
-* A mathematical paper where the symbols $\cup$ and $\cap$ were
+* A mathematical paper where the symbols `$\cup$` and `$\cap$` were
reversed would be very hard to read, even if the author told you so on the
first page.
@@ -708,8 +679,6 @@ In Python, the standard style is set out in [PEP8](https://peps.python.org/pep-0
(Docstrings)=
### Docstrings
-```{index} single: Python; Docstrings
-```
Python has a system for adding comments to modules, classes, functions, etc. called *docstrings*.
diff --git a/lectures/python_oop.md b/lectures/python_oop.md
index 14d4403f..cd0d5e31 100644
--- a/lectures/python_oop.md
+++ b/lectures/python_oop.md
@@ -7,25 +7,24 @@ kernelspec:
display_name: Python 3
language: python
name: python3
+exports:
+ - format: ipynb
+ markdown: commonmark
+ images: attachment
+ output: exports/python_oop.ipynb
+downloads:
+ - file: ./python_oop.md
+ title: Markdown (md)
+ - file: exports/python_oop.ipynb
+ title: IPython (.ipynb)
---
-(python_oop)=
-```{raw} jupyter
-
-```
-
-# {index}`OOP II: Building Classes `
+# OOP II: Building Classes
-```{index} single: Python; Object-Oriented Programming
-```
## Overview
-In an {doc}`earlier lecture `, we learned some foundations of object-oriented programming.
+In an [earlier lecture](oop_intro.md), we learned some foundations of object-oriented programming.
The objectives of this lecture are
@@ -74,10 +73,8 @@ Let's cover general OOP concepts before we specialize to Python.
### Key Concepts
-```{index} single: Object-Oriented Programming; Key Concepts
-```
-As discussed an {doc}`earlier lecture `, in the OOP paradigm, data and functions are **bundled together** into "objects".
+As discussed an [earlier lecture](oop_intro.md), in the OOP paradigm, data and functions are **bundled together** into "objects".
An example is a Python list, which not only stores data but also knows how to sort itself, etc.
@@ -145,8 +142,6 @@ When we use OOP, the `simulate` method is conveniently bundled together with the
## Defining Your Own Classes
-```{index} single: Object-Oriented Programming; Classes
-```
Let's build some simple classes to start off.
@@ -352,9 +347,6 @@ That's why the statement `self.wealth += y` inside `earn` ends up modifying `c1.
(oop_solow_growth)=
### Example: The Solow Growth Model
-```{index} single: Object-Oriented Programming; Methods
-```
-
For our next example, let's write a simple class to implement the Solow growth model.
The Solow growth model is a neoclassical growth model in which the per capita
@@ -694,8 +686,6 @@ Notice that there is no value of $r$ that leads to a steady state oscillating am
## Special Methods
-```{index} single: Object-Oriented Programming; Special Methods
-```
Python provides special methods that come in handy.
diff --git a/lectures/scipy.md b/lectures/scipy.md
index 0a9eb913..c1d655e6 100644
--- a/lectures/scipy.md
+++ b/lectures/scipy.md
@@ -7,21 +7,19 @@ kernelspec:
display_name: Python 3
language: python
name: python3
+exports:
+ - format: ipynb
+ markdown: commonmark
+ images: attachment
+ output: exports/scipy.ipynb
+downloads:
+ - file: ./scipy.md
+ title: Markdown (md)
+ - file: exports/scipy.ipynb
+ title: IPython (.ipynb)
---
-(sp)=
-```{raw} jupyter
-
-```
-
-# {index}`SciPy `
-
-```{index} single: Python; SciPy
-```
+# SciPy
In addition to what’s in Anaconda, this lecture will need the following libraries:
@@ -60,7 +58,7 @@ A more common approach is to get some idea of what's in the library and then loo
In this lecture, we aim only to highlight some useful parts of the package.
-## {index}`SciPy ` versus {index}`NumPy `
+## SciPy versus NumPy
SciPy is a package that contains various tools that are built on top of NumPy, using its array data type and related functionality.
@@ -93,8 +91,6 @@ Let's explore some of the major sub-packages.
## Statistics
-```{index} single: SciPy; Statistics
-```
The `scipy.stats` subpackage supplies
@@ -227,10 +223,7 @@ The unique root is approximately 0.408.
Let's consider some numerical techniques for finding roots.
-### {index}`Bisection `
-
-```{index} single: SciPy; Bisection
-```
+### Bisection
One of the most common algorithms for numerical root-finding is *bisection*.
@@ -249,8 +242,9 @@ Here's a simplistic implementation of the algorithm in Python.
It works for all sufficiently well behaved increasing continuous functions with $f(a) < 0 < f(b)$
-(bisect_func)=
```{code-cell} python3
+:name: bisect_func
+
def bisect(f, a, b, tol=10e-5):
"""
Implements the bisection root finding algorithm, assuming that f is a
@@ -284,10 +278,7 @@ from scipy.optimize import bisect
bisect(f, 0, 1)
```
-### The {index}`Newton-Raphson Method `
-
-```{index} single: SciPy; Newton-Raphson Method
-```
+### Newton-Raphson Method
Another very common root-finding algorithm is the [Newton-Raphson method](https://en.wikipedia.org/wiki/Newton%27s_method).
@@ -348,8 +339,6 @@ with qe.Timer(unit="milliseconds"):
### Multivariate Root-Finding
-```{index} single: SciPy; Multivariate Root-Finding
-```
Use `scipy.optimize.fsolve`, a wrapper for a hybrid method in MINPACK.
@@ -359,8 +348,6 @@ See the [documentation](https://docs.scipy.org/doc/scipy/reference/generated/sci
A **fixed point** of a real function $f$ on $[a,b]$ is an $x \in [a, b]$ such that $f(x)=x$.
-```{index} single: SciPy; Fixed Points
-```
SciPy has a function for finding (scalar) fixed points too
@@ -373,10 +360,7 @@ fixed_point(lambda x: x**2, 10.0) # 10.0 is an initial guess
If you don't get good results, you can always switch back to the `brentq` root finder, since
the fixed point of a function $f$ is the root of $g(x) := x - f(x)$.
-## {index}`Optimization `
-
-```{index} single: SciPy; Optimization
-```
+## Optimization
Most numerical packages provide only functions for *minimization*.
@@ -399,8 +383,6 @@ fminbound(lambda x: x**2, -1, 2) # Search in [-1, 2]
### Multivariate Optimization
-```{index} single: Optimization; Multivariate
-```
Multivariate local optimizers include `minimize`, `fmin`, `fmin_powell`, `fmin_cg`, `fmin_bfgs`, and `fmin_ncg`.
@@ -408,10 +390,8 @@ Constrained multivariate local optimizers include `fmin_l_bfgs_b`, `fmin_tnc`, `
See the [documentation](https://docs.scipy.org/doc/scipy/reference/optimize.html) for details.
-## {index}`Integration `
+## Integration
-```{index} single: SciPy; Integration
-```
Most numerical integration methods work by computing the integral of an approximating polynomial.
@@ -438,10 +418,8 @@ There are also functions for multivariate integration.
See the [documentation](https://docs.scipy.org/doc/scipy/reference/integrate.html) for more details.
-## {index}`Linear Algebra `
+## Linear Algebra
-```{index} single: SciPy; Linear Algebra
-```
We saw that NumPy provides a module for linear algebra called `linalg`.
@@ -588,9 +566,9 @@ print(f"The Monte Carlo option price is {P:3f}")
```{exercise}
:label: sp_ex1
-In {ref}`this lecture `, we discussed the concept of {ref}`recursive function calls `.
+In [this lecture](functions.md), we discussed the concept of {ref}`recursive function calls `.
-Try to write a recursive implementation of the homemade bisection function {ref}`described above `.
+Try to write a recursive implementation of the homemade bisection function {ref}`described above `.
Test it on the function {eq}`root_f`.
```
diff --git a/lectures/sympy.md b/lectures/sympy.md
index a79c8d30..79d9a453 100644
--- a/lectures/sympy.md
+++ b/lectures/sympy.md
@@ -9,21 +9,19 @@ kernelspec:
display_name: Python 3 (ipykernel)
language: python
name: python3
+exports:
+ - format: ipynb
+ markdown: commonmark
+ images: attachment
+ output: exports/sympy.ipynb
+downloads:
+ - file: ./sympy.md
+ title: Markdown (md)
+ - file: exports/sympy.ipynb
+ title: IPython (.ipynb)
---
-(sympy)=
-```{raw} jupyter
-
-```
-
-# {index}`SymPy `
-
-```{index} single: Python; SymPy
-```
+# SymPy
## Overview
diff --git a/lectures/test_table.csv b/lectures/test_table.csv
new file mode 100644
index 00000000..03fcd0fb
--- /dev/null
+++ b/lectures/test_table.csv
@@ -0,0 +1,11 @@
+Date,Open,High,Low,Close,Volume,Adj Close
+2009-05-21,9280.35,9286.35,9189.92,9264.15,133200,9264.15
+2009-05-20,9372.72,9399.40,9311.61,9344.64,143200,9344.64
+2009-05-19,9172.56,9326.75,9166.97,9290.29,167000,9290.29
+2009-05-18,9167.05,9167.82,8997.74,9038.69,147800,9038.69
+2009-05-15,9150.21,9272.08,9140.90,9265.02,172000,9265.02
+2009-05-14,9212.30,9223.77,9052.41,9093.73,169400,9093.73
+2009-05-13,9305.79,9379.47,9278.89,9340.49,176000,9340.49
+2009-05-12,9358.25,9389.61,9298.61,9298.61,188400,9298.61
+2009-05-11,9460.72,9503.91,9342.75,9451.98,230800,9451.98
+2009-05-08,9351.40,9464.43,9349.57,9432.83,220200,9432.83
diff --git a/lectures/troubleshooting.md b/lectures/troubleshooting.md
index 1cfa95f5..fb4b38a2 100644
--- a/lectures/troubleshooting.md
+++ b/lectures/troubleshooting.md
@@ -7,16 +7,18 @@ kernelspec:
display_name: Python 3
language: python
name: python3
+exports:
+ - format: ipynb
+ markdown: commonmark
+ images: attachment
+ output: exports/troubleshooting.ipynb
+downloads:
+ - file: ./troubleshooting.md
+ title: Markdown (md)
+ - file: exports/troubleshooting.ipynb
+ title: IPython (.ipynb)
---
-(troubleshooting)=
-```{raw} jupyter
-
-```
# Troubleshooting
@@ -29,7 +31,7 @@ The basic assumption of the lectures is that code in a lecture should execute wh
1. it is executed in a Jupyter notebook and
1. the notebook is running on a machine with the latest version of Anaconda Python.
-You have installed Anaconda, haven't you, following the instructions in {doc}`this lecture `?
+You have installed Anaconda, haven't you, following the instructions in [this lecture](getting_started.md)?
Assuming that you have, the most common source of problems for our readers is that their Anaconda distribution is not up to date.
@@ -49,7 +51,7 @@ If your local environment is still not working you can do two things.
First, you can use a remote machine instead, by clicking on the Launch Notebook icon available for each lecture
-```{image} _static/lecture_specific/troubleshooting/launch.png
+```{figure} _static/lecture_specific/troubleshooting/launch.png
```
diff --git a/lectures/us_cities.txt b/lectures/us_cities.txt
new file mode 100644
index 00000000..9be9260f
--- /dev/null
+++ b/lectures/us_cities.txt
@@ -0,0 +1,9 @@
+new york: 8244910
+los angeles: 3819702
+chicago: 2707120
+houston: 2145146
+philadelphia: 1536471
+phoenix: 1469471
+san antonio: 1359758
+san diego: 1326179
+dallas: 1223229
diff --git a/lectures/workspace.md b/lectures/workspace.md
index 71bd745c..076fe69c 100644
--- a/lectures/workspace.md
+++ b/lectures/workspace.md
@@ -9,17 +9,18 @@ kernelspec:
name: python3
display_name: Python 3 (ipykernel)
language: python
+exports:
+ - format: ipynb
+ markdown: commonmark
+ images: attachment
+ output: exports/workspace.ipynb
+downloads:
+ - file: ./workspace.md
+ title: Markdown (md)
+ - file: exports/workspace.ipynb
+ title: IPython (.ipynb)
---
-(workspace)=
-```{raw} jupyter
-
-```
-
# Writing Longer Programs
## Overview
diff --git a/lectures/writing_good_code.md b/lectures/writing_good_code.md
index ea674215..2186989c 100644
--- a/lectures/writing_good_code.md
+++ b/lectures/writing_good_code.md
@@ -7,22 +7,20 @@ kernelspec:
display_name: Python 3
language: python
name: python3
+exports:
+ - format: ipynb
+ markdown: commonmark
+ images: attachment
+ output: exports/writing_good_code.ipynb
+downloads:
+ - file: ./writing_good_code.md
+ title: Markdown (md)
+ - file: exports/writing_good_code.ipynb
+ title: IPython (.ipynb)
---
-(writing_good_code)=
-```{raw} jupyter
-
-```
-
# Writing Good Code
-```{index} single: Models; Code style
-```
-
```{epigraph}
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." -- Martin Fowler
```
@@ -216,7 +214,7 @@ While the odd global in small scripts is no big deal, we recommend that you teac
For scientific computing, there is another good reason to avoid global variables.
-As {doc}`we've seen in previous lectures `, JIT compilation can generate excellent performance for scripting languages like Python.
+As [we've seen in previous lectures](numba.md), JIT compilation can generate excellent performance for scripting languages like Python.
But the task of the compiler used for JIT compilation becomes harder when global variables are present.
diff --git a/myst_requirements.txt b/myst_requirements.txt
new file mode 100644
index 00000000..31db4c70
--- /dev/null
+++ b/myst_requirements.txt
@@ -0,0 +1,9 @@
+jupyter-server
+ipykernel
+numpy
+scipy
+matplotlib
+pandas
+quantecon
+sympy
+networkx
\ No newline at end of file