Skip to content

Commit

Permalink
fixed sbi deprecation error. fixes in docs formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
vvbragin committed Sep 4, 2024
1 parent 9c765a8 commit 840db3d
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 56 deletions.
1 change: 1 addition & 0 deletions doc/source/user_documentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2710,6 +2710,7 @@ The ``update`` method will update the ``SimConfig`` object ``first`` with values
This replaces the previous idiom for updating the SimConfig object with mappings from the batched job submission
.. code-block:: python
try:
from __main__ import cfg # import SimConfig object with params from parent module
except:
Expand Down
65 changes: 34 additions & 31 deletions netpyne/batch/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,37 +62,40 @@ def tupleToStr(obj):
class Batch(object):
"""
Class that handles batch simulations on NetPyNE.
Relevant Attributes:
batchLabel : str
The label of the batch used for directory/file naming of batch generated files.
cfgFile : str
The path of the file containing the `netpyne.simConfig.SimConfig` object
cfg : `netpyne.simConfig.SimConfig`
The `netpyne.simConfig.SimConfig` object
N.B. either cfg or cfgFile should be specified #TODO: replace with typechecked single argument
netParamsFile : str
The path of the file containing the `netpyne.netParams.NetParams` object
netParams : `netpyne.netParams.NetParams`
The `netpyne.netParams.NetParams` object
N.B. either netParams or netParamsFile should be specified #TODO: replace with typechecked single argument
initCfg : dict
params dictionary that is used to modify the batch cfg prior to any algorithm based parameter modifications
saveFolder : str
The path of the folder where the batch will be saved (defaults to batchLabel)
method : str
The algorithm method used for batch
runCfg : dict
Keyword: Arg dictionary used to generate submission templates (see utils.py)
evolCfg : dict #TODO: replace with algoCfg? to merge with optimCfg
Keyword: Arg dictionary used to define evolutionary algorithm parameters (see evol.py)
optimCfg : dict #TODO: replace with algoCfg? to merge with evolCfg
Keyword: Arg dictionary used to define optimization algorithm parameters
(see asd_parallel.py, optuna_parallel.py, sbi_parallel.py)
params : list
Dictionary of parameters to be explored per algorithm (grid, evol, asd, optuna, sbi)
(see relevant algorithm script for details)
seed : int
Seed for random number generator for some algorithms
Attributes
----------
batchLabel : str
The label of the batch used for directory/file naming of batch generated files.
cfgFile : str
The path of the file containing the `netpyne.simConfig.SimConfig` object
cfg : `netpyne.simConfig.SimConfig`
The `netpyne.simConfig.SimConfig` object
N.B. either cfg or cfgFile should be specified #TODO: replace with typechecked single argument
netParamsFile : str
The path of the file containing the `netpyne.netParams.NetParams` object
netParams : `netpyne.netParams.NetParams`
The `netpyne.netParams.NetParams` object
N.B. either netParams or netParamsFile should be specified #TODO: replace with typechecked single argument
initCfg : dict
params dictionary that is used to modify the batch cfg prior to any algorithm based parameter modifications
saveFolder : str
The path of the folder where the batch will be saved (defaults to batchLabel)
method : str
The algorithm method used for batch
runCfg : dict
Keyword: Arg dictionary used to generate submission templates (see utils.py)
evolCfg : dict #TODO: replace with algoCfg? to merge with optimCfg
Keyword: Arg dictionary used to define evolutionary algorithm parameters (see evol.py)
optimCfg : dict #TODO: replace with algoCfg? to merge with evolCfg
Keyword: Arg dictionary used to define optimization algorithm parameters
(see asd_parallel.py, optuna_parallel.py, sbi_parallel.py)
params : list
Dictionary of parameters to be explored per algorithm (grid, evol, asd, optuna, sbi)
(see relevant algorithm script for details)
seed : int
Seed for random number generator for some algorithms
"""

