def fromProtoModel(cls, protomodel, nsteps=10000, strategy="aggressive", walkerid=0, dump_training=False, dbpath="<rundir>/database.pcl", expected=False, select="all", catch_exceptions=True, keep_meta=True, rundir=None, do_combine=False, seed=None, stopTeleportationAfter=-1): ret = cls( walkerid, nsteps=nsteps, dbpath = dbpath, expected=expected, select=select, catch_exceptions = catch_exceptions, rundir = rundir, do_combine = do_combine, seed = seed, stopTeleportationAfter = \ stopTeleportationAfter ) ret.manipulator.M = protomodel ret.manipulator.setWalkerId(walkerid) ret.manipulator.backupModel() if dump_training: ## we use the accelerator only to dump the training data from accelerator import Accelerator ret.accelerator = Accelerator(walkerid=walkerid, dump_training=True, is_trained=False) return ret
def __init__(self, walkerid=0, nsteps=10000, strategy="aggressive", dump_training=False, cheatcode=0, dbpath="./database.pcl", expected=False, select="all", catch_exceptions=True, rundir=None, nevents=100000, do_combine=False, record_history=False, seed=None, stopTeleportationAfter=-1): """ initialise the walker :param nsteps: maximum number of steps to perform, negative is infinity :param cheatcode: cheat mode. 0 is no cheating, 1 is with ranges, 2 is the Z323 model. :param expected: remove possible signals from database :param select: select only subset of results (all for all, em for efficiency maps only, ul for upper limits only, alternatively select for txnames via e.g. "txnames:T1,T2" :param catch_exceptions: should we catch exceptions :param nevents: number of MC events when computing cross-sections :param do_combine: if true, then also perform combinations, either via simplified likelihoods or via pyhf :param record_history: if true, attach a history recorder class :param seed: random seed, int or None :param stopTeleportationAfter: int or None. we stop teleportation after this step nr. If negative or None, we dont teleport at all """ if type(walkerid) != int or type(nsteps) != int or type( strategy) != str: self.pprint("Wrong call of constructor: %s, %s, %s" % (walkerid, nsteps, strategy)) sys.exit(-2) self.walkerid = walkerid ## walker id, for parallel runs self.rundir = rundir if rundir == None: self.rundir = "./" if seed is not None: from ptools import helpers helpers.seedRandomNumbers(seed + walkerid) self.pprint(f"setting random seed to {seed}") #Initialize Predictor self.predictor = Predictor(self.walkerid, dbpath=dbpath, expected=expected, select=select, do_combine=do_combine) #Initialize Hiscore (with access to the predictor) self.hiscoreList = Hiscore(walkerid, True, "%s/H%d.hi" % (self.rundir, walkerid), backup=False, predictor=self.predictor) self.hiscoreList.nkeep = 1 #Initialize ProtoModel and Manipulator: protomodel = ProtoModel( self.walkerid, keep_meta=True, nevents=nevents, dbversion=self.predictor.database.databaseVersion) self.manipulator = Manipulator(protomodel, strategy, do_record=record_history, seed=seed) self.catch_exceptions = catch_exceptions self.maxsteps = nsteps if stopTeleportationAfter == None: stopTeleportationAfter = -1 # stopTeleportationAfter = self.maxsteps/3. self.stopTeleportationAfter = stopTeleportationAfter self.accelerator = None if record_history: from ptools.history import History self.recorder = History(f"{self.rundir}/history{walkerid}.list") self.manipulator.do_record = True jobid = "unknown" if "SLURM_JOBID" in os.environ: jobid = os.environ["SLURM_JOBID"] self.pprint("Ramping up with slurm jobid %s" % jobid) if cheatcode <= 0: self.takeStep() # the first step should be considered as "taken" #Set current Z and K values to threshold values self.currentZ = -0.1 self.currentK = -20.0 else: self.manipulator.cheat(cheatcode) self.predictor.predict(self.protomodel) self.pprint ( "Cheat model gets Z=%.2f, K=%.2f" % \ ( self.manipulator.M.Z, self.manipulator.M.K ) ) # self.printStats ( substep=4 ) self.manipulator.backupModel() self.hiscoreList.newResult(self.manipulator) self.printStats(substep=5) self.currentK = self.manipulator.M.K self.currentZ = self.manipulator.M.Z if dump_training: from accelerator import Accelerator ## we use the accelerator only to dump the training data self.accelerator = Accelerator(walkerid=walkerid, dump_training=True, is_trained=False)