def csir_layout(self, rlayout): ''' cassegrain focus infrared ''' r1layout = QtGui.QVBoxLayout() #r1layout.addWidget(self.d1) empty_shell = Dummy(height=25, logger=self.logger) r1layout.addWidget(empty_shell) self.tipchop = TipChop(logger=self.logger) r1layout.addWidget(self.tipchop) empty_shell = Dummy(height=35, logger=self.logger) r1layout.addWidget(empty_shell) r2layout = QtGui.QVBoxLayout() r2layout.setSpacing(1) empty_shell = Dummy(height=1, logger=self.logger) r2layout.addWidget(empty_shell) self.insrot = InsRot.InsRotCs(logger=self.logger) r2layout.addWidget(self.insrot) empty_shell = Dummy(height=320, logger=self.logger) r2layout.addWidget(empty_shell) rlayout.addLayout(r1layout) rlayout.addLayout(r2layout)
def main(): NETWORK_1 = "../data/Networks/RL/Gen_2/network.h5" NETWORK_2 = "../data/Networks/RL/Gen_2/network.h5" NETWORK_3 = "" NETWORK_4 = "" BIDDING_1 = "../data/Networks/RL/Gen_2/bidding" BIDDING_2 = "../data/Networks/RL/Gen_2/bidding" BIDDING_3 = "" BIDDING_4 = "" # network_1 = loadNetwork (NETWORK_1) # biddingBase_1 = loadBiddingBase (BIDDING_1) network_1 = loadNetwork("") biddingBase_1 = loadBiddingBase("") agent_1 = Agent(network_1, biddingBase_1) # agent_2 = Agent (network_1, biddingBase_1) # agent_3 = Agent (network_1, biddingBase_1) # agent_4 = Agent (network_1, biddingBase_1) agent_2 = Dummy() agent_3 = Agent(network_1, biddingBase_1) agent_4 = Dummy() agents = [agent_1, agent_2, agent_3, agent_4] for agent in agents: agent.setCoefficient(BIDDING_ALPHA, EXPLORE_COEFFICIENT) episodes = 500 # deal = gd.genDeal () # gd.printHand (deal) # (par, resTable) = gd.getPar (deal) # print (resTable) # deal = gd.genDeal () deal = gd.getDealFromPreset(1) for i in range(episodes): # deal = gd.genDeal () giveHands(agents, gd.getHand(deal)) bids = play(agents) results = [] counter = -1 for agent in agents: counter += 1 if counter > 3: counter = 0 if counter != 0: continue results.append((counter, agent.feedback())) (par, resTable) = gd.getPar(deal) score = getScore(bids, resTable) # learn (network_1, results, par, score, resTable) expReplay(network_1, par, gd.getHand(deal), resTable, mode=2) writeBiddingBase(biddingBase_1, BIDDING_1) print(bids) print(par, score) print("----") saveNetwork(network_1, NETWORK_1)
def testA(self): """ Check worker methods get called. We sleep occasionally to ensure these asynchronous calls have enough time to be called """ # Create a worker manager compDummy = Dummy() print('create manager') manager = WorkerThreadManager(compDummy) # Pause it print('pause workers') manager.pauseWorkers() # Add a worker, and check init method gets called print('add worker') manager.addWorker(DummyWorker1(), 1) time.sleep(3) self.assertEqual(WorkerThreadsTest._setupCalled, True) # Ensure the algo wasn't called whilst paused self.assertEqual(WorkerThreadsTest._algoCalled, False) print('resume workers') # Run the workers, pause, and check algo method gets called manager.resumeWorkers() time.sleep(3) manager.pauseWorkers() self.assertEqual(WorkerThreadsTest._algoCalled, True) print('terminate workers') # Terminate the workers, and check terminate method gets called manager.terminateWorkers() time.sleep(3) self.assertEqual(WorkerThreadsTest._terminateCalled, True)
def testB(self): """ Check we can terminate before pausing workers """ compDummy = Dummy() print('create manager') manager = WorkerThreadManager(compDummy) print('add worker') manager.addWorker(DummyWorker2(), 1) print('terminate worker') manager.terminateWorkers()
def popt_layout(self, rlayout): ''' prime focus optical''' r1layout=QtGui.QVBoxLayout() #r1layout.addWidget(self.d1) empty_shell=Dummy(height=95, logger=self.logger) r1layout.addWidget(empty_shell) r2layout=QtGui.QVBoxLayout() r2layout.setSpacing(1) empty_shell=Dummy(height=1, logger=self.logger) r2layout.addWidget(empty_shell) self.insrot=InsRot.InsRotPf(logger=self.logger) r2layout.addWidget(self.insrot) self.adc = Adc.AdcPf(logger=self.logger) r2layout.addWidget(self.adc) empty_shell=Dummy(height=285, logger=self.logger) r2layout.addWidget(empty_shell) rlayout.addLayout(r1layout) rlayout.addLayout(r2layout)
def nsopt_layout(self, rlayout): ''' nasmyth focus optical''' r1layout=QtGui.QVBoxLayout() #r1layout.addWidget(self.d1) empty_shell=Dummy(height=95, logger=self.logger) r1layout.addWidget(empty_shell) r2layout=QtGui.QVBoxLayout() r2layout.setSpacing(1) empty_shell=Dummy(height=1, logger=self.logger) r2layout.addWidget(empty_shell) self.imgrot=ImgRot.ImgRotNsOpt(logger=self.logger) r2layout.addWidget(self.imgrot) self.adc = Adc.Adc(logger=self.logger) r2layout.addWidget(self.adc) empty_shell=Dummy(height=277, logger=self.logger) r2layout.addWidget(empty_shell) rlayout.addLayout(r1layout) rlayout.addLayout(r2layout)
def addNew(self, name, scanType): """ Try to add a new scan with the given name and tnype ParameterScanCollectionException is raised if there is a problem (name already taken or invalid type). Returns a reference to the newly created scan. """ if name in self.scans.keys(): raise ParameterScanCollectionException("Name '" + name + "' already taken") scanFolder = os.path.join(self.folder, "scans", name) if scanType == "ParameterScan::Dummy" or scanType == "Dummy": from Dummy import Dummy Dummy.createNew(scanFolder) self.scans[name] = newScan = Dummy(scanFolder, self) elif scanType == "ParameterScan::DummySubscan" or scanType == "DummySubscan": from DummySubscan import DummySubscan DummySubscan.createNew(scanFolder) self.scans[name] = newScan = DummySubscan(scanFolder, self) elif scanType == "ParameterScan::TuneFreq" or scanType == "TuneFreq": from TuneFreq import TuneFreq TuneFreq.createNew(scanFolder) self.scans[name] = newScan = TuneFreq(scanFolder,self) elif scanType == "ParameterScan::Scan2D" or scanType == "Scan2D": from Scan2D import Scan2D Scan2D.createNew(scanFolder) self.scans[name] = newScan = Scan2D(scanFolder,self) elif scanType == "ParameterScan::Scan2D_Tune" or scanType == "Scan2D_Tune": from Scan2D_Tune import Scan2D_Tune Scan2D_Tune.createNew(scanFolder) self.scans[name] = newScan = Scan2D_Tune(scanFolder,self) else: if scanType in self.parameterScanTypes or "ParameterScan::"+scanType in self.parameterScanTypes: raise NotImplementedError("Forgot to implement support for ParameterScan '" + scanType + "'!") raise ParameterScanCollectionException("Unknown ParameterScan type '" + scanType + "'") self.__paramfile.dataDict["scans"].pushBack(name,newScan.type) self.__paramfile.write() return self.scans[name]
def nsir_layout(self, rlayout): ''' nasmyth focus infrared''' r1layout=QtGui.QVBoxLayout() #r1layout.addWidget(self.d1) empty_shell=Dummy(height=95, logger=self.logger) r1layout.addWidget(empty_shell) r2layout=QtGui.QVBoxLayout() r2layout.setSpacing(1) empty_shell=Dummy(height=1, logger=self.logger) r2layout.addWidget(empty_shell) self.imgrot=ImgRot.ImgRotNsIr(logger=self.logger) r2layout.addWidget(self.imgrot) self.waveplate=Waveplate(logger=self.logger) r2layout.addWidget(self.waveplate) empty_shell=Dummy(height=250, logger=self.logger) r2layout.addWidget(empty_shell) rlayout.addLayout(r1layout) rlayout.addLayout(r2layout)
def pir_layout(self, rlayout): ''' prime focus infrared''' r1layout=QtGui.QVBoxLayout() #r1layout.addWidget(self.d1) empty_shell=Dummy(height=95, logger=self.logger) r1layout.addWidget(empty_shell) r2layout=QtGui.QVBoxLayout() r2layout.setSpacing(1) empty_shell=Dummy(height=1, logger=self.logger) r2layout.addWidget(empty_shell) self.insrot=InsRot.InsRotPf(logger=self.logger) r2layout.addWidget(self.insrot) empty_shell=Dummy(height=320, logger=self.logger) r2layout.addWidget(empty_shell) rlayout.addLayout(r1layout) rlayout.addLayout(r2layout)
def processdummy(model, parent): d = Object.Get(model) dt = d.getType() putlog(NBLog.INFO, "Processing %s (%s)" % (model, dt)) if dt != 'Empty': putlog(NBLog.CRITICAL, "Internal error: Can't process this type here!") return dummy = Dummy() if parent != "NULL": dummy.setParent(parent) dummy.setName(model) dummyloc = d.getLocation() dummy.setPosition(dummyloc) return dummy
def processdummy(model,parent): d = Object.Get(model) dt = d.getType() putlog(NBLog.INFO, "Processing %s (%s)" % (model, dt)) if dt != 'Empty': putlog(NBLog.CRITICAL, "Internal error: Can't process this type here!") return dummy = Dummy() if parent != "NULL": dummy.setParent(parent) dummy.setName(model) dummyloc = d.getLocation() dummy.setPosition(dummyloc) return dummy
def testWorkerError(self): """If a worker raises an exception terminate the entire component""" compDummy = Dummy() print('create manager') manager = WorkerThreadManager(compDummy) # needed for handling errors - harness would generally set this myThread = threading.currentThread() myThread.workerThreadManager = manager print('add workers') manager.addWorker(DummyWorker1(), 0.1) manager.addWorker(ErrorWorker(), 0.1) print('run workers, one will throw an error') manager.resumeWorkers() # should do something smarter here # too short a time and threads havent exited yet time.sleep(6) # all threads should have ended after worker raised exception self.assertEqual(manager.activeThreadCount, 0)
def testA(self): """ __testSubscribe__ Test subscription of a component. """ raise nose.SkipTest myThread = threading.currentThread() # create a 'fake' component that contains a arg dictionary. component = Dummy() # load default parameters. config = self.testInit.getConfiguration() # normally assigned by the harness of the test component. config.Agent.componentName = "TestComponent" component.config = config threadPools = [] for i in xrange(0, ThreadPoolTest._nrOfPools): threadPool = ThreadPool("WMCore.ThreadPool.ThreadSlave", \ component, 'MyPool_'+str(i), ThreadPoolTest._nrOfThreads) threadPools.append(threadPool) # this is how you would use the threadpool. The threadpool retrieves # events/payloads from the message service. If a thread is available # it is dispatched, otherwise it is stored in the trheadpool. # make the number of tasks bigger than number of threads to tesT # the persistent queue. for i in xrange(0, ThreadPoolTest._nrOfThreads * 10): event = 'eventNr_' + str(i) payload = 'payloadNr_' + str(i) # normally you would have different events per threadpool and # even different objects per pool. the payload part will be # pickled into the database enabling flexibility in passing # information. for j in xrange(0, ThreadPoolTest._nrOfPools): threadPools[j].enqueue(event, \ {'event' : event, 'payload' : payload}) # this commit you want to be in the agent harness, so the message is # actual removed from the msgService. we can do this as the threadpool # acts as a dispatcher and is a shortlived action: dispatch to thread # or queue and tell agent harness it is finished. finished = False timeout = 60 # secs currenttime = 0 while not finished: print('waiting for threads to finishs. Work left:') for j in xrange(0, ThreadPoolTest._nrOfPools): print('pool_' + str(j) + ':' + str(threadPools[j].callQueue)) time.sleep(1) finished = True currenttime += 1 if (timeout == currenttime): raise RuntimeError for j in xrange(0, ThreadPoolTest._nrOfPools): if (len(threadPools[j].resultsQueue) < ThreadPoolTest._nrOfThreads * 10): finished = False break # check if the tables are really empty and all messages # have been processed. for j in xrange(0, ThreadPoolTest._nrOfPools): assert len(threadPools[j].resultsQueue) == \ ThreadPoolTest._nrOfThreads*10 myThread.transaction.begin() for j in xrange(0, ThreadPoolTest._nrOfPools): self.assertEqual(threadPools[j].countMessages(), 0) myThread.transaction.commit()
def testA(self): """ __testSubscribe__ Test subscription of a component. """ raise nose.SkipTest myThread = threading.currentThread() # create a 'fake' component that contains a arg dictionary. component = Dummy() # load default parameters. config = self.testInit.getConfiguration() # normally assigned by the harness of the test component. config.Agent.componentName = "TestComponent" component.config = config threadPools = [] for i in xrange(0, ThreadPoolTest._nrOfPools): threadPool = ThreadPool("WMCore.ThreadPool.ThreadSlave", \ component, 'MyPool_'+str(i), ThreadPoolTest._nrOfThreads) threadPools.append(threadPool) # this is how you would use the threadpool. The threadpool retrieves # events/payloads from the message service. If a thread is available # it is dispatched, otherwise it is stored in the trheadpool. # make the number of tasks bigger than number of threads to tesT # the persistent queue. for i in xrange(0, ThreadPoolTest._nrOfThreads*10): event = 'eventNr_'+str(i) payload = 'payloadNr_'+str(i) # normally you would have different events per threadpool and # even different objects per pool. the payload part will be # pickled into the database enabling flexibility in passing # information. for j in xrange(0, ThreadPoolTest._nrOfPools): threadPools[j].enqueue(event, \ {'event' : event, 'payload' : payload}) # this commit you want to be in the agent harness, so the message is # actual removed from the msgService. we can do this as the threadpool # acts as a dispatcher and is a shortlived action: dispatch to thread # or queue and tell agent harness it is finished. finished = False timeout = 60 # secs currenttime = 0 while not finished: print('waiting for threads to finishs. Work left:') for j in xrange(0, ThreadPoolTest._nrOfPools): print('pool_'+str(j)+ ':' + str(threadPools[j].callQueue)) time.sleep(1) finished = True currenttime += 1 if (timeout == currenttime): raise RuntimeError for j in xrange(0, ThreadPoolTest._nrOfPools): if (len(threadPools[j].resultsQueue) < ThreadPoolTest._nrOfThreads*10): finished = False break # check if the tables are really empty and all messages # have been processed. for j in xrange(0, ThreadPoolTest._nrOfPools): assert len(threadPools[j].resultsQueue) == \ ThreadPoolTest._nrOfThreads*10 myThread.transaction.begin() for j in xrange(0, ThreadPoolTest._nrOfPools): self.assertEqual( threadPools[j].countMessages() , 0 ) myThread.transaction.commit()
def createAndLoadAnalysis(anaType, runConfig, folder, name=None): """ Creates a new analysis of the specified anaType, with common analysis folder given. If name is specified, use this name, else use the default for this analysis anaType. The created analysis is then loaded and returned. raises AnalysisException_createFail if something goes wrong. """ if not anaType in AnalysisInterface.getTypes(): raise AnalysisException_createFail("Type '" + anaType + "' is not valid") name = AnalysisInterface.getName(anaType, name) if os.path.exists(os.path.join(folder, name)): raise AnalysisException_createFail("Analysis file already created?!?") import acdOpti.AcdOptiRunConfig assert isinstance(runConfig, acdOpti.AcdOptiRunConfig.AcdOptiRunConfig) if anaType == "Dummy": from Dummy import Dummy Dummy.createNew(folder, name) return Dummy(folder, name, runConfig) if anaType == "DummyInput": from DummyInput import DummyInput DummyInput.createNew(folder, name) return DummyInput(folder, name, runConfig) elif anaType == "FileList": from FileList import FileList FileList.createNew(folder,name) return FileList(folder,name,runConfig) elif anaType == "Omega3P_modeInfo": from Omega3P_modeInfo import Omega3P_modeInfo Omega3P_modeInfo.createNew(folder, name) return Omega3P_modeInfo(folder,name,runConfig) elif anaType == "RFpost": from RFpost import RFpost RFpost.createNew(folder, name) return RFpost(folder, name, runConfig) elif anaType == "RFpost_local": from RFpost_local import RFpost_local RFpost_local.createNew(folder, name) return RFpost_local(folder,name,runConfig) elif anaType == "GroupVelocity": from GroupVelocity import GroupVelocity GroupVelocity.createNew(folder, name) return GroupVelocity(folder, name, runConfig) elif anaType == "ScMax": from ScMax import ScMax ScMax.createNew(folder, name) return ScMax(folder, name, runConfig) elif anaType == "ModeFileRecalc": from ModeFileRecalc import ModeFileRecalc ModeFileRecalc.createNew(folder, name) return ModeFileRecalc(folder, name, runConfig) elif anaType == "Metadata": from Metadata import Metadata Metadata.createNew(folder, name) return Metadata(folder,name,runConfig) else: raise AnalysisException_createFail("Unknown analysis type '" + anaType + "'")