def on_menuFileRunBatch_select(self, event): wildcard = "Options Files (*.ini)|*.ini" result = dialog.fileDialog(self, 'Select any number of Circuitscape Options Files within one directory', '', '', wildcard ) if result.accepted==True: wx.BeginBusyCursor() # @UndefinedVariable GUI.logger.debug('Running Circuitscape in batch mode') startTime = time.time() startTimeHMS = time.strftime('%H:%M:%S') self.statusBar.SetStatusText('Batch start ' + str(startTimeHMS), 0) job = 0 numjobs = len(result.paths) for selection in result.paths: job += 1 _configDir, configFile = os.path.split(selection) GUI.logger.debug('Processing ' + configFile) self.statusBar.SetStatusText('Batch start ' + str(startTimeHMS) + '. Running job ' + str(job) +'/' + str(numjobs), 0) try: cs = Compute(selection, GUI.log_handler) except RuntimeError as error: wx.EndBusyCursor() # @UndefinedVariable message = str(error) dial = wx.MessageDialog(None, message, 'Error', wx.OK | wx.ICON_ERROR) # @UndefinedVariable dial.ShowModal() return except MemoryError: wx.EndBusyCursor() # @UndefinedVariable self.memory_error_feedback() return except: wx.EndBusyCursor() # @UndefinedVariable self.unknown_exception() return try: self.statusBar.SetStatusText('',1) self.statusBar.SetStatusText('',2) result, _solver_failed = cs.compute() GUI.logger.debug('Finished processing ' + configFile) except RuntimeError as error: message = str(error) dial = wx.MessageDialog(None, message, 'Error', wx.OK | wx.ICON_ERROR) # @UndefinedVariable dial.ShowModal() except MemoryError: self.memory_error_feedback() return except: self.unknown_exception() GUI.logger.debug('Done with batch operations.') wx.EndBusyCursor() # @UndefinedVariable self.components.calcButton.SetFocus() self.reset_status_bar() (hours,mins,secs) = ComputeBase.elapsed_time(startTime) if hours > 0: self.statusBar.SetStatusText('Batch job took ' + str(hours) +' hours ' + str(mins) + ' minutes to complete.',2) else: self.statusBar.SetStatusText('Batch job took ' + str(mins) +' minutes ' + str(secs) + ' seconds to complete.',2)
def pro(): print('pro...') if (os.path.exists('./temp')): shutil.rmtree('./temp') os.mkdir('./temp') else: os.mkdir('./temp') if (os.path.exists('./res')): shutil.rmtree('./res') os.mkdir('./res') else: os.mkdir('./res') if (os.path.exists('./binary')): shutil.rmtree('./binary') os.mkdir('./binary') else: os.mkdir('./binary') if (os.path.exists('./json')): shutil.rmtree('./json') os.mkdir('./json') else: os.mkdir('./json') c = Compute() # show the post with the given id, the id is an integer #return 'Post %s' % base data = request.get_json()['img'] imgdata = base64.b64decode(data) filename = './temp/image.jpg' # I assume you have a way of picking unique filenames with open(filename, 'wb') as f: f.write(imgdata) return c.compute()
def __init__(self): self._compute = Compute() self._input = [] self._x = [[i] for i in range(9)] self._Ox = [] self._Tx = [] self._p = 0 self._chiSquare = 0 self._freedom = 0
def test_construction(self, compute): subject = Compute('Google', 'project', 'usa') self.mock_compute.assert_called_with('compute', 'v1') assert subject.project == 'project' assert subject.zone == 'usa' assert subject.ip == '' assert subject.machine_name() == 'Google' assert subject.node.machine_name() == 'Google' assert subject.dns.machine_name() == 'Google' assert subject.traffic.machine_name() == 'Google'
def test_restart_instance(self, printing, compute): subject = Compute('Resettable', 'reset project', 'resetosphere') result = subject.restart_instance() self.mock_print.assert_called_with( '\tRestarting Resettable Compute instance') self.mock_reset.assert_called_with(project='reset project', zone='resetosphere', instance='Resettable') assert result == 'reset'
def test_start_instance(self, printing, compute): subject = Compute('Startable', 'start project', 'startosphere') result = subject.start_instance() self.mock_print.assert_called_with( '\tStarting Startable Compute instance') self.mock_start.assert_called_with(project='start project', zone='startosphere', instance='Startable') assert result == 'started'
def test_get_external_ip(self, mocker, printing, compute, time): subject = Compute('Google', 'project', 'usa') result = subject.get_external_ip() self.mock_compute.return_value.instances.return_value.list.assert_called_with( project='project', zone='usa') self.mock_print.assert_has_calls([ mocker.call( '\t\tWaiting for external IP for Google Compute instance...'), mocker.call('\t\tdone.') ]) self.mock_time.sleep.assert_called_with(1) assert result == '1.2.3.4'
def create_infrastructure(self): self.dfCEs = ou.load_compute() self.total_cores = self.dfCEs.cores.sum() print('total cores:', self.total_cores) # create origin server self.storage.add_storage('Data Lake', parent_name='', servers=1, level=2, origin=True) # create cloud level cache servers self.cloud_weights = self.dfCEs.groupby('cloud').sum()['cores'] print(self.cloud_weights) if conf.CLOUD_LEVEL_CACHE: for cloud, sum_cores in self.cloud_weights.items(): servers = sum_cores // 2000 + 1 self.storage.add_storage(cloud, parent_name='Data Lake', servers=servers, level=1, origin=False) # create CEs. CEs have local caches. for ce in self.dfCEs.itertuples(): servers = ce.cores // 1000 + 1 if conf.CLOUD_LEVEL_CACHE: p_name = ce.cloud else: p_name = 'Data Lake' self.storage.add_storage(ce.name, parent_name=p_name, servers=servers, level=0, origin=False) self.comp_sites.append(Compute(ce.name, ce.tier, ce.cloud, ce.cores, self.storage, ce.name)) # calculate site weights self.cloud_weights /= self.cloud_weights.sum() for cl, clv in self.dfCEs.groupby('cloud'): self.site_weights[cl] = clv['cores'] self.site_weights[cl] /= self.site_weights[cl].sum()
def test_node_property(self, compute, node_ssh_commands): subject = Compute('Google', 'project', 'usa') subject.node.shell() self.mock_node_ssh_commands.assert_called_with(subject.get_external_ip) self.mock_node_ssh_commands.return_value.shell.assert_called_with()
def install_mean_stack(subnet, vcn): compute = Compute(config, subnet) compute.launch_instance() compute.get_vnic(vcn) mean_stack = MeanStackConfig(compute) mean_stack.connect() mean_stack.install()
demand_callback_index, 0, # null capacity slack data['vehicle_capacities'], # vehicle maximum capacities True, # start cumul to zero 'Capacity') # Allow to drop nodes. penalty = 1000000 for node in range(1, len(data['cost_matrix'])): routing.AddDisjunction([manager.NodeToIndex(node)], penalty) # Setting first solution heuristic (IF TAKES A LONG TIME CHANGE THE FirstSolutionStrategy OR LocalSearchMetaheuristic) search_parameters = pywrapcp.DefaultRoutingSearchParameters() search_parameters.first_solution_strategy = ( routing_enums_pb2.FirstSolutionStrategy.CHRISTOFIDES) search_parameters.local_search_metaheuristic = ( routing_enums_pb2.LocalSearchMetaheuristic.GUIDED_LOCAL_SEARCH) search_parameters.time_limit.FromSeconds(1) # Solve the problem. assignment = routing.SolveWithParameters(search_parameters) # Print solution on console. if assignment: print_solution(data, manager, routing, assignment, number) if __name__ == '__main__': for i in tqdm(range(1, 7)): main(40, i) Compute().recompute((i + 1))
# put in all of the moves into a database sqltrack.create_database() logger = configure_logger(get_basepath(), get_hostname()) # need to set IP by art piece -gary motors = initialize_motors(feed_ip=feed_ip, eat_ip=eat_ip, sim=sim) if sim == 0: waiter = Wait() if file in Data.paths.keys(): ingredients = Data(data_path=Data.paths[file]) else: # Data() uses sea level data by default ingredients = Data() kitchen = Compute(target_diameter=Compute.diameter_after_half_paper_moved) # distribute total_inches_to_move into meals based on how many datapoints we have, # and the percentage of their integrals to the total integral of the function. # determine how many portions are in a meal based on the total # of movements # divided by the # of meals. meals = [ ingredients.percents[i] * kitchen.total_inches_to_move for i in range(len(ingredients.percents)) ] portions_per_meal = kitchen.total_num_movements / len(meals) steps_completed = 0 move_sum = 0.0 if sim == 1: outname = "move-{}.txt".format(file)
def set_resources(self): """ Prepare some values that include: image_ref, get an image id and set to image_ref. if the image not existing, create it. image_ref_alt, get another image id and set to image_ref_alt. if the image not existing, create it. public_network_id, get public network id and set to public_network_id. fixed_network_name, retrieve a fixed network name and set to fixed_network_name, if the network not existing, create it. public_router_id, get public router id and set to public_router_id. if the router not existing, create it. flavor_ref, get a flavor id and set to flavor_ref. flavor_ref_alt, get another flavor id and set to flavor_ref_alt. compute_host_count, get the count of the compute host and set to compute_host_count """ image = Image(self.params) net = Network(self.params) compute = Compute(self.params) utils_misc.set_openstack_environment() # get image id and alt image id image_ref = image.get_image_id(self.image_ref_name) if image_ref is None: self.image_ref_path = os.environ["image_ref_path"] image_ref = image.create_image(self.image_ref_name, self.image_ref_path) self.image_ref = image_ref LOG.info("image_ref is %s" % self.image_ref) image_ref_alt = image.get_image_id(self.image_ref_alt_name) if image_ref_alt is None: self.image_ref_alt_path = os.environ["image_ref_alt_path"] image_ref_alt = image.create_image(self.image_ref_alt_name, self.image_ref_alt_path) self.image_ref_alt = image_ref_alt LOG.info("image_ref_alt is %s" % self.image_ref_alt) # get the public net id self.public_network_id = net.get_network_id(self.public_network_name) LOG.info("public_network_id is %s" % self.public_network_id) # get network and create it if it does not existing. fixed_network = net.get_network(self.fixed_network_name) if fixed_network is None: LOG.info('Creating fixed network: %s' % self.fixed_network_name) net.create_network(name=self.fixed_network_name, subnet=True) LOG.info("fixed_network_name is %s" % self.fixed_network_name) # get the public router id public_router_id = net.get_router_id(self.public_router_name) if public_router_id is None: public_router = net.create_router( {"name": self.public_router_name}, True) public_router_id = public_router["router"]["id"] self.public_router_id = public_router_id LOG.info("public_router_id is %s" % self.public_router_id) # get flavor id self.flavor_ref = compute.get_flavor_id(self.flavor_ref_name) LOG.info("flavor_ref is %s" % self.flavor_ref) self.flavor_ref_alt = compute.get_flavor_id(self.flavor_ref_alt_name) LOG.info("flavor_ref_alt is %s" % self.flavor_ref_alt) # get compute host count self.compute_host_count = compute.get_compute_host_count() LOG.info("compute_host_count is %s" % self.compute_host_count)
class Dowels(): """ Main class that allows computation and output printing. """ def __init__(self): self._compute = Compute() self._input = [] self._x = [[i] for i in range(9)] self._Ox = [] self._Tx = [] self._p = 0 self._chiSquare = 0 self._freedom = 0 def parseInput(self): """ Parse input into the _input list. """ for index in range(1, len(argv)): self._input.append(int(argv[index])) self._Ox = deepcopy(self._input) def statisticalArray(self) -> None: """ Compute and print an array showing observed and theoretical sizes for each statistical class (with totals). """ def normalizeEntries() -> None: """ Compute ._x and .Ox lists' values. """ def merge(lst, index): lst[index] += lst[index + 1] lst.pop(index + 1) i = 0 while i < len(self._Ox): if self._Ox[i] < 10: if i is 0: merge(self._Ox, i) merge(self._x, i) elif i is len(self._Ox) - 1: merge(self._Ox, i - 1) merge(self._x, i - 1) else: if (self._Ox[i - 1] <= self._Ox[i + 1]): merge(self._Ox, i - 1) merge(self._x, i - 1) else: merge(self._Ox, i) merge(self._x, i) else: i += 1 def printXLine() -> None: print(" x\t|", end='') for x in self._x: if (len(x) > 1): if (x[-1] is 8): print(" {}+\t|".format(x[0]), end='') else: print(" {}-{}\t|".format(x[0], x[-1]), end='') else: if (x[0] is 8): print(" {}+\t|".format(x[0]), end='') else: print(" {}\t|".format(x[0]), end='') print(" Total") def printOxLine() -> None: print(" 0x\t|", end='') for Ox in self._Ox: print(" {}\t|".format(Ox), end='') print(" 100") def printTxLine() -> None: print(" Tx\t|", end='') rest = 100 for xray in self._x: tmp = 0 for x in xray: tmp += self._compute.computeTheoreticalSize( x, 100, 100, self._p) rest -= tmp if xray is self._x[-1]: tmp += rest self._Tx.append(tmp) print(" {:.1f}\t|".format(tmp), end='') print(" 100") normalizeEntries() printXLine() printOxLine() printTxLine() def distribution(self) -> None: """ Compute and print distribution. """ print("Distribution:\t\tB(100, {:.4f})".format(self._p)) def chiSquared(self) -> None: """ Compute and print chi-squared. """ for i in range(len(self._Ox)): self._chiSquare += ((self._Ox[i] - self._Tx[i])**2) / self._Tx[i] print("Chi-squared:\t\t{:.3f}".format(self._chiSquare)) def freedomDegrees(self) -> None: """ Compute and print degrees of freedom. """ self._freedom = len(self._x) - 2 print("Degrees of freedom:\t{:d}".format(self._freedom)) def fitValidity(self) -> None: """ Compute and print fit validity. """ v = [] for x in range(len(dist_table[self._freedom])): if (dist_table[self._freedom][x] < self._chiSquare) and (x < 12): v.append(dist_table[0][x + 1]) if len(v) is 0: print("Fit validity:\t\tP > 99%") elif len(v) > 0 and (self._chiSquare > dist_table[self._freedom][len(v)]): print("Fit validity:\t\tP < 1%") else: print("Fit validity:\t\t{}% < P < {}%".format(v[-1], v[-2])) def run(self) -> None: """ Run computations and process output printing. """ self.parseInput() self._p = self._compute.computeProbabilty(100, 100, self._x, self._Ox) self.statisticalArray() self.distribution() self.chiSquared() self.freedomDegrees() self.fitValidity()
import numpy as np import cv2 import os from loader import Loader from matcher import Matcher from numpy import linalg from scipy.linalg import svd from compute import Compute match = Matcher() load = Loader(0.3) comp = Compute() if __name__ == "__main__": folder = "./data/5" saveto = str(folder[-1]) + "/" images = load.load_images(folder) print("Image shape:", images[0].shape) I2 = images[1] print("total images in folder:", len(images)) for i in range(1, len(images) + 1): I1 = images[i - 1] # Finding matches between the two images pts1, pts2 = match.find_matches(I1, I2) H = comp.compute_H(pts1, pts2) print("COmputed Homography:" + "(" + str(i - 1) + "-" + str(i) + ")\n", H) I2 = comp.stitch_images(I1, I2, H) cv2.imwrite("./results/" + saveto + str(i) + ".jpg", I2)
def test_traffic_property(self, compute, traffic_ssh_commands): subject = Compute('Google', 'project', 'usa') self.mock_traffic_ssh_commands.assert_called_with( subject.get_external_ip)
SIZE_IN_BITS = toBits(BSIZE*BSIZE, DT) NUM_BLOCKS = (SIZE/BSIZE) * (SIZE/BSIZE) NUM_BLOCK_MULTIPLIES_TOTAL = NUM_BLOCKS * (SIZE/BSIZE) NUM_BLOCK_MULTIPLIES_COMPUTE_UNIT = float(NUM_BLOCK_MULTIPLIES_TOTAL) / NUM_COMPUTE_UNITS # --- Design instantiations --- # Instantiate memory units to interface with compute unit memA = Memory(SIZE_IN_BITS, A_SHARING, A_PORTS, A_PORT_WIDTH) memB = Memory(SIZE_IN_BITS, B_SHARING, B_PORTS, C_PORT_WIDTH) memC = Memory(SIZE_IN_BITS, C_SHARING, C_PORTS, C_PORT_WIDTH) # Instantiate compute unit, calculate total compute time computeUnit = Compute(memA, memB, memC, TMADD, BSIZE) computeTime = computeUnit.getComputeTime(BSIZE, DT) totalComputeTime = computeTime * NUM_BLOCK_MULTIPLIES_COMPUTE_UNIT # Instantiate and compute DMA unit time dmaUnit = Dma(DMA_WIDTH, DMA_BURST_LENGTH, DMA_BURST_OVERHEAD) dmaCostPerBlock = BSIZE * dmaUnit.getDmaTime(toBits(BSIZE, DT)) numDmaPerBlockA = NUM_A_REQD # to and fro numDmaPerBlockB = (SIZE/BSIZE) numDmaPerBlockC = (SIZE/BSIZE) * 2 totalNumDma = (NUM_BLOCKS) * (numDmaPerBlockA + numDmaPerBlockB + numDmaPerBlockC) totalDmaTime = totalNumDma * dmaCostPerBlock totalTime = totalComputeTime + totalDmaTime computePercent = float(totalComputeTime) * 100 / totalTime dmaPercent = float(totalDmaTime) * 100 / totalTime
def test_fibonacci(): assert Compute.fibonacci(3) == 2 assert Compute.fibonacci(-8) == -21
def on_calcButton_mouseClick(self, event): self.components.habitatFile.SetFocus() #Need to force loseFocus on text boxes to make sure they are updated. self.components.outFile.SetFocus() self.components.calcButton.SetFocus() out_base, _out_ext = os.path.splitext(self.options.output_file) #if (self.options.log_file is None) or (not os.path.exists(self.options.log_file)): self.options.log_file = out_base + '.log' # For now, just write log file to output directory. if (self.options.print_rusages and not sys.platform.startswith('win')) or (self.options.print_timings): self.options.profiler_log_file = out_base + '_rusages.log' #For now, always write log file to output directory. else: self.options.profiler_log_file = None #Check to see if all inputs are chosen (all_options_entered, message) = self.options.check() if not all_options_entered: dial = wx.MessageDialog(None, message, 'Not all options entered', wx.OK | wx.ICON_EXCLAMATION) # @UndefinedVariable dial.ShowModal() self.reset_status_bar() return #save selected options in local directory configFile = 'circuitscape.ini' self.options.write(configFile) try: self.options.write(self.options.output_file, True) except RuntimeError as ex: dial = wx.MessageDialog(None, str(ex), 'Error', wx.OK | wx.ICON_ERROR) # @UndefinedVariable dial.ShowModal() self.reset_status_bar() return GUI.logger.info('Calling Circuitscape...') startTime = time.strftime('%H:%M:%S') self.statusBar.SetStatusText('Job started ' + str(startTime), 0) try: cs = Compute('circuitscape.ini', GUI.log_handler) except RuntimeError as error: message = str(error) dial = wx.MessageDialog(None, message, 'Error', wx.OK | wx.ICON_ERROR) # @UndefinedVariable dial.ShowModal() self.reset_status_bar() return except: self.unknown_exception() self.reset_status_bar() return try: filetype = CSIO._guess_file_type(self.options.habitat_file) if self.options.data_type == 'network': if filetype != CSIO.FILE_TYPE_TXTLIST: raise RuntimeError('Error reading network file "' + self.options.habitat_file + '".\nPlease check file format.') elif filetype != CSIO.FILE_TYPE_AAGRID and filetype != CSIO.FILE_TYPE_NPY: raise RuntimeError('File "' + self.options.habitat_file + '"\ndoes not appear to be a raster. Please check file format.') terminate = self.checkHeaders() if terminate == True: self.reset_status_bar() return except RuntimeError as error: message = str(error) dial = wx.MessageDialog(None, message, 'Error', wx.OK | wx.ICON_ERROR) # @UndefinedVariable dial.ShowModal() self.reset_status_bar() return except: self.unknown_exception() self.reset_status_bar() return if self.options.data_type == 'network': GUI.logger.debug('Running in Network (Graph) Mode') if self.options.scenario == 'pairwise': try: wx.BeginBusyCursor() # @UndefinedVariable self.statusBar.SetStatusText('',1) self.statusBar.SetStatusText('',2) resistances, solver_failed = cs.compute() if solver_failed == True: msg = '\nPairwise resistances (-1 indicates disconnected focal node pair, -777 indicates failed solve):' else: msg = '\nPairwise resistances (-1 indicates disconnected node pair):\nNode1\tNode2\tResistance' resistances3ColumnsStr = self.formatResistanceOutput(resistances) GUI.logger.info(msg + "\n" + resistances3ColumnsStr) GUI.logger.info('Done.\n') if solver_failed == True: message = 'At least one solve failed. Failure is coded as -777 in output resistance matrix.' dial = wx.MessageDialog(None, message, 'Error', wx.OK | wx.ICON_EXCLAMATION) # @UndefinedVariable dial.ShowModal() wx.EndBusyCursor() # @UndefinedVariable self.components.calcButton.SetFocus() except MemoryError: wx.EndBusyCursor() # @UndefinedVariable self.memory_error_feedback() self.reset_status_bar() return except RuntimeError as error: wx.EndBusyCursor() # @UndefinedVariable message = str(error) dial = wx.MessageDialog(None, message, 'Error', wx.OK | wx.ICON_ERROR) # @UndefinedVariable dial.ShowModal() self.reset_status_bar() return except: wx.EndBusyCursor() # @UndefinedVariable self.unknown_exception() elif self.options.scenario == 'advanced': if self.options.write_cur_maps == False and self.options.write_volt_maps == False: message = 'Advanced mode selected but no output maps checked.\nThere is nothing to do.' dial = wx.MessageDialog(None, message, 'Error', wx.OK | wx.ICON_ERROR) # @UndefinedVariable dial.ShowModal() return wx.BeginBusyCursor() # @UndefinedVariable try: self.statusBar.SetStatusText('',1) self.statusBar.SetStatusText('',2) _voltages, solver_failed = cs.compute() wx.EndBusyCursor() # @UndefinedVariable self.components.calcButton.SetFocus() if solver_failed == True: message = 'Solver failed!' dial = wx.MessageDialog(None, message, 'Error', wx.OK | wx.ICON_EXCLAMATION) # @UndefinedVariable dial.ShowModal() GUI.logger.info('Done.\n') except RuntimeError as error: wx.EndBusyCursor() # @UndefinedVariable message = str(error) dial = wx.MessageDialog(None, message, 'Error', wx.OK | wx.ICON_ERROR) # @UndefinedVariable dial.ShowModal() self.reset_status_bar() return except MemoryError: wx.EndBusyCursor() # @UndefinedVariable self.memory_error_feedback() self.reset_status_bar() return except: wx.EndBusyCursor() # @UndefinedVariable self.unknown_exception() self.reset_status_bar() return else: try: wx.BeginBusyCursor() # @UndefinedVariable self.statusBar.SetStatusText('',1) self.statusBar.SetStatusText('',2) resistances, solver_failed = cs.compute() wx.EndBusyCursor() # @UndefinedVariable self.components.calcButton.SetFocus() if self.options.scenario == 'all-to-one': if solver_failed == True: msg = '\nResult for each focal node (0 indicates successful calculation, -1 indicates disconnected node, -777 indicates failed solve):' else: msg = '\nResult for each focal node (0 indicates successful calculation, -1 indicates disconnected node):' elif solver_failed == True: msg = '\nResistances to ground(-1 indicates disconnected node, -777 indicates failed solve):\n Node Resistance' else: msg = '\nResistances to ground (-1 indicates disconnected node):\nNode\tResistance' resistanceString = self.formatResistanceOutput(resistances) GUI.logger.info(msg + '\n' + resistanceString) GUI.logger.info('Done.\n') if solver_failed == True: message = 'At least one solve failed. Failure is coded as -777 in output node/resistance list.' dial = wx.MessageDialog(None, message, 'Error', wx.OK | wx.ICON_EXCLAMATION) # @UndefinedVariable dial.ShowModal() except RuntimeError as error: wx.EndBusyCursor() # @UndefinedVariable message = str(error) dial = wx.MessageDialog(None, message, 'Error', wx.OK | wx.ICON_ERROR) # @UndefinedVariable dial.ShowModal() self.reset_status_bar() except MemoryError: wx.EndBusyCursor() # @UndefinedVariable self.memory_error_feedback() self.reset_status_bar() return except: wx.EndBusyCursor() # @UndefinedVariable self.unknown_exception() self.reset_status_bar() return