Skip to content

Commit

Permalink
Merge pull request #303 from chaoming0625/parallel_doc
Browse files Browse the repository at this point in the history
update doc
  • Loading branch information
chaoming0625 authored Nov 25, 2022
2 parents 68bfc36 + de997ae commit 4c3433d
Showing 1 changed file with 46 additions and 48 deletions.
94 changes: 46 additions & 48 deletions docs/tutorial_simulation/parallel_computing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 9,
"outputs": [],
"source": [
"current = bm.linspace(1, 10.1, 10) # here only one parameter"
Expand All @@ -153,25 +153,25 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 10,
"outputs": [
{
"data": {
"text/plain": " 0%| | 0/10 [00:00<?, ?it/s]",
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "c84de99cfcad4b528dc75cc44f911b3e"
"model_id": "8760d226fe2743619106637872b9b4f4"
}
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": "[0, 1, 0, 0, 0, 0, 60, 62, 66, 68]"
"text/plain": "[0, 0, 0, 48, 53, 57, 60, 63, 66, 68]"
},
"execution_count": 16,
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -198,14 +198,14 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 11,
"outputs": [],
"source": [
"def hh_spike_num2(bg_current): # \"input\" is the bg_current\n",
" import brainpy as bp # needed to reimport packages when\n",
" # run the function in Jupyter\n",
"\n",
" bg_current = bm.as_jax(bg_current)\n",
" bg_current = bp.math.as_jax(bg_current)\n",
" model = bp.neurons.HH(1)\n",
" runner = bp.dyn.DSRunner(model, monitors=['spike'], inputs=['input', bg_current])\n",
" runner.run(1000.)\n",
Expand All @@ -228,25 +228,25 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 12,
"outputs": [
{
"data": {
"text/plain": " 0%| | 0/10 [00:00<?, ?it/s]",
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "a85026f739154dfd9627ecd4964aabb3"
"model_id": "10d02874c8584954a79129168536accd"
}
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": "[0, 1, 0, 0, 53, 57, 58, 63, 65, 68]"
"text/plain": "[0, 0, 1, 47, 0, 57, 60, 63, 66, 68]"
},
"execution_count": 17,
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -261,6 +261,15 @@
"collapsed": false
}
},
{
"cell_type": "markdown",
"source": [
"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."
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
"source": [
Expand Down Expand Up @@ -313,7 +322,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 3,
"outputs": [],
"source": [
"def hh_spike_num3(bg_current): # \"input\" is the bg_current\n",
Expand All @@ -329,15 +338,15 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 14,
"outputs": [
{
"data": {
"text/plain": " 0%| | 0/10000 [00:00<?, ?it/s]",
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "63fd00c7f08c4f89891c286bcad2b55d"
"model_id": "a0c1b9e2544c4b7d9324b5a1d257dab8"
}
},
"metadata": {},
Expand All @@ -349,7 +358,7 @@
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "4826a51fb553470fa0fb4149a5b3d7e6"
"model_id": "9e534fb4c06d445b8df7ed5300d25bd1"
}
},
"metadata": {},
Expand All @@ -361,7 +370,7 @@
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "2dacbf527e5e4b2f8a83be2cc94d3560"
"model_id": "3d7cb69912994ee7ac3e44cde95373b8"
}
},
"metadata": {},
Expand All @@ -373,17 +382,17 @@
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "1224b579ba7d49e4a930f6e7ce2d82fe"
"model_id": "903708f92cbf4e2086157712080635b7"
}
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": "JaxArray([ 0, 1, 1, 47, 53, 57, 45, 62, 66, 68], dtype=int32)"
"text/plain": "JaxArray([ 0, 0, 0, 0, 0, 0, 60, 63, 66, 68], dtype=int32)"
},
"execution_count": 19,
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -408,15 +417,15 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 15,
"outputs": [
{
"data": {
"text/plain": " 0%| | 0/10000 [00:00<?, ?it/s]",
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "845008715fb04111bea98520eb0d140e"
"model_id": "ff15303b2a394ce488fcf4d65ce3eca8"
}
},
"metadata": {},
Expand All @@ -428,7 +437,7 @@
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "919c9c8484144eb48a77d7172162b599"
"model_id": "52b82eeb8c874946aeceaed549fc024b"
}
},
"metadata": {},
Expand All @@ -440,7 +449,7 @@
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "dda8f8878d1643ec9c4bdfd2bab5be9f"
"model_id": "f974774c2e1948bb87b1307d34bc69ee"
}
},
"metadata": {},
Expand All @@ -452,17 +461,17 @@
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "e21c4351ca884c43a54df14763b1373d"
"model_id": "7ba11b94834d435eb1791948c8db2048"
}
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": "array([ 0, 0, 1, 48, 53, 57, 60, 63, 66, 68])"
"text/plain": "array([ 0, 0, 0, 0, 0, 55, 58, 59, 65, 68])"
},
"execution_count": 20,
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -532,45 +541,33 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 4,
"outputs": [
{
"data": {
"text/plain": " 0%| | 0/10000 [00:00<?, ?it/s]",
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "309900c672e7486cac5ef417b2e821de"
"model_id": "ffad3289fd574502a4a4862ab1f767fe"
}
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": " 0%| | 0/10000 [00:00<?, ?it/s]",
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "9dedc7a8c96c4f6ab4d290f246b94274"
}
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": "array([ 0, 0, 0, 0, 0, 0, 0, 49, 52, 54, 0, 50, 59, 61, 62, 63, 65,\n 66, 67, 68])"
"text/plain": "array([ 0, 0, 0, 0, 0, 0, 0, 49, 52, 54, 56, 58, 59, 61, 62, 63, 65,\n 66, 67, 68])"
},
"execution_count": 21,
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bp.math.set_host_device_count(10)\n",
"bp.math.set_host_device_count(10) # this should place on the top of the file\n",
"current = bm.linspace(1., 10.1, 20)\n",
"r = bp.running.jax_vectorize_map(hh_spike_num3, [current], num_parallel=10, clear_buffer=True)\n",
"r = bp.running.jax_parallelize_map(hh_spike_num3, [current], num_parallel=10, clear_buffer=True)\n",
"r"
],
"metadata": {
Expand All @@ -587,10 +584,10 @@
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"cell_type": "markdown",
"source": [
"```python\n",
"\n",
"#!/bin/bash\n",
"#SBATCH -J <name>\n",
"#SBATCH -o <file name>\n",
Expand All @@ -599,7 +596,8 @@
"#SBATCH -N <int>\n",
"#SBATCH -c <int>\n",
"\n",
"python your_script.py"
"python your_script.py\n",
"```"
],
"metadata": {
"collapsed": false
Expand Down

0 comments on commit 4c3433d

Please sign in to comment.