def __init__(self, searchParams, workerID=None, cjDAO=None, jobID=None,<EOL>logLevel=None):
<EOL>self.logger = logging.getLogger("<STR_LIT:.>".join( ['<STR_LIT>',<EOL>self.__class__.__module__, self.__class__.__name__]))<EOL>if logLevel is not None:<EOL><INDENT>self.logger.setLevel(logLevel)<EOL><DEDENT>random.seed(<NUM_LIT>)<EOL>self._searchParams = searchParams<EOL>self._workerID = workerID<EOL>self._cjDAO = cjDAO<EOL>self._jobID = jobID<EOL>self.logger.info("<STR_LIT>" % (pprint.pformat(<EOL>clippedObj(searchParams))))<EOL>self._createCheckpoints = self._searchParams.get('<STR_LIT>',<EOL>False)<EOL>self._maxModels = self._searchParams.get('<STR_LIT>', None)<EOL>if self._maxModels == -<NUM_LIT:1>:<EOL><INDENT>self._maxModels = None<EOL><DEDENT>self._predictionCacheMaxRecords = self._searchParams.get('<STR_LIT>', None)<EOL>self._speculativeParticles = self._searchParams.get('<STR_LIT>',<EOL>bool(int(Configuration.get(<EOL>'<STR_LIT>'))))<EOL>self._speculativeWaitSecondsMax = float(Configuration.get(<EOL>'<STR_LIT>'))<EOL>self._maxBranching= int(Configuration.get(<EOL>'<STR_LIT>'))<EOL>self._minFieldContribution= float(Configuration.get(<EOL>'<STR_LIT>'))<EOL>self._jobCancelled = False<EOL>if '<STR_LIT>' in self._searchParams:<EOL><INDENT>useTerminators = self._searchParams['<STR_LIT>']<EOL>useTerminators = str(int(useTerminators))<EOL>Configuration.set('<STR_LIT>', useTerminators)<EOL>Configuration.set('<STR_LIT>', useTerminators)<EOL>Configuration.set('<STR_LIT>', useTerminators)<EOL><DEDENT>if '<STR_LIT>' in os.environ:<EOL><INDENT>self._maxModels = int(os.environ['<STR_LIT>'])<EOL><DEDENT>self._dummyModel = self._searchParams.get('<STR_LIT>', None)<EOL>self._tempDir = None<EOL>try:<EOL><INDENT>if '<STR_LIT:description>' in self._searchParams:<EOL><INDENT>if ('<STR_LIT>' in self._searchParams or<EOL>'<STR_LIT>' in self._searchParams or<EOL>'<STR_LIT>' in self._searchParams):<EOL><INDENT>raise RuntimeError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>searchParamObj = self._searchParams<EOL>anomalyParams = searchParamObj['<STR_LIT:description>'].get('<STR_LIT>',<EOL>dict())<EOL>if anomalyParams is None:<EOL><INDENT>anomalyParams = dict()<EOL><DEDENT>if (('<STR_LIT>' not in anomalyParams) or<EOL>(anomalyParams['<STR_LIT>'] is None)):<EOL><INDENT>streamDef = self._getStreamDef(searchParamObj['<STR_LIT:description>'])<EOL>from nupic.data.stream_reader import StreamReader<EOL>try:<EOL><INDENT>streamReader = StreamReader(streamDef, isBlocking=False,<EOL>maxTimeout=<NUM_LIT:0>, eofOnTimeout=True)<EOL>anomalyParams['<STR_LIT>'] =streamReader.getDataRowCount()<EOL><DEDENT>except Exception:<EOL><INDENT>anomalyParams['<STR_LIT>'] = None<EOL><DEDENT>self._searchParams['<STR_LIT:description>']['<STR_LIT>'] = anomalyParams<EOL><DEDENT>outDir = self._tempDir = tempfile.mkdtemp()<EOL>expGenerator([<EOL>'<STR_LIT>' % (<EOL>json.dumps(self._searchParams['<STR_LIT:description>'])),<EOL>'<STR_LIT>',<EOL>'<STR_LIT>' % (outDir)])<EOL>permutationsScript = os.path.join(outDir, '<STR_LIT>')<EOL><DEDENT>elif '<STR_LIT>' in self._searchParams:<EOL><INDENT>if ('<STR_LIT:description>' in self._searchParams or<EOL>'<STR_LIT>' in self._searchParams or<EOL>'<STR_LIT>' in self._searchParams):<EOL><INDENT>raise RuntimeError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>permutationsScript = self._searchParams['<STR_LIT>']<EOL><DEDENT>elif '<STR_LIT>' in self._searchParams:<EOL><INDENT>if ('<STR_LIT:description>' in self._searchParams or<EOL>'<STR_LIT>' in self._searchParams):<EOL><INDENT>raise RuntimeError(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>assert ('<STR_LIT>' in self._searchParams)<EOL>outDir = self._tempDir = tempfile.mkdtemp()<EOL>permutationsScript = os.path.join(outDir, '<STR_LIT>')<EOL>fd = open(permutationsScript, '<STR_LIT:w>')<EOL>fd.write(self._searchParams['<STR_LIT>'])<EOL>fd.close()<EOL>fd = open(os.path.join(outDir, '<STR_LIT>'), '<STR_LIT:w>')<EOL>fd.write(self._searchParams['<STR_LIT>'])<EOL>fd.close()<EOL><DEDENT>else:<EOL><INDENT>raise RuntimeError ("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>self._basePath = os.path.dirname(permutationsScript)<EOL>self._baseDescription = open(os.path.join(self._basePath,<EOL>'<STR_LIT>')).read()<EOL>self._baseDescriptionHash = hashlib.md5(self._baseDescription).digest()<EOL>modelDescription, _ = helpers.loadExperiment(self._basePath)<EOL>self._readPermutationsFile(permutationsScript, modelDescription)<EOL>if self._cjDAO is not None:<EOL><INDENT>updated = self._cjDAO.jobSetFieldIfEqual(jobID=self._jobID,<EOL>fieldName='<STR_LIT>',<EOL>curValue=None,<EOL>newValue = self._baseDescription)<EOL>if updated:<EOL><INDENT>permContents = open(permutationsScript).read()<EOL>self._cjDAO.jobSetFieldIfEqual(jobID=self._jobID,<EOL>fieldName='<STR_LIT>',<EOL>curValue=None,<EOL>newValue = permContents)<EOL><DEDENT><DEDENT>if self._dummyModelParamsFunc is not None:<EOL><INDENT>if self._dummyModel is None:<EOL><INDENT>self._dummyModel = dict()<EOL><DEDENT><DEDENT>if self.logger.getEffectiveLevel() <= logging.DEBUG:<EOL><INDENT>msg = io.StringIO()<EOL>print("<STR_LIT>", file=msg)<EOL>info = dict()<EOL>for key in ['<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>',<EOL>'<STR_LIT>', '<STR_LIT>', '<STR_LIT>']:<EOL><INDENT>info[key] = getattr(self, key)<EOL><DEDENT>print(pprint.pformat(info), file=msg)<EOL>self.logger.debug(msg.getvalue())<EOL>msg.close()<EOL><DEDENT>self._resultsDB = ResultsDB(self)<EOL>self._swarmTerminator = SwarmTerminator()<EOL>self._hsState = None<EOL>self._maxUniqueModelAttempts = int(Configuration.get(<EOL>'<STR_LIT>'))<EOL>self._modelOrphanIntervalSecs = float(Configuration.get(<EOL>'<STR_LIT>'))<EOL>self._maxPctErrModels = float(Configuration.get(<EOL>'<STR_LIT>'))<EOL><DEDENT>except:<EOL><INDENT>if self._tempDir is not None:<EOL><INDENT>shutil.rmtree(self._tempDir)<EOL>self._tempDir = None<EOL><DEDENT>raise<EOL><DEDENT>return<EOL>
Instantiate the HyperseachV2 instance.

        Parameters:
        ----------------------------------------------------------------------
        searchParams:   a dict of the job's search parameters. The format is:

          persistentJobGUID:  REQUIRED.
                              Persistent, globally-unique identifier for this job
                              for use in constructing persistent model checkpoint
                              keys. MUST be compatible with S3 key-naming rules, but
                              MUST NOT contain forward slashes. This GUID is
                              expected to retain its global uniqueness across
                              clusters and cluster software updates (unlike the
                              record IDs in the Engine's jobs table, which recycle
                              upon table schema change and software update). In the
                              future, this may also be instrumental for checkpoint
                              garbage collection.

          permutationsPyFilename:
                              OPTIONAL - path to permutations.py file
          permutationsPyContents:
                              OPTIONAL - JSON encoded string with
                                          contents of permutations.py file
          descriptionPyContents:
                              OPTIONAL - JSON encoded string with
                                          contents of base description.py file
          description:        OPTIONAL - JSON description of the search
          createCheckpoints:  OPTIONAL - Whether to create checkpoints
          useTerminators      OPTIONAL - True of False (default config.xml). When set
                                         to False, the model and swarm terminators
                                         are disabled
          maxModels:          OPTIONAL - max # of models to generate
                                        NOTE: This is a deprecated location for this
                                        setting. Now, it should be specified through
                                        the maxModels variable within the permutations
                                        file, or maxModels in the JSON description
          dummyModel:         OPTIONAL - Either (True/False) or a dict of parameters
                                         for a dummy model. If this key is absent,
                                         a real model is trained.
                                         See utils.py/OPFDummyModel runner for the
                                         schema of the dummy parameters
          speculativeParticles OPTIONAL - True or False (default obtained from
                                         nupic.hypersearch.speculative.particles.default
                                         configuration property). See note below.

          NOTE: The caller must provide just ONE of the following to describe the
          hypersearch:
                1.) permutationsPyFilename
            OR  2.) permutationsPyContents & permutationsPyContents
            OR  3.) description

          The schema for the description element can be found at:
           "py/nupic/frameworks/opf/expGenerator/experimentDescriptionSchema.json"

          NOTE about speculativeParticles: If true (not 0), hypersearch workers will
          go ahead and create and run particles in subsequent sprints and
          generations before the current generation or sprint has been completed. If
          false, a worker will wait in a sleep loop until the current generation or
          sprint has finished before choosing the next particle position or going
          into the next sprint. When true, the best model can be found faster, but
          results are less repeatable due to the randomness of when each worker
          completes each particle. This property can be overridden via the
          speculativeParticles element of the Hypersearch job params.


        workerID:   our unique Hypersearch worker ID

        cjDAO:      ClientJobsDB Data Access Object
        jobID:      job ID for this hypersearch job
        logLevel:   override logging level to this value, if not None