Skip to content

Commit

Permalink
Migrate from Jupyter Notebook to JupyterLab
Browse files Browse the repository at this point in the history
  • Loading branch information
jngrad committed Nov 30, 2023
1 parent 0f10949 commit f632143
Show file tree
Hide file tree
Showing 32 changed files with 1,813 additions and 1,337 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/push_pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
debian:
runs-on: ubuntu-latest
container:
image: ghcr.io/espressomd/docker/debian:fbdf2f2f9d76b761c0aa1308f17fb17e38501850-base-layer
image: ghcr.io/espressomd/docker/debian:339903979196fd7e72127f2cb5bfb27759d129f9-base-layer
credentials:
username: ${{ github.actor }}
password: ${{ secrets.github_token }}
Expand Down Expand Up @@ -74,7 +74,7 @@ jobs:
runs-on: ubuntu-latest
if: ${{ github.repository == 'espressomd/espresso' }}
container:
image: ghcr.io/espressomd/docker/ubuntu-wo-dependencies:fbdf2f2f9d76b761c0aa1308f17fb17e38501850-base-layer
image: ghcr.io/espressomd/docker/ubuntu-wo-dependencies:339903979196fd7e72127f2cb5bfb27759d129f9-base-layer
credentials:
username: ${{ github.actor }}
password: ${{ secrets.github_token }}
Expand Down
11 changes: 6 additions & 5 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
image: ghcr.io/espressomd/docker/ubuntu-22.04:fbdf2f2f9d76b761c0aa1308f17fb17e38501850
image: ghcr.io/espressomd/docker/ubuntu-22.04:339903979196fd7e72127f2cb5bfb27759d129f9

stages:
- prepare
Expand Down Expand Up @@ -144,7 +144,7 @@ no_rotation:
fedora:36:
<<: *global_job_definition
stage: build
image: ghcr.io/espressomd/docker/fedora:fbdf2f2f9d76b761c0aa1308f17fb17e38501850
image: ghcr.io/espressomd/docker/fedora:339903979196fd7e72127f2cb5bfb27759d129f9
variables:
with_cuda: 'false'
with_gsl: 'false'
Expand Down Expand Up @@ -390,6 +390,7 @@ installation:
- bash maintainer/CI/build_cmake.sh
- cd build
- make install
- cmake . -D ESPRESSO_BUILD_TESTS=ON
# get path of installed files
- CI_INSTALL_DIR="/tmp/espresso-unit-tests"
- CI_INSTALL_PYTHON_PATH=$(dirname $(find "${CI_INSTALL_DIR}/lib" -name espressomd))
Expand All @@ -398,9 +399,9 @@ installation:
- cp -r "src/python/object_in_fluid" "${CI_INSTALL_PYTHON_PATH}/object_in_fluid"
# run all tests with the installed files
- sed -i "s|$(pwd)/pypresso|${CI_INSTALL_DIR}/bin/pypresso|" testsuite/{python,scripts/samples,scripts/tutorials}/CTestTestfile.cmake
- make -j ${CI_CORES} check_python_skip_long
- make -j ${CI_CORES} check_samples
- make -j 2 check_tutorials
- make check_python_skip_long
- make check_samples
- make check_tutorials
tags:
- espresso
- cuda
Expand Down
22 changes: 8 additions & 14 deletions doc/sphinx/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -197,42 +197,36 @@ To run the samples and tutorials, start by installing the following packages:
The tutorials are written in the
`Notebook Format <https://nbformat.readthedocs.io/en/latest/>`__
:cite:`kluyver16a` version <= 4.4 and can be executed by any of these tools:
:cite:`kluyver16a` version 4.5 and can be executed by any of these tools:

* `Jupyter Notebook <https://jupyter-notebook.readthedocs.io/en/stable/notebook.html>`__
* `JupyterLab <https://jupyterlab.readthedocs.io/en/stable/>`__
* `IPython <https://ipython.org/>`__ (not recommended)
* `VS Code Jupyter <https://github.com/microsoft/vscode-jupyter>`__
* `Jupyter Notebook <https://jupyter-notebook.readthedocs.io/en/stable/notebook.html>`__
* `IPython <https://ipython.org/>`__ (not recommended)

