tutorial de jupyter notebook€¦ · dicionário de termos como funciona o jupyter notebook »...

28
Tutorial de Jupyter Notebook Infraestrutura necessária Carlos Adean Junho de 2020 1

Upload: others

Post on 13-Nov-2020

25 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Tutorial de Jupyter Notebook€¦ · Dicionário de termos Como funciona o Jupyter Notebook » Servidor Jupyter Notebook ou Servidor Jupyter, tanto faz. » Servidor Jupyter é um

Tutorial de Jupyter NotebookInfraestrutura necessária

Carlos AdeanJunho de 2020

1

Page 2: Tutorial de Jupyter Notebook€¦ · Dicionário de termos Como funciona o Jupyter Notebook » Servidor Jupyter Notebook ou Servidor Jupyter, tanto faz. » Servidor Jupyter é um

Sobre mim

» Graduação em Análise e Desenvolvimento de Sistemas» Pós-graduado em Administração de Banco de dados» Certificações LPIC e RedHat» Colaborador do LIneA desde 2011

Carlos Adean

2

Page 3: Tutorial de Jupyter Notebook€¦ · Dicionário de termos Como funciona o Jupyter Notebook » Servidor Jupyter Notebook ou Servidor Jupyter, tanto faz. » Servidor Jupyter é um

Agenda

» Como funciona o Jupyter Notebook» Como instalar no Windows e Linux» Extensões e widgets» Servidor JupyterHub

3

Page 4: Tutorial de Jupyter Notebook€¦ · Dicionário de termos Como funciona o Jupyter Notebook » Servidor Jupyter Notebook ou Servidor Jupyter, tanto faz. » Servidor Jupyter é um

Dicionário de termos

Como funciona o Jupyter Notebook

» Servidor Jupyter Notebook ou Servidor Jupyter, tanto faz.» Servidor Jupyter é um servidor standalone e single-user.» JupyterLab é uma nova interface para o Servidor Jupyter.» Servidor JupyterHub é um servidor multiusuário.» Notebook é o arquivo que contém o código e as anotações.

4

Page 5: Tutorial de Jupyter Notebook€¦ · Dicionário de termos Como funciona o Jupyter Notebook » Servidor Jupyter Notebook ou Servidor Jupyter, tanto faz. » Servidor Jupyter é um

Como funciona o Jupyter Notebook

5

Page 6: Tutorial de Jupyter Notebook€¦ · Dicionário de termos Como funciona o Jupyter Notebook » Servidor Jupyter Notebook ou Servidor Jupyter, tanto faz. » Servidor Jupyter é um

Histórico

Como funciona o Jupyter Notebook

1991 2001 2011 2014 2015

6

Page 7: Tutorial de Jupyter Notebook€¦ · Dicionário de termos Como funciona o Jupyter Notebook » Servidor Jupyter Notebook ou Servidor Jupyter, tanto faz. » Servidor Jupyter é um

Terminal IPython

Como funciona o Jupyter Notebook

» Terminal interativo para Python» Interface original do IPython

while True: code = input(">>> ") exec(code)

» Modelo REPL - Read-Eval-Print-Loop» Utiliza como backend o ipykernel (a.k.a

kernel IPython)

7

Representação do modelo REPL

Page 8: Tutorial de Jupyter Notebook€¦ · Dicionário de termos Como funciona o Jupyter Notebook » Servidor Jupyter Notebook ou Servidor Jupyter, tanto faz. » Servidor Jupyter é um

O kernel IPython

Como funciona o Jupyter Notebook

» Kernel ‘zero’» Executar o código e completar comandos

Exemplos de kernel para Go e SSH

» JSON para troca de mensagens » Interação do Frontend com o kernel é via

socket zeroMQ» Wrapper kernel e Native kernel

8

Page 9: Tutorial de Jupyter Notebook€¦ · Dicionário de termos Como funciona o Jupyter Notebook » Servidor Jupyter Notebook ou Servidor Jupyter, tanto faz. » Servidor Jupyter é um

Exemplo.ipynb

O servidor Jupyter Notebook

Como funciona o Jupyter Notebook

» ‘Executa’ os códigos» Interface flexível e dinâmica» Armazena o código e sua saída junto com

anotações em markdown» Notebook é um JSON com extensão .ipynb

9

