Skip to content

Commit 6b84e76

Browse files
committed
edits to contributors pages
1 parent 153ab74 commit 6b84e76

File tree

7 files changed

+266
-183
lines changed

7 files changed

+266
-183
lines changed

index.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,10 @@ Requires moderate computational resources. Run-times may exceed several minutes
106106
The computational resources required to execute this notebook exceed those provided by standard laptop computers. To execute the notebook, please deploy to a cluster computing environment.
107107
```
108108

109+
Want to Add a Tutorial?
110+
-----------------------
111+
112+
Please visit the [Contributing to User Tutorials](notebooks/contributing_index.md) page to find out how you can add a tutorial.
113+
114+
115+

myst.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ project:
117117
- file: notebooks/12-pgi-inversion/plot_inv_2_joint_pf_pgi_no_info_tutorial.ipynb
118118
- file: notebooks/contributing_index.md
119119
children:
120-
- file: notebooks/getting_started.md
121-
- file: notebooks/notebook_formatting.md
122-
- file: notebooks/generating_pr.md
120+
- file: notebooks/contributing/build_website.md
121+
- file: notebooks/contributing/formatting.md
122+
- file: notebooks/contributing/pull_request.md
123123

124124
site:
125125
template: book-theme
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
Building the User Tutorials Website Locally
2+
===========================================
3+
4+
Here, we provide instructions for setting up an appropriate Python environment and building the SimPEG user tutorials website locally with [MyST](https://mystmd.org/).
5+
6+
## Step 1: Cloning the GitHub Repository
7+
8+
The URL for the SimPEG user tutorials GitHub repository is: https://github.com/simpeg/user-tutorials/. If using the Git Bash shell:
9+
10+
```bash
11+
git clone https://github.com/simpeg/user-tutorials
12+
cd user-tutorials
13+
```
14+
15+
## Step 2: Setting Up a Python Environment
16+
17+
The Jupyter notebooks containing the tutorials are maintained to run properly using the [latest release of SimPEG](https://github.com/simpeg/simpeg/releases).
18+
Notebooks may not run correctly if SimPEG is being imported from an earlier release or development branch.
19+
The [mystmd][install-mystmd] and [nodejs](https://nodejs.org/api/packages.html) are also required to build the website locally.
20+
21+
We advise building a Python environment from the `environment.yml` file in the root directory of the repository.
22+
To create the `simpeg-user-tutorials` environment using conda:
23+
24+
```bash
25+
conda env create -f environment.yml
26+
```
27+
28+
Once built, you can activate using:
29+
30+
```bash
31+
conda activate simpeg-user-tutorials
32+
```
33+
34+
## Step 3: Build and Execution Commands
35+
36+
The SimPEG user tutorials are a collection of [Jupyter Notebook](https://jupyter.org/) (and [Markdown](https://www.markdownguide.org/getting-started/)) files,
37+
which [MyST][mystmd.org] builds into a website. Here, we describe the commands that contributors should be familiar with.
38+
39+
:::{important}
40+
The tutorial notebooks, including their states, are tracked by GitHub. When the SimPEG user tutorials repository was cloned, all notebooks had been run and saved. Therefore, you do not need to rerun all of the notebooks prior to building the website!
41+
:::
42+
43+
### Locally Build and Serve Website
44+
45+
The following command will build the website and serve it locally.
46+
This will allow you to preview the website and observe any changes to notebooks on the fly.
47+
To locally build and serve the website:
48+
the website:
49+
50+
```bash
51+
msyt start
52+
```
53+
54+
Next, follow the instructions prompted by the command to launch the local build in your brower.
55+
56+
### Build Only
57+
58+
The following command will build the website and store the HTML files in
59+
a new `_build` folder:
60+
61+
```bash
62+
msyt build --html
63+
```
64+
65+
### Clean Cached Builds
66+
67+
```bash
68+
myst clean --all
69+
```
70+
71+
### Rerunning Notebooks
72+
73+
When making alterations and rerunning notebooks, we typically do so by launching Jupyter Notebooks:
74+
75+
```bash
76+
jupyter notebook
77+
```
78+
79+
However, we can rerun a notebook and overwrite its output cells in place using `nbconvert`.
80+
To rerun a single notebook, use:
81+
82+
```bash
83+
jupyter nbconvert --to notebook --execute --inplace notebook.ipynb
84+
```
85+
86+
We may also want to rerun all notebooks in the repository.
87+
To rerun all notebooks, use:
88+
89+
```bash
90+
jupyter nbconvert --to notebook --execute --inplace notebooks/**/*.ipynb
91+
```
92+
93+
:::{danger}
94+
Rerunning all notebooks is a computationally intensive task. Some notebooks
95+
require significant amount of memory to allocate large sensitivity matrices.
96+
:::
97+
98+
> [!IMPORTANT]
99+
> If you are using bash as your shell, make sure to run `shopt -s
100+
> globstar` to enable the `globstar` feature that allows the use of `**` for
101+
> filename expansion.
102+
103+
104+
105+
106+
[install-mystmd]: https://mystmd.org/guide/quickstart
107+
[jupyter]: https://jupyter.org
108+
[mystmd.org]: https://mystmd.org
109+
Lines changed: 118 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1-
Structure and Formatting for Notebooks
2-
======================================
1+
Tutorial Structure and Formatting Requirements
2+
==============================================
33

4-
For consistency, tutorial notebooks follow strict structure and formatting requirements. Each notebook begins with an introductory section, comprised of several Markdown cells. The contents of the notebook are parsed into sections. Each section contains a Markdown cells, code cells, and plot outputs. For example, see the [3D integral formulation](xref:simpeg#simpeg.potential_fields.gravity.Simulation3DIntegral) tutorial. The structure and formatting requirements for tutorial notebooks are discussed below.
4+
To ensure quality and consistency, the [Jupyter Notebooks](https://jupyter.org/) containing tutorials must follow strict structure and formatting requirements. The contents of each notebooks must be parsed sensibly into a set of sections. Sufficient explanation and links to API documentation are required when presenting functionality. Each section within a tutorial contains a combination of [Markdown](https://www.markdownguide.org/getting-started/) and coding cells. Our notebooks use the functionality in [MyST Parser](https://myst-parser.readthedocs.io/en/latest/) to augment the contents of Markdown cells. Before moving forward, we advise the contributor to:
55

6-
### Introduction Markdown
6+
* Be familiar with the structure and formatting that is used by most forward simulation and inversion tutorials. E.g. [3D Forward Simulation of Gravity Anomaly Data](../03-gravity/fwd_gravity_anomaly_3d.ipynb) and [3D Inversion of Gravity Anomaly Data](../03-gravity/inv_gravity_anomaly_3d.ipynb).
77

8-
Every tutorial notebook must provide a thorough introduction.
8+
* Refer to the Markdown syntax used by [MyST Parser](https://myst-parser.readthedocs.io/en/latest/).
99

10-
#### Cell 1: Title Cell
10+
* Refer to the [style guide](https://docs.simpeg.xyz/latest/content/getting_started/contributing/code-style.html) for coding cells.
1111

12-
The first cell in the notebooks is a Markdown cell containing the title and the author for the tutorial. It is formatted as follows.
12+
13+
## Notebook Introduction
14+
15+
Every tutorial notebook requires an introduction section. The Markdown cells required for the introduction are described below.
16+
17+
### Cell 1: Title Cell
18+
19+
The first cell contains the title and the author for the tutorial. It is formatted as follows.
1320
The title is in quotations. You will need to add yourself as an author in the `myst.yml` file in the root directory of the repository.
1421

1522
```
@@ -20,7 +27,7 @@ authors:
2027
---
2128
```
2229

23-
#### Cell 2: Tutorial Difficulty
30+
### Cell 2: Tutorial Difficulty
2431

2532
Here, we indicate whether the notebook contains introductory, intermediate or advanced content. The author is required to choose
2633
from one of the following [MyST admonitions](https://myst-parser.readthedocs.io/en/latest/syntax/admonitions.html), which is rendered when the webpage is built.
@@ -51,7 +58,7 @@ the user is already an experienced SimPEG user.
5158
:::
5259
```
5360

