<commit_before>{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Running NetPyNE in a Jupyter Notebook\n",
    "\n",
    "## Preliminaries\n",
    "\n",
    "We don't want to affect your system in any way, so we will operate from a virtual environment. These preliminary steps must be completed before going through this tutorial. You can't complete the preliminary steps from within Jupyter because you can't enter a virtual environment in Jupyter, you have to switch to a kernel made from your virtual environment.\n",
    "\n",
    "First we will empty your path of all but essentials. Then we will create and activate a virtual environment. Then we will update pip and install some necessary packages in the virtual environment, and finally we will create a kernel from the virtual environment that can be used by Jupyter.  \n",
    "\n",
    "### Create and activate a virtual environment\n",
    "\n",
    "First, open a Terminal and switch to the directory where you downloaded this notebook:\n",
    "\n",
    "    cd netpyne_tuts/netpyne/netpyne/tutorials/netpyne_tut1\n",
    "\n",
    "Next, clear your PATH of all but the essentials. Don't worry, your normal PATH will return the next time you open a Terminal.\n",
    "\n",
    "    export PATH=/bin:/usr/bin\n",
    "    \n",
    "Next, create a virtual environment named \"env\":\n",
    "\n",
    "    python3 -m venv env\n",
    "    \n",
    "Check to see where you are currently running Python from:\n",
    "\n",
    "    which python3\n",
    "    \n",
    "Enter your new virtual environment:\n",
    "\n",
    "    source env/bin/activate\n",
    "    \n",
    "You should see in your prompt that you are in **env**.  \n",
    "\n",
    "Now see where you are running Python from:\n",
    "\n",
    "    which python3\n",
    "    \n",
    "It should come from inside your new virtual environment.  Any changes we make here will only exist in the \"env\" directory that was created here.  \n",
    "\n",
    "To exit your virtual environment, enter:\n",
    "\n",
    "    deactivate\n",
    "    \n",
    "Your prompt should reflect the change.  To get back in, enter:\n",
    "\n",
    "    source env/bin/activate\n",
    "    \n",
    "### Update pip and install packages\n",
    "\n",
    "We will now update pip and install some necessary packages in the virtual environment. From inside your virtual environment, enter:\n",
    "\n",
    "    python3 -m pip install --upgrade pip\n",
    "    python3 -m pip install --upgrade ipython\n",
    "    python3 -m pip install --upgrade ipykernel\n",
    "    python3 -m pip install --upgrade jupyter\n",
    "    \n",
    "### Make a Jupyter kernel out of this virtual environment\n",
    "\n",
    "Now we will create a kernel that can be used by Jupyter Notebooks.  Enter:\n",
    "\n",
    "    ipython kernel install --user --name=env\n",
    "\n",
    "### Launch this notebook in Jupyter Notebook\n",
    "\n",
    "Now we will launch Jupyter from within the virtual environment.  Enter:\n",
    "\n",
    "    jupyter notebook netpyne_tut1.ipynb\n",
    "    \n",
    "This should open a web browser with Jupyter running this notebook.  From the menu bar, click on **Kernel**, hover over **Change kernel** and select **env**.  We are now operating in the virtual environment (see **env** in the upper right instead of **Python 3**) and can begin the tutorial.\n",
    "\n",
    "### To run this again in the future\n",
    "\n",
    "Be sure to enter your virtual environment before running Jupyter!\n",
    "\n",
    "    cd Desktop/netpyne_tut1\n",
    "    source env/bin/activate\n",
    "    jupyter notebook netpyne_tut1.ipynb\n",
    "    \n",
    "And then make sure you are in the **env** kernel in Jupyter.\n",
    "\n",
    "## Single line command\n",
    "\n",
    "Entering the following single line command should perform all the previous steps and launch this tutorial in a Jupyter notebook in your web browser:\n",
    "\n",
    "    git clone https://github.com/Neurosim-lab/netpyne.git && cd netpyne/netpyne/tutorials/netpyne_tut1 && export PATH=/bin:/usr/bin && python3 -m venv env && source env/bin/activate && python3 -m pip install --upgrade pip && python3 -m pip install --upgrade ipython && python3 -m pip install --upgrade ipykernel && python3 -m pip install --upgrade jupyter && ipython kernel install --user --name=env && jupyter notebook netpyne_tut1.ipynb\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Software installation\n",
    "\n",
    "Once you are in the **env** kernel in Jupyter, you can execute the following commands to install the software.  The exclamation point at the beginning means this is a command to be executed in your terminal (in your current virtual environment / kernel).  You can also execute these commands directly in your terminal, just leave off the exclamation point.\n",
    "\n",
    "First we will install NEURON.  Shift+Enter the following:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "!python3 -m pip install --upgrade neuron"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now we will install NetPyNE.  Shift+Enter the following:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "!python3 -m pip install --upgrade netpyne"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Tutorial 1 -- a simple network with one population\n",
    "\n",
    "Now we are ready to start NetPyNE Tutorial 1, which will create a simple network model we can simulate.  We will create a fairly simple network model of 40 pyramidal-like, two-compartment neurons with standard Hodgkin-Huxley dynamics in the somas and passive dynamics in the dendrites.  We will then connect the neurons randomly with a 10% probability of connection using a standard double-exponential synapse model.  Finally, we will add a current clamp stimulus to one cell to activate the network.  Then we will explore the model."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Instantiate network parameters and simulation configuration\n",
    "\n",
    "You need two things to define a model/simulation in NetPyNE: 1) the parameters of the network and all its components (**netParams**) and 2) the configuration of the simulation (**simConfig**).  These requirements exist as objects in NetPyNE.  Let's instantiate them now."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true<commit_msg>Updated netpyne_tut1 with new install info<commit_after>{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Running NetPyNE in a Jupyter Notebook\n",
    "\n",
    "## Preliminaries\n",
    "\n",
    "Hopefully you already completed these preliminaries by following the instructions at https://github.com/Neurosim-lab/netpyne/blob/development/netpyne/tutorials/README.md.  We will now walk you through how we installed the NetPyNE tutorials.\n",
    "\n",
    "We don't want to affect your system in any way, so we will operate from a virtual environment. These preliminary steps must be completed before going through this tutorial. You can't complete the preliminary steps from within Jupyter because you can't enter a virtual environment in Jupyter, you have to switch to a kernel made from your virtual environment.\n",
    "\n",
    "First we will empty your path of all but essentials. Then we will create and activate a virtual environment. Then we will update pip and install some necessary packages in the virtual environment, and finally we will create a kernel from the virtual environment that can be used by Jupyter.  \n",
    "\n",
    "### Create and activate a virtual environment\n",
    "\n",
    "First, open a Terminal and switch to the directory where you downloaded this notebook:\n",
    "\n",
    "    cd netpyne_tuts\n",
    "\n",
    "Next, clear your PATH of all but the essentials. Don't worry, your normal PATH will return the next time you open a Terminal.\n",
    "\n",
    "    export PATH=/bin:/usr/bin\n",
    "    \n",
    "Next, create a virtual environment named \"env\":\n",
    "\n",
    "    python3 -m venv env\n",
    "    \n",
    "Check to see where you are currently running Python from:\n",
    "\n",
    "    which python3\n",
    "    \n",
    "Enter your new virtual environment:\n",
    "\n",
    "    source env/bin/activate\n",
    "    \n",
    "You should see in your prompt that you are in **env**.  \n",
    "\n",
    "Now see where you are running Python from:\n",
    "\n",
    "    which python3\n",
    "    \n",
    "It should come from inside your new virtual environment.  Any changes we make here will only exist in the **env** directory that was created here.  \n",
    "\n",
    "To exit your virtual environment, enter:\n",
    "\n",
    "    deactivate\n",
    "    \n",
    "Your prompt should reflect the change.  To get back in, enter:\n",
    "\n",
    "    source env/bin/activate\n",
    "    \n",
    "### Update pip and install packages\n",
    "\n",
    "We will now update pip and install some necessary packages in the virtual environment. From inside your virtual environment, enter:\n",
    "\n",
    "    python3 -m pip install --upgrade pip\n",
    "    python3 -m pip install --upgrade ipython\n",
    "    python3 -m pip install --upgrade ipykernel\n",
    "    python3 -m pip install --upgrade jupyter\n",
    "    \n",
    "### Make a Jupyter kernel out of this virtual environment\n",
    "\n",
    "Now we will create a kernel that can be used by Jupyter Notebooks.  Enter:\n",
    "\n",
    "    ipython kernel install --user --name=env\n",
    "\n",
    "### Install NEURON and NetPyNE\n",
    "\n",
    "    python3 -m pip install --upgrade neuron\n",
    "    python3 -m pip install --upgrade netpyne\n",
    "    \n",
    "### Launch this notebook in Jupyter Notebook\n",
    "\n",
    "Now we will launch Jupyter from within the virtual environment.  Enter:\n",
    "\n",
    "    jupyter notebook netpyne_tut1.ipynb\n",
    "    \n",
    "This should open a web browser with Jupyter running this notebook.  From the menu bar, click on **Kernel**, hover over **Change kernel** and select **env**.  We are now operating in the virtual environment (see **env** in the upper right instead of **Python 3**) and can begin the tutorial.\n",
    "\n",
    "## Single line command\n",
    "\n",
    "Entering the following single line command should perform all the previous steps and launch this tutorial in a Jupyter notebook in your web browser:\n",
    "\n",
    "    git clone https://github.com/Neurosim-lab/netpyne.git && cd netpyne/netpyne/tutorials/netpyne_tut1 && export PATH=/bin:/usr/bin && python3 -m venv env && source env/bin/activate && python3 -m pip install --upgrade pip && python3 -m pip install --upgrade ipython && python3 -m pip install --upgrade ipykernel && python3 -m pip install --upgrade jupyter && ipython kernel install --user --name=env && jupyter notebook netpyne_tut1.ipynb\n",
    "\n",
    "\n",
    "## To run this again in the future\n",
    "\n",
    "Be sure to enter your virtual environment before running Jupyter!\n",
    "\n",
    "    cd netpyne_tuts\n",
    "    source env/bin/activate\n",
    "    jupyter notebook netpyne_tut1.ipynb\n",
    "    \n",
    "And then make sure you are in the **env** kernel in Jupyter.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Tutorial 1 -- a simple network with one population\n",
    "\n",
    "Now we are ready to start NetPyNE Tutorial 1, which will create a simple network model we can simulate.  We will create a fairly simple network model of 40 pyramidal-like, two-compartment neurons with standard Hodgkin-Huxley dynamics in the somas and passive dynamics in the dendrites.  We will then connect the neurons randomly with a 10% probability of connection using a standard double-exponential synapse model.  Finally, we will add a current clamp stimulus to one cell to activate the network.  Then we will explore the model."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Instantiate network parameters and simulation configuration\n",
    "\n",
    "You need two things to define a model/simulation in NetPyNE: 1) the parameters of the network and all its components (**netParams**) and 2) the configuration of the simulation (**simConfig**).  These requirements exist as objects in NetPyNE.  Let's instantiate them now."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
{'fraction_non_alphanumeric': 0.12140077821011673, 'fraction_numerical': 0.00443579766536965, 'mean_word_length': 2.8009464655427387, 'pattern_counts': {'":': 46, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4146582', 'n_tokens_mistral': 3978, 'n_tokens_neox': 3848, 'n_words': 1593}