Page 10: Tutorial de Jupyter Notebook€¦ · Dicionário de termos Como funciona o Jupyter Notebook » Servidor Jupyter Notebook ou Servidor Jupyter, tanto faz. » Servidor Jupyter é um

Como instalar

10

Page 11: Tutorial de Jupyter Notebook€¦ · Dicionário de termos Como funciona o Jupyter Notebook » Servidor Jupyter Notebook ou Servidor Jupyter, tanto faz. » Servidor Jupyter é um

Como instalar

» Anaconda Individual Edition» Gerenciador de pacotes» www.anaconda.com/downloads

Windows

IPython é o kernel padrão

» Next > Next > Next > Finish» Jupyter Notebook instalado por padrão

11

Page 12: Tutorial de Jupyter Notebook€¦ · Dicionário de termos Como funciona o Jupyter Notebook » Servidor Jupyter Notebook ou Servidor Jupyter, tanto faz. » Servidor Jupyter é um

Como instalar

Via python-pip, anaconda ou docker

Debian / Ubuntu $ sudo apt install python3-pip python3-venv

RedHat / CentOS / Fedora $ sudo yum install python3-pip python3-virtualenv

$ python3 -m venv jupyter-env $ source jupyter-env/bin/activate $ pip3 install jupyter

Linux

IPython é o kernel padrão12

Page 13: Tutorial de Jupyter Notebook€¦ · Dicionário de termos Como funciona o Jupyter Notebook » Servidor Jupyter Notebook ou Servidor Jupyter, tanto faz. » Servidor Jupyter é um

Extensões e widgets

13

Page 14: Tutorial de Jupyter Notebook€¦ · Dicionário de termos Como funciona o Jupyter Notebook » Servidor Jupyter Notebook ou Servidor Jupyter, tanto faz. » Servidor Jupyter é um

Extensões e widgets

Jupyter widgets

ipyleaflet

bqplotjupyter-gmaps

k3d-jupyter

pythreejs

14

bakerx

Page 15: Tutorial de Jupyter Notebook€¦ · Dicionário de termos Como funciona o Jupyter Notebook » Servidor Jupyter Notebook ou Servidor Jupyter, tanto faz. » Servidor Jupyter é um

nbgraderjupyter-drive

rise (presentation)

Jupyter extensions

Extensões e widgets

15

voilá

Page 16: Tutorial de Jupyter Notebook€¦ · Dicionário de termos Como funciona o Jupyter Notebook » Servidor Jupyter Notebook ou Servidor Jupyter, tanto faz. » Servidor Jupyter é um

Como instalar widgets e extensões

Pode ser instalado via python-pip ou anaconda

AnacondaAbrir o terminal Anaconda conda install -c conda-forge <nome>

PipAbrir o terminal $ source jupyter-env/bin/activate $ pip3 install <nome>

Para ativar o widget jupyter nbextension enable --py --sys-prefix <nome>

conda install -c conda-forge k3djupyter nbextension enable k3d

source jupyter-env/bin/activatepip3 install k3djupyter nbextension enable k3d

Extensões e widgets

16

Page 17: Tutorial de Jupyter Notebook€¦ · Dicionário de termos Como funciona o Jupyter Notebook » Servidor Jupyter Notebook ou Servidor Jupyter, tanto faz. » Servidor Jupyter é um

Servidor JupyterHub

17

Page 18: Tutorial de Jupyter Notebook€¦ · Dicionário de termos Como funciona o Jupyter Notebook » Servidor Jupyter Notebook ou Servidor Jupyter, tanto faz. » Servidor Jupyter é um

Servidor JupyterHub

http://localhost:8888/http://localhost:8888/ http://localhost:8888/ http://localhost:8888/

Jupyter Notebook vs JupyterHub

18

Page 19: Tutorial de Jupyter Notebook€¦ · Dicionário de termos Como funciona o Jupyter Notebook » Servidor Jupyter Notebook ou Servidor Jupyter, tanto faz. » Servidor Jupyter é um

Servidor JupyterHub

» Servidor Jupyter multiusuário» Administração centralizada» Servidores Jupyter sob demanda» Sistema de arquivos compartilhados» Diferentes flavors de imagem docker» OAuth providers (CILogon, Google, Github etc)» Plugin ldapauthenticator (LIneA)

