Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make model.nvar a property #720

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/contrib-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
sudo apt-get update
sudo apt install libbz2-dev libhdf5-serial-dev liblzo2-dev
python3 -m pip install --upgrade setuptools==59.8.0 pip wheel
pip3 install --user --upgrade numpy
pip3 install --user --upgrade numpy<2
python3 -m pip install scikit-build pytest
pip3 install --user --no-build-isolation tvb-gdist
cd tvb_library
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ class EpileptorT(ModelNumbaDfun):

state_variables = ['x1', 'y1', 'z', 'x2', 'y2', 'g']

_nvar = 6
cvar = numpy.array([0,1,2,3,4,5,], dtype = numpy.int32)

def dfun(self, vw, c, local_coupling=0.0):
Expand Down
1 change: 0 additions & 1 deletion tvb_contrib/tvb/contrib/rateML/generatedModels/kuramoto.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class KuramotoT(ModelNumbaDfun):

state_variables = ['V']

_nvar = 1
cvar = numpy.array([0,], dtype = numpy.int32)

def dfun(self, vw, c, local_coupling=0.0):
Expand Down
1 change: 0 additions & 1 deletion tvb_contrib/tvb/contrib/rateML/generatedModels/montbrio.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ class MontbrioT(ModelNumbaDfun):

state_variables = ['r', 'V']

_nvar = 2
cvar = numpy.array([0,1,], dtype = numpy.int32)

def dfun(self, vw, c, local_coupling=0.0):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ class OscillatorT(ModelNumbaDfun):

state_variables = ['V', 'W']

_nvar = 2
cvar = numpy.array([0,1,], dtype = numpy.int32)

def dfun(self, vw, c, local_coupling=0.0):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ class RwongwangT(ModelNumbaDfun):

state_variables = ['V', 'W']

_nvar = 2
cvar = numpy.array([0,1,], dtype = numpy.int32)

def dfun(self, vw, c, local_coupling=0.0):
Expand Down
1 change: 0 additions & 1 deletion tvb_contrib/tvb/contrib/rateML/tmpl8_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ class ${modelname}(ModelNumbaDfun):
%endfor
]

_nvar = ${dynamics.state_variables.__len__()}
cvar = numpy.array([\
% for i, itemF in enumerate(dynamics.state_variables):
${i},\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ class Linear(Linear):

state_variables = ('R', 'Rin')
integration_variables = ('R',)
_nvar = 2
cvar = numpy.array([0], dtype=numpy.int32)

def update_derived_parameters(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ class ReducedWongWangExcIO(TVBReducedWongWang):

state_variables = ['S', 'Rint', 'R', 'Rin', 'I']
non_integrated_variables = ['R', 'Rin', 'I']
_nvar = 5
cvar = numpy.array([0], dtype=numpy.int32)
_R = None
_Rin = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ class ReducedWongWangExcIOInhI(TVBReducedWongWangExcInh):

state_variables = ['S_e', 'S_i', 'R_e', 'R_i', 'Rin_e', 'Rin_i', 'I_e', 'I_i']
non_integrated_variables = ['Rin_e', 'Rin_i', 'I_e', 'I_i']
_nvar = 8
cvar = numpy.array([0], dtype=numpy.int32)
_Rin = None
_stimulus = 0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ class SpikingWongWangExcIOInhI(Model):
state_variables = ["s_AMPA", "x_NMDA", "s_NMDA", "s_GABA", "s_AMPA_ext", "V_m", "t_ref", # state variables
"spikes_ext", "spikes", "I_L", "I_AMPA", "I_NMDA", "I_GABA", "I_AMPA_ext"] # non-state variables
non_integrated_variables = ["spikes_ext", "spikes", "I_L", "I_AMPA", "I_NMDA", "I_GABA", "I_AMPA_ext"]
_nvar = 14
cvar = numpy.array([0], dtype=numpy.int32)
number_of_modes = 200 # assuming that 0...N_E-1 are excitatory and N_E ... number_of_modes-1 are inhibitory
_stimulus = 0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ class WilsonCowan(TVBWilsonCowan):
doc="""default state variables to be monitored""")

state_variables = ['E', 'I', 'Ein', 'Iin']
_nvar = 4

def update_derived_parameters(self):
"""
Expand Down
1 change: 0 additions & 1 deletion tvb_contrib/tvb/contrib/simulator/models/brunel_wang.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,6 @@ class BrunelWang(models.Model):
The corresponding state-variable units for this model are kHz.""")

state_variables = ["E", "I"]
_nvar = 2
cvar = numpy.array([0, 1], dtype=numpy.int32)

def configure(self):
Expand Down
1 change: 0 additions & 1 deletion tvb_contrib/tvb/contrib/simulator/models/epileptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ class HMJEpileptor(models.Model):
doc="""default state variables to be monitored""")

