def test_ports(self): # Signature: name # Return an iterator over all the port (Event & Analog) in the # component # from nineml.abstraction.component.componentqueryer import # ComponentClassQueryer c = Dynamics( name='Comp1', regimes=[ Regime(name='r1', transitions=[ On('spikeinput1', do=[]), On('spikeinput2', do=OutputEvent('ev_port2'), to='r2')]), Regime(name='r2', transitions=[ On('V > a', do=OutputEvent('ev_port2')), On('spikeinput3', do=OutputEvent('ev_port3'), to='r1')]) ], aliases=['A1:=0', 'C:=0'], analog_ports=[AnalogSendPort('A1'), AnalogReceivePort('B'), AnalogSendPort('C')] ) ports = list(list(c.ports)) port_names = [p.name for p in ports] self.assertEquals(len(port_names), 8) self.assertEquals(set(port_names), set(['A1', 'B', 'C', 'spikeinput1', 'spikeinput2', 'spikeinput3', 'ev_port2', 'ev_port3']) )
def test_output_filtering(self): """ Tests whether the 'outputs' argument is able to filter (presumably) unconnected nonlinear mappings from inputs and states to analog send ports """ e = Dynamics(name='E', regimes=[ Regime('dSV1/dt = -SV1 / P1', 'dSV2/dt = -SV2 / P1 + ARP1 * P2', name='R1') ], aliases=['A1:=SV1 * C1', 'A2:=SV1 * SV2'], analog_ports=[ AnalogReceivePort('ARP1', dimension=un.per_time), AnalogSendPort('A1', dimension=un.current), AnalogSendPort('A2', dimension=un.dimensionless) ], parameters=[ Parameter('P1', dimension=un.time), Parameter('P2', dimension=un.dimensionless) ], constants=[Constant('C1', 10, units=un.mA)]) self.assertFalse(e.is_linear()) self.assertTrue(e.is_linear(outputs=['A1']))
def test_nonlinear_state_assignment_in_onevent(self): """Test that nonlinear state assignements in on events""" g = Dynamics(name='G', regimes=[ Regime('dSV1/dt = -SV1 / P1', 'dSV2/dt = -SV2 / P1 + ARP1 * P2', name='R1', transitions=[ OnEvent('ERP1', state_assignments=[ StateAssignment( 'SV2', 'SV2 + A2') ]) ]) ], aliases=['A1:=SV1 * C1', 'A2:=P3 * P4 / ADP1'], analog_ports=[ AnalogReceivePort('ARP1', dimension=un.per_time), AnalogReducePort('ADP1', operator='+', dimension=un.dimensionless), AnalogSendPort('A1', dimension=un.current), AnalogSendPort('A2', dimension=un.dimensionless) ], event_ports=[EventReceivePort('ERP1')], parameters=[ Parameter('P1', dimension=un.time), Parameter('P2', dimension=un.dimensionless), Parameter('P3', dimension=un.resistance), Parameter('P4', dimension=un.conductance) ], constants=[Constant('C1', 10, units=un.nA)]) self.assertFalse(g.is_linear())
def duplicate_port_name_event_analog(self): # Check different names are OK: Dynamics( name='C1', aliases=['A1:=1'], event_ports=[EventReceivePort('A')], analog_ports=[AnalogSendPort('A')]) self.assertRaises( NineMLUsageError, Dynamics, name='C1', aliases=['A1:=1'], event_ports=[EventReceivePort('A')], analog_ports=[AnalogSendPort('A')] )
def test_all_expressions(self): a = Dynamics( name='A', aliases=['A1:=P1 * SV2', 'A2 := ARP1 + SV2', 'A3 := SV1'], state_variables=[ StateVariable('SV1', dimension=un.voltage), StateVariable('SV2', dimension=un.current)], regimes=[ Regime( 'dSV1/dt = -SV1 / P2', 'dSV2/dt = A3 / ARP2 + SV2 / P2', transitions=[On('SV1 > P3', do=[OutputEvent('emit')]), On('spikein', do=[OutputEvent('emit')])], name='R1' ), Regime(name='R2', transitions=On('(SV1 > C1) & (SV2 < P4)', to='R1')) ], analog_ports=[AnalogReceivePort('ARP1', dimension=un.current), AnalogReceivePort('ARP2', dimension=(un.resistance * un.time)), AnalogSendPort('A1', dimension=un.voltage * un.current), AnalogSendPort('A2', dimension=un.current)], parameters=[Parameter('P1', dimension=un.voltage), Parameter('P2', dimension=un.time), Parameter('P3', dimension=un.voltage), Parameter('P4', dimension=un.current)], constants=[Constant('C1', value=1.0, units=un.mV)] ) self.assertEqual( set(a.all_expressions), set(( sympify('P1 * SV2'), sympify('ARP1 + SV2'), sympify('SV1'), sympify('-SV1 / P2'), sympify('-SV1 / P2'), sympify('A3 / ARP2 + SV2 / P2'), sympify('SV1 > P3'), sympify('(SV1 > C1) & (SV2 < P4)'))), "All expressions were not extracted from component class")
def setUp(self): self.a = Dynamics(name='A', aliases=['A1:=P1', 'A2 := ARP1 + SV2', 'A3 := SV1'], regimes=[ Regime( 'dSV1/dt = -SV1 / (P2*t)', 'dSV2/dt = SV1 / (ARP1*t) + SV2 / (P1*t)', transitions=[ On('SV1 > P1', do=[OutputEvent('emit')]), On('spikein', do=[OutputEvent('emit')]) ], name='R1', ), Regime(name='R2', transitions=On('SV1 > 1', to='R1')) ], analog_ports=[ AnalogReceivePort('ARP1'), AnalogReceivePort('ARP2'), AnalogSendPort('A1'), AnalogSendPort('A2') ], parameters=['P1', 'P2']) self.b = Dynamics(name='B', aliases=[ 'A1:=P1', 'A2 := ARP1 + SV2', 'A3 := SV1', 'A4 := SV1^3 + SV2^3' ], regimes=[ Regime( 'dSV1/dt = -SV1 / (P2*t)', 'dSV2/dt = SV1 / (ARP1*t) + SV2 / (P1*t)', 'dSV3/dt = -SV3/t + P3/t', transitions=[ On('SV1 > P1', do=[OutputEvent('emit')]), On('spikein', do=[ OutputEvent('emit'), StateAssignment('SV1', 'P1') ]) ], name='R1', ), Regime(name='R2', transitions=[ On('SV1 > 1', to='R1'), On('SV3 < 0.001', to='R2', do=[StateAssignment('SV3', 1)]) ]) ], analog_ports=[ AnalogReceivePort('ARP1'), AnalogReceivePort('ARP2'), AnalogSendPort('A1'), AnalogSendPort('A2'), AnalogSendPort('A3'), AnalogSendPort('SV3') ], parameters=['P1', 'P2', 'P3']) self.a_props = DynamicsProperties(name="AProps", definition=self.a, properties={ 'P1': 1, 'P2': 2 }) self.b_props = DynamicsProperties(name="BProps", definition=self.b, properties={ 'P1': 1, 'P2': 2, 'P3': 3 })
def test_basic_flattening(self): c = Dynamics(name='C', aliases=['C1:=cp1', 'C2 := cIn1', 'C3 := SV1'], regimes=[ Regime( 'dSV1/dt = -SV1/(cp2*t)', transitions=[ On('SV1>cp1', do=[OutputEvent('emit')]), On('spikein', do=[ OutputEvent('emit'), StateAssignment('SV1', '10') ]) ], name='r1', ), Regime(name='r2', transitions=On('SV1>1', to='r1')) ], analog_ports=[ AnalogReceivePort('cIn1'), AnalogReceivePort('cIn2'), AnalogSendPort('C1'), AnalogSendPort('C2') ], parameters=['cp1', 'cp2']) d = Dynamics(name='D', aliases=['D1:=dp1', 'D2 := dIn1', 'D3 := SV1'], regimes=[ Regime( 'dSV1/dt = -SV1/(dp2*t)', transitions=[ On('SV1>dp1', do=[OutputEvent('emit')]), On('spikein', do=[OutputEvent('emit')]) ], name='r1', ), Regime(name='r2', transitions=On('SV1>1', to='r1')) ], analog_ports=[ AnalogReceivePort('dIn1'), AnalogReceivePort('dIn2'), AnalogSendPort('D1'), AnalogSendPort('D2') ], parameters=['dp1', 'dp2']) e = MultiDynamics(name='E', sub_components={ 'a': c, 'b': d }, port_connections=[('a', 'C1', 'b', 'dIn1'), ('a', 'C2', 'b', 'dIn2')], port_exposures=[('a', 'cIn1', 'ARP1'), ('a', 'cIn2', 'ARP2'), ('a', 'spikein', 'ERP1'), ('a', 'emit', 'ESP1')]) # ===================================================================== # General properties # ===================================================================== self.assertEqual(e.name, 'E') self.assertEqual(set(e.parameter_names), set(['cp1__a', 'cp2__a', 'dp1__b', 'dp2__b'])) cp1 = e.parameter('cp1__a') self.assertEqual(cp1.dimension, un.dimensionless) self.assertEqual(set(e.analog_receive_port_names), set(['ARP1', 'ARP2'])) arp1 = e.analog_receive_port('ARP1') self.assertEqual(arp1.dimension, un.dimensionless) self.assertEqual(set(e.event_receive_port_names), set(['ERP1'])) self.assertEqual(set(e.event_send_port_names), set(['ESP1'])) self.assertEqual( set(e.alias_names), set([ 'C1__a', 'C2__a', 'C3__a', 'D1__b', 'D2__b', 'D3__b', 'cIn1__a', 'cIn2__a', 'dIn1__b', 'dIn2__b' ])) self.assertEqual(e.alias('C1__a').rhs, sympy.sympify('cp1__a')) self.assertIsInstance(e.alias('cIn1__a'), _ReceivePortExposureAlias) self.assertIsInstance(e.alias('dIn1__b'), _LocalAnalogReceivePortConnection) self.assertEqual(set(e.state_variable_names), set(['SV1__a', 'SV1__b'])) self.assertEqual( e.state_variable('SV1__a').dimension, un.dimensionless) # - Regimes and Transitions: self.assertEqual(set(e.regime_names), set(['r1___r1', 'r1___r2', 'r2___r1', 'r2___r2'])) # ===================================================================== # Regime a=1, b=2 # ===================================================================== r11 = e.regime('r1___r1') self.assertEqual(r11.num_on_conditions, 2) self.assertEqual(r11.num_on_events, 1) oe1 = r11.on_event('ERP1') self.assertEqual(oe1.num_output_events, 1) out1 = oe1.output_event('ESP1') self.assertEqual(out1.port, e.event_send_port('ESP1')) self.assertEqual(oe1.num_state_assignments, 1) self.assertEqual(oe1.state_assignment('SV1__a').rhs, 10) self.assertEqual(set(oe1.state_assignment_variables), set( ('SV1__a', ))) self.assertEqual(r11.num_on_conditions, 2) oc1 = r11.on_condition('SV1__a > cp1__a') self.assertEqual(oc1.num_output_events, 1) self.assertEqual(oc1.target_regime, r11) out1 = oc1.output_event('ESP1') self.assertEqual(out1.port, e.event_send_port('ESP1')) self.assertEqual(oc1.num_state_assignments, 0) oc2 = r11.on_condition('SV1__b > dp1__b') self.assertEqual(oc2.num_output_events, 0) self.assertEqual(oc2.num_state_assignments, 0) self.assertEqual(oc2.target_regime, r11) # ===================================================================== # Regime a=1, b=2 # ===================================================================== r12 = e.regime('r1___r2') self.assertEqual(r12.num_on_conditions, 2) oc1 = r12.on_condition('SV1__a > cp1__a') self.assertEqual(set(oc1.output_event_port_names), set(('ESP1', ))) self.assertEqual(oc1.target_regime, r12) oc2 = r12.on_condition('SV1__b > 1') self.assertEqual(oc2.num_output_events, 0) self.assertEqual(oc2.target_regime, r11) self.assertEqual(r12.num_on_events, 1) self.assertEqual( r12.on_event('ERP1').port.port, c.event_receive_port('spikein')) # ===================================================================== # Regime a=2, b=1 # ===================================================================== r21 = e.regime('r2___r1') self.assertEqual(r21.num_on_conditions, 2) oc1 = r21.on_condition('SV1__a > 1') self.assertEqual(oc1.num_output_events, 0) self.assertEqual(oc1.num_state_assignments, 0) self.assertEqual(oc1.target_regime, r11) oc2 = r21.on_condition('SV1__b > dp1__b') self.assertEqual(oc2.num_output_events, 0) self.assertEqual(oc2.num_state_assignments, 0) self.assertEqual(oc2.target_regime, r21) self.assertEqual(r21.num_on_events, 0) # ===================================================================== # Regime a=2, b=2 # ===================================================================== r22 = e.regime('r2___r2') self.assertEqual(r21.num_on_conditions, 2) oc1 = r22.on_condition('SV1__a > 1') self.assertEqual(oc1.num_output_events, 0) self.assertEqual(oc1.num_state_assignments, 0) self.assertEqual(oc1.target_regime, r12) oc2 = r22.on_condition('SV1__b > 1') self.assertEqual(oc2.num_output_events, 0) self.assertEqual(oc2.num_state_assignments, 0) self.assertEqual(oc2.target_regime, r21) # - Ports & Parameters: self.assertEqual(set(e.analog_receive_port_names), set(['ARP1', 'ARP2'])) self.assertEqual(set(e.parameter_names), set(['cp1__a', 'cp2__a', 'dp1__b', 'dp2__b'])) self.assertEqual(set(e.state_variable_names), set(['SV1__a', 'SV1__b']))
def test_analog_ports(self): # Signature: name # No Docstring c = Dynamics(name='C1') self.assertEqual(len(list(c.analog_ports)), 0) c = Dynamics(name='C1') self.assertEqual(len(list(c.analog_ports)), 0) c = Dynamics(name='C1', aliases=['A:=2'], analog_ports=[AnalogSendPort('A')]) self.assertEqual(len(list(c.analog_ports)), 1) self.assertEqual(list(c.analog_ports)[0].mode, 'send') self.assertEqual(len(list(c.analog_send_ports)), 1) self.assertEqual(len(list(c.analog_receive_ports)), 0) self.assertEqual(len(list(c.analog_reduce_ports)), 0) c = Dynamics(name='C1', analog_ports=[AnalogReceivePort('B')]) self.assertEqual(len(list(c.analog_ports)), 1) self.assertEqual(list(c.analog_ports)[0].mode, 'recv') self.assertEqual(len(list(c.analog_send_ports)), 0) self.assertEqual(len(list(c.analog_receive_ports)), 1) self.assertEqual(len(list(c.analog_reduce_ports)), 0) c = Dynamics(name='C1', analog_ports=[AnalogReducePort('B', operator='+')]) self.assertEqual(len(list(c.analog_ports)), 1) self.assertEqual(list(c.analog_ports)[0].mode, 'reduce') self.assertEqual(list(c.analog_ports)[0].operator, '+') self.assertEqual(len(list(c.analog_send_ports)), 0) self.assertEqual(len(list(c.analog_receive_ports)), 0) self.assertEqual(len(list(c.analog_reduce_ports)), 1) # Duplicate Port Names: self.assertRaises( NineMLUsageError, Dynamics, name='C1', aliases=['A1:=1'], analog_ports=[AnalogReducePort('B', operator='+'), AnalogSendPort('B')] ) self.assertRaises( NineMLUsageError, Dynamics, name='C1', aliases=['A1:=1'], analog_ports=[AnalogSendPort('A'), AnalogSendPort('A')] ) self.assertRaises( NineMLUsageError, Dynamics, name='C1', aliases=['A1:=1'], analog_ports=[AnalogReceivePort('A'), AnalogReceivePort('A')] ) self.assertRaises( NineMLUsageError, lambda: Dynamics(name='C1', analog_ports=[AnalogReceivePort('1')]) ) self.assertRaises( NineMLUsageError, lambda: Dynamics(name='C1', analog_ports=[AnalogReceivePort('?')]) )
do=["tspike = t", "V = vreset", OutputEvent('spikeoutput')], to="refractoryregime"), ), Regime( name="refractoryregime", transitions=[On("t >= tspike + taurefrac", to="subthresholdregime")], ) ], state_variables=[ StateVariable('V', un.voltage), StateVariable('tspike', un.time), ], analog_ports=[AnalogSendPort("V", un.voltage), AnalogReducePort("ISyn", un.current, operator="+"), ], event_ports=[EventSendPort('spikeoutput'), ], parameters=[Parameter('cm', un.capacitance), Parameter('taurefrac', un.time), Parameter('gl', un.conductance), Parameter('vreset', un.voltage), Parameter('vrest', un.voltage), Parameter('vthresh', un.voltage)]) coba = Dynamics( name="CobaSyn", aliases=["I:=g*(vrev-V)", ], regimes=[ Regime(
'dSV1/dt = -SV1 / P2', 'dSV2/dt = A3 / ARP2 + SV2 / P2', transitions=[On(Trigger('SV1 > P3'), do=[OutputEvent('ESP1')]), On('ERP1', do=[OutputEvent('ESP2')])], name='R1' ), Regime(name='R2', transitions=[ OnCondition('(SV1 > C1) & (SV2 < P4)', target_regime_name='R1')]) ], analog_ports=[AnalogReceivePort('ARP1', dimension=un.current), AnalogReceivePort('ARP2', dimension=(un.resistance * un.time)), AnalogSendPort('A1', dimension=un.voltage * un.current), AnalogSendPort('A2', dimension=un.current)], parameters=[Parameter('P1', dimension=un.voltage), Parameter('P2', dimension=un.time), Parameter('P3', dimension=un.voltage), Parameter('P4', dimension=un.current)], constants=[Constant('C1', value=-71.0, units=un.mV), Constant('C2', value=22.2, units=un.degC)]) ref.state_variable('SV2').annotations.set(('Z1', 'NS1'), 'Y1', 'X1', 2.0) A = Dynamics( name='dyn', aliases=['A1:=SV2', 'A2 := ARP1 + SV2', 'A3 := SV1', 'A4 := C2 * SV1'], state_variables=[
def _transform_full_component(self, trfrm, component_class, v, **kwargs): # ----------------------------------------------------------------- # Remove all analog send ports with 'current' dimension so they # don't get confused with the converted voltage time derivative # expression # ----------------------------------------------------------------- for port in list(trfrm.analog_send_ports): if port.dimension == un.current: trfrm.remove(port) # ----------------------------------------------------------------- # Insert membrane capacitance if not present # ----------------------------------------------------------------- # Get or guess the location of the membrane capacitance try: name = kwargs['membrane_capacitance'] try: orig_cm = component_class.parameter(name) except KeyError: raise Pype9BuildError( "Could not find specified membrane capacitance '{}'" .format(name)) cm = trfrm.parameter(orig_cm.name) except KeyError: # 'membrane_capacitance' was not specified candidate_cms = [ccm for ccm in component_class.parameters if ccm.dimension == un.capacitance] if len(candidate_cms) == 1: orig_cm = candidate_cms[0] cm = trfrm.parameter(orig_cm.name) logger.info("Guessing that '{}' is the membrane capacitance" .format(orig_cm)) elif len(candidate_cms) > 1: raise Pype9BuildError( "Could not guess the membrane capacitance, candidates:" " '{}'".format("', '".join(candidate_cms))) else: cm = Parameter("cm___pype9", dimension=un.capacitance) trfrm.add(cm) cm.annotations.set((BUILD_TRANS, PYPE9_NS), TRANSFORM_SRC, None) trfrm.annotations.set((BUILD_TRANS, PYPE9_NS), MEMBRANE_CAPACITANCE, cm.name) # ----------------------------------------------------------------- # Replace membrane voltage equation with membrane current # ----------------------------------------------------------------- # Determine the regimes in which each state variables has a time # derivative in has_td = defaultdict(list) # List which regimes need to be clamped to their last voltage # (as it has no time derivative) clamped_regimes = [] # The voltage clamp equation where v_clamp is the last voltage # value and g_clamp_ is a large conductance clamp_i = sympy.sympify('g_clamp___pype9 * (v - v_clamp___pype9)') memb_is = [] for regime in trfrm.regimes: # Add an appropriate membrane current try: # Convert the voltage time derivative into a membrane # current dvdt = regime.time_derivative(v.name) regime.remove(dvdt) i = -dvdt.rhs * cm memb_is.append(i) except KeyError: i = clamp_i clamped_regimes.append(regime) regime.add(Alias('i___pype9', i)) # Record state vars that have a time deriv. in this regime for var in regime.time_derivative_variables: if var != 'v': has_td[var].append(regime) # Pick the most popular membrane current to be the alias in # the global scope assert memb_is, "No regimes contain voltage time derivatives" memb_i = Alias('i___pype9', max(memb_is, key=memb_is.count)) # Add membrane current along with a analog send port trfrm.add(memb_i) i_port = AnalogSendPort('i___pype9', dimension=un.current) i_port.annotations.set((BUILD_TRANS, PYPE9_NS), ION_SPECIES, NONSPECIFIC_CURRENT) trfrm.add(i_port) # Remove membrane currents that match the membrane current in the # outer scope for regime in trfrm.regimes: if regime.alias('i___pype9') == memb_i: regime.remove(regime.alias('i___pype9')) # If there are clamped regimes add extra parameters and set the # voltage to clamp to in the regimes that trfrmition to them if clamped_regimes: trfrm.add(StateVariable('v_clamp___pype9', un.voltage)) trfrm.add(Constant('g_clamp___pype9', 1e8, un.uS)) for trans in trfrm.transitions: if trans.target_regime in clamped_regimes: # Assign v_clamp_ to the value try: v_clamp_rhs = trans.state_assignment('v').rhs except KeyError: v_clamp_rhs = 'v' trans.add(StateAssignment('v_clamp___pype9', v_clamp_rhs)) # ----------------------------------------------------------------- trfrm.annotations.set( (BUILD_TRANS, PYPE9_NS), NO_TIME_DERIVS, ','.join(['v'] + [sv for sv in trfrm.state_variable_names if sv not in has_td])) trfrm.annotations.set((BUILD_TRANS, PYPE9_NS), NUM_TIME_DERIVS, len(has_td)) # ----------------------------------------------------------------- # Remove the external input currents # ----------------------------------------------------------------- # Analog receive or reduce ports that are of dimension current and # are purely additive to the membrane current and nothing else # (actually subtractive as it is outward current) try: ext_is = [] for i_name in kwargs['external_currents']: try: ext_i = trfrm.analog_receive_port(i_name) except KeyError: try: ext_i = trfrm.analog_reduce_port(i_name) except KeyError: raise Pype9BuildError( "Did not find specified external current port " "'{}'".format(i_name)) if ext_i.dimension != un.current: raise Pype9BuildError( "Analog receive port matching specified external " "current '{}' does not have 'current' dimension " "({})".format(ext_i.name, ext_i.dimension)) ext_is.append(ext_i) except KeyError: ext_is = [] for port in chain(component_class.analog_receive_ports, component_class.analog_reduce_ports): # Check to see if the receive/reduce port has current dimension if port.dimension != un.current: continue # Check to see if the current appears in the membrane current # expression # FIXME: This test should check to to see if the port is # additive to the membrane current and substitute all # aliases. if port.name not in memb_i.rhs_symbol_names: continue # Get the number of expressions the receive port appears in # an expression if len([e for e in component_class.all_expressions if port.symbol in e.free_symbols]) > 1: continue # If all those conditions are met guess that port is a external # current that can be removed (ports that don't meet these # conditions will have to be specified separately) ext_is.append(port) if ext_is: logger.info("Guessing '{}' are external currents to be removed" .format(ext_is)) trfrm.annotations.set((BUILD_TRANS, PYPE9_NS), EXTERNAL_CURRENTS, ','.join(p.name for p in ext_is)) # Remove external input current ports (as NEURON handles them) for ext_i in ext_is: trfrm.remove(ext_i) for expr in chain(trfrm.aliases, trfrm.all_time_derivatives()): expr.subs(ext_i, 0) expr.simplify()
def setUp(self): liaf = Dynamics( name='liaf', parameters=[ Parameter(name='R', dimension=un.resistance), Parameter(name='Vreset', dimension=un.voltage), Parameter(name='tau', dimension=un.time), Parameter(name='tau_rp', dimension=un.time), Parameter(name='theta', dimension=un.voltage) ], analog_ports=[ AnalogReducePort(name='Isyn', dimension=un.current, operator='+'), AnalogSendPort(name='V', dimension=un.voltage), AnalogSendPort(name='t_rpend', dimension=un.time) ], event_ports=[EventSendPort(name='spikeOutput')], state_variables=[ StateVariable(name='V', dimension=un.voltage), StateVariable(name='t_rpend', dimension=un.time) ], regimes=[ Regime(name='refractoryRegime', transitions=[ OnCondition('t > t_rpend', target_regime_name='subthresholdRegime') ]), Regime( name='subthresholdRegime', time_derivatives=[TimeDerivative('V', '(Isyn*R - V)/tau')], transitions=[ OnCondition('V > theta', target_regime_name='refractoryRegime', state_assignments=[ StateAssignment('V', 'Vreset'), StateAssignment( 't_rpend', 't + tau_rp') ], output_events=[OutputEvent('spikeOutput')]) ]) ]) poisson = Dynamics( name='Poisson', parameters=[Parameter(name='rate', dimension=un.per_time)], event_ports=[EventSendPort(name='spikeOutput')], state_variables=[StateVariable(name='t_next', dimension=un.time)], regimes=[ Regime(name='default', transitions=[ OnCondition( 't > t_next', target_regime_name='default', state_assignments=[ StateAssignment( 't_next', 'one_ms*random.exponential(' 'rate*thousand_milliseconds) + t') ], output_events=[OutputEvent('spikeOutput')]) ]) ], constants=[ Constant(name='one_ms', units=un.ms, value=1.0), Constant(name='thousand_milliseconds', units=un.ms, value=1000.0) ]) static = Dynamics( name='StaticConnection', analog_ports=[AnalogSendPort(name='weight', dimension=un.current)], state_variables=[ StateVariable(name='weight', dimension=un.current) ], regimes=[ Regime(name='default', time_derivatives=[TimeDerivative('weight', 'zero')]) ], constants=[Constant(name='zero', units=un.A / un.s, value=0.0)]) psr = Dynamics( name='AlphaPSR', parameters=[Parameter(name='tau_syn', dimension=un.time)], event_ports=[EventReceivePort(name='spike')], analog_ports=[ AnalogReceivePort(name='weight', dimension=un.current), AnalogSendPort(name='A', dimension=un.current), AnalogSendPort(name='B', dimension=un.current), AnalogSendPort(name='Isyn', dimension=un.current) ], state_variables=[ StateVariable(name='A', dimension=un.current), StateVariable(name='B', dimension=un.current) ], regimes=[ Regime(name='default', time_derivatives=[ TimeDerivative('A', '(-A + B)/tau_syn'), TimeDerivative('B', '-B/tau_syn') ], transitions=[ OnEvent('spike', target_regime_name='default', state_assignments=[ StateAssignment('B', 'B + weight') ]) ]) ], aliases=['Isyn:=A']) one_to_one_class = ConnectionRule( 'OneToOneClass', standard_library=( "http://nineml.net/9ML/1.0/connectionrules/OneToOne")) self.one_to_one = ConnectionRuleProperties("OneToOne", one_to_one_class, {}) random_fan_in_class = ConnectionRule( name="RandomFanIn", parameters=[Parameter(name="number")], standard_library=( "http://nineml.net/9ML/1.0/connectionrules/RandomFanIn")) exc_random_fan_in = ConnectionRuleProperties( name="RandomFanInProps", definition=random_fan_in_class, properties={'number': 100}) inh_random_fan_in = ConnectionRuleProperties( name="RandomFanInProps", definition=random_fan_in_class, properties={'number': 200}) self.celltype = DynamicsProperties(name="liaf_props", definition=liaf, properties={ 'tau': self.tau, 'theta': self.theta, 'tau_rp': 2.0 * un.ms, 'Vreset': 10.0 * un.mV, 'R': 1.5 * un.Mohm }, initial_values={ "V": 0.0 * un.mV, "t_rpend": 0.0 * un.ms }) ext_stim = DynamicsProperties(name="stim", definition=poisson, properties={'rate': self.input_rate}, initial_values={"t_next": 0.5 * un.ms}) self.psr = DynamicsProperties(name="syn", definition=psr, properties={'tau_syn': self.tau_syn}, initial_values={ "A": 0.0 * un.nA, "B": 0.0 * un.nA }) exc = Population("Exc", self.order * 4, self.celltype) inh = Population("Inh", self.order, self.celltype) ext = Population("Ext", self.order * 5, ext_stim) exc_and_inh = Selection("All", Concatenate((exc, inh))) self.static_ext = DynamicsProperties( "ExternalPlasticity", static, {}, initial_values={"weight": self.Je * un.nA}) static_exc = DynamicsProperties( "ExcitatoryPlasticity", static, {}, initial_values={"weight": self.Je * un.nA}) static_inh = DynamicsProperties( "InhibitoryPlasticity", static, initial_values={"weight": self.Ji * un.nA}) ext_prj = Projection("External", pre=ext, post=exc_and_inh, response=self.psr, plasticity=self.static_ext, connection_rule_properties=self.one_to_one, delay=self.delay, port_connections=[ ('response', 'Isyn', 'post', 'Isyn'), ('plasticity', 'weight', 'response', 'weight') ]) exc_prj = Projection("Excitation", pre=exc, post=exc_and_inh, response=self.psr, plasticity=static_exc, connection_rule_properties=exc_random_fan_in, delay=self.delay, port_connections=[ ('response', 'Isyn', 'post', 'Isyn'), ('plasticity', 'weight', 'response', 'weight') ]) inh_prj = Projection("Inhibition", pre=inh, post=exc_and_inh, response=self.psr, plasticity=static_inh, connection_rule_properties=inh_random_fan_in, delay=self.delay, port_connections=[ ('response', 'Isyn', 'post', 'Isyn'), ('plasticity', 'weight', 'response', 'weight') ]) self.model = Network("brunel_network") self.model.add(ext) self.model.add(exc) self.model.add(inh) self.model.add(exc_and_inh) self.model.add(ext_prj) self.model.add(exc_prj) self.model.add(inh_prj)
def setUp(self): self.pre_dynamics = Dynamics( name='PreDynamics', state_variables=[StateVariable('SV1', dimension=un.voltage)], regimes=[ Regime('dSV1/dt = -SV1 / P1', transitions=[On('SV1 > P2', do=[OutputEvent('emit')])], name='R1'), ], parameters=[ Parameter('P1', dimension=un.time), Parameter('P2', dimension=un.voltage) ]) self.post_dynamics = Dynamics( name='PostDynamics', state_variables=[StateVariable('SV1', dimension=un.voltage)], regimes=[ Regime('dSV1/dt = -SV1 / P1 + ARP1 / P2', name='R1'), ], analog_ports=[AnalogReceivePort('ARP1', dimension=un.current)], parameters=[ Parameter('P1', dimension=un.time), Parameter('P2', dimension=un.capacitance) ]) self.response_dynamics = Dynamics( name='ResponseDynamics', state_variables=[StateVariable('SV1', dimension=un.current)], regimes=[ Regime('dSV1/dt = -SV1 / P1', transitions=[ On('receive', do=[StateAssignment('SV1', 'SV1 + P2')]) ], name='R1'), ], analog_ports=[AnalogSendPort('SV1', dimension=un.current)], parameters=[ Parameter('P1', dimension=un.time), Parameter('P2', dimension=un.current) ]) self.pre = Population(name="PrePopulation", size=1, cell=DynamicsProperties( name="PreDynamicsProps", definition=self.pre_dynamics, properties={ 'P1': 1 * un.ms, 'P2': -65 * un.mV })) self.post = Population(name="PostPopulation", size=1, cell=DynamicsProperties( name="PostDynamicsProps", definition=self.post_dynamics, properties={ 'P1': 1 * un.ms, 'P2': 1 * un.uF })) self.one_to_one = ConnectionRule( name="OneToOne", standard_library=(NINEML_NS + '/connectionrules/OneToOne')) self.projection = Projection( name="Projection", pre=self.pre, post=self.post, response=DynamicsProperties(name="ResponseProps", definition=self.response_dynamics, properties={ 'P1': 10 * un.ms, 'P2': 1 * un.nA }), connection_rule_properties=ConnectionRuleProperties( name="ConnectionRuleProps", definition=self.one_to_one), delay=1 * un.ms)
OutputEvent('spikeoutput')], to="refractoryregime"), ), Regime( name="refractoryregime", transitions=[ On("t >= tspike + taurefrac", to="subthresholdregime") ], ) ], state_variables=[ StateVariable('V', un.voltage), StateVariable('tspike', un.time), ], analog_ports=[ AnalogSendPort("V", un.voltage), AnalogReducePort("ISyn", un.current, operator="+"), ], event_ports=[ EventSendPort('spikeoutput'), ], parameters=[ Parameter('cm', un.capacitance), Parameter('taurefrac', un.time), Parameter('gl', un.conductance), Parameter('vreset', un.voltage), Parameter('vrest', un.voltage), Parameter('vthresh', un.voltage) ]) coba = Dynamics(name="CobaSyn",
def get_compound_component(): """Cannot yet be implemented in PyDSTool """ from nineml.abstraction.testing_utils import RecordValue from nineml.abstraction import Dynamics, Regime, On, OutputEvent, AnalogSendPort, AnalogReducePort emitter = Dynamics( name='EventEmitter', parameters=['cyclelength'], regimes=[ Regime(transitions=On('t > tchange + cyclelength', do=[OutputEvent('emit'), 'tchange=t'])), ]) ev_based_cc = Dynamics( name='EventBasedCurrentClass', parameters=['dur', 'i'], analog_ports=[AnalogSendPort('I')], regimes=[ Regime(transitions=[ On('inputevent', do=['I=i', 'tchange = t']), On('t>tchange + dur', do=['I=0', 'tchange=t']) ]) ]) pulsing_emitter = Dynamics(name='pulsing_cc', subnodes={ 'evs': emitter, 'cc': ev_based_cc }, portconnections=[('evs.emit', 'cc.inputevent')]) nrn = Dynamics( name='LeakyNeuron', parameters=['Cm', 'gL', 'E'], regimes=[ Regime('dV/dt = (iInj + (E-V)*gL )/Cm'), ], aliases=['iIn := iInj'], analog_ports=[ AnalogSendPort('V'), AnalogReducePort('iInj', operator='+') ], ) combined_comp = Dynamics(name='Comp1', subnodes={ 'nrn': nrn, 'cc1': pulsing_emitter, 'cc2': pulsing_emitter }, portconnections=[('cc1.cc.I', 'nrn.iInj'), ('cc2.cc.I', 'nrn.iInj')]) combined_comp = al.flattening.flatten(combined_comp) ## records = [ ## RecordValue(what='cc1_cc_I', tag='Current', label='Current Clamp 1'), ## RecordValue(what='cc2_cc_I', tag='Current', label='Current Clamp 2'), ## RecordValue(what='nrn_iIn', tag='Current', label='Total Input Current'), ## RecordValue(what='nrn_V', tag='Voltage', label='Neuron Voltage'), ## RecordValue(what='cc1_cc_tchange', tag='Tchange', label='tChange CC1'), ## RecordValue(what='cc2_cc_tchange', tag='Tchange', label='tChange CC2'), ## RecordValue(what='regime', tag='Regime', label='Regime'), ## ] parameters = al.flattening.ComponentFlattener.flatten_namespace_dict({ 'cc1.cc.i': 13.8, 'cc1.cc.dur': 10, 'cc1.evs.cyclelength': 30, 'cc2.cc.i': 20.8, 'cc2.cc.dur': 5.0, 'cc2.evs.cyclelength': 20, 'nrn.gL': 4.3, 'nrn.E': -70 }) return combined_comp, parameters
def setUp(self): self.a = Dynamics( name='A', aliases=[ 'A1:=P1 / P2', 'A2 := ARP2 + P3', 'A3 := A4 * P4 * P5', 'A4:=P6 ** 2 + ADP1', 'A5:=SV1 * SV2 * P8', 'A6:=SV1 * P1 / P8', 'A7:=A1 / P8' ], regimes=[ Regime('dSV1/dt = -A1 / A2', 'dSV2/dt = -ADP1 / P7', 'dSV3/dt = -A1 * A3 / (A2 * C1)', transitions=[ OnCondition('SV1 > 10', target_regime_name='R2') ], aliases=[ Alias('A1', 'P1 / P2 * 2'), Alias('A5', 'SV1 * SV2 * P8 * 2') ], name='R1'), Regime('dSV1/dt = -A1 / A2', 'dSV3/dt = -A1 / A2 * A4', transitions=[ OnCondition('C2 > A6', state_assignments=[ StateAssignment('SV1', 'SV1 - A7') ], target_regime_name='R1') ], name='R2') ], analog_ports=[ AnalogReceivePort('ARP1', dimension=un.resistance), AnalogReceivePort('ARP2', dimension=un.charge), AnalogReducePort('ADP1', dimension=un.dimensionless), AnalogSendPort('A5', dimension=un.current) ], parameters=[ Parameter('P1', dimension=un.voltage), Parameter('P2', dimension=un.resistance), Parameter('P3', dimension=un.charge), Parameter('P4', dimension=old_div(un.length, un.current**2)), Parameter('P5', dimension=old_div(un.current**2, un.length)), Parameter('P6', dimension=un.dimensionless), Parameter('P7', dimension=un.time), Parameter('P8', dimension=un.current) ], constants=[ Constant('C1', value=10.0, units=un.unitless), Constant('C2', value=1.0, units=un.ohm) ]) self.ref_substituted_a = Dynamics( name='substituted_A', aliases=['A5:=SV1 * SV2 * P8'], regimes=[ Regime('dSV1/dt = -2 * (P1 / P2) / (ARP2 + P3)', 'dSV2/dt = -ADP1 / P7', ('dSV3/dt = -2 * (P1 / P2) * ((P6 ** 2 + ADP1) * P4 * ' 'P5) / ((ARP2 + P3) * C1)'), transitions=[ OnCondition('SV1 > 10', target_regime_name='R2') ], aliases=[Alias('A5', 'SV1 * SV2 * P8 * 2')], name='R1'), Regime('dSV1/dt = -(P1 / P2) / (ARP2 + P3)', 'dSV3/dt = -(P1 / P2) / (ARP2 + P3) * (P6 ** 2 + ADP1)', transitions=[ OnCondition('C2 > (SV1 * P1 / P8)', state_assignments=[ StateAssignment( 'SV1', 'SV1 - (P1 / P2) / P8') ], target_regime_name='R1') ], name='R2') ], analog_ports=[ AnalogReceivePort('ARP1', dimension=un.resistance), AnalogReceivePort('ARP2', dimension=un.charge), AnalogReducePort('ADP1', dimension=un.dimensionless), AnalogSendPort('A5', dimension=un.current) ], parameters=[ Parameter('P1', dimension=un.voltage), Parameter('P2', dimension=un.resistance), Parameter('P3', dimension=un.charge), Parameter('P4', dimension=old_div(un.length, un.current**2)), Parameter('P5', dimension=old_div(un.current**2, un.length)), Parameter('P6', dimension=un.dimensionless), Parameter('P7', dimension=un.time), Parameter('P8', dimension=un.current) ], constants=[ Constant('C1', value=10.0, units=un.unitless), Constant('C2', value=1.0, units=un.ohm) ])
On(Trigger('SV1 > P3'), do=[OutputEvent('ESP1')]), On('ERP1', do=[OutputEvent('ESP2')]) ], name='R1'), Regime(name='R2', transitions=[ OnCondition('(SV1 > C1) & (SV2 < P4)', target_regime_name='R1') ]) ], analog_ports=[ AnalogReceivePort('ARP1', dimension=un.current), AnalogReceivePort('ARP2', dimension=(un.resistance * un.time)), AnalogSendPort('A1', dimension=un.voltage * un.current), AnalogSendPort('A2', dimension=un.current) ], parameters=[ Parameter('P1', dimension=un.voltage), Parameter('P2', dimension=un.time), Parameter('P3', dimension=un.voltage), Parameter('P4', dimension=un.current) ], constants=[ Constant('C1', value=-71.0, units=un.mV), Constant('C2', value=22.2, units=un.degC) ]) dynB = Dynamics( name='dynB',
def test_name(self): # Signature: name # The name of the port, local to the current component self.assertEqual(AnalogReceivePort('A').name, 'A') self.assertEqual(AnalogReducePort('B', operator='+').name, 'B') self.assertEqual(AnalogSendPort('C').name, 'C')