Contenu connexe Similaire à Jupyter Kernel: How to Speak in Another Language (20) Plus de Wey-Han Liaw (13) Jupyter Kernel: How to Speak in Another Language10. Agenda
• Jupyter, IPython, notebook, console, client, kernel
• The Interactive Computing Protocol
• Implementing a Kernel
• Live Demo
11. About this guy
• 廖偉涵 Adrian Liaw
• github.com/adrianliaw
• High School Homeschooler
• A Pythonista
• Student of Udacity’s
Data Analyst Nanodegree
12. About this guy
• Amateur Pianist
• Classical Music Lover
• Coffee Shop Lover
19. -Project Jupyter
“Project Jupyter was born out of the
IPython Project in 2014 as it evolved
to support interactive data science
and scientific computing across all
programming languages.”
26. What’s Inside IPython
• The Interactive IPython Shell (No ØMQ)
• Magic Commands
• Auto Word Completer
• Beautiful Traceback
• Shell History Management
29. What’s Inside Jupyter
• Web-based Notebook Interface & nbconvert
• Interactive Qt Console
• Terminal-based Console
• Spec for Notebook Document Format
• Spec for Interactive Computing Protocol
33. Connection File
{
"transport": "tcp",
"ip": "127.0.0.1",
"shell_port": 56166,
"iopub_port": 56167,
"stdin_port": 56168,
"control_port": 56169,
"hb_port": 56170,
"signature_scheme": "hmac-sha256",
"key": "<hashed key>"
}
34. Message Format
{
'header' : {
'msg_id' : str,
'username' : str,
'session' : str,
'date': str,
'msg_type' : str,
'version' : '5.0',
},
'parent_header' : dict,
'metadata' : dict,
'content' : dict,
}
37. CLIENT KERNEL
Shell
{
"header": {
"msg_type": "kernel_info_reply",
...
},
"parent_header": {...},
"content": {
"banner": "Python 3.5.1 ... IPython 4.0.0 ...",
"implementation": "ipython",
"implementation_version": "4.0.0",
"language_info": {
"name": "python",
"version": "3.5.1",
...
},
},
}
42. CLIENT KERNELIOPub
{
"header": {"msg_type": "execute_result", ...},
"parent_header": {...},
"content": {
"execution_count": 5,
"data": {
"text/plain": " col1 col2n A 3n....",
"text/html": "<div><table>...</table></div>",
},
},
}
47. CLIENT KERNELIOPub
{
"header": {"msg_type": "execute_result", ...},
"parent_header": {...},
"content": {
"execution_count": 1,
"data": {
"text/plain": " col1 col2n A 3n....",
"text/html": "<table>...</table>",
},
},
}
51. IRKernel
11. zmqctx <<- zmq.ctx.new()
12. sockets <<- list(
13. hb = zmq.socket(zmqctx, .pbd_env$ZMQ.ST$REP),
14. iopub = zmq.socket(zmqctx, .pbd_env$ZMQ.ST$PUB),
15. control = zmq.socket(zmqctx, .pbd_env$ZMQ.ST$ROUTER),
16. stdin = zmq.socket(zmqctx, .pbd_env$ZMQ.ST$ROUTER),
17. shell = zmq.socket(zmqctx, .pbd_env$ZMQ.ST$ROUTER))
60. Reference
• P.3, P.4, P.17, P.20, P.50 images: Project Jupyter
• P.6, P.7, P.8 images: Molg H.
• P.16: Project Jupyter
• P.11 image: Toomore Chiang
• P.12 image: Virginia Cheng
• P.13 image: ipython
• P.45 image: R