def _runExperimentImpl(options, model=None):
json_helpers.validate(options.privateOptions,<EOL>schemaDict=g_parsedPrivateCommandLineOptionsSchema)<EOL>experimentDir = options.experimentDir<EOL>descriptionPyModule = helpers.loadExperimentDescriptionScriptFromDir(<EOL>experimentDir)<EOL>expIface = helpers.getExperimentDescriptionInterfaceFromModule(<EOL>descriptionPyModule)<EOL>if options.privateOptions['<STR_LIT>']:<EOL><INDENT>_printAvailableCheckpoints(experimentDir)<EOL>return None<EOL><DEDENT>experimentTasks = expIface.getModelControl().get('<STR_LIT>', [])<EOL>if (len(experimentTasks) == <NUM_LIT:0> and<EOL>expIface.getModelControl()['<STR_LIT>'] == OpfEnvironment.Nupic):<EOL><INDENT>expIface.convertNupicEnvToOPF()<EOL>experimentTasks = expIface.getModelControl().get('<STR_LIT>', [])<EOL><DEDENT>expIface.normalizeStreamSources()<EOL>newSerialization = options.privateOptions['<STR_LIT>']<EOL>if options.privateOptions['<STR_LIT>']:<EOL><INDENT>print("<STR_LIT>")<EOL>for label in [t['<STR_LIT>'] for t in experimentTasks]:<EOL><INDENT>print("<STR_LIT:\t>", label)<EOL><DEDENT>return None<EOL><DEDENT>if options.privateOptions['<STR_LIT>']:<EOL><INDENT>assert model is None<EOL>checkpointName = options.privateOptions['<STR_LIT>']<EOL>model = ModelFactory.loadFromCheckpoint(<EOL>savedModelDir=_getModelCheckpointDir(experimentDir, checkpointName),<EOL>newSerialization=newSerialization)<EOL><DEDENT>elif model is not None:<EOL><INDENT>print("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>modelDescription = expIface.getModelDescription()<EOL>model = ModelFactory.create(modelDescription)<EOL><DEDENT>if options.privateOptions['<STR_LIT>']:<EOL><INDENT>checkpointName = options.privateOptions['<STR_LIT>']<EOL>_saveModel(model=model,<EOL>experimentDir=experimentDir,<EOL>checkpointLabel=checkpointName,<EOL>newSerialization=newSerialization)<EOL>return model<EOL><DEDENT>taskIndexList = list(range(len(experimentTasks)))<EOL>customTaskExecutionLabelsList = options.privateOptions['<STR_LIT>']<EOL>if customTaskExecutionLabelsList:<EOL><INDENT>taskLabelsList = [t['<STR_LIT>'] for t in experimentTasks]<EOL>taskLabelsSet = set(taskLabelsList)<EOL>customTaskExecutionLabelsSet = set(customTaskExecutionLabelsList)<EOL>assert customTaskExecutionLabelsSet.issubset(taskLabelsSet),("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>") % (customTaskExecutionLabelsSet - taskLabelsSet,<EOL>customTaskExecutionLabelsList)<EOL>taskIndexList = [taskLabelsList.index(label) for label in<EOL>customTaskExecutionLabelsList]<EOL>print("<STR_LIT>" % [taskLabelsList[i] for<EOL>i in taskIndexList])<EOL><DEDENT>for taskIndex in taskIndexList:<EOL><INDENT>task = experimentTasks[taskIndex]<EOL>taskRunner = _TaskRunner(model=model,<EOL>task=task,<EOL>cmdOptions=options)<EOL>taskRunner.run()<EOL>del taskRunner<EOL>if options.privateOptions['<STR_LIT>']:<EOL><INDENT>_saveModel(model=model,<EOL>experimentDir=experimentDir,<EOL>checkpointLabel=task['<STR_LIT>'],<EOL>newSerialization=newSerialization)<EOL><DEDENT><DEDENT>return model<EOL>
Creates and runs the experiment

    Args:
      options: namedtuple ParseCommandLineOptionsResult
      model: For testing: may pass in an existing OPF Model instance
          to use instead of creating a new one.

    Returns: reference to OPFExperiment instance that was constructed (this
        is provided to aid with debugging) or None, if none was
        created.