##// END OF EJS Templates
Update parallel example notebooks for Python 3
Thomas Kluyver -
Show More
@@ -67,7 +67,7 b''
67 "cell_type": "code",
67 "cell_type": "code",
68 "collapsed": false,
68 "collapsed": false,
69 "input": [
69 "input": [
70 "%px print a"
70 "%px print(a)"
71 ],
71 ],
72 "language": "python",
72 "language": "python",
73 "metadata": {},
73 "metadata": {},
@@ -98,7 +98,8 b''
98 "cell_type": "code",
98 "cell_type": "code",
99 "collapsed": false,
99 "collapsed": false,
100 "input": [
100 "input": [
101 "%px print >> sys.stderr, \"ERROR\""
101 "%px from __future__ import print_function\n",
102 "%px print(\"ERROR\", file=sys.stderr)"
102 ],
103 ],
103 "language": "python",
104 "language": "python",
104 "metadata": {},
105 "metadata": {},
@@ -208,7 +209,7 b''
208 "%%px --noblock\n",
209 "%%px --noblock\n",
209 "x = np.linspace(0,np.pi,1000)\n",
210 "x = np.linspace(0,np.pi,1000)\n",
210 "for n in range(id,12, stride):\n",
211 "for n in range(id,12, stride):\n",
211 " print n\n",
212 " print(n)\n",
212 " plt.plot(x,np.sin(n*x))\n",
213 " plt.plot(x,np.sin(n*x))\n",
213 "plt.title(\"Plot %i\" % id)"
214 "plt.title(\"Plot %i\" % id)"
214 ],
215 ],
@@ -248,7 +249,7 b''
248 "%%px --group-outputs=engine\n",
249 "%%px --group-outputs=engine\n",
249 "x = np.linspace(0,np.pi,1000)\n",
250 "x = np.linspace(0,np.pi,1000)\n",
250 "for n in range(id+1,12, stride):\n",
251 "for n in range(id+1,12, stride):\n",
251 " print n\n",
252 " print(n)\n",
252 " plt.figure()\n",
253 " plt.figure()\n",
253 " plt.plot(x,np.sin(n*x))\n",
254 " plt.plot(x,np.sin(n*x))\n",
254 " plt.title(\"Plot %i\" % n)"
255 " plt.title(\"Plot %i\" % n)"
@@ -296,6 +297,8 b''
296 "cell_type": "code",
297 "cell_type": "code",
297 "collapsed": false,
298 "collapsed": false,
298 "input": [
299 "input": [
300 "from __future__ import print_function\n",
301 "\n",
299 "def generate_output():\n",
302 "def generate_output():\n",
300 " \"\"\"function for testing output\n",
303 " \"\"\"function for testing output\n",
301 " \n",
304 " \n",
@@ -305,13 +308,13 b''
305 " import sys,os\n",
308 " import sys,os\n",
306 " from IPython.display import display, HTML, Math\n",
309 " from IPython.display import display, HTML, Math\n",
307 " \n",
310 " \n",
308 " print \"stdout\"\n",
311 " print(\"stdout\")\n",
309 " print >> sys.stderr, \"stderr\"\n",
312 " print(\"stderr\", file=sys.stderr)\n",
310 " \n",
313 " \n",
311 " display(HTML(\"<b>HTML</b>\"))\n",
314 " display(HTML(\"<b>HTML</b>\"))\n",
312 " \n",
315 " \n",
313 " print \"stdout2\"\n",
316 " print(\"stdout2\")\n",
314 " print >> sys.stderr, \"stderr2\"\n",
317 " print(\"stderr2\", file=sys.stderr)\n",
315 " \n",
318 " \n",
316 " display(Math(r\"\\alpha=\\beta\"))\n",
319 " display(Math(r\"\\alpha=\\beta\"))\n",
317 " \n",
320 " \n",
@@ -461,7 +464,7 b''
461 "cell_type": "markdown",
464 "cell_type": "markdown",
462 "metadata": {},
465 "metadata": {},
463 "source": [
466 "source": [
464 "As of IPython 0.14, you can instruct `%%px` to also execute the cell locally.\n",
467 "As of IPython 1.0, you can instruct `%%px` to also execute the cell locally.\n",
465 "This is useful for interactive definitions,\n",
468 "This is useful for interactive definitions,\n",
466 "or if you want to load a data source everywhere,\n",
469 "or if you want to load a data source everywhere,\n",
467 "not just on the engines."
470 "not just on the engines."
@@ -474,7 +477,7 b''
474 "%%px --local\n",
477 "%%px --local\n",
475 "import os\n",
478 "import os\n",
476 "thispid = os.getpid()\n",
479 "thispid = os.getpid()\n",
477 "print thispid"
480 "print(thispid)"
478 ],
481 ],
479 "language": "python",
482 "language": "python",
480 "metadata": {},
483 "metadata": {},
@@ -1,6 +1,6 b''
1 {
1 {
2 "metadata": {
2 "metadata": {
3 "name": "helloworld"
3 "name": ""
4 },
4 },
5 "nbformat": 3,
5 "nbformat": 3,
6 "nbformat_minor": 0,
6 "nbformat_minor": 0,
@@ -20,6 +20,7 b''
20 "cell_type": "code",
20 "cell_type": "code",
21 "collapsed": true,
21 "collapsed": true,
22 "input": [
22 "input": [
23 "from __future__ import print_function\n",
23 "from IPython.parallel import Client"
24 "from IPython.parallel import Client"
24 ],
25 ],
25 "language": "python",
26 "language": "python",
@@ -69,8 +70,8 b''
69 "cell_type": "code",
70 "cell_type": "code",
70 "collapsed": false,
71 "collapsed": false,
71 "input": [
72 "input": [
72 "print \"Submitted tasks:\", hello.msg_ids + world.msg_ids\n",
73 "print(\"Submitted tasks:\", hello.msg_ids + world.msg_ids)\n",
73 "print hello.get(), world.get()"
74 "print(hello.get(), world.get())"
74 ],
75 ],
75 "language": "python",
76 "language": "python",
76 "metadata": {},
77 "metadata": {},
@@ -18,6 +18,7 b''
18 "cell_type": "code",
18 "cell_type": "code",
19 "collapsed": true,
19 "collapsed": true,
20 "input": [
20 "input": [
21 "from __future__ import print_function\n",
21 "from IPython.parallel import Client"
22 "from IPython.parallel import Client"
22 ],
23 ],
23 "language": "python",
24 "language": "python",
@@ -110,7 +111,7 b''
110 "cell_type": "code",
111 "cell_type": "code",
111 "collapsed": false,
112 "collapsed": false,
112 "input": [
113 "input": [
113 "print \"a, b, c: \", ar.get()"
114 "print(\"a, b, c: \", ar.get())"
114 ],
115 ],
115 "language": "python",
116 "language": "python",
116 "metadata": {},
117 "metadata": {},
@@ -1,6 +1,6 b''
1 {
1 {
2 "metadata": {
2 "metadata": {
3 "name": "taskmap"
3 "name": ""
4 },
4 },
5 "nbformat": 3,
5 "nbformat": 3,
6 "nbformat_minor": 0,
6 "nbformat_minor": 0,
@@ -18,6 +18,7 b''
18 "cell_type": "code",
18 "cell_type": "code",
19 "collapsed": true,
19 "collapsed": true,
20 "input": [
20 "input": [
21 "from __future__ import print_function\n",
21 "from IPython.parallel import Client"
22 "from IPython.parallel import Client"
22 ],
23 ],
23 "language": "python",
24 "language": "python",
@@ -42,7 +43,7 b''
42 "collapsed": false,
43 "collapsed": false,
43 "input": [
44 "input": [
44 "result = v.map(lambda x: 2*x, range(10))\n",
45 "result = v.map(lambda x: 2*x, range(10))\n",
45 "print \"Simple, default map: \", list(result)"
46 "print(\"Simple, default map: \", list(result))"
46 ],
47 ],
47 "language": "python",
48 "language": "python",
48 "metadata": {},
49 "metadata": {},
@@ -69,9 +70,9 b''
69 "collapsed": false,
70 "collapsed": false,
70 "input": [
71 "input": [
71 "ar = v.map_async(lambda x: 2*x, range(10))\n",
72 "ar = v.map_async(lambda x: 2*x, range(10))\n",
72 "print \"Submitted tasks, got ids: \", ar.msg_ids\n",
73 "print(\"Submitted tasks, got ids: \", ar.msg_ids)\n",
73 "result = ar.get()\n",
74 "result = ar.get()\n",
74 "print \"Using a mapper: \", result"
75 "print(\"Using a mapper: \", result)"
75 ],
76 ],
76 "language": "python",
77 "language": "python",
77 "metadata": {},
78 "metadata": {},
@@ -95,7 +96,7 b''
95 "def f(x): return 2*x\n",
96 "def f(x): return 2*x\n",
96 "\n",
97 "\n",
97 "result = f.map(range(10))\n",
98 "result = f.map(range(10))\n",
98 "print \"Using a parallel function: \", result"
99 "print(\"Using a parallel function: \", result)"
99 ],
100 ],
100 "language": "python",
101 "language": "python",
101 "metadata": {},
102 "metadata": {},
General Comments 0
You need to be logged in to leave comments. Login now