Skip to content

Commit

Permalink
Updated define_parameters so sectionlist can be a list of string
Browse files Browse the repository at this point in the history
  • Loading branch information
Hjorthmedh committed Jul 23, 2024
1 parent 157384e commit ebf7057
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,56 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "5b55f23d-62ac-4433-8639-07870af8c40a",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Reading connectivity from data/connectivity.json\n",
"Adding neurons: dspn from dir data/dspn\n",
"Writing networks/neuromodulation_example_anu_with_real_dspn/network-config.json\n",
"Writing networks/neuromodulation_example_anu_with_real_dspn/network-config.json\n",
"Placing neurons\n",
"Network path: networks/neuromodulation_example_anu_with_real_dspn\n",
"Reading SNUDDA_DATA=None from networks/neuromodulation_example_anu_with_real_dspn/network-config.json\n",
"Reading SNUDDA_DATA=/home/hjorth/HBP/Snudda/snudda/utils/../data from networks/neuromodulation_example_anu_with_real_dspn/network-synapses.hdf5\n",
"No n_putative_points and putative_density, setting n_putative_points = 63\n",
"(this must be larger than the number of neurons you want to place)\n",
"Generating 63 points for networks/neuromodulation_example_anu_with_real_dspn/mesh/Cube-cube-mesh-2.917951293943981e-05.obj\n",
"Filtering, keeping inside points: 4 / 26\n",
"neuron_name = 'dspn_0', num = 2, neuron_path = 'data/dspn/str-dspn-e150602_c1_D1-mWT-0728MSN01-v20211026'\n",
"stop_parallel disabled, to keep pool running.\n",
"\n",
"Execution time: 0.0s\n",
"Touch detection\n",
"Network path: networks/neuromodulation_example_anu_with_real_dspn\n",
"Reading SNUDDA_DATA=None from networks/neuromodulation_example_anu_with_real_dspn/network-config.json\n",
"Reading SNUDDA_DATA=/home/hjorth/HBP/Snudda/snudda/utils/../data from networks/neuromodulation_example_anu_with_real_dspn/network-synapses.hdf5\n",
"No d_view specified, running distribute neurons in serial\n",
"Processing hyper voxel : 0/27 (2 neurons)\n",
"Processing hyper voxel : 1/27 (2 neurons)\n",
"Processing hyper voxel : 3/27 (2 neurons)\n",
"Processing hyper voxel : 4/27 (2 neurons)\n",
"Processing hyper voxel : 9/27 (2 neurons)\n",
"Processing hyper voxel : 10/27 (2 neurons)\n",
"Processing hyper voxel : 12/27 (2 neurons)\n",
"Processing hyper voxel : 13/27 (2 neurons)\n",
"Reading SNUDDA_DATA=None from networks/neuromodulation_example_anu_with_real_dspn/network-config.json\n",
"stop_parallel disabled, to keep pool running.\n",
"\n",
"Execution time: 0.5s\n",
"Prune synapses\n",
"Network path: networks/neuromodulation_example_anu_with_real_dspn\n",
"No file networks/neuromodulation_example_anu_with_real_dspn/pruning_merge_info.json\n",
"stop_parallel disabled, to keep pool running.\n",
"\n",
"Execution time: 0.5s\n"
]
}
],
"source": [
"import os\n",
"from snudda import Snudda\n",
Expand All @@ -69,21 +115,87 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "41e96e4a-0f52-4d77-8a1f-ba8d270b9b78",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Setting up inputs, assuming input.json exists\n",
"Reading SNUDDA_DATA=None from networks/neuromodulation_example_anu_with_real_dspn/network-config.json\n",
"Reading SNUDDA_DATA=/home/hjorth/HBP/Snudda/snudda/utils/../data from networks/neuromodulation_example_anu_with_real_dspn/network-synapses.hdf5\n",
"Writing input spikes to networks/neuromodulation_example_anu_with_real_dspn/input-spikes.hdf5\n",
"Reading SNUDDA_DATA=None from networks/neuromodulation_example_anu_with_real_dspn/network-config.json\n",
"Reading SNUDDA_DATA=/home/hjorth/HBP/Snudda/snudda/utils/../data from networks/neuromodulation_example_anu_with_real_dspn/network-synapses.hdf5\n",
"!!! Warning, combining definition of cortical with cortical input for neuron dspn_0 0 (meta modified by input_config)\n",
"Writing spikes to networks/neuromodulation_example_anu_with_real_dspn/input-spikes.hdf5\n",
"stop_parallel disabled, to keep pool running.\n",
"\n",
"Execution time: 0.6s\n"
]
},
{
"data": {
"text/plain": [
"<snudda.input.input.SnuddaInput at 0xffff90377b20>"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"input_config = os.path.join(\"data\", \"input_v2.json\")\n",
"snudda.setup_input(input_config=input_config)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "d019b580-4193-4321-9ee8-9bdd3988209f",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Using input file networks/neuromodulation_example_anu_with_real_dspn/input-spikes.hdf5\n",
"NEURON mechanisms already compiled, make sure you have the correct version of NEURON modules.\n",
"If you delete x86_64, aarch64, arm64 directories (or nrnmech.dll) then you will force a recompilation of the modules.\n",
"Reading SNUDDA_DATA=None from networks/neuromodulation_example_anu_with_real_dspn/network-config.json\n",
"Reading SNUDDA_DATA=/home/hjorth/HBP/Snudda/snudda/utils/../data from networks/neuromodulation_example_anu_with_real_dspn/network-synapses.hdf5\n",
"Using network_file: networks/neuromodulation_example_anu_with_real_dspn/network-synapses.hdf5\n",
"Using input_file: networks/neuromodulation_example_anu_with_real_dspn/input-spikes.hdf5\n",
"Using output_file: networks/neuromodulation_example_anu_with_real_dspn/simulation/output.hdf5\n",
"Using logFile: networks/neuromodulation_example_anu_with_real_dspn/log/network-simulation-log.txt-0\n",
"Worker 0 : Loading network from networks/neuromodulation_example_anu_with_real_dspn/network-synapses.hdf5\n",
"Loading config file networks/neuromodulation_example_anu_with_real_dspn/network-config.json\n",
"0 : Memory status: 61% free\n",
"Distributing neurons.\n",
"Setup neurons\n",
"Node 0 - cell 0 dspn_0\n"
]
},
{
"ename": "AttributeError",
"evalue": "mod_pka_g_min_kir_ms, the mechanism does not exist at dspn_0[0].axon[0](0.5)",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[3], line 3\u001b[0m\n\u001b[1;32m 1\u001b[0m mech_dir \u001b[38;5;241m=\u001b[39m os\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39mjoin(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m..\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m..\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m..\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m..\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mBasalGangliaData\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdata\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mneurons\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmechanisms\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 2\u001b[0m sample_dt \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;66;03m# 0.00005\u001b[39;00m\n\u001b[0;32m----> 3\u001b[0m sim \u001b[38;5;241m=\u001b[39m \u001b[43msnudda\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msimulate\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtime\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mmech_dir\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmech_dir\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mverbose\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43msample_dt\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43msample_dt\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[0;32m~/HBP/Snudda/snudda/core.py:815\u001b[0m, in \u001b[0;36mSnudda.simulate\u001b[0;34m(self, network_file, input_file, output_file, snudda_data, time, mech_dir, disable_synapses, disable_gj, record_volt, record_all, sample_dt, simulation_config, export_core_neuron, verbose)\u001b[0m\n\u001b[1;32m 805\u001b[0m \u001b[38;5;66;03m# Simulate is deterministic, no random seed.\u001b[39;00m\n\u001b[1;32m 806\u001b[0m sim \u001b[38;5;241m=\u001b[39m SnuddaSimulate(network_file\u001b[38;5;241m=\u001b[39mnetwork_file,\n\u001b[1;32m 807\u001b[0m input_file\u001b[38;5;241m=\u001b[39minput_file,\n\u001b[1;32m 808\u001b[0m output_file\u001b[38;5;241m=\u001b[39moutput_file,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 813\u001b[0m sample_dt\u001b[38;5;241m=\u001b[39msample_dt,\n\u001b[1;32m 814\u001b[0m verbose\u001b[38;5;241m=\u001b[39mverbose)\n\u001b[0;32m--> 815\u001b[0m \u001b[43msim\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msetup\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 816\u001b[0m sim\u001b[38;5;241m.\u001b[39madd_external_input()\n\u001b[1;32m 818\u001b[0m sim\u001b[38;5;241m.\u001b[39mcheck_memory_status()\n",
"File \u001b[0;32m~/HBP/Snudda/snudda/simulate/simulate.py:274\u001b[0m, in \u001b[0;36mSnuddaSimulate.setup\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 271\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mdistribute_neurons()\n\u001b[1;32m 272\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mpc\u001b[38;5;241m.\u001b[39mbarrier()\n\u001b[0;32m--> 274\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msetup_neurons\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 275\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mcheck_memory_status()\n\u001b[1;32m 276\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mpc\u001b[38;5;241m.\u001b[39mbarrier()\n",
"File \u001b[0;32m~/HBP/Snudda/snudda/simulate/simulate.py:667\u001b[0m, in \u001b[0;36mSnuddaSimulate.setup_neurons\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 664\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mwrite_log(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mNode \u001b[39m\u001b[38;5;132;01m{\u001b[39;00m\u001b[38;5;28mint\u001b[39m(\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mpc\u001b[38;5;241m.\u001b[39mid())\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m - cell \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mID\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mname\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 666\u001b[0m \u001b[38;5;66;03m# We need to instantiate the cell\u001b[39;00m\n\u001b[0;32m--> 667\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mneurons\u001b[49m\u001b[43m[\u001b[49m\u001b[43mID\u001b[49m\u001b[43m]\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minstantiate\u001b[49m\u001b[43m(\u001b[49m\u001b[43msim\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msim\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 668\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mset_resting_voltage(ID)\n\u001b[1;32m 670\u001b[0m \u001b[38;5;66;03m# !!! DIRTY FIX for\u001b[39;00m\n\u001b[1;32m 671\u001b[0m \u001b[38;5;66;03m# https://github.com/BlueBrain/BluePyOpt/blob/master/bluepyopt/ephys/morphologies.py\u001b[39;00m\n\u001b[1;32m 672\u001b[0m \u001b[38;5;66;03m# This is likely the offending line, that pushes a segment to the stack\u001b[39;00m\n\u001b[1;32m 673\u001b[0m \u001b[38;5;66;03m# --> sim.neuron.h.execute('create axon[2]', icell)\u001b[39;00m\n",
"File \u001b[0;32m~/HBP/Snudda/snudda/neurons/neuron_model_extended.py:445\u001b[0m, in \u001b[0;36mNeuronModel.instantiate\u001b[0;34m(self, sim)\u001b[0m\n\u001b[1;32m 443\u001b[0m mechanism\u001b[38;5;241m.\u001b[39minstantiate(sim\u001b[38;5;241m=\u001b[39msim, icell\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39micell)\n\u001b[1;32m 444\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m param \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mparams\u001b[38;5;241m.\u001b[39mvalues():\n\u001b[0;32m--> 445\u001b[0m \u001b[43mparam\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minstantiate\u001b[49m\u001b[43m(\u001b[49m\u001b[43msim\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43msim\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43micell\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43micell\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 447\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmodulation:\n\u001b[1;32m 448\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmodulation\u001b[38;5;241m.\u001b[39mload_json()\n",
"File \u001b[0;32m~/HBP/Snudda/venv/lib/python3.9/site-packages/bluepyopt/ephys/parameters.py:381\u001b[0m, in \u001b[0;36mNrnRangeParameter.instantiate\u001b[0;34m(self, sim, icell, params)\u001b[0m\n\u001b[1;32m 379\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m isection \u001b[38;5;129;01min\u001b[39;00m location\u001b[38;5;241m.\u001b[39minstantiate(sim\u001b[38;5;241m=\u001b[39msim, icell\u001b[38;5;241m=\u001b[39micell):\n\u001b[1;32m 380\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m seg \u001b[38;5;129;01min\u001b[39;00m isection:\n\u001b[0;32m--> 381\u001b[0m \u001b[38;5;28;43msetattr\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mseg\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;132;43;01m%s\u001b[39;49;00m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m%\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mparam_name\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 382\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mvalue_scale_func\u001b[49m\u001b[43m(\u001b[49m\u001b[43m_values\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mseg\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43msim\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43msim\u001b[49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 383\u001b[0m logger\u001b[38;5;241m.\u001b[39mdebug(\n\u001b[1;32m 384\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mSet \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m in \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m to \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m with scaler \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mparam_name,\n\u001b[1;32m 385\u001b[0m [\u001b[38;5;28mstr\u001b[39m(location)\n\u001b[1;32m 386\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m location \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlocations],\n\u001b[1;32m 387\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mvalue,\n\u001b[1;32m 388\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mvalue_scaler)\n",
"\u001b[0;31mAttributeError\u001b[0m: mod_pka_g_min_kir_ms, the mechanism does not exist at dspn_0[0].axon[0](0.5)"
]
}
],
"source": [
"mech_dir = os.path.join(\"..\", \"..\", \"..\", \"..\", \"BasalGangliaData\", \"data\", \"neurons\", \"mechanisms\")\n",
"sample_dt = None # 0.00005\n",
Expand Down
66 changes: 37 additions & 29 deletions snudda/neurons/neuron_model_extended.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,35 +238,43 @@ def define_parameters(self, parameter_config, parameter_id=None, parameter_key=N
if param_config['dist_type'] == 'uniform':
scaler = ephys.parameterscalers.NrnSegmentLinearScaler()
elif param_config['dist_type'] in ['exp', 'distance']:
scaler = ephys.parameterscalers.NrnSegmentSomaDistanceScaler(
distribution=param_config['dist'])
seclist_loc = ephys.locations.NrnSeclistLocation(
param_config['sectionlist'],
seclist_name=param_config['sectionlist'])

name = '%s.%s' % (param_config['param_name'],
param_config['sectionlist'])

if param_config['type'] == 'section':
parameters.append(
ephys.parameters.NrnSectionParameter(
name=name,
param_name=param_config['param_name'],
value_scaler=scaler,
value=value,
frozen=frozen,
bounds=bounds,
locations=[seclist_loc]))
elif param_config['type'] == 'range':
parameters.append(
ephys.parameters.NrnRangeParameter(
name=name,
param_name=param_config['param_name'],
value_scaler=scaler,
value=value,
frozen=frozen,
bounds=bounds,
locations=[seclist_loc]))
scaler = ephys.parameterscalers.NrnSegmentSomaDistanceScaler(distribution=param_config['dist'])

# 2024-07-23: Updated format, so that "sectionlist" is allowed to be either a string (of one section type)
# or a list of strings with section types.

section_list = param_config['sectionlist']
if not isinstance(section_list, list):
section_list = [section_list]

for seclist_item in section_list:

seclist_loc = ephys.locations.NrnSeclistLocation(seclist_item,
seclist_name=param_config['sectionlist'])

name = '%s.%s' % (param_config['param_name'],
seclist_item)

if param_config['type'] == 'section':
parameters.append(
ephys.parameters.NrnSectionParameter(
name=name,
param_name=param_config['param_name'],
value_scaler=scaler,
value=value,
frozen=frozen,
bounds=bounds,
locations=[seclist_loc]))
elif param_config['type'] == 'range':
parameters.append(
ephys.parameters.NrnRangeParameter(
name=name,
param_name=param_config['param_name'],
value_scaler=scaler,
value=value,
frozen=frozen,
bounds=bounds,
locations=[seclist_loc]))
else:
raise Exception(f"Param config type has to be global, section or range: {param_config}")

Expand Down
Loading

0 comments on commit ebf7057

Please sign in to comment.