def __init__(
Expand Down
15 changes: 7 additions & 8 deletions netpyne/batch/sbi_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,11 @@
from neuron import h
from sbi import utils as utils
from sbi import analysis as analysis
from sbi.inference.base import infer
from sbi.analysis.plot import pairplot
from sbi import utils
from sbi import analysis
from sbi import inference
from sbi.inference import SNPE, SNLE, SNRE, simulate_for_sbi, prepare_for_sbi
from sbi.inference import SNPE, SNLE, SNRE, simulate_for_sbi
from sbi.inference.trainers.base import process_simulator, process_prior
import torch
import torch.nn as nn
import torch.nn.functional as F
from scipy.stats import kurtosis

pc = h.ParallelContext() # use bulletin board master/slave

Expand Down Expand Up @@ -188,7 +183,11 @@ def objectiveFunc(param):
updateBestFit(candidate, fitness)
return torch.as_tensor(fitness + sum_statistics)

simulator, prior = prepare_for_sbi(lambda param: objectiveFunc(param), prior)
# Check prior, return PyTorch prior.
prior, _, prior_returns_numpy = process_prior(prior)
# Check simulator, returns PyTorch simulator able to simulate batches.
simulator = process_simulator(simulator, prior, prior_returns_numpy)

inference = sbi_md[sbi_method](prior=prior)

if inference_type == 'single':
Expand Down
11 changes: 8 additions & 3 deletions netpyne/batchtools/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,19 @@ def generate_constructors(job_type, comm_type = 'socket', **kwargs):

def generate_parameters(params, algorithm, **kwargs):
"""
returns a dictionary of parameters for ray_search based on the input dictionary
from NOTES Salvador:
Parameters
----------
params = {'synMechTau2': [3.0, 5.0, 7.0], # assumes list of values by default if grid search-like algo
#'synMechTau2': [3.0, 7.0], # assumes lower/upper bounds by default if evol-like algo
'connWeight' : paramtypes.sample_from(lambda _: numpy.random.uniform(0.005, 0.15))} # can optionally pass any of the paramtypes (= ray.tune data types)
#TODO: bloated function, prone to error
Returns
-------
a dictionary of parameters for ray_search based on the input dictionary
"""
#TODO: bloated function, prone to error
ray_params = {}
for param, space in params.items():
if isinstance(space, (list, tuple, range, numpy.ndarray)) and algorithm in {'variant_generator'}:
Expand Down
2 changes: 1 addition & 1 deletion netpyne/cell/compartCell.py
Original file line number Diff line number Diff line change
Expand Up @@ -1678,7 +1678,7 @@ def calcAbsSegCoords(self):
self._segCoords['d1'] = morphSegCoords['d1']

def setImembPtr(self):
"""Set PtrVector to point to the i_membrane_"""
"""Set PtrVector to point to the `i_membrane_`"""
jseg = 0
for sec in list(self.secs.values()):
hSec = sec['hObj']
Expand Down
26 changes: 13 additions & 13 deletions netpyne/network/stim.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ def addStims(self):
"""
Internal function to add stims specified in specs.NetParams
Usage:
Creates and attaches stims to targets via CompartCell.addstim() based on entries in the specs.NetParams sub-
dictionaries -- specs.NetParams.stimSourceParams and specs.NetParams.stimTargetParams (see below)
NetParams.stimSourceParams entries contain key-value pairs to describe NEURON point processes specified by the
'type' entry (i.e. 'IClamp', 'VClamp', 'SEClamp', 'AlphaSynapse', 'VecStim')
NetParams.stimTargetParams entries contain key-value pairs to describe the post-synaptic connections for a
stimSourceParam entry specified by the 'source' entry, including a 'sec' and 'loc' entry (describing section
and location) for where the post-synaptic connection will exist and a 'conds' entry with a dictionary
specifying the cell criteria for the post-synaptic connections: (i.e. 'x', 'y', 'z' or 'xnorm', 'ynorm', 'znorm'
specifying cell criteria by location, 'cellList' specifying cell criteria by specific gid, or arbitrary
'key': 'value' tags.
For 'VecStim' point processes, it may be more convenient to create an artificial cell (i.e.netParams.popParams
see: netpyne/cell/pointCell.py) which allows pattern generation ('rhythmic', 'evoked', 'poisson', 'gauss')
by key-value entries in a 'spikePattern' dictionary.
Creates and attaches stims to targets via CompartCell.addstim() based on entries in the specs.NetParams sub-
dictionaries -- specs.NetParams.stimSourceParams and specs.NetParams.stimTargetParams (see below)
NetParams.stimSourceParams entries contain key-value pairs to describe NEURON point processes specified by the
'type' entry (i.e. 'IClamp', 'VClamp', 'SEClamp', 'AlphaSynapse', 'VecStim')
NetParams.stimTargetParams entries contain key-value pairs to describe the post-synaptic connections for a
stimSourceParam entry specified by the 'source' entry, including a 'sec' and 'loc' entry (describing section
and location) for where the post-synaptic connection will exist and a 'conds' entry with a dictionary
specifying the cell criteria for the post-synaptic connections: (i.e. 'x', 'y', 'z' or 'xnorm', 'ynorm', 'znorm'
specifying cell criteria by location, 'cellList' specifying cell criteria by specific gid, or arbitrary
'key': 'value' tags.
For 'VecStim' point processes, it may be more convenient to create an artificial cell (i.e.netParams.popParams
see: netpyne/cell/pointCell.py) which allows pattern generation ('rhythmic', 'evoked', 'poisson', 'gauss')
by key-value entries in a 'spikePattern' dictionary.
Parameters
----------
Expand Down
1 change: 1 addition & 0 deletions tut-backup/cells_netpyne2021
Submodule cells_netpyne2021 added at 59af57

0 comments on commit 840db3d

Please sign in to comment.