54-
#### Cell 3: Computational Requirements
61+
### Cell 3: Computational Requirements
5562

5663
Here, we specify the computational requirements to run the notebook. Whereas some notebooks can be run easily on laptop computers, some notebook may need to be exported as Python files and run using cluster computing. The author is required to choose from one of the following [MyST admonitions](https://myst-parser.readthedocs.io/en/latest/syntax/admonitions.html), which is rendered when the webpage is built.
5764

@@ -80,15 +87,15 @@ to a cluster computing environment.
8087
:::
8188
```
8289

83-
#### Cell 4: Keywords, Summary and Learning Objectives
90+
### Cell 4: Keywords, Summary and Learning Objectives
8491

85-
In this cell, please provide keywords relevant to the notebook. E.g.
92+
In this cell, the contributor must provide a set of relevant keywords. E.g.
8693

8794
```
8895
**Keywords:** gravity inversion, sparse-norm inversion, integral formulation, tree mesh.
8996
```
9097

91-
Next, summarize the purpose of the tutorial. The summary should be roughly one paragraph. If your tutorial focusses on particular functionality within SimPEG, please link to the API documentation. Please link to tutorials you feel the reader should have already worked through. E.g.
98+
Next, the contributor must provide a summary of the tutorial. The summary should be roughly one paragraph. If your tutorial focusses on particular functionality within SimPEG, please link to the API documentation. Also, link to tutorials you feel the reader should have already worked through. E.g.
9299

93100
```
94101
**Summary:** Here we invert gravity anomaly data to recover a density contrast model.
@@ -106,7 +113,7 @@ become familiar with functionality explained in the [3D Forward Simulation of Gr
106113
Anomaly Data](fwd_gravity_anomaly_3d.ipynb) tutorial before working through this one.
107114
```
108115

109-
Finally, provide learning objectives as a bullet list. E.g.
116+
Finally, the contributor must provide learning objectives using a bullet list. E.g.
110117

111118
```
112119
**Learning Objectives:**
@@ -121,21 +128,68 @@ Finally, provide learning objectives as a bullet list. E.g.
121128
- How to analyse inversion results.
122129
```
123130

124-
### Formatting Tutorial Sections
131+
## Import Functionality
132+
133+
Following the introduction section, the contributor must import all functionality used by the tutorial and briefly explain the functionality that is most important.
134+
135+
### Cell 1: Header and Summary
136+
137+
This Markdown cell uses the heading **Import Modules**. For functionality that relates
138+
directly to the purpose of the tutorial, some context and a link to API documentation
139+
should be provided. E.g.
140+
141+
:::
142+
## Import Modules
143+
144+
Here, we import all of the functionality required to run the notebook for the tutorial
145+
exercise. All of the functionality specific to simulating gravity data are imported from
146+
[simpeg.potential_fields.gravity](xref:simpeg#simpeg.potential_fields.gravity). We also
147+
import some useful utility functions from [simpeg.utils](xref:simpeg#simpeg.utils).
148+
To simulate gravity data, we need to define our problem geometry on a numerical grid
149+
(or mesh). To generate the mesh, we used the
150+
[discretize](https://discretize.simpeg.xyz/en/main) package.
151+
:::
152+
153+
### Cell 2: Code Cell
154+
155+
The coding cell where functionality is imported should be organized. E.g.
156+
157+
```python
158+
# SimPEG functionality
159+
from simpeg.potential_fields import gravity
160+
from simpeg.utils import plot2Ddata, model_builder
161+
from simpeg import maps
162+
163+
# discretize functionality
164+
from discretize import TensorMesh
165+
from discretize.utils import mkvc, active_from_xyz
166+
167+
# Common Python functionality
168+
import numpy as np
169+
from scipy.interpolate import LinearNDInterpolator
170+
import matplotlib as mpl
171+
172+
mpl.rcParams.update({"font.size": 14})
173+
import matplotlib.pyplot as plt
174+
import os
175+
```
176+
177+
## Tutorial Sections (and Subsections)
125178

126179
Each section (or subsection) is constructed using a combination of Markdown and code cells. The structure and formatting of these are discussed below.
127180

128-
#### Section Header and Summary Cell
181+
### Cell 1: Header and Summary
129182

130-
Each section (or subsection) begins with a Markdown cell containing the section header and a summary.
131-
Here, the author must:
183+
Each section (or subsection) begins with a Markdown cell containing the header and a summary.
184+
Here, the contributor must:
132185

133186
* summarize what is being done in the section
134187
* describe any new functionality that is being introduced
135188
* provide links to all relevant API documentation
136-
* describe the choices for hyperparameter values used in the tutorial.
189+
* describe the choices for hyperparameter values used in the tutorial
137190

138191
E.g.
192+
139193
```
140194
## Define the Survey
141195
@@ -158,14 +212,26 @@ which are to be measured. For the tutorial simulation, the receivers are located
158212
5 m above the surface topography and spaced 10 m apart.
159213
```
160214

161-
#### Code Block Cells:
215+
If something has been thoroughly explained in an introductory tutorial, you can avoid repetition by linking to that tutorial.
216+
However, the choice in values used in your tutorial should always be stated. E.g.
217+
218+
```
219+
## Assign Uncertainties
220+
221+
Approaches for applying reasonable uncertainties to normalized voltage and apparent
222+
resistivity data were presented in the [2.5D Inversion](inv_dcr_2d.ipynb) tutorial.
223+
Here, we apply uncertainties of 1e-7 V/A + 10 % to the normalized voltage data being
224+
inverted.
225+
```
226+
227+
### Code Block Cells
162228

163229
Code blocks must follow the [style required by SimPEG](https://docs.simpeg.xyz/latest/content/getting_started/contributing/code-style.html).
164230
Please provide comments when defining new objects. This is especially important when exposing the reader to new functionality.
231+
Avoid lengthy code blocks that can be better parsed into multiple cells. Markdown cells can also be added between code cells
232+
to provide additional explanation to the reader.
165233

166-
E.g.
167-
168-
```
234+
```python
169235
# Define the component(s) of the field we want to simulate as strings within
170236
# a list. Here we simulate only the vertical component of the gravity anomaly.
171237
components = ["gz"]
@@ -183,10 +249,38 @@ source_field = gravity.sources.SourceField(receiver_list=receiver_list)
183249
survey = gravity.survey.Survey(source_field)
184250
```
185251

186-
#### Comments on Plotting:
252+
### Comments on Plotting
187253

188254
The author is required to plot data, models, etc... When generating plot, please ensure:
189255

190256
* the figure renders at an appropriate size for display
191257
* the code used to generate the plot is compact
192-
* text and features within the plot are legible
258+
* text and features within the plot are legible
259+
260+
261+
## Check Style of Notebooks
262+
263+
We can check the code style of our notebooks using [`ruff`][ruff] and
264+
[`nbqa`][nbqa]. Simply run the following command to check the style of the
265+
notebooks:
266+
267+
```bash
268+
nbqa ruff notebooks
269+
```
270+
271+
And run this to autoformat them:
272+
273+
```bash
274+
nbqa ruff --fix notebooks
275+
```
276+
277+
Alternatively, you can use the targets we have in the `Makefile`, like `make
278+
check` and `make format`. Read more information about the available targets
279+
by running `make help`.
280+
281+
282+
283+
284+
[install-mystmd]: https://mystmd.org/guide/quickstart
285+
[jupyter]: https://jupyter.org
286+
[mystmd.org]: https://mystmd.org
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
GitHub Pull Request and Review
2-
==============================
1+
GitHub Pull Request and Review Process
2+
======================================
33

44
Requirements Checklist
55
----------------------

0 commit comments

Comments
 (0)