def run(): count = 500 for i in umpf.map(umpf_test.f, xrange(count), xrange(count+2)): i boris = umpf_test.Boris() for i in umpf.map(boris.g, xrange(count), xrange(count+2)): i for i in umpf.map(boris, xrange(count), xrange(count+2)): i
def do(self, count): """ Enumerate all possible reactant collections and determine products via :py:meth:`achemkit.achem.AChem.all_reactions`. Uses :py:mod:`umpf` for parallelism. :param integer count: Maximum number of additional molecular species to discover. :rtype: yields :py:class:`achemkit.Event` objects. """ self.maxmols += count while len(self.mols) < self.maxmols and len(self.untested) > 0: untested = tuple(self.untested) self.untested = [] results = umpf.map(self.achem.all_reactions, untested) while len(self.mols) < self.maxmols: try: reactions = results.next() except StopIteration: break else: for reaction in reactions: reactants, products = reaction e = Event(0.0, reactants, products, reactions[reaction]) yield e for product in products: self.add_mol(product)
def do(self, count): """ Enumerate all possible reactant collections and determine products via :py:meth:`achemkit.achem.AChem.all_reactions`. Uses :py:mod:`umpf` for parallelism. :param integer count: Maximum number of additional molecular species to discover. :rtype: yields :py:class:`achemkit.Event` objects. """ self.maxmols += count while len(self.mols) < self.maxmols and len(self.untested) > 0: untested = tuple(self.untested) self.untested = [] results = umpf.map(self.achem.all_reactions, untested) while len(self.mols) < self.maxmols: try: reactions = next(results) except StopIteration: break else: for reaction in reactions: reactants, products = reaction e = Event(0.0, reactants, products, reactions[reaction]) yield e for product in products: self.add_mol(product)
def do(self, time): """ Assign all molecules to a collection of reactants. Use the combined collections of products as the new molecules. Uses :py:mod:`umpf` for parallelism. :param float time: Time to simulate, at a rate of one step per unit. :rtype: yields :py:class:`achemkit.Event` objects. """ self.maxtime += time while self.time < self.maxtime: self.mols = tuple(self.rng.sample(self.mols, len(self.mols))) newmols = () allreactants = [] while len(self.mols) > 0: noreactants = get_sample(self.achem.noreactants) if noreactants <= len(self.mols): reactants = self.mols[:noreactants] self.mols = self.mols[noreactants:] allreactants.append(OrderedFrozenBag(reactants)) else: break allproducts = umpf.map(self.achem.react, allreactants) results = itertools.izip(allreactants, allproducts) for reactants, products in results: e = Event(self.time, reactants, products) newmols += tuple(products) yield e self.mols = newmols self.time += 1.0
def do(self, time): """ Assign all molecules to a collection of reactants. Use the combined collections of products as the new molecules. Uses :py:mod:`umpf` for parallelism. :param float time: Time to simulate, at a rate of one step per unit. :rtype: yields :py:class:`achemkit.Event` objects. """ self.maxtime += time while self.time < self.maxtime: self.mols = tuple(self.rng.sample(self.mols, len(self.mols))) newmols = () allreactants = [] while len(self.mols) > 0: noreactants = get_sample(self.achem.noreactants) if noreactants <= len(self.mols): reactants = self.mols[:noreactants] self.mols = self.mols[noreactants:] allreactants.append(OrderedFrozenBag(reactants)) else: break allproducts = umpf.map(self.achem.react, allreactants) results = zip(allreactants, allproducts) for reactants, products in results: e = Event(self.time, reactants, products) newmols += tuple(products) yield e self.mols = newmols self.time += 1.0