state_variables = ["y%d" % i for i in range(6)]
_nvar = 6
cvar = numpy.array([0, 3], dtype=numpy.int32)

def dfun(self, state_variables, coupling, local_coupling=0.0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ class Generic2dOscillator(models.Model):
history, it is also provides the default range of phase-plane plots.""")

state_variables = ["V", "W"]
_nvar = 2
cvar = numpy.array([0], dtype=numpy.int32)

def dfun(self, state_variables, coupling, local_coupling=0.0):
Expand Down
1 change: 0 additions & 1 deletion tvb_contrib/tvb/contrib/simulator/models/hindmarsh_rose.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ class HindmarshRose(models.Model):
:math:`y = 1`,and :math:`z = 2`.""")

state_variables = ["x", "y", "z"]
_nvar = 3
cvar = numpy.array([0], dtype=numpy.int32)

def dfun(self, state_variables, coupling, local_coupling=0.0):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ class JansenRitDavid(models.Model):
:math:`y5 = 5`""")

state_variables = ["x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7"]
_nvar = 8
cvar = numpy.array([1, 2], dtype=numpy.int32)

def dfun(self, state_variables, coupling, local_coupling=0.0):
Expand Down
1 change: 0 additions & 1 deletion tvb_contrib/tvb/contrib/simulator/models/larter.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ class Larter(models.Model):
:math:`W = 1`, and :math:`Z = 2`.""")

state_variables = ["V", "W", "Z"]
_nvar = 3
cvar = numpy.array([0], dtype=numpy.int32)

def dfun(self, state_variables, coupling, local_coupling=0.0):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,6 @@ class LarterBreakspear(models.Model):
history, it is also provides the default range of phase-plane plots.""")

state_variables = ["V", "W", "Z"]
_nvar = 3
cvar = numpy.array([0], dtype=numpy.int32)

def dfun(self, state_variables, coupling, local_coupling=0.0):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ class LileySteynRoss(models.Model):
and :math:`I = 1`.""")

state_variables = ["he", "hi"]
_nvar = 2
cvar = numpy.array([0, 1], dtype=numpy.int32)

