ImperialCollegeLondon / RCDS-profiling-and-optimisation-in-python

Other
32 stars 11 forks source link

Include requirements.txt file #1

Open mearlboro opened 1 year ago

mearlboro commented 1 year ago

Dear team,

I appreciate you providing the course materials for users who do not want to rely on Google. However, in lack of a requirements.txt file, reconstructing the necessary Python environment to run the notebooks is taking some time. Whilst you do specify some of the packages required the list is not complete. Moreover, some packages are being installed repeatedly inside code blocks in the Jupyter notebook, instead of being installed in the environment, i.e. the same pip install command is repeated many times in the same notebook. This is not recommended in lack of a virtual environment, but the instructions you provide do not stress the importance of using one, or offer alternatives to Anaconda. Providing a requirements.txt is the simplest and most agnostic way to support people in running this code locally inside a Python environment. I have done this in preparation of attending the course, so below is the content of the requirements.txt file I used

graphviz
jupyterlab
jupyter_contrib_nbextensions
line_profiler
numba
pycallgraph2
pympler
mearlboro commented 1 year ago

The error

'The pycallgraph module is not an IPython extension.'

has appeared after I managed to get the notebook to run, when trying to run the pycallgraph section in profile.ipynb.

This drove me to notice that:

I amended the issue to add iPython, pycallgraph2 and jupyter_contrib_nbextensions.

This also requires enabling Jupyter extensions, this is described for system-wide enabling here, or, if you're working in a python environment for example pipenv one can do

pipenv run jupyter contrib nbextension install --sys-prefix
pipenv run jupyter nbextension enable pycallgraph2 --sys-prefix 

and then after restarting the notebook server, go to the NBExtensions tab, untick "disable configuration for nbextensions without explicit compatibility", and make sure pycallgraph2 is ticked as well.

Running the relevant cell will then produce the call graph image as a PNG in the same directory you run notebooks.

cmcooling commented 1 year ago

Thanks again for finding these problems and suggesting the solutions. The method you suggest works, but it's quite a lot of work for students who are unfamiliar with the command line and Python package management. As a result, I've decided to remove the section on call graphs for now. It's not so bad as I don't think it's actually required for solving any of the problems in the course, and trying to find a good solution to this has caused me problems for a while. I may bring it back at some point - I'm considering trying GitHub Codespaces as a way to provide a pre-configured environment for students, and this would make it easier to use these packages.

In any case, your suggestion of a requirements file is still a good one, so I've added this for the other packages required for the course and updated "Packages" section of the readme. If you notice any problems with requirements file or the readme please feel free to let me know!

Thanks again for the feedback and suggestions.