Jupyter Notebooks are a data science tool primarily used for statistics and machine learning, some of the most energy-intensive computing areas. To make users of Jupyter Notebooks more aware of their notebooks' energy consumption, this project aims to offer a Jupyter Notebook plugin that informs you of the energy use since the notebook started.
For an overview of the project scope, see this blog article.
Here's a quick overview of the repo folders:
This folder contains a Rust program that shows you your current and cumulative energy use, along with some comparisons:
Current energy use: 7.48 joules.
Since program start: 457.2 joules.
With this energy, you could crack a piñata. 🪅
To get data about energy consumption, the program just calls perf
and parses the output.
This folder contains Python code that interacts with C code via FFI to directly perform syscalls to get the energy usage from the OS.
On a system with Intel CPUs, there are several interesting files in /sys/bus/event_source/devices/power/events
:
<event>
: contains a hex value likeevent=0x02
<event>.scale
: contains a small number like2.3431267432e-10
<event>.unit
: contains a unit likeJoules
The C code in measure.c
calls the perf_event_open
syscall with the event's hex value to request listening to energy events from the OS.
This syscall returns a file that you can read the cumulative amount of ticks since the measurement started.
It then calculates the actual energy use by subtracting the initial ticks, multiplying the difference with the scale, and using the unit.
There are two ways to use the C file:
- Run it as a standalone program:
gcc measure.c -o measure && sudo ./measure
- Compile it into a shared library:
gcc --shared measure.c -o measure.so
The python file measure.py
is a wrapper that communicates with the precompiled shared library using FFI.
Again, there are two ways to use the Python file:
- Run it as a standalone program:
python3 measure.py
.
It will then start a webserver onhttp://localhost:35396
that reports the cumulative energy use since the server start as JSON. - Include it as a library. Then, you can use it like this:
ongoing_recording = record_energy("energy-pkg") sleep(1) ongoing_recording.used_joules()
This folder contains an extension for Jupyter Notebooks.
- Create an environment that will hold our dependencies:
conda create -n jupyter-energy -c conda-forge python
- Activate the virtual environment that pipenv created for us
conda activate jupyter-energy
- Do a dev install of jupyter-energy and its dependencies
pip install --editable .[dev]
- Enable the server extension:
jupyter serverextension enable --py jupyter_energy --sys-prefix
Note: if you're using Jupyter Server:
jupyter server extension enable --py jupyter_energy --sys-prefix
- Install and enable the nbextension for use with Jupyter Classic Notebook.
jupyter nbextension install --py jupyter_energy --symlink --sys-prefix
jupyter nbextension enable --py jupyter_energy --sys-prefix
- Start a Jupyter Notebook instance, open a new notebook and check out the energy consumption in the top right!
jupyter notebook
- better labels
- write more documentation (also for benchmark)