def update_codegen_ignore(spec): with io.open(CODEGEN_IGNORE_PATH) as f: ignore_lines = set(f.read().splitlines()) import kubernetes k8s_apis = dir(kubernetes.client.apis) k8s_models = dir(kubernetes.client.models) api_modules = set() model_modules = set() for path in list(spec['paths'].values()): for op_name in list(path.keys()): if op_name != 'parameters': op = path[op_name] for tag in op['tags']: tag = '_'.join([string_utils.camel_case_to_snake(x) for x in tag.split('_')]) api_modules.add(tag + '_api') for model in list(spec['definitions'].keys()): module_name = '_'.join([string_utils.camel_case_to_snake(x) for x in model.split('.')]) model_modules.add(module_name) for api_module in api_modules: suffix = api_module.split('_')[-1] if suffix in ['0', 'pre012'] or api_module in k8s_apis: ignore_lines.add('client/apis/{}.py'.format(api_module)) for model_module in model_modules: if model_module in k8s_models: ignore_lines.add('client/models/{}.py'.format(model_module)) with io.open(CODEGEN_IGNORE_PATH, mode='w') as f: f.write('\n'.join(sorted(ignore_lines)))
def basic_topo(url, priority, path): for sw in path.keys(): if simple_path(url, sw, path[sw][0], path[sw][1], priority) != 200: return 1 if simple_path(url, sw, path[sw][1], path[sw][0], priority) != 200: return 1 return 0
def expand(self, n): ret = set([(n, 0.1)]) path = nx.single_source_shortest_path(self.G, n, cutoff=3) for nn in path.keys(): d = self.distance(self.G.node[n]["words"], self.G.node[nn]["words"]) if d > 0.25: ret.add((nn, d)) return ret
def del_path(url, priority, path, nw_src=None, tp_src=None, nw_dst=None, tp_dst=None): for sw in path.keys(): if del_flow(url, sw, path[sw][0], priority, \ nw_src, tp_src, nw_dst, tp_dst) != 200: return 1 if del_flow(url, sw, path[sw][1], priority, \ nw_dst, tp_dst, nw_src, tp_src) != 200: return 1 return 0
def get_planning_diff(kind, doc_id, diff): path = diff["path"] if len(path) == 2 and isinstance(path, dict): assert path.keys() == {"stock_id", "path"}, path assert path["stock_id"].startswith(doc_id + "/"), (doc_id, path) kind = "stock state" doc_id = path["stock_id"] path = path["path"] return Diff( kind=kind, doc_id=doc_id, diff_type=diff["type"], path=json.dumps(path), old_value=json_or_none(diff, "old_value"), new_value=json_or_none(diff, "new_value"), )
def dict_to_diff(kind, doc_id, data, *, _make_diff=Diff): def json_or_none(data, key): return json.dumps(data[key]) if key in data else None path = data["path"] if len(path) == 2 and isinstance(path, dict): assert path.keys() == {"stock_id", "path"}, path assert path["stock_id"].startswith(doc_id + "/"), (doc_id, path) kind = "stock state" doc_id = path["stock_id"] path = path["path"] return _make_diff( kind=kind, doc_id=doc_id, diff_type=data["type"], path=json.dumps(path), old_value=json_or_none(data, "old_value"), new_value=json_or_none(data, "new_value"), )
def update_codegen_ignore(spec, output_path): import io import os import string_utils import kubernetes codegen_ignore_path = os.path.join(os.path.dirname(output_path), '.swagger-codegen-ignore') ignore_lines = set() k8s_apis = dir(kubernetes.client.apis) k8s_models = dir(kubernetes.client.models) api_modules = set() model_modules = set() for path in list(spec['paths'].values()): for op_name in list(path.keys()): if op_name != 'parameters': op = path[op_name] for tag in op.get('tags', []): tag = '_'.join([ string_utils.camel_case_to_snake(x) for x in tag.split('_') ]) api_modules.add(tag + '_api') for model in list(spec['definitions'].keys()): module_name = '_'.join( [string_utils.camel_case_to_snake(x) for x in model.split('.')]) model_modules.add(module_name) for api_module in api_modules: suffix = api_module.split('_')[-1] if suffix in ['0', 'pre012'] or api_module in k8s_apis: ignore_lines.add('client/apis/{}.py'.format(api_module)) print( "Skipping generation of client/apis/{}.py".format(api_module)) else: print("Not skipping generation of client/apis/{}.py".format( api_module)) for model_module in model_modules: if model_module in k8s_models: ignore_lines.add('client/models/{}.py'.format(model_module)) print("Skipping generation of client/models/{}.py".format( model_module)) else: print("Not skipping generation of client/models/{}.py".format( model_module)) for module in list(ignore_lines): module_name = module.split('/')[-1].split('.')[0] test_module_name = 'test_{}'.format(module_name) docs_module_name = "".join( map(lambda x: x.capitalize(), module_name.split('_'))) ignore_lines.add("test/{}.py".format(test_module_name)) ignore_lines.add('docs/{}.md'.format(docs_module_name)) print("Skipping generation of test/{}.py".format(test_module_name)) print("Skipping generation of docs/{}.md".format(docs_module_name)) ignore_lines = ignore_lines.union(DEFAULT_CODEGEN_IGNORE_LINES) with open(codegen_ignore_path, 'w') as f: f.write('\n'.join(sorted(ignore_lines)))
def events(self): # catch all events here for event in pg.event.get(): #print("got event of type", event.type) if event.type == pg.QUIT: self.quit() if event.type == pg.MOUSEBUTTONDOWN: pos = pg.mouse.get_pos() if event.button == 1: # if click play set qubit moving and build up circuit if self.play_button.rect.collidepoint(pos): self.play_button.kill() self.player_placeholder.load += 1 # call out to the bg thread to run the circuit # self.qthread.build_circuit( self.circuit.qubit_operation) try: self.qthread.execute( callback=self.mesurement_callback) except Exception as e: print(e) # control placement behaviour of the gates for gate in self.gate_group: now = pg.time.get_ticks() if gate.rect.collidepoint( pos) and gate.clicked == False: gate.clicked = True gate.click_time = now if gate.type == "I": gate.image = pg.image.load( getfilepath('Igate_pressed.png')) elif gate.type == "X": gate.image = pg.image.load( getfilepath('Xgate_pressed.png')) elif gate.type == "H": gate.image = pg.image.load( getfilepath('Hgate_pressed.png')) elif gate.type == "K": gate.image = pg.image.load( getfilepath('CXgate_pressed.png')) for gap in self.gaps_group: if gap.rect.collidepoint( pos) and gate.clicked == True: gate_start_x = gate.rect.x / TILESIZE gate_start_y = gate.rect.y / TILESIZE gate.clicked = False Gates(self, gate.type, gate_start_x, gate_start_y) gate_x = gap.rect.x / TILESIZE gate_y = gap.rect.y / TILESIZE Gates(self, gate.type, gate_x, gate_y) gate.kill() self.gate_group.draw(self.screen) #gate.clicked = False self.circuit.qubit_operation[ gap.id] = gate.type gap.kill() if now - gate.click_time > 10 and gate.clicked == True: gate.clicked = False Gates(self, gate.type, gate.x, gate.y) gate.kill() if event.type == QVMRET.type: self.player_placeholder.load = False """Runs the main game loop - processes the quantum sample list from the QVM, and instructs the penguins etc to play out the results. """ self.player_placeholder.kill() qubit_list = self.all_qubits.sprites() for index, qubit in enumerate(qubit_list): if index == 0: qubit.speedx = 5 else: prev_qubit = qubit_list[index - 1] if prev_qubit.end == 1: qubit.speedx = 5 print(self.players) msmt_outcomes = self.msmt_outcomes # saved by the callback msmt_outcomes = [tuple(msmt) for msmt in msmt_outcomes] # x=set(x) # the defaultdict holds 0 in all key locations - we then # incriment each observed sample so we know the relative # amplitude for each penguin. relative final amp. the prefix # needs to be the sum of amps at that point. x = defaultdict(lambda: 0) for sample in msmt_outcomes: x[sample] += (1. / len(msmt_outcomes)) # move penguin according to mmt outcomes. # # test with only the first msmnt outcome self.players.empty() for pidx in range(len(x.keys())): # additional players Player(self, *self.inital_player_loc) print("no unique paths:", len(self.players.sprites())) # need a list of steps. # [ [(x, y, weight)], [(x, y, weight), (x, y, weight)] ... ] # each element of this list is a map of locations -> amplitude for # the penguins after gate i. print("walking the penguins") paths = [OrderedDict() for _ in range(len(msmt_outcomes[0]))] for path in paths: path[(0, 0)] = 1. / len(msmt_outcomes) for pengidx, (path, weight) in enumerate(x.items()): px, py = 0, 0 for step in path: if step == 1: px += 2 else: py += 2 paths[pengidx][(px, py)] = paths[pengidx].get( (px, py), 0) + weight pathlists = [path.keys() for path in paths] print("penguin paths", pathlists) for penguin, path in zip(self.players.sprites(), pathlists): penguin.add_target_walk(path)
def get_data(): dataset = {} train_data = {} # load json file # load h5 file print('loading h5 file...') with h5py.File(input_ques_h5,'r') as hf: # total number of training data is 215375 # question is (26, ) tem = hf.get('ques_train') train_data['question'] = np.array(tem)-1 # max length is 23 tem = hf.get('ques_length_train') train_data['length_q'] = np.array(tem) # total 82460 img tem = hf.get('img_pos_train') # convert into 0~82459 train_data['img_list'] = np.array(tem)-1 # answer is 1~1000 tem = hf.get('answers') train_data['answers'] = np.array(tem)-1 tem = hf.get('question_id_train') train_data['ques_id'] = np.array(tem) for image_path in os.listdir(pathdir): question_id=image_path.split('_')[0] path[question_id]=image_path newdic={} newdatavqa=[] ids=[] count=0 for x in range(len(train_data['ques_id'])): if str(train_data['ques_id'][x]) in path.keys(): ids.append(x) y=train_data['ques_id'][x] newdatavqa.append(get_attention_vqa(str(path[str(y)]))) count=count+1 print count newdic['vqahat']=np.array(newdatavqa) newdic['question']=train_data['question'][ids,:] newdic['img_list']=train_data['img_list'][ids] newdic['length_q']=train_data['length_q'][ids] newdic['answers']=train_data['answers'][ids] print('question aligning') newdic['question'] = right_align(newdic['question'], newdic['length_q']) pickle.dump(newdic, open("save4.pkl", "wb"))