Hello world
I’m a software developer from Mjøndalen in Norway. My first experience with programming was scripting VBA in Excel while studying economics. I remember working day and night scripting excel to automate a bunch of stuff for an assignment and really having a great time with it. Later I figured out that scripting excel was pretty much the only thing I enjoyed about the economics studies, so I went on to study computer science as well. I enjoyed computer science a lot, and this made me extra happy and relieved because of how boring I found economics studies.
FastAI
I’m currently following the fast ai course, and will hopefully post a lot about stuff related to that. Jeremy seems like a great teacher.
How to FastAI
I liked these points on “how to do a fast.ai lesson” from here:
- Watch lecture
- Run notebook and experiment
- Reproduce results
- Repeat with different dataset
It is fine to not do all of the steps the first time you go through the course, but take it as far as you can and try to push yourself more and more on each iteration.
I also liked this quote from a former student: “One of my favorite pieces of advice was from FastAI’s Jeremy Howard. He told me to focus on making one really great project that showed off my skills. He says that so many people have many interesting but half-finished projects on github, and that it’s so much better to have a single one that is really polished.”
I will to try to make something that assists players of the boardgame Twilight Imperium 4 by collecting data of the state of the game and then visualizing the data. The reason for doing this specifically is that I enjoy playing TI4 a lot so it will hopefully give some extra motivation to finish the project. Also, TI4 is such a complex game with lots of different components, and it would be nice to have a tool that helped to keep track of it all. The first thing I want to try out is to keep track of the public objectives.
Notes from live coding sessions and more
Timestamps and links from the fast.ai live coding sessions (and sometimes other places) that might be useful. Jeremy shows a lot of useful stuff in these sessions.
Session 1:
- Install mamba (python environment thingy)
- There is a bunch of scripts automating getting setup stuff in fastai’s fastsetup repo, e.g. setup-conda.sh for installing mamba
Session 2:
Session 3:
- How to handle python environments with mamba in such a way that one does not need to freeze version numbers and thus do not need to rely as much on docker containers (specifically for data scientists? the point seems to be to facilitate rapid iteration)
- Setup a jupyter notebook in paperspace gradient
- Python debugger and set_trace
- Tip: learn the textual python debugger as its similar to debuggers for other languages so the knowledge generalizes (in contrast to learning properietary tools where you will probably have to re-learn it somewhat)
- Tip: in general, use the keybindings that the tools offer instead of coming up with your own keybindings as it’s easier to switch between environments
- It’s fine to use pip to install anything that’s only reliant on python code. When you install stuff that relies on code outside of python like pytorch (relies on cuda) it’s faster to use conda as it also handles the dependencies outside of python. Sometimes you need to use pip as it let’s you install something only on your user in cases where you are not admin: pip install -U –user package_name
- In paperspace, everything on the machine is whiped out after you’re finished. However, you have a /storage folder where stuff is stored persistantly. Use this and symlinks (ln -s path_to_file_to_symlink) to not have to install stuff again each time you start the machine
- In paperspace, you can create a file called .bash.local in storage which will be run everytime you open the terminal. Create symlinks there :)
- When opening a paperspace notebook, /run.sh is executed. This script can’t be changed, but it will execute /storage/pre-run.sh which might be a better place to put the symlinks and stuff like that
Session 4:
- Virtues of a great programmer: laziness, impatience and hubris. One way of being lazy is to learn stuff that is re-usable, such as using python for scripts rather than shell because python can be used for more purposes.
Terminal tricks:
- !! last command
- !$ last token in last command
- ctrl + u: delete everything left of the cursor
- ctrl + k: delete everything right of the cursor
For some more terminal tricks check out this file.
Jupyter notebook tricks (given a function f):
- something. + click tab will show available methods for something
- f?: displays function signature, docstring, file and type on running
- f??: displays function source code on running
- f: displays where the function is from and its parameters on running
- f( and shift+tab: displays the same as f? in the active jupyter block (do not need to run it)
- shift+m: merge blocks?
- 0 0: restarts the kernal - nice to use when you want to re run everything
- a hotkey for running everything is not set by default, but can be assigned through help > edit keyboard shortcuts > run all cells
Python technicalities and related stuff:
- Inside of a class, the class does not know about itself. For type hinting to work one has to wrap the class name in quotes. From this clip
- fastcore.utils has functionality for defining funtions for a class outside of the class (like extension functions in kotlin?). This is done with the fastcore.utils.patch decorator. At this point python will know about the class, so no need to wrap type hint of the class in quotes
- showcase of using nbdev for testing
Other:
- “When you’re trying to understand enough of a new codebase to make a specific PR, it’s best to use an editor which lets you jump to definitions to understand how the code works. Reading and experimenting in the notebooks is the best way to understand the bigger picture more thoroughly.” (from here)