Top-level API (myogen)¶
Reproducibility¶
Module-level state:
myogen.RANDOM_GENERATOR— deprecated compatibility attribute; useget_random_generator()instead.myogen.SEED— deprecated compatibility attribute; useget_random_seed()instead.
set_random_seed ¶
set_random_seed(seed: int = _DEFAULT_SEED) -> None
Set the random seed for reproducibility.
Rebuilds the global NumPy Generator. All modules that read the RNG
through get_random_generator will observe the new state on their
next draw; this includes seeds derived for non-NumPy RNGs (e.g. sklearn
random_state arguments or Cython Mersenne generators), which are now
drawn from the global RNG rather than read from a frozen module constant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seed
|
int
|
Seed value to set, by default 180319. |
_DEFAULT_SEED
|
Source code in myogen/__init__.py
get_random_generator ¶
get_random_generator() -> Generator
Return the current global RNG.
Always reflects the most recent set_random_seed call. Prefer this
accessor over importing RANDOM_GENERATOR directly — a direct import
captures a stale reference that will not update when the seed changes.
Source code in myogen/__init__.py
derive_subseed ¶
Derive a deterministic, seed-tracking sub-seed from the current seed and a tuple of integer labels.
Intended for seeding non-NumPy generators (Cython Mersenne spike
generators, sklearn random_state, etc.) so that a call to
set_random_seed propagates to them. Label order matters:
derive_subseed(a, b) and derive_subseed(b, a) yield different
sub-seeds. Each label must be a non-negative integer; callers with
signed identifiers should offset them beforehand (NumPy's
numpy.random.SeedSequence, which backs this helper, rejects
negatives).
This replaces the pre-existing SEED + (class_id+1)*(global_id+1)
derivation, which collided on swapped factors — e.g. (0, 5) and
(1, 2) both produced +6. The present mixing function uses
numpy.random.SeedSequence to fold the inputs into a 32-bit
integer; collisions remain possible in principle (birthday-paradox
probability ≈ N² / 2³³) but are negligible for realistic motor-unit
pool sizes (≲ 10⁻⁷ at 1000 cells).
Returns:
| Type | Description |
|---|---|
int
|
A non-negative 32-bit integer suitable for passing as a seed to NumPy, sklearn, or the bundled Cython RNG wrappers. |
Source code in myogen/__init__.py
load_nmodl_mechanisms ¶
Load pre-compiled NMODL mechanisms into current NEURON session.
This function loads previously compiled mechanisms into NEURON. It should be called at the start of every script that uses NEURON.
Args: quiet: If True, suppress output messages strict: If True, raise exceptions on errors instead of returning False. Recommended for production code to catch configuration issues early.
Returns: bool: True if mechanisms loaded successfully, False otherwise
Raises: NMODLLoadError: If strict=True and mechanisms fail to load
Source code in myogen/utils/nmodl.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 | |
get_mechanism_parameters ¶
Get list of valid parameters for a NEURON mechanism.
Args: mechanism_name: Name of the mechanism (e.g., "mAHP", "na3rp")
Returns: List of parameter names available for this mechanism
Raises: ValueError: If mechanism is not loaded or doesn't exist
Source code in myogen/utils/nmodl.py
validate_mechanism_parameter ¶
Validate that a parameter exists on a section before setting it.
Args: section: NEURON Section object param_name: Parameter name (e.g., "gcamax_mAHP" or just "gcamax" with mechanism_name) mechanism_name: Optional mechanism name if param_name doesn't include suffix
Raises: AttributeError: If the parameter doesn't exist on the section
Example: >>> validate_mechanism_parameter(soma, "gcamax_mAHP") # Validates before setting >>> soma.gcamax_mAHP = 1e-5 # Now safe to set
Source code in myogen/utils/nmodl.py
set_mechanism_param ¶
Set a mechanism parameter with optional validation.
Args: section: NEURON Section object param_name: Parameter name (e.g., "gcamax_mAHP") value: Value to set validate: If True, validate parameter exists first (default: True)
Raises: AttributeError: If validate=True and parameter doesn't exist
Example: >>> set_mechanism_param(soma, "gcamax_mAHP", 1e-5) # Safe setting >>> set_mechanism_param(soma, "gcamax_mAHPr", 1e-5) # Raises AttributeError (typo)