https://jupyter.linea.gov.br

JupyterHub standalone

LDAP

19

Page 20: Tutorial de Jupyter Notebook€¦ · Dicionário de termos Como funciona o Jupyter Notebook » Servidor Jupyter Notebook ou Servidor Jupyter, tanto faz. » Servidor Jupyter é um

Servidor JupyterHub

https://jupyter.linea.gov.br

JupyterHub standalone

LIneAIdP

20

» Servidor Jupyter multiusuário» Administração centralizada» Servidores Jupyter sob demanda» Sistema de arquivos compartilhados» Diferentes flavors de imagem docker» OAuth providers (CILogon, Google, Github etc)» Plugin ldapauthenticator (LIneA)

Page 21: Tutorial de Jupyter Notebook€¦ · Dicionário de termos Como funciona o Jupyter Notebook » Servidor Jupyter Notebook ou Servidor Jupyter, tanto faz. » Servidor Jupyter é um

Servidor JupyterHub

https://jupyter.linea.gov.br

JupyterHub standalone

LIneAIdP

21

» Servidor Jupyter multiusuário» Administração centralizada» Servidores Jupyter sob demanda» Sistema de arquivos compartilhados» Diferentes flavors de imagem docker» OAuth providers (CILogon, Google, Github etc)» Plugin ldapauthenticator (LIneA)

Page 22: Tutorial de Jupyter Notebook€¦ · Dicionário de termos Como funciona o Jupyter Notebook » Servidor Jupyter Notebook ou Servidor Jupyter, tanto faz. » Servidor Jupyter é um

Servidor JupyterHub

https://jupyter.linea.gov.br

LIneAIdP

» Cluster JupyterHub» K8S local ou na nuvem» Diferentes ‘flavors’ de configuração

JupyterHub + Kubernetes

22

Page 23: Tutorial de Jupyter Notebook€¦ · Dicionário de termos Como funciona o Jupyter Notebook » Servidor Jupyter Notebook ou Servidor Jupyter, tanto faz. » Servidor Jupyter é um

Servidor JupyterHub

https://jupyter.linea.gov.br

LIneAIdP

» Cluster JupyterHub» K8S local ou na nuvem» Diferentes ‘flavors’ de configuração» Ambiente HPC integrado via PARSL

JupyterHub + Kubernetes + HPC Escalonador de Jobs

Cluster HPC

PARSL

HPC User 23

DBFS

Page 24: Tutorial de Jupyter Notebook€¦ · Dicionário de termos Como funciona o Jupyter Notebook » Servidor Jupyter Notebook ou Servidor Jupyter, tanto faz. » Servidor Jupyter é um

Links

● https://jupyter.org

● https://jupyterhub.readthedocs.io

● https://github.com/jupyter/jupyter/wiki/Jupyter-kernels

● https://en.wikipedia.org/wiki/Project_Jupyter

● https://en.wikipedia.org/wiki/Albert_Einstein

● https://zeromq.org

● https://ipython.org

● https://en.wikipedia.org/wiki/IPython

● https://youtu.be/GExKsQ-OU78

● https://youtu.be/4GJFNQBB26s

● parsl-project.org

● kubernetes.io

24

Page 25: Tutorial de Jupyter Notebook€¦ · Dicionário de termos Como funciona o Jupyter Notebook » Servidor Jupyter Notebook ou Servidor Jupyter, tanto faz. » Servidor Jupyter é um

Obrigado! [email protected]

Page 26: Tutorial de Jupyter Notebook€¦ · Dicionário de termos Como funciona o Jupyter Notebook » Servidor Jupyter Notebook ou Servidor Jupyter, tanto faz. » Servidor Jupyter é um

Extras

26

Page 27: Tutorial de Jupyter Notebook€¦ · Dicionário de termos Como funciona o Jupyter Notebook » Servidor Jupyter Notebook ou Servidor Jupyter, tanto faz. » Servidor Jupyter é um

Como funciona o Jupyter Notebook

Diagrama de sequência de uma requisição

27

Page 28: Tutorial de Jupyter Notebook€¦ · Dicionário de termos Como funciona o Jupyter Notebook » Servidor Jupyter Notebook ou Servidor Jupyter, tanto faz. » Servidor Jupyter é um

Servidor JupyterHub

Arquitetura do servidor JupyterHub

28