def spiking_component_type_to_nineml(cls):
     """Return a 9ML ComponentClass describing the spike source model."""
     source = al.ComponentClass(
         name="poisson_spike_source",
         regimes=[
             al.Regime(
                 name="before",
                 transitions=[al.On("t > start",
                                    do=["t_spike = -1"],
                                    to="on")]),
             al.Regime(
                 name="on",
                 transitions=[al.On("t >= t_spike",
                                    do=["t_spike = t_spike + random.exponential(rate)",
                                        al.OutputEvent('spike_output')]),
                              al.On("t >= start + duration",
                                    to="after")],
             ),
             al.Regime(name="after")
         ],
         state_variables=[
             al.StateVariable('t_spike'), #, dimension='[T]'
         ],
         event_ports=[al.EventSendPort('spike_output'), ],
         parameters=['start', 'rate', 'duration'],  # add dimensions, or infer them from dimensions of variables
     )
     return source
 def spiking_component_type_to_nineml(cls):
     """Return a 9ML ComponentClass describing the neuron model."""
     iaf = al.ComponentClass(
         name="iaf_tau",
         regimes=[
             al.Regime(
                 name="subthreshold_regime",
                 time_derivatives=["dv/dt = (v_rest - v)/tau_m + (i_offset + i_syn)/cm"],
                 transitions=al.On("v > v_thresh",
                                   do=["t_spike = t",
                                       "v = v_reset",
                                       al.OutputEvent('spike_output')],
                                   to="refractory_regime"),
             ),  
             al.Regime(
                 name="refractory_regime",
                 time_derivatives=["dv/dt = 0"],
                 transitions=[al.On("t >= t_spike + tau_refrac",
                                    to="subthreshold_regime")],
             )
         ],
         state_variables=[
             al.StateVariable('v'), #, dimension='[V]' # '[V]' should be an alias for [M][L]^2[T]^-3[I]^-1
             al.StateVariable('t_spike'), #, dimension='[T]'
         ],
         analog_ports=[al.AnalogSendPort("v"),
                       al.AnalogReducePort("i_syn", reduce_op="+"), ],
         event_ports=[al.EventSendPort('spike_output'), ],
         parameters=['cm', 'tau_refrac', 'tau_m', 'v_reset', 'v_rest', 'v_thresh', 'i_offset']  # add dimensions, or infer them from dimensions of variables
                                                                                                # in fact, we should be able to infer what are the parameters, without listing them
     )
     return iaf
 def synaptic_receptor_component_type_to_nineml(cls, synapse_type):
     """Return a 9ML ComponentClass describing the synaptic receptor model."""
     coba = al.ComponentClass(
         name="cond_exp_syn",
         aliases=["i_syn:=g_syn*(e_rev-v)", ],
         regimes=[
             al.Regime(
                 name="coba_default_regime",
                 time_derivatives=["dg_syn/dt = -g_syn/tau_syn", ],
                 transitions=al.On('spike_input', do=["g_syn=g_syn+q"]),
             )
         ],
         state_variables=[al.StateVariable('g_syn')],  #, dimension='[G]'  # alias [M]^-1[L]^-2[T]^3[I]^2
         analog_ports=[al.AnalogReceivePort("v"), al.AnalogSendPort("i_syn"), al.AnalogReceivePort('q')],
         parameters=['tau_syn', 'e_rev']
     )
     return coba
 def spiking_component_type_to_nineml(cls):
     """Return a 9ML ComponentClass describing the spike source model."""
     source = al.ComponentClass(
         name="spike_source_array",
         regimes=[
             al.Regime(
                 name="on",
                 transitions=[al.On("t >= spike_times[i]",  # this is currently illegal
                                    do=["i = i + 1",
                                        al.OutputEvent('spike_output')])],
             ),
         ],
         state_variables=[
             al.StateVariable('t_spike'), #, dimension='[T]'
             al.StateVariable('i'), #, dimension='[T]'
         ],
         event_ports=[al.EventSendPort('spike_output'), ],
         parameters=['start', 'rate', 'duration'],  # add dimensions, or infer them from dimensions of variables
     )
     return source