def dfun(self, state_variables, coupling, local_coupling=0.0):
Expand Down
1 change: 0 additions & 1 deletion tvb_contrib/tvb/contrib/simulator/models/morris_lecar.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ class MorrisLecar(models.Model):
and :math:`N = 1`.""")

state_variables = ["V", "N"]
_nvar = 2
cvar = numpy.array([0], dtype=numpy.int32)

def dfun(self, state_variables, coupling, local_coupling=0.0):
Expand Down
1 change: 0 additions & 1 deletion tvb_contrib/tvb/contrib/simulator/models/wong_wang.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ class WongWang(models.Model):
doc="""default state variables to be monitored""")

state_variables = ["S1", "S2"]
_nvar = 2
cvar = numpy.array([0], dtype=numpy.int32)

def configure(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class ReducedWongWangProxy(ReducedWongWang):
modify class in order to take in count proxy firing rate and to monitor the firing rate
"""
state_variables = 'S H'.split()
_nvar = 2
state_variable_range = Final(
label="State variable ranges [lo, hi]",
default={"S": numpy.array([0.0, 1.0]),
Expand Down
1 change: 0 additions & 1 deletion tvb_documentation/dsl/tvb_dsl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ translates to:
)
state_variables = ('x1', 'y1', ...)

_nvar = 2
cvar = numpy.array([0], dtype=numpy.int32)


Expand Down
5 changes: 2 additions & 3 deletions tvb_library/tvb/simulator/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ class Model(HasTraits):
state_variables = () # type: typing.Tuple[str]
non_integrated_variables = None # type: typing.Tuple[str]
variables_of_interest = ()
_nvar = None # todo make this a prop len(state_variables)
_nintvar = _nvar
number_of_modes = 1
cvar = None
stvar = None
Expand Down Expand Up @@ -108,6 +106,7 @@ def configure(self):
@property
def nvar(self):
""" The number of state variables in this model. """
self._nvar = len(self.state_variables)
return self._nvar

@property
Expand All @@ -118,7 +117,7 @@ def nintvar(self):
@property
def nnonintvar(self):
""" The number of non integrated state variables in this model. """
return self._nvar - self._nintvar
return self.nvar - self.nintvar

@property
def has_nonint_vars(self):
Expand Down
2 changes: 0 additions & 2 deletions tvb_library/tvb/simulator/models/epileptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ class Epileptor(ModelNumbaDfun):

state_variables = ('x1', 'y1', 'z', 'x2', 'y2', 'g')

_nvar = 6
cvar = numpy.array([0, 3], dtype=numpy.int32) # should these not be constant Attr's?
cvar.setflags(write=False) # todo review this

Expand Down Expand Up @@ -475,7 +474,6 @@ class Epileptor2D(ModelNumbaDfun):

state_variables = ('x1', 'z')

_nvar = 2
cvar = numpy.array([0], dtype=numpy.int32)

def _numpy_dfun(self, state_variables, coupling, local_coupling=0.0,
Expand Down
1 change: 0 additions & 1 deletion tvb_library/tvb/simulator/models/epileptor_rs.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ class EpileptorRestingState(ModelNumbaDfun):

state_variables = ("x1", "y1", "z", "x2", "y2", "g", "x_rs", "y_rs")

_nvar = 8 # number of state-variables
cvar = numpy.array([0, 3, 6], dtype=numpy.int32) # coupling variables

def _numpy_dfun(self, state_variables, coupling, local_coupling=0.0,
Expand Down
2 changes: 0 additions & 2 deletions tvb_library/tvb/simulator/models/epileptorcodim3.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ class EpileptorCodim3(ModelNumbaDfun):
state_variables = ('x', 'y', 'z')

# number of state variables
_nvar = 3
cvar = numpy.array([0], dtype=numpy.int32)

# If there are derived parameters from the predefined parameters, then initialize them to None
Expand Down Expand Up @@ -486,7 +485,6 @@ class EpileptorCodim3SlowMod(ModelNumbaDfun):
state_variables = ('x', 'y', 'z', 'uA', 'uB')

# number of state variables
_nvar = 5
cvar = numpy.array([0], dtype=numpy.int32)

# If there are derived parameters from the predefined parameters, then initialize them to None
Expand Down
2 changes: 0 additions & 2 deletions tvb_library/tvb/simulator/models/hopfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,13 @@ class Hopfield(Model):

state_variables = ('x', 'theta')

_nvar = 2
cvar = numpy.array([0], dtype=numpy.int32)

def configure(self):
"""Set the threshold as a state variable for a dynamical threshold."""
super(Hopfield, self).configure()
if self.dynamic:
self.dfun = self.dfunDyn
self._nvar = 2
self.cvar = numpy.array([0, 1], dtype=numpy.int32)
# self.variables_of_interest = ["x", "theta"]

Expand Down
6 changes: 0 additions & 6 deletions tvb_library/tvb/simulator/models/infinite_theta.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ class MontbrioPazoRoxin(Model):
default='tau Delta eta J I cr cv'.split())

state_variables = ('r', 'V')
_nvar = 2
# Cvar is the coupling variable.
cvar = numpy.array([0, 1], dtype=numpy.int32)
# Stvar is the variable where stimulus is applied.
Expand Down Expand Up @@ -298,7 +297,6 @@ class CoombesByrne(Model):
)

state_variables = ('r', 'V', 'g', 'q')
_nvar = 4
# Cvar is the coupling variable.
cvar = numpy.array([0, 1, 2, 3], dtype=numpy.int32)

Expand Down Expand Up @@ -410,7 +408,6 @@ class CoombesByrne2D(Model):
)

state_variables = ('r', 'V')
_nvar = 2
# Cvar is the coupling variable.
cvar = numpy.array([0, 1], dtype=numpy.int32)

Expand Down Expand Up @@ -560,7 +557,6 @@ class GastSchmidtKnosche_SD(Model):
)

