def gtgen(gtmapfn, base, nsample, outdir): assert nsample <= 999999, 'Do not support 7+ digits of samples for now' if not os.path.exists(outdir): os.makedirs(outdir, mode=0770) uw = pyosr.UnitWorld() uw.loadModelFromFile(aniconf.env_fn) uw.loadRobotFromFile(aniconf.rob_fn) uw.scaleToUnit() uw.angleModel(0.0, 0.0) ''' init_state = np.array([17.97,7.23,10.2,1.0,0.0,0.0,0.0]) if not uw.is_valid_state(uw.translate_to_unit_state(init_state)): return ''' gt = pyosr.GTGenerator(uw) gt.rl_stepping_size = 0.0125 gt.verify_magnitude = 0.0125 / 64 gtdata = np.load(gtmapfn) gt.install_gtdata(gtdata['V'], gtdata['E'], gtdata['D'], gtdata['N']) gt.init_knn_in_batch() for i in range(nsample): ofn = "{}/aa-gt-{:06d}.npz".format(outdir, base + i) if os.path.exists(ofn): print("Skipping existing file {}".format(ofn)) continue is_final = False while not is_final: init_state = uw_random.gen_init_state(uw) keys, _, is_final = gt.generate_gt_path(init_state, 1024 * 4, False) cont_tr, cont_rot, cont_dists, _ = gt.cast_path_to_cont_actions_in_UW(keys, path_is_verified=True) np.savez(ofn, TR=cont_tr, ROT=cont_rot, DIST=cont_dists)
def visibilty_matrix_calculator(aniconf, V0, V1, q0start, q0end, q1start, q1end, out_dir, index=None, block_size=None): r = pyosr.UnitWorld() # pyosr.Renderer is not avaliable in HTCondor r.loadModelFromFile(aniconf.env_fn) r.loadRobotFromFile(aniconf.rob_fn) r.scaleToUnit() r.angleModel(0.0, 0.0) VM = r.calculate_visibility_matrix2(V0[q0start:q0end], False, V1[q1start:q1end], False, 0.0125 * 4 / 8, enable_mt=False) if out_dir == '-': print(VM) else: if index is None or block_size is None: fn = '{}/q0-{}T{}-q1-{}T{}.npz'.format(out_dir, q0start, q0end, q1start, q1end) else: fn = '{}/index-{}-under-bs-{}.npz'.format( out_dir, index, block_size) # Second naming scheme np.savez(fn, VMFrag=VM, Locator=[q0start, q0end, q1start, q1end])
def create_unit_world(puzzle_file): # Well this is against PEP 08 but we do not always need pyosr # (esp in later pipeline stages) # Note pyosr is a heavy-weight module with # + 55 dependencies on Fedora 29 (control node) # + 43 dependencies on Ubuntu 18.04 (GPU node) # + 26 dependencies on Ubuntu 16.04 (HTCondor node) import pyosr uw = pyosr.UnitWorld() _load_unit_world(uw, puzzle_file) return uw
def _create_uw(aniconf, cmd): if cmd == 'show': return None # show command does not need unit world object if 'render' in cmd or cmd in ['atlas2prim', 'useuniformatlas']: pyosr.init() dpy = pyosr.create_display() glctx = pyosr.create_gl_context(dpy) r = pyosr.Renderer() # 'project' command requires a Renderer if cmd in ['atlas2prim', 'useuniformatlas']: r.pbufferWidth = ATLAS_RES r.pbufferHeight = ATLAS_RES r.setup() r.views = np.array([[0.0, 0.0]], dtype=np.float32) else: r = pyosr.UnitWorld() # pyosr.Renderer is not avaliable in HTCondor if aniconf.rob_ompl_center is None: ''' When OMPL_center is not specified ''' assert aniconf.env_wt_fn == aniconf.env_uv_fn assert aniconf.rob_wt_fn == aniconf.rob_uv_fn if cmd in ['run', 'isect']: # fb = r.render_barycentric(r.BARY_RENDERING_ROBOT, np.array([1024, 1024], dtype=np.int32)) # imsave('1.png', fb) # sys.exit(0) r.loadModelFromFile(aniconf.env_wt_fn) r.loadRobotFromFile(aniconf.rob_wt_fn) else: # All the remaining commands need UV coordinates r.loadModelFromFile(aniconf.env_uv_fn) r.loadRobotFromFile(aniconf.rob_uv_fn) if aniconf.rob_ompl_center is not None: r.enforceRobotCenter(aniconf.rob_ompl_center) r.scaleToUnit() r.angleModel(0.0, 0.0) return r
def main(): if sys.argv[1] in ['-h', 'help']: usage() return cmd = sys.argv[1] input_file_position = None if cmd == 'saforce': input_file_position = 3 elif cmd == 'numeric': input_file_position = 0 else: assert False, "unsupported command {}".format(cmd) r = pyosr.UnitWorld() # pyosr.Renderer is not avaliable in HTCondor r.loadModelFromFile(aniconf.env_wt_fn) r.loadRobotFromFile(aniconf.rob_wt_fn) r.enforceRobotCenter(aniconf.rob_ompl_center) r.scaleToUnit() r.angleModel(0.0, 0.0) mc_reference, taskfile, task, vmoutdir = sys.argv[2:] assert os.path.isfile(mc_reference) assert os.path.isfile(taskfile) assert os.path.isdir(vmoutdir), "{} is not a directory".format(vmoutdir) mc_reference = np.load(mc_reference)['V'] with open(taskfile) as f: tasks = json.load(f) task = tasks[int(task)] fn = task[input_file_position] fn_base = os.path.basename(fn) ofn = '{}/{}'.format(vmoutdir, fn_base) V0 = [] dic = np.load(fn) q0start, q0end = task[1], task[2] if 'ALL_RQS' in dic: assert cmd == 'saforce' for traj in dic['ALL_RQS']: V0.append(traj[-1]) # Note: q0start and q0start are not used, because ALL_RQS are already # tailored by condor_saforce.py elif 'CRQS' in dic: assert cmd == 'numeric' V0 = dic['CRQS'] start = q0start end = min(len(V0), q0end) # Bound to the size limit V0 = V0[start:end] else: assert False, "Unsupported input, neither 'ALL_RQS' nor 'CRQS' existed" V0 = np.array(V0, dtype=float) # print(V0) # V0 = np.load(task[0])['TOCRQS'][q0start:q0end] os.environ['OMP_NUM_THREADS'] = '1' VM = r.calculate_visibility_matrix2( V0, True, mc_reference[0:-1], False, # mc_reference[0:4], False, 0.0125 * 4 / 8) q1start, q1end = 0, -1 # Sameve as above np.savez(ofn, VMFrag=VM, Locator=[q0start, q0end, q1start, q1end])
def __init__(self, args): super().__init__(args) self._uw = pyosr.UnitWorld() _setup_unitworld(self._uw, args)