Commit 07c31ad7 authored by paugier's avatar paugier
Browse files

First course nearly ready

parent d0f0e239
Pipeline #49930 passed with stage
in 43 seconds
......@@ -4,30 +4,39 @@
Pierre Augier (LEGI) and Enzo Le BoueDec (LEGI)
(And Cyrille Bonamy (LEGI), Eric Maldonado (Irstea), Franck Thollard (ISTerre), Christophe Picard (LJK), Loïc Huder (ISTerre)...)
%% Cell type:markdown id: tags:
## Scientific computing course 2020
During sessions 1, 2 and 4 (9 hours), we will present an introduction on
scientific computing and programming:
During sessions 1, 2 and 4 (9 hours), we will study some basics on Linux and Python for scientific computing.
We will also give an introduction on scientific computing and programming:
- Computers to compute (CPU, memories, GPU, clusters)
- Numbers in computers
- Programming languages
- Difference open-source / close-source
- Operating systems and importance of Linux for scientific computing
- Install a good environment, example of Conda
- Versioning and Gitlab (https://gricad-gitlab.univ-grenoble-alpes.fr)
We will study some basics on Linux and Python for scientific computing.
The personal project part will be presented during session 3. Sessions 3, 5, 6
and 7 will be dedicated to practical exercises on (3) Computation of integrals,
(5) Finite Difference methods, (6) Gradient descent and (7) Machine learning.
We will work together on your personal projects during session 8.
This course should be fun! Do not hesitate to interrupt and ask any questions!
%% Cell type:markdown id: tags:
## Why using Python for this course ?
- A very nice, clean and well-thought programming language.
- **Generalist**: good for several applications, [used with success in many fields](http://brochure.getpython.info/).
- For academic purposes (teaching, research): **great scientific ecosystem**.
Nowadays, scientists must know a bit of Python... Good first language.
......
%% Cell type:markdown id: tags:
# Introduction to Bash
# First steps with Bash and Linux
Bash is the most standard shell on Unix systems (Linux, MacOS, ...). A shell is a basic programming language to interact with the computer and launch commands.
There are standard commands (corresponding to programs) to do many basic tasks. You can read this short document https://files.fosswire.com/2007/08/fwunixref.pdf.
......
......@@ -4,21 +4,11 @@
Pierre Augier (LEGI) and Enzo Le BoueDec (LEGI)
(And Cyrille Bonamy (LEGI), Eric Maldonado (Irstea), Franck Thollard (ISTerre), Christophe Picard (LJK), Loïc Huder (ISTerre)...)
# First steps
%% Cell type:markdown id: tags:
## Why Python ?
- A very nice and well-thought programming language.
- **Generalist**: good for several applications, [used with success in many fields](http://brochure.getpython.info/).
- For academic purposes (teaching, research): **great scientific ecosystem**.
# First steps. Different ways to use Python.
%% Cell type:markdown id: tags:
## Python: a language, an interpreter
......
%% Cell type:markdown id: tags:
# Python training UGA 2017
# Scientific computing course 2020
**A training to acquire strong basis in Python to use it efficiently**
**Acquire strong basis in Python to use it efficiently**
Pierre Augier (LEGI), Cyrille Bonamy (LEGI), Eric Maldonado (Irstea), Franck Thollard (ISTerre), Christophe Picard (LJK), Loïc Huder (ISTerre)
# Characteristics of the Python language
%% Cell type:markdown id: tags:
## Characteristics of the Python language
......
......@@ -18,15 +18,13 @@
return display_base(HTML(code))
```
%% Cell type:markdown id: tags:
# Overview of the Python HPC landscape 🚀
# Introduction on scientific computing
%% Cell type:markdown id: tags:
<div align="middle"> Python, only a great glue language? </div>
# Why using Python for this course?
%% Cell type:markdown id: tags:
<div align="middle"> Pierre Augier </div>
......@@ -38,11 +36,25 @@
<img src="./fig/logo-uga-vo-cmjn.jpg" style="width: 15%">
</div>
%% Cell type:markdown id: tags:
# Python for High-Performance Computing?
# Scientific computing: humans and computers
%% Cell type:markdown id: tags:
Code for sciences
- Humans communicating with humans with code
- Humans using computers
We want to go fast and right. We don't like bugs. We like clear and maintainable codes.
%% Cell type:markdown id: tags:
# Python for scientific computing?
1. *Fast prototyping* (Numpy!)
2. *Popular*:
......@@ -56,22 +68,20 @@
- Readability counts
- Expressivity counts
4. Anyway, one needs a good and well-known *scripting language* so yes!
(even considering Julia)
4. Anyway, one needs a good and well-known *scripting language*!
### *Where / when should we stop ?*
%% Cell type:markdown id: tags:
# Python & fast prototyping...
## The software engineering method for scientists 👩‍🔬 👨‍🔬 and HPC
## The software engineering method for scientists 👩‍🔬 👨‍🔬
1. Fast prototyping
2. Solidify **as needed**
......@@ -113,95 +123,59 @@
- Usually interpreted
%% Cell type:markdown id: tags:
## Python interpreters
## Other programming languages, other compromises ⚖️
- Fortran
- C
- C++
- Matlab (widely used in some laboratories, but close-source)
- R (for statistics)
- Java
- Javascript (web)
- Rust (new language for more security)
- Julia
%% Cell type:markdown id: tags:
## Python, one language and different interpreters
### [CPython](https://github.com/python/cpython) <img src="./fig/logo_python.png" align="left" style="width: 7%; margin-bottom: 2px; margin-right: 5px;">
Interpreted (nearly) instruction per instruction, (nearly) no code optimization
The numerical stack (Numpy, Scipy, Scikits, ...) based on the CPython C API (CPython implementation details)!
<br>
### [PyPy](https://pypy.org/) <img src="./fig/logo_pypy.png" align="left" style="width: 7%; margin-bottom: 0px; margin-right: 5px;">
Optimized implementation with tracing Just-In-Time compilation
["Abstractions for free"](https://www.youtube.com/watch?v=NQfpHQII2cU)
The CPython C API is an issue! PyPy can't accelerate Numpy code!
<br>
The CPython C API is an issue! PyPy can't accelerate Numpy code! [HPy](https://github.com/hpyproject/hpy) could solve this!
### [Micropython](http://micropython.org/) <img src="./fig/logo_micropython.jpeg" align="left" style="width: 7%; margin-bottom: 0px; margin-right: 5px;">
For microcontrollers
%% Cell type:markdown id: tags:
## Python & performance
### References and PyObjects
%% Cell type:code id: tags:
``` python
mylist = [1, 3, 5]
```
<br>
%% Cell type:markdown id: tags:
### and others
`list`: array of references towards PyObjects
%% Cell type:markdown id: tags:
### The C / Python border
%% Cell type:code id: tags:
``` python
arr = 2 * np.arange(10)
print(arr[2])
```
[GraalPython](https://github.com/graalvm/graalpython), Jython, IronPython, etc.
%% Cell type:markdown id: tags:
## Python & performance
### Python interpreters bad at crunching numbers
%% Cell type:markdown id: tags:
Pure Python terrible 🐢 (except with PyPy)...
%% Cell type:code id: tags:
``` python
from math import sqrt
my_const = 10.
result = [elem * sqrt(my_const * 2 * elem**2) for elem in range(1000)]
```
%% Cell type:markdown id: tags:
but even this is not *very* efficient (temporary objects)...
%% Cell type:code id: tags:
``` python
import numpy as np
a = np.arange(1000)
result = a * np.sqrt(my_const * 2 * a**2)
```
%% Cell type:markdown id: tags:
Even slightly worth with PyPy 🙁
### Python interpreters bad at "crunching numbers"
%% Cell type:markdown id: tags:
## Is Python efficient enough?
......@@ -267,10 +241,38 @@
`unittest`, `pytest`
%% Cell type:markdown id: tags:
## Representation of numbers in computers
[Binary numbers](https://en.wikipedia.org/wiki/Binary_number)
%% Cell type:markdown id: tags:
Different types
- integers (exact)
%% Cell type:code id: tags:
``` python
f"{42:b}"
```
%%%% Output: execute_result
'101010'
%% Cell type:markdown id: tags:
- floats, as scientific numbers (approximate)
Numbers can be contiguous in memory.
%% Cell type:markdown id: tags:
## "Crunching numbers" and computers architectures
%% Cell type:raw id: tags:
<div align="middle">
......@@ -472,11 +474,11 @@
Cython, Numba, Pythran, Transonic, PyTorch, ...
%% Cell type:markdown id: tags:
# First conclusions
# Conclusions
- Python great language & ecosystem for sciences & data
%% Cell type:markdown id: tags:
......@@ -486,13 +488,13 @@
%% Cell type:markdown id: tags:
- Many good accelerators and compilers for Python-Numpy code
- All have pros and cons!
%% Cell type:markdown id: tags:
**⇒ We shouldn't have to write specialized code for one accelerator!**
- CPython C API is an issue for the interpreters. The [HPy](https://github.com/hpyproject/hpy) project could solve that!
%% Cell type:markdown id: tags:
- Other languages don't replace Python for sciences
......
......@@ -2,9 +2,10 @@ from pathlib import Path
import sys
titles = {
"Intro hpc": "Introduction on scientific computing & why Python?",
"Intro first steps": "First step with Python",
"Intro language": "Some characteristics of the language",
"Intro bash": "First steps with Linux and Bash",
"Intro computing": "Introduction on scientific computing & why using Python for this course?",
"Intro first steps": "First steps with Python",
"Intro python language": "Some characteristics of the language",
"Readwritefiles": "Read and write files",
"Import standard library": "Import statements and the standart library",
"Data struct": "Standard data structure (list, tuple, set and dict)",
......@@ -33,7 +34,7 @@ for path in ipynb_files:
title = titles[title]
path_html = name + ".slides.html"
lines.append(f"- [{index}] `{title} <{path_html}>`_")
lines.append(f"- `{title} <{path_html}>`_")
back = "\n"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment