HHTypedNeuron#

class braincell.HHTypedNeuron(size, name=None, **ion_channels)#

The base class for the Hodgkin-Huxley typed neuronal membrane dynamics.

Parameters:
  • size (int | Sequence[int] | integer | Sequence[integer]) – The size of the simulation target. Can be an integer or a tuple of integers. Must be at least 1-dimensional, representing (…, n_neuron, n_compartment).

  • name (str | None) – The name of the HHTypedNeuron instance. If not provided, a default name will be used.

  • **ion_channels – A dictionary of ion channel instances to be added to the neuron. Each key-value pair represents an ion channel name and its corresponding instance.

Raises:
  • ValueError – If the size parameter is not correctly formatted (must be int or tuple/list of int).

  • AssertionError – If the size is less than 1-dimensional.

add(**elements)[source]#

Add new elements to the neuron group.

This method adds new ion channel elements to the neuron group. It checks the hierarchies of the new elements and updates the ion_channels dictionary with the formatted elements.

Parameters:

**elements (Any) – A dictionary of new elements to add. Each key-value pair represents an ion channel name and its corresponding instance.

Raises:

TypeError – If the hierarchies of the new elements are incompatible with the current structure.

Notes

The method uses TreeNode.check_hierarchies to ensure the new elements are compatible with the existing structure. It then formats the elements as IonChannel instances before adding them to the ion_channels dictionary.

compute_derivative(*args, **kwargs)[source]#

Compute the derivative of the state variables for the ion channel.

This method calculates the rate of change of the state variables associated with the ion channel. It is an abstract method that must be implemented by subclasses to provide specific behavior for each type of ion channel.

Parameters:
  • *args – Variable length argument list. Specific arguments should be defined in the subclass implementation.

  • **kwargs – Arbitrary keyword arguments. Specific keyword arguments should be defined in the subclass implementation.

Raises:

NotImplementedError – This method must be implemented by subclasses.

Notes

Subclasses should override this method to implement the specific equations governing the dynamics of the ion channel. The implementation should calculate how the state variables change over time based on the current state and any input parameters.

current(*args, **kwargs)[source]#

Generate ion channel current.

This method calculates and returns the current generated by the ion channel. It must be implemented by subclasses to provide specific behavior for each type of ion channel.

Parameters:
  • *args – Variable length argument list. Specific arguments should be defined in the subclass implementation.

  • **kwargs – Arbitrary keyword arguments. Specific keyword arguments should be defined in the subclass implementation.

Returns:

The calculated ion channel current. The exact type and shape of the return value depend on the specific implementation in the subclass.

Return type:

float or ndarray

Raises:

NotImplementedError – If this method is not overridden in a subclass.

Notes

This is an abstract method that must be implemented by all subclasses. The implementation should provide the logic for calculating the ion channel current based on the channel’s properties and current state.

get_spike(last_V, next_V)[source]#

Surrogate-gradient spike indicator at the V_th crossing.

Uses self.V_th (threshold voltage) and self.spk_fun (surrogate-gradient callable) supplied by subclasses. The product of rising- and falling-crossing terms produces a non-zero value only when last_V < V_th <= next_V.

init_state(batch_size=None)[source]#

Initialize the state variables of the neuron group.

This method initializes the state variables for all ion channels in the neuron group. It retrieves all IonChannel nodes, checks their hierarchies, and calls the init_state method for each channel.

Parameters:

batch_size (int, optional) – The batch size for the simulation. If provided, it will be passed to each channel’s init_state method to initialize states with the specified batch size.

Notes

  • This method uses the current membrane potential (self.V.value) when initializing the state of each channel.

  • The hierarchy of each IonChannel node is checked to ensure proper structure.

property n_compartment: int#

Get the number of compartments in the neuron group.

This property represents the number of distinct compartments within each neuron in the group. Compartments are typically used to model different sections of a neuron, such as the soma, dendrites, and axon.

Returns:

The number of compartments in each neuron of the group.

Return type:

int

Raises:

NotImplementedError – This method is not implemented in the base class and must be implemented by subclasses.

property pop_size: Tuple[int, ...]#

Get the population size of the neuron group.

This property returns the size of the neuron population, which represents the number of neurons in each dimension of the group.

Returns:

A tuple of integers representing the population size in each dimension. For example, (100, 50) would represent a 2D population with 100 neurons in the first dimension and 50 in the second.

Return type:

Tuple[int, …]

Raises:

NotImplementedError – This method is not implemented in the base class and must be implemented by subclasses.

post_integral(*args, **kwargs)[source]#

Perform any necessary operations after the integral step in the simulation.

This method is called after the integration of the differential equations in each time step. For the neuron model, this typically corresponds to the update() function, where state variables are updated based on the results of the integration.

Parameters:
  • *args – Variable length argument list. Specific arguments should be defined in the subclass implementation.

  • **kwargs – Arbitrary keyword arguments. Specific keyword arguments should be defined in the subclass implementation.

Notes

Subclasses should override this method to implement any necessary operations that need to be performed after the integration step, such as updating membrane potentials, ion concentrations, or other state variables of the neuron model.

pre_integral(*args, **kwargs)[source]#

Perform any necessary operations before the integral step in the simulation.

This method is called before the integration of the differential equations in each time step. It allows for any preprocessing or setup required before the actual integration occurs.

Parameters:
  • *args – Variable length argument list. Specific arguments should be defined in the subclass implementation.

  • **kwargs – Arbitrary keyword arguments. Specific keyword arguments should be defined in the subclass implementation.

Raises:

NotImplementedError – This method must be implemented by subclasses to provide specific pre-integration behavior.

Notes

Subclasses should override this method to implement any necessary operations that need to be performed before the integration step. This could include updating certain variables, checking conditions, or preparing data for the integration process.

reset_state(batch_size=None)[source]#

Reset the state variables of the neuron group to their initial values.

This method iterates through all IonChannel nodes in the neuron group and calls their respective reset_state methods. It’s typically used to reinitialize the neuron group’s state, often before starting a new simulation or when transitioning between different phases of a simulation.

Parameters:

batch_size (int, optional) – The batch size for the simulation. If provided, it will be passed to each channel’s reset_state method to reset states with the specified batch size. This is useful for maintaining consistency in batched simulations.

Notes

  • The method uses the current membrane potential (self.V.value) when resetting the state of each channel.

  • Only IonChannel nodes with an allowed hierarchy of (1, 1) are considered.