Using the Python interpreter¶
Learning objectives
- Practice using the UPPMAX documentation
- Practice using the Python book How to Think Like a Computer Scientist: Learning with Python 3
- To be able to login to Rackham autonomously
- To be able to load a Python version autonomously
- to be able to start an interactive session autonomously
- To be able to run a minimal Python program autonomously
For teachers
Teaching goals are:
- Learners have used the UPPMAX documentation
- Learners have used the Python interpreter
- Learners have loaded Python using the module system
Other goals are:
- Verify that learners indeed have learned how to login
- Verify that learners indeed have learned how to start an interactive session
- Verify that learners indeed have learned how to use the module system
Prior question:
- What is Python?
- What are features of the Python language?
- What is an interpreted language?
- What is a scripting language?
- What is an interpreter?
- What is an HPC cluster?
- What are features of the Rackham HPC cluster?
- What is the rule on what to run on a login node?
- When to use an interactive session?
Lesson plan:
- 5 mins: prior knowledge
- 5 mins: presentation
- 15 mins: challenge
- 5 mins: feedback
Why?¶
You want to make a computer run Python code, for some good reason. Here we do so!
To develop code in Python on the UPPMAX clusters, one needs to:
- Login to Rackham, to be on an UPPMAX cluster
- Load the Python module, to be able to use a modern Python interpreter
- Use the Python interpreter, to run Python code
Luckily, UPPMAX has documentation that should allow you to do so yourself!
These exercises will ensure you are able to run a minimal Python program.
flowchart TD
python[[Python]]
%% Give a white background to all nodes, instead of a transparent one
classDef node fill:#fff,color:#000,stroke:#000
subgraph sub_programming_language[Python as a language]
interpreted_language[Interpreted language]
programming_language[Programming language]
scripting_language[Scripting language]
interpreter[Interpreter]
%% scripts[Scripts]
%% text_files[Text files]
end
style sub_programming_language fill:#ccf,color:#000,stroke:#fcc
subgraph sub_uppmax[UPPMAX]
uppmax[UPPMAX]
uppmax_modules[UPPMAX modules]
uppmax_clusters[UPPMAX clusters]
%% text_editors[Text editors]
%%x_forwarding[X-forwarding]
%%remote_desktop[Remote desktop]
end
style sub_uppmax fill:#fcc,color:#000,stroke:#fcc
python --> |is a| programming_language
python --> |is a| interpreted_language
python --> |is a| scripting_language
%% programming_language --> |uses| text_files
interpreted_language --> |has a| interpreter
scripting_language --> |is a|interpreted_language
%% scripting_language --> |runs| scripts
%% scripts --> |are| text_files
%% scripts --> |can use| command_line_arguments
uppmax --> |has| uppmax_clusters
uppmax_clusters --> |have| uppmax_modules
%%uppmax_clusters --> |have| text_editors
%%uppmax_clusters --> |allow| x_forwarding
%%uppmax_clusters --> |has| remote_desktop
%% uppmax_modules --> |allow the use of| python_packages
uppmax_modules --> |allow the use of| interpreter
%% text_editors --> |work on|text_files
%%x_forwarding --> |allows|graphics
%%remote_desktop --> |allows|graphics
%% variables ~~~ uppmax
Exercises¶
Enjoy a video?
You can find a video with solutions to these exercises here
See the exercise procedure here.
Exercise 1: login to Rackham¶
Go to the UPPMAX documentation at https://docs.uppmax.uu.se, then answer these questions:
- Login to Rackham in any way
Answer
This is described at the UPPMAX page 'Login to Rackham':
- Remote desktop via website: go to https://rackham-gui.uppmax.uu.se
- Using SSH:
Exercise 2: start an interactive session¶
Learning objectives
- to be able to start an interactive session autonomously
Go to the UPPMAX documentation at https://docs.uppmax.uu.se, then answer these questions:
- Start an interactive session of max seven hours
If this does not work out, go to the next step: we will be only doing light work on the login node. However, using an interactive session is a good idea.
Answer
This is described at the UPPMAX page 'Starting an interactive node on Rackham':
Exercise 3: load the Python module¶
Learning objectives
- to be able to load a Python version autonomously
Go to the UPPMAX documentation at https://docs.uppmax.uu.se, then answer these questions:
- Load Python version 3.10.8
Exercise 4: write a 'Hello world' program¶
Learning objectives
- to be able to run a minimal Python program autonomously
Go to the UPPMAX documentation at https://docs.uppmax.uu.se, then answer these questions:
- Start Python on Rackham
- Find the UPPMAX documentation page on Python programming
Answer
It can be found at https://docs.uppmax.uu.se/software/python_programming/
- On the UPPMAX documentation page on Python programming, find out how to run a 'Hello world' program from the interpreter. Then do this yourself
Answer
The documentation can be found at https://docs.uppmax.uu.se/software/python_programming/#use-the-python-interpreter.
In the Python interpreter, type
to run your 'Hello world' program