To check whether one of them is installed, run these commands:

.. code-block:: bash
jupyter notebook --version
jupyter lab --version
jupyter notebook --version
ipython --version
code --version
If you don't have any of these tools installed and aren't sure which one
to use, we recommend installing the historic Jupyter Notebook, since the
|es| tutorials have been designed with the ``exercise2`` plugin in mind.

To use Jupyter Notebook, install the following packages:
to use, we recommend installing JupyterLab:

.. code-block:: bash
python3 -m pip install --user -c requirements.txt \
nbformat nbconvert notebook jupyter_contrib_nbextensions==0.5.1
jupyter contrib nbextension install --user
jupyter nbextension enable rubberband/main
jupyter nbextension enable exercise2/main
nbformat nbconvert jupyterlab
Alternatively, to use JupyterLab, install the following packages:
If you prefer the look and feel of Jupyter Classic, install the following:

.. code-block:: bash
python3 -m pip install --user -c requirements.txt \
nbformat nbconvert notebook jupyterlab
nbformat nbconvert jupyterlab nbclassic
Alternatively, to use VS Code Jupyter, install the following extensions:

Expand Down
51 changes: 11 additions & 40 deletions doc/sphinx/running.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,40 +82,25 @@ in the build folder, do:
make tutorials
The tutorials contain solutions hidden with the ``exercise2`` NB extension.
Since this extension is only available for Jupyter Notebook, JupyterLab
users need to convert the tutorials:

.. code-block:: bash
for f in doc/tutorials/*/*.ipynb; do
./pypresso doc/tutorials/convert.py exercise2 --to-jupyterlab ${f}
done
Likewise, VS Code Jupyter users need to convert the tutorials:

.. code-block:: bash
for f in doc/tutorials/*/*.ipynb; do
./pypresso doc/tutorials/convert.py exercise2 --to-vscode-jupyter ${f}
done
The tutorials contain solutions hidden inside disclosure boxes.
Click on "Show solution" to reveal them.

To interact with notebooks, move to the directory containing the tutorials
and call the ``ipypresso`` script to start a local Jupyter session.

For Jupyter Notebook and IPython users:
For JupyterLab users:

.. code-block:: bash
cd doc/tutorials
../../ipypresso notebook
../../ipypresso lab
For JupyterLab users:
For Jupyter Classic users:

.. code-block:: bash
cd doc/tutorials
../../ipypresso lab
../../ipypresso nbclassic
For VS Code Jupyter users, no action is needed if ``pypresso`` was set as
the interpreter path (see details in :ref:`Running inside an IDE`).
Expand All @@ -140,29 +125,15 @@ will exit the Python interpreter and Jupyter will notify you that the current
Python kernel stopped. If a cell takes too long to execute, you may interrupt
it with the stop button.

Solutions cells are created using the ``exercise2`` plugin from nbextensions.
To prevent solution code cells from running when clicking on "Run All", these
code cells need to be converted to Markdown cells and fenced with `````python``
and ```````.
Solutions cells are marked up with the code comment ``# SOLUTION CELL``
(must be on the first line). In the build folder, these solution cells
will be automatically converted to Markdown cells.

To close the Jupyter session, go to the terminal where it was started and use
the keyboard shortcut Ctrl+C twice.

When starting a Jupyter session, you may see the following warning in the
terminal:

.. code-block:: none
[TerminalIPythonApp] WARNING | Subcommand `ipython notebook` is deprecated and will be removed in future versions.
[TerminalIPythonApp] WARNING | You likely want to use `jupyter notebook` in the future
This only means |es| was compiled with IPython instead of Jupyter. If Jupyter
is installed on your system, the notebook will automatically close IPython and
start Jupyter. To recompile |es| with Jupyter, provide ``cmake`` with the flag
``-D IPYTHON_EXECUTABLE=$(which jupyter)``.

You can find the official Jupyter documentation at
https://jupyter.readthedocs.io/en/latest/running.html
You can find the official JupyterLab documentation at
https://jupyterlab.readthedocs.io/en/latest/user/interface.html

