Skip to content

Commit de997ae

Browse files
committed
update doc
1 parent 16d37ba commit de997ae

File tree

1 file changed

+46
-48
lines changed

1 file changed

+46
-48
lines changed

docs/tutorial_simulation/parallel_computing.ipynb

Lines changed: 46 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
},
134134
{
135135
"cell_type": "code",
136-
"execution_count": 15,
136+
"execution_count": 9,
137137
"outputs": [],
138138
"source": [
139139
"current = bm.linspace(1, 10.1, 10) # here only one parameter"
@@ -153,25 +153,25 @@
153153
},
154154
{
155155
"cell_type": "code",
156-
"execution_count": 16,
156+
"execution_count": 10,
157157
"outputs": [
158158
{
159159
"data": {
160160
"text/plain": " 0%| | 0/10 [00:00<?, ?it/s]",
161161
"application/vnd.jupyter.widget-view+json": {
162162
"version_major": 2,
163163
"version_minor": 0,
164-
"model_id": "c84de99cfcad4b528dc75cc44f911b3e"
164+
"model_id": "8760d226fe2743619106637872b9b4f4"
165165
}
166166
},
167167
"metadata": {},
168168
"output_type": "display_data"
169169
},
170170
{
171171
"data": {
172-
"text/plain": "[0, 1, 0, 0, 0, 0, 60, 62, 66, 68]"
172+
"text/plain": "[0, 0, 0, 48, 53, 57, 60, 63, 66, 68]"
173173
},
174-
"execution_count": 16,
174+
"execution_count": 10,
175175
"metadata": {},
176176
"output_type": "execute_result"
177177
}
@@ -198,14 +198,14 @@
198198
},
199199
{
200200
"cell_type": "code",
201-
"execution_count": 12,
201+
"execution_count": 11,
202202
"outputs": [],
203203
"source": [
204204
"def hh_spike_num2(bg_current): # \"input\" is the bg_current\n",
205205
" import brainpy as bp # needed to reimport packages when\n",
206206
" # run the function in Jupyter\n",
207207
"\n",
208-
" bg_current = bm.as_jax(bg_current)\n",
208+
" bg_current = bp.math.as_jax(bg_current)\n",
209209
" model = bp.neurons.HH(1)\n",
210210
" runner = bp.dyn.DSRunner(model, monitors=['spike'], inputs=['input', bg_current])\n",
211211
" runner.run(1000.)\n",
@@ -228,25 +228,25 @@
228228
},
229229
{
230230
"cell_type": "code",
231-
"execution_count": 17,
231+
"execution_count": 12,
232232
"outputs": [
233233
{
234234
"data": {
235235
"text/plain": " 0%| | 0/10 [00:00<?, ?it/s]",
236236
"application/vnd.jupyter.widget-view+json": {
237237
"version_major": 2,
238238
"version_minor": 0,
239-
"model_id": "a85026f739154dfd9627ecd4964aabb3"
239+
"model_id": "10d02874c8584954a79129168536accd"
240240
}
241241
},
242242
"metadata": {},
243243
"output_type": "display_data"
244244
},
245245
{
246246
"data": {
247-
"text/plain": "[0, 1, 0, 0, 53, 57, 58, 63, 65, 68]"
247+
"text/plain": "[0, 0, 1, 47, 0, 57, 60, 63, 66, 68]"
248248
},
249-
"execution_count": 17,
249+
"execution_count": 12,
250250
"metadata": {},
251251
"output_type": "execute_result"
252252
}
@@ -261,6 +261,15 @@
261261
"collapsed": false
262262
}
263263
},
264+
{
265+
"cell_type": "markdown",
266+
"source": [
267+
"If you think that the order of the running results does not matter, you can also use ``cpu_unordered_parallel()`` function. This can maximize the running efficiency of all processors, since all workers run with a non-blocking and unordered manner."
268+
],
269+
"metadata": {
270+
"collapsed": false
271+
}
272+
},
264273
{
265274
"cell_type": "markdown",
266275
"source": [
@@ -313,7 +322,7 @@
313322
},
314323
{
315324
"cell_type": "code",
316-
"execution_count": 18,
325+
"execution_count": 3,
317326
"outputs": [],
318327
"source": [
319328
"def hh_spike_num3(bg_current): # \"input\" is the bg_current\n",
@@ -329,15 +338,15 @@
329338
},
330339
{
331340
"cell_type": "code",
332-
"execution_count": 19,
341+
"execution_count": 14,
333342
"outputs": [
334343
{
335344
"data": {
336345
"text/plain": " 0%| | 0/10000 [00:00<?, ?it/s]",
337346
"application/vnd.jupyter.widget-view+json": {
338347
"version_major": 2,
339348
"version_minor": 0,
340-
"model_id": "63fd00c7f08c4f89891c286bcad2b55d"
349+
"model_id": "a0c1b9e2544c4b7d9324b5a1d257dab8"
341350
}
342351
},
343352
"metadata": {},
@@ -349,7 +358,7 @@
349358
"application/vnd.jupyter.widget-view+json": {
350359
"version_major": 2,
351360
"version_minor": 0,
352-
"model_id": "4826a51fb553470fa0fb4149a5b3d7e6"
361+
"model_id": "9e534fb4c06d445b8df7ed5300d25bd1"
353362
}
354363
},
355364
"metadata": {},
@@ -361,7 +370,7 @@
361370
"application/vnd.jupyter.widget-view+json": {
362371
"version_major": 2,
363372
"version_minor": 0,
364-
"model_id": "2dacbf527e5e4b2f8a83be2cc94d3560"
373+
"model_id": "3d7cb69912994ee7ac3e44cde95373b8"
365374
}
366375
},
367376
"metadata": {},
@@ -373,17 +382,17 @@
373382
"application/vnd.jupyter.widget-view+json": {
374383
"version_major": 2,
375384
"version_minor": 0,
376-
"model_id": "1224b579ba7d49e4a930f6e7ce2d82fe"
385+
"model_id": "903708f92cbf4e2086157712080635b7"
377386
}
378387
},
379388
"metadata": {},
380389
"output_type": "display_data"
381390
},
382391
{
383392
"data": {
384-
"text/plain": "JaxArray([ 0, 1, 1, 47, 53, 57, 45, 62, 66, 68], dtype=int32)"
393+
"text/plain": "JaxArray([ 0, 0, 0, 0, 0, 0, 60, 63, 66, 68], dtype=int32)"
385394
},
386-
"execution_count": 19,
395+
"execution_count": 14,
387396
"metadata": {},
388397
"output_type": "execute_result"
389398
}
@@ -408,15 +417,15 @@
408417
},
409418
{
410419
"cell_type": "code",
411-
"execution_count": 20,
420+
"execution_count": 15,
412421
"outputs": [
413422
{
414423
"data": {
415424
"text/plain": " 0%| | 0/10000 [00:00<?, ?it/s]",
416425
"application/vnd.jupyter.widget-view+json": {
417426
"version_major": 2,
418427
"version_minor": 0,
419-
"model_id": "845008715fb04111bea98520eb0d140e"
428+
"model_id": "ff15303b2a394ce488fcf4d65ce3eca8"
420429
}
421430
},
422431
"metadata": {},
@@ -428,7 +437,7 @@
428437
"application/vnd.jupyter.widget-view+json": {
429438
"version_major": 2,
430439
"version_minor": 0,
431-
"model_id": "919c9c8484144eb48a77d7172162b599"
440+
"model_id": "52b82eeb8c874946aeceaed549fc024b"
432441
}
433442
},
434443
"metadata": {},
@@ -440,7 +449,7 @@
440449
"application/vnd.jupyter.widget-view+json": {
441450
"version_major": 2,
442451
"version_minor": 0,
443-
"model_id": "dda8f8878d1643ec9c4bdfd2bab5be9f"
452+
"model_id": "f974774c2e1948bb87b1307d34bc69ee"
444453
}
445454
},
446455
"metadata": {},
@@ -452,17 +461,17 @@
452461
"application/vnd.jupyter.widget-view+json": {
453462
"version_major": 2,
454463
"version_minor": 0,
455-
"model_id": "e21c4351ca884c43a54df14763b1373d"
464+
"model_id": "7ba11b94834d435eb1791948c8db2048"
456465
}
457466
},
458467
"metadata": {},
459468
"output_type": "display_data"
460469
},
461470
{
462471
"data": {
463-
"text/plain": "array([ 0, 0, 1, 48, 53, 57, 60, 63, 66, 68])"
472+
"text/plain": "array([ 0, 0, 0, 0, 0, 55, 58, 59, 65, 68])"
464473
},
465-
"execution_count": 20,
474+
"execution_count": 15,
466475
"metadata": {},
467476
"output_type": "execute_result"
468477
}
@@ -532,45 +541,33 @@
532541
},
533542
{
534543
"cell_type": "code",
535-
"execution_count": 21,
544+
"execution_count": 4,
536545
"outputs": [
537546
{
538547
"data": {
539548
"text/plain": " 0%| | 0/10000 [00:00<?, ?it/s]",
540549
"application/vnd.jupyter.widget-view+json": {
541550
"version_major": 2,
542551
"version_minor": 0,
543-
"model_id": "309900c672e7486cac5ef417b2e821de"
552+
"model_id": "ffad3289fd574502a4a4862ab1f767fe"
544553
}
545554
},
546555
"metadata": {},
547556
"output_type": "display_data"
548557
},
549558
{
550559
"data": {
551-
"text/plain": " 0%| | 0/10000 [00:00<?, ?it/s]",
552-
"application/vnd.jupyter.widget-view+json": {
553-
"version_major": 2,
554-
"version_minor": 0,
555-
"model_id": "9dedc7a8c96c4f6ab4d290f246b94274"
556-
}
557-
},
558-
"metadata": {},
559-
"output_type": "display_data"
560-
},
561-
{
562-
"data": {
563-
"text/plain": "array([ 0, 0, 0, 0, 0, 0, 0, 49, 52, 54, 0, 50, 59, 61, 62, 63, 65,\n 66, 67, 68])"
560+
"text/plain": "array([ 0, 0, 0, 0, 0, 0, 0, 49, 52, 54, 56, 58, 59, 61, 62, 63, 65,\n 66, 67, 68])"
564561
},
565-
"execution_count": 21,
562+
"execution_count": 4,
566563
"metadata": {},
567564
"output_type": "execute_result"
568565
}
569566
],
570567
"source": [
571-
"bp.math.set_host_device_count(10)\n",
568+
"bp.math.set_host_device_count(10) # this should place on the top of the file\n",
572569
"current = bm.linspace(1., 10.1, 20)\n",
573-
"r = bp.running.jax_vectorize_map(hh_spike_num3, [current], num_parallel=10, clear_buffer=True)\n",
570+
"r = bp.running.jax_parallelize_map(hh_spike_num3, [current], num_parallel=10, clear_buffer=True)\n",
574571
"r"
575572
],
576573
"metadata": {
@@ -587,10 +584,10 @@
587584
}
588585
},
589586
{
590-
"cell_type": "code",
591-
"execution_count": null,
592-
"outputs": [],
587+
"cell_type": "markdown",
593588
"source": [
589+
"```python\n",
590+
"\n",
594591
"#!/bin/bash\n",
595592
"#SBATCH -J <name>\n",
596593
"#SBATCH -o <file name>\n",
@@ -599,7 +596,8 @@
599596
"#SBATCH -N <int>\n",
600597
"#SBATCH -c <int>\n",
601598
"\n",
602-
"python your_script.py"
599+
"python your_script.py\n",
600+
"```"
603601
],
604602
"metadata": {
605603
"collapsed": false

0 commit comments

Comments
 (0)