def setSwarmState(self, swarmId, newStatus):
assert (newStatus in ['<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'])<EOL>swarmInfo = self._state['<STR_LIT>'][swarmId]<EOL>if swarmInfo['<STR_LIT:status>'] == newStatus:<EOL><INDENT>return<EOL><DEDENT>if swarmInfo['<STR_LIT:status>'] == '<STR_LIT>' and newStatus == '<STR_LIT>':<EOL><INDENT>return<EOL><DEDENT>self._dirty = True<EOL>swarmInfo['<STR_LIT:status>'] = newStatus<EOL>if newStatus == '<STR_LIT>':<EOL><INDENT>(modelId, errScore) = self._hsObj._resultsDB.bestModelIdAndErrScore(swarmId)<EOL>swarmInfo['<STR_LIT>'] = modelId<EOL>swarmInfo['<STR_LIT>'] = errScore<EOL><DEDENT>if newStatus != '<STR_LIT>' and swarmId in self._state['<STR_LIT>']:<EOL><INDENT>self._state['<STR_LIT>'].remove(swarmId)<EOL><DEDENT>if newStatus=='<STR_LIT>':<EOL><INDENT>self._hsObj.killSwarmParticles(swarmId)<EOL><DEDENT>sprintIdx = swarmInfo['<STR_LIT>']<EOL>self.isSprintActive(sprintIdx)<EOL>sprintInfo = self._state['<STR_LIT>'][sprintIdx]<EOL>statusCounts = dict(active=<NUM_LIT:0>, completing=<NUM_LIT:0>, completed=<NUM_LIT:0>, killed=<NUM_LIT:0>)<EOL>bestModelIds = []<EOL>bestErrScores = []<EOL>for info in self._state['<STR_LIT>'].values():<EOL><INDENT>if info['<STR_LIT>'] != sprintIdx:<EOL><INDENT>continue<EOL><DEDENT>statusCounts[info['<STR_LIT:status>']] += <NUM_LIT:1><EOL>if info['<STR_LIT:status>'] == '<STR_LIT>':<EOL><INDENT>bestModelIds.append(info['<STR_LIT>'])<EOL>bestErrScores.append(info['<STR_LIT>'])<EOL><DEDENT><DEDENT>if statusCounts['<STR_LIT>'] > <NUM_LIT:0>:<EOL><INDENT>sprintStatus = '<STR_LIT>'<EOL><DEDENT>elif statusCounts['<STR_LIT>'] > <NUM_LIT:0>:<EOL><INDENT>sprintStatus = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>sprintStatus = '<STR_LIT>'<EOL><DEDENT>sprintInfo['<STR_LIT:status>'] = sprintStatus<EOL>if sprintStatus == '<STR_LIT>':<EOL><INDENT>if len(bestErrScores) > <NUM_LIT:0>:<EOL><INDENT>whichIdx = numpy.array(bestErrScores).argmin()<EOL>sprintInfo['<STR_LIT>'] = bestModelIds[whichIdx]<EOL>sprintInfo['<STR_LIT>'] = bestErrScores[whichIdx]<EOL><DEDENT>else:<EOL><INDENT>sprintInfo['<STR_LIT>'] = <NUM_LIT:0><EOL>sprintInfo['<STR_LIT>'] = numpy.inf<EOL><DEDENT>bestPrior = numpy.inf<EOL>for idx in range(sprintIdx):<EOL><INDENT>if self._state['<STR_LIT>'][idx]['<STR_LIT:status>'] == '<STR_LIT>':<EOL><INDENT>(_, errScore) = self.bestModelInCompletedSprint(idx)<EOL>if errScore is None:<EOL><INDENT>errScore = numpy.inf<EOL><DEDENT><DEDENT>else:<EOL><INDENT>errScore = numpy.inf<EOL><DEDENT>if errScore < bestPrior:<EOL><INDENT>bestPrior = errScore<EOL><DEDENT><DEDENT>if sprintInfo['<STR_LIT>'] >= bestPrior:<EOL><INDENT>self._state['<STR_LIT>'] = sprintIdx-<NUM_LIT:1><EOL><DEDENT>if self._state['<STR_LIT>'] is not Noneand not self.anyGoodSprintsActive():<EOL><INDENT>self._state['<STR_LIT>'] = True<EOL><DEDENT><DEDENT>
Change the given swarm's state to 'newState'. If 'newState' is
        'completed', then bestModelId and bestErrScore must be provided.

        Parameters:
        ---------------------------------------------------------------------
        swarmId:      swarm Id
        newStatus:    new status, either 'active', 'completing', 'completed', or
                        'killed'