.. _Running inside an IDE:

Expand Down
20 changes: 6 additions & 14 deletions doc/tutorials/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,31 +62,23 @@ function(NB_EXPORT)
"${NB_FILE};${NB_EXPORT_ADD_SCRIPTS};${CMAKE_BINARY_DIR}/doc/tutorials/convert.py;${CMAKE_BINARY_DIR}/testsuite/scripts/importlib_wrapper.py"
COMMAND
${CMAKE_BINARY_DIR}/pypresso
${CMAKE_BINARY_DIR}/doc/tutorials/convert.py ci --execute --exercise2
--remove-empty-cells --input ${NB_FILE} --output ${NB_FILE_RUN}
${CMAKE_BINARY_DIR}/doc/tutorials/convert.py ci --execute
--prepare-for-html --input ${NB_FILE} --output ${NB_FILE_RUN}
--substitutions ${NB_EXPORT_VAR_SUBST} --scripts
${NB_EXPORT_ADD_SCRIPTS})
else()
set(NB_FILE_RUN ${NB_FILE})
endif()

add_custom_command(
OUTPUT ${HTML_FILE}
DEPENDS ${NB_FILE_RUN};${NB_EXPORT_ADD_SCRIPTS}
COMMAND
${CMAKE_BINARY_DIR}/pypresso ${CMAKE_BINARY_DIR}/doc/tutorials/convert.py
ci --exercise2 --input ${NB_FILE_RUN} --output ${NB_FILE_RUN}~
OUTPUT ${HTML_FILE} DEPENDS ${NB_FILE_RUN};${NB_EXPORT_ADD_SCRIPTS}
COMMAND ${IPYTHON_EXECUTABLE} nbconvert --to "html" --output ${HTML_FILE}
${NB_FILE_RUN}~)
${NB_FILE_RUN})

add_custom_command(
OUTPUT ${PY_FILE}
DEPENDS ${NB_FILE}
COMMAND
${CMAKE_BINARY_DIR}/pypresso ${CMAKE_BINARY_DIR}/doc/tutorials/convert.py
ci --exercise2 --input ${NB_FILE} --output ${NB_FILE}~
OUTPUT ${PY_FILE} DEPENDS ${NB_FILE}
COMMAND ${IPYTHON_EXECUTABLE} nbconvert --to "python" --output ${PY_FILE}
${NB_FILE}~)
${NB_FILE})

add_custom_target("${NB_EXPORT_TARGET}_html" DEPENDS ${HTML_FILE}
${DEPENDENCY_OF_TARGET})
Expand Down
24 changes: 2 additions & 22 deletions doc/tutorials/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ physical systems.
* **Electrodes**
Modelling electrodes and measuring differential capacitance with the ELC method.
[Part 1](electrodes/electrodes_part1.ipynb) |
Part 2 (work in progress)
[Part 2](electrodes/electrodes_part2.ipynb)
* **Constant pH method**
Modelling an acid dissociation curve using the constant pH method.
[Guide](constant_pH/constant_pH.ipynb)
Expand Down Expand Up @@ -91,32 +91,12 @@ in the build folder, do:
make tutorials
```

The tutorials contain solutions hidden with the ``exercise2`` extension.
Since this extension is only available for Jupyter Notebook, JupyterLab
users need to convert the tutorials:

```sh
for f in doc/tutorials/*/*.ipynb; do
./pypresso doc/tutorials/convert.py exercise2 --to-jupyterlab ${f};
done
```

All tutorials can be viewed with their solutions
[online](https://espressomd.github.io/doc/tutorials.html).

### Running the tutorials interactively

To view the tutorials, first change to the tutorials directory and then run
the `ipypresso` script from the directory into which espresso was compiled.

For Jupyter Notebook and IPython users:

```sh
cd doc/tutorials
../../ipypresso notebook
```

For JupyterLab users:
To view the tutorials in the build folder, run the following commands:

```sh
cd doc/tutorials
Expand Down
Loading

0 comments on commit f632143

Please sign in to comment.