state_variables = ('r', 'V', 'A', 'B')
_nvar = 4
# Cvar is the coupling variable.
cvar = numpy.array([0, 1, 2, 3], dtype=numpy.int32)

Expand Down Expand Up @@ -719,7 +715,6 @@ class GastSchmidtKnosche_SF(Model):
)

state_variables = ('r', 'V', 'A', 'B')
_nvar = 4
# Cvar is the coupling variable.
cvar = numpy.array([0, 1, 2, 3], dtype=numpy.int32)

Expand Down Expand Up @@ -917,7 +912,6 @@ class DumontGutkin(Model):
)

state_variables = ('r_e', 'V_e', 's_ee', 's_ei', 'r_i', 'V_i', 's_ie', 's_ii')
_nvar = 8
# Cvar is the coupling variable.
cvar = numpy.array([0, 1, 4, 5], dtype=numpy.int32)

Expand Down
2 changes: 0 additions & 2 deletions tvb_library/tvb/simulator/models/jansen_rit.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ class JansenRit(ModelNumbaDfun):
:math:`y5 = 5`""")

state_variables = tuple('y0 y1 y2 y3 y4 y5'.split())
_nvar = 6
cvar = numpy.array([1, 2], dtype=numpy.int32)

def _numpy_dfun(self, state_variables, coupling, local_coupling=0.0):
Expand Down Expand Up @@ -467,7 +466,6 @@ class ZetterbergJansen(Model):
:math:`v_5 = 5`""")

state_variables = tuple('v1 y1 v2 y2 v3 y3 v4 y4 v5 y5 v6 v7'.split())
_nvar = 12
cvar = numpy.array([10], dtype=numpy.int32)
Heke = None # self.He * self.ke
Hiki = None # self.Hi * self.ki
Expand Down
1 change: 0 additions & 1 deletion tvb_library/tvb/simulator/models/k_ion_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ class KIonEx(Model):
)

state_variables = ['x', 'V','n','DKi','Kg']
_nvar = 5
# Cvar is the coupling variable.
cvar = numpy.array([0], dtype=numpy.int32)
# Stvar is the variable where stimulus is applied.
Expand Down
1 change: 0 additions & 1 deletion tvb_library/tvb/simulator/models/larter_breakspear.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,6 @@ class LarterBreakspear(Model):

state_variables = tuple('V W Z'.split())
_state_variables = ("V", "W", "Z")
_nvar = 3
cvar = numpy.array([0], dtype=numpy.int32)

def dfun(self, state_variables, coupling, local_coupling=0.0):
Expand Down
1 change: 0 additions & 1 deletion tvb_library/tvb/simulator/models/linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ class Linear(Model):
default=tuple('gamma'.split()))

state_variables = ('x',)
_nvar = 1
cvar = numpy.array([0], dtype=numpy.int32)

def dfun(self, state, coupling, local_coupling=0.0):
Expand Down
9 changes: 3 additions & 6 deletions tvb_library/tvb/simulator/models/oscillator.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ class Generic2dOscillator(ModelNumbaDfun):
doc="The quantities of interest for monitoring for the generic 2D oscillator.")

state_variables = ('V', 'W')
_nvar = 2
cvar = numpy.array([0], dtype=numpy.int32)

def _numpy_dfun(self, state_variables, coupling, local_coupling=0.0):
Expand Down Expand Up @@ -452,7 +451,6 @@ class Kuramoto(Model):
is not necessary to change the default here.""")

state_variables = ['theta']
_nvar = 1
cvar = numpy.array([0], dtype=numpy.int32)

def dfun(self, state_variables, coupling, local_coupling=0.0,
Expand Down Expand Up @@ -538,16 +536,15 @@ class SupHopf(ModelNumbaDfun):
conditions when the simulation isn't started from an explicit
history, it is also provides the default range of phase-plane plots.""")

state_variables = 'x y'.split(' ')

variables_of_interest = List(
of=str,
label="Variables watched by Monitors",
choices=("x", "y"),
choices=state_variables,
default=("x",),
doc="Quantities of supHopf available to monitor.")

state_variables = ["x", "y"]

_nvar = 2 # number of state-variables
cvar = numpy.array([0, 1], dtype=numpy.int32) # coupling variables

def _numpy_dfun(self, state_variables, coupling, local_coupling=0.0,
Expand Down
Loading