私は現在、SciPy.integrate.odeを使用してPythonで複雑な微生物食物網を実装しています。システムに種や反応を簡単に追加する機能が必要なので、非常に一般的なものをコーディングする必要があります。私のスキームは次のようになります。
class Reaction(object):
def __init__(self):
#stuff common to all reactions
def __getReactionRate(self, **kwargs):
raise NotImplementedError
... Reaction subclasses that
... implement specific types of reactions
class Species(object):
def __init__(self, reactionsDict):
self.reactionsDict = reactionsDict
#reactionsDict looks like {'ReactionName':reactionObject, ...}
#stuff common to all species
def sumOverAllReactionsForThisSpecies(self, **kwargs):
#loop over all the reactions and return the
#cumulative change in the concentrations of all solutes
...Species subclasses where for each species
... are defined and passed to the superclass constructor
class FermentationChamber(object):
def __init__(self, speciesList, timeToSolve, *args):
#do initialization
def step(self):
#loop over each species, which in turn loops
#over each reaction inside it and return a
#cumulative dictionary of total change for each
#solute in the whole system
if __name__==__main__:
f = FermentationChamber(...)
o = ode(...) #initialize ode solver
while o.successful() and o.t<timeToSolve:
o.integrate()
#process o.t and o.y (o.t contains the time points
#and o.y contains the solution matrix)
したがって、問題は、との辞書を反復処理するときにSpecies.sumOverAllReactionsForThisSpecies()
、FermentationChamber.step()
最初と最後の反復の間に辞書に要素が追加または削除されない場合、辞書の反復順序が同じであることが保証されるかどうかです。つまり、辞書から各反復で作成されるnumpy配列の順序は変わらないと想定できますか?たとえば、ディクショナリの形式が{'Glucose':10、'Fructose':12}の場合、このディクショナリから作成された配列の順序は常に同じになります(順序が何であっても、それは決定論的です)。
メガポストで申し訳ありませんが、私がどこから来たのかをお知らせしたいと思います。