Crash introduction for Visual Studio Code for a select few AIDS (KID) students at DTU with the aim of migrating them from using Spyder for AI/ML development.
This is an informal student to student introduction.
- Basic programming skills
- GitHub account
- Anaconda (the animal)
- Non-possessed computer
- Slightly above average brain
The following is preparatory work each participant needs to do before the live introduction.
If you encounter any issues, feel free to contact me.
- Visit https://code.visualstudio.com/
- Download and follow onscreen instructions
- Enable option
"Add to PATH"
- ???
- Profit - open VSCode
The following plugins are necessary for Python development.
Install by pressing ctrl+shift+x
inside VSCode and apply brain.
- Anaconda Extension Pack
- Jupyter
- Pylance
- Visual Studio IntelliCode
- Live Share
- Bracket Pair Colorizer 2
- Python Indent
The following are notes for a live introduction which will be held at an agreed upon date by the participants.
The notes can later be used as a cheatsheet/reference material.
- Open VSCode
- On Windows:
- Open Anaconda Prompt (not navigator)
- Run the command
code
- Hint: Make a shortcut that does all this
- Linux/MacOS:
- Open VSCode normally
- On Windows:
- Open a folder/project with
ctrl+k, ctrl+o
(or File->Open Folder...) - Open file via
- Search:
ctrl+p
- File panel:
ctrl+shift+e
- Search:
- View
- New file:
ctrl+n
- New window:
ctrl+shift+n
- Switch tab:
ctrl+tab
andctrl+shift+tab
- Close/unclose tab:
ctrl+w
andctrl+shift+t
- File panel:
ctrl+shift+e
- Problems panel:
ctrl+shift+m
- Debug console:
ctrl+shift+y
- Split window right:
ctrl+(
ordrag and drop tab
- Split window down:
ctrl+k, ctrl+(
ordrag and drop tab
- New file:
- File
- Save file:
ctrl+s
- Save all:
ctrl+k, s
- Find file:
ctrl+p
- Go to definition:
F12
orctrl+left click
- Go to references:
shift+F12
- Go to symbol:
ctrl+shift+o
- Go to bracket:
ctrl+shift+(
- Go to line:
ctrl+g
- Save file:
- Selection
- Select line above/below:
ctrl+shift+up
andctrl+shift+down
- Select character left/right:
shift+left
andshift+right
- Select word left/right:
ctrl+shift+left
andctrl+shift+right
- New cursor above/below:
ctrl+shift+alt+down
andctrl+shift+alt+down
- New cursor at click:
alt+left mouse button
- New cursor at next same word:
ctrl+d
- New cursor at occurrences of word:
ctrl+shift+l
- Select line above/below:
- Editing
- Undo/Redo:
ctrl+z
andctrl+shift+z
- Move line(s):
alt+up
andalt+down
- Duplicate line(s):
alt+shift+up
andalt+shift+down
- Comment line(s):
ctrl+'
- Delete line(s):
ctrl+shift+k
- Rename variable:
F2
- Find:
ctrl+f
- Replace:
ctrl+h
- Indent/unindent line(s):
tab
andshift+tab
- New line below/above:
ctrl+enter
andctrl+shift+enter
- Undo/Redo:
- Multi-purpose
- Do everything:
ctrl+shift+p
- Fix everything:
ctrl+.
- Do everything:
- Miscellaneous
- Remember to run the correct file
- Run:
ctrl+F5
- Snippets:
tab
,tab
,tab
... - Surround: Select text, press
'
,"
,(
,[
, or{
- Change case: Select text,
ctrl+shift+p
,transform to [...]
- Word wrap:
alt+z
- Functions can be collapsed (hidden from view)
- Jupyter Notebooks supported
- Ensure
Python (conda)
selected (top right) F10
to run cell, line by line- New notebook:
ctrl+shift+p
,new notebook
- Works like normal
- Ensure
- Interactive mode
- Useful as playground for experimentation
- Program state is stored - double edged sword
- Create a cell:
#%%
- Run current cell:
ctrl+enter
- Execute command:
shift+enter
- Buggy/complex program?
- Run with debug:
F5, enter
- Pause program on one of
- Error
- Breakpoint
- Next line
- Predict expected program state
- Find inconsistency with actual state
- Branch
- If root cause found, deal with it
- Else, go to step 2 and pause near cause of inconsistency
- Run with debug:
- Tools to examine state
- Navigation
- Stop/restart:
shift+F5
andctrl+shift+F5
- Continue/pause:
F5
andF6
- Step in/out:
F11
andshift+F11
- Step over:
F10
- Line/inline breakpoint:
F9
andshift+F9
- Conditional:
right click breakpoint, edit breakpoint...
- Conditional:
- Stop/restart:
- State
- Hover mouse on variable
- Debug panel:
ctrl+shift+d
- Read/write variables
- Watch expressions
- (Call stack)/(stack trace)
- "Map sequence" of which functions called each other
- Scope of variables is different
- Use to get context on issues
- Manipulation
- Debug console:
ctrl+shift+y
- Examine state
- Change variables
- Run functions
- Interactive mode
- Quick experimentation
- Reproduce issue
- Test potential fix
- Access to data viewer
- Quick experimentation
- Debug console:
- Navigation
- Miscellaneous
- Remember to run the correct file
- Slower execution
- Do not test speed of program in debug mode
- Long experiments take even longer in debug mode
- Concurrency related issues may not happen because it's slower
- Setup
- Sign in with GitHub:
ctrl+shift+p, live share sign in browser
- Start read/write session (only with trusted people)
- Share:
ctrl+shift+p, live share start
- Join:
ctrl+shift+p, live share join
orctrl+alt+j
- Share:
- Sign in with GitHub:
- Google Docs (Beta - Developer Edition)
- Usually perfect, sometimes not
- Changes may not propagate
- Participants are not visible or do not move
- Mangled console output
- Fix:
Restart Live Share session and VSCode
- Usually perfect, sometimes not
- Collaborative debugging
- Follow mode
- Highlighting
- Only host can (should) interact with consoles (terminal, debug, interactive)
- No more backseat programmers
- Task examples
- Training models
- Collecting experiment data
Ethereum mining
- Crash -> Loss of training progress or experiment data
- Fail-safe techniques
- Redirect
- Open
Anaconda Prompt
- Navigate to python file with
cd "<path to folder>"
- Run python file
- Overwrite:
python "<name of python file>.py" > "<name of output file>"
- Append:
python "<name of python file>.py" >> "<name of output file>"
- Overwrite:
- Open
- In code
- More complicated, more flexible
- Use
pickle
module for serialization - Get file handles with
open
function.
- Redirect
- Caveats
- Force buffer flush:
print(some_text, flush=True)
- Printing and file operations are slow
- Force buffer flush:
- Git panel:
ctrl+shift+g
- SCRUB, LEARN THE CONSOLE
- Core actions
- Push
- Pull
- Add
- Commit
- Branch
- Checkout
- Merge
- Workflow
- Branch
- Work
- Commit
- Pull
- Push
- GitHub Student Developer Pack
- https://education.github.com/pack
- Connect your DTU email to GitHub