当前位置: 首页>>代码示例>>Python>>正文


Python Serializer.read_config方法代码示例

本文整理汇总了Python中serializer.Serializer.read_config方法的典型用法代码示例。如果您正苦于以下问题:Python Serializer.read_config方法的具体用法?Python Serializer.read_config怎么用?Python Serializer.read_config使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在serializer.Serializer的用法示例。


在下文中一共展示了Serializer.read_config方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from serializer import Serializer [as 别名]
# 或者: from serializer.Serializer import read_config [as 别名]
class SimulationRunner:
    def __init__(self, problem, config):
        self.abs_path = os.path.dirname(os.path.abspath(__file__))
        self.serializer = Serializer()
        self.config_file = config
        self.config = self.serializer.read_config(self.abs_path + "/" + config)        
        self.ik_solution_generator = IKSolutionGenerator()        
        self.clear_stats(problem)
        self.run(problem)
        
    def clear_stats(self, problem):
        for file in glob.glob(self.abs_path + "/../problems/" + problem + "/log.log"):
            os.remove(file)
        for file in glob.glob(self.abs_path + "/../problems/" + problem + "/log.log"):
            os.remove(file)
        if os.path.isdir(self.abs_path + "/stats"):
            cmd = "rm -rf " + self.abs_path + "/stats/*"        
            os.system(cmd)
        else:
            os.makedirs(self.abs_path + "/stats")
        
    def write_rewards(self, log_file_path):
        rewards = []
        for line in tuple(open(log_file_path, 'r')):
            if "Reward" in line:                
                rewards.append(float(line.split(":")[1][1:]))        
        n, min_max, mean_rewards, reward_variances, skew, kurt = stats.describe(np.array(rewards))            
        if np.isnan(np.asscalar(reward_variances)):
            reward_variances = np.array(0.0)
            
        with open(log_file_path, "a+") as f:
            f.write("Reward variance: " + str(np.asscalar(reward_variances)) + " \n")
        with open(log_file_path, "a+") as f:
            f.write("Reward standard deviation: " + str(np.asscalar(np.sqrt(reward_variances))) + " \n")
    
    def read_float_data(self, log_file_path, searchstring):
        data = 0.0
        for line in tuple(open(log_file_path, 'r')):
            if searchstring in line:
                data = float(line.split(":")[1].split(" ")[1].rstrip("\n"))
        return data
    
    def read_int_data(self, log_file_path, searchstring):
        data = 0.0
        for line in tuple(open(log_file_path, 'r')):
            if searchstring in line:
                data = int(float(line.split(":")[1].split(" ")[1].rstrip("\n")))
        return data      
    
    def read_avg_path_length(self, log_file_path, num_runs):
        l = 0
        for line in tuple(open(log_file_path, 'r')):
            if "S:" in line:
                l += 1
        return l / num_runs
                
    def replace_option_in_config(self, option_name, value, problem, is_bool=False):
        bool_str = None
        if is_bool:
            bool_str = "false"
            if value:
                bool_str = "true"    
        lines = list(open(self.abs_path + "/../problems/" + problem + "/default.cfg", 'r'))
        idx = -1       
        for i in xrange(len(lines)):
            if option_name in lines[i]:
                idx = i 
        if not idx == -1:
            if is_bool:
                lines[idx] = option_name + " = " + str(bool_str) + "\n"
            else:
                lines[idx] = option_name + " = " + str(value) + "\n"
        os.remove(self.abs_path + "/../problems/" + problem + "/default.cfg")
        with open(self.abs_path + "/../problems/" + problem + "/default.cfg", 'a+') as f:
            for line in lines:
                f.write(line)
                
    def compareEnvironmentToTmpFiles(self, problem, model_file, environment_path, environment_file):
        if not os.path.exists(self.abs_path + "/tmp/" + problem):
            os.makedirs(self.abs_path + "/tmp/" + problem)
            return False
        
        if not (os.path.exists(self.abs_path + '/tmp/' + problem + '/' + environment_file) and
                os.path.exists(self.abs_path + '/tmp/' + problem + '/' + self.config_file) and
                os.path.exists(self.abs_path + '/tmp/' + problem + '/' + model_file)):            
            return False
        
        with open(self.abs_path + '/../problems/' + problem + "/environment/" + environment_file, 'r') as f1, open(self.abs_path + '/tmp/' + problem + '/' + environment_file, 'r') as f2:
            missing_from_b = [
                diff[2:] for diff in Differ().compare(f1.readlines(), f2.readlines())
                if diff.startswith('-')
            ]
            if len(missing_from_b) != 0:
                return False
            
        with open(self.abs_path + '/../problems/' + problem + "/model/" + model_file, 'r') as f1, open(self.abs_path + '/tmp/' + problem + '/' + model_file, 'r') as f2:
            missing_from_b = [
                diff[2:] for diff in Differ().compare(f1.readlines(), f2.readlines())
                if diff.startswith('-')
            ]
#.........这里部分代码省略.........
开发者ID:hoergems,项目名称:abt_newt,代码行数:103,代码来源:run.py

示例2: __init__

# 需要导入模块: from serializer import Serializer [as 别名]
# 或者: from serializer.Serializer import read_config [as 别名]
 def __init__(self, save):
     logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
     if not os.path.isdir("stats"):
         os.makedirs("stats")      
     self.save = save
     self.utils = Utils()
     logging.info("Loading cartesian coordinates...") 
     serializer = Serializer()
     
     rave_env = Environment()
     f = "stats/model/test.urdf"
     rave_env.initializeEnvironment(f)
     self.link_dimensions = rave_env.getRobotLinkDimensions()
     rave_env.destroy()
     
     self.setup_kinematics(serializer, "stats")
     self.process_covariances = []
     for logfile in glob.glob("stats" + "/*.log"):
         self.process_covariances.append(serializer.read_process_covariance(logfile))
     #arr = serializer.deserialize_joint_angles(path="stats", file="state_path1.txt")        
     #self.plot_state_path(serializer, arr)
     #sleep()
     
     self.create_video(serializer, "stats")
     logging.info("plotting paths")  
     try:  
         self.plot_paths(serializer)
     except:
         logging.warn("Paths could not be plotted")        
     logging.info("Reading config") 
     config = serializer.read_config("config.yaml", path="stats")
         
     #try:
     #self.plot_end_effector_paths(serializer, plot_scenery=True, plot_manipulator=True)
     #except:
     #    print "Error. End effector paths could not be plotted"
     
     logging.info("Plotting mean planning times")
     self.plot_mean_planning_times(serializer, 
                                   dir="stats", 
                                   filename="mean_planning_times_per_step*.yaml", 
                                   output="mean_planning_times_per_step.pdf")
     self.plot_mean_planning_times(serializer, 
                                   dir="stats", 
                                   filename="mean_planning_times_per_run*.yaml", 
                                   output="mean_planning_times_per_run.pdf")
     
     self.plot_particles(serializer, particle_limit=config['particle_plot_limit'])
     
     try:
         self.plot_paths(serializer, best_paths=True)
     except:
         logging.warn("Best_paths could not be plotted")
         
     try:
         cart_coords = serializer.load_cartesian_coords(path="stats")
     except:
         logging.warn("Cartesian_coords could not be plotted")
     
     logging.info("Plotting average distance to goal" )       
     try:
         self.plot_average_dist_to_goal(serializer, cart_coords)
     except:
         logging.warn("Average distance to goal could not be plotted")
     
     logging.info("plotting mean rewards")
     try:
         self.plot_mean_rewards(serializer)
     except Exception as e:
         logging.warn("Mean rewards could not be plotted: " + str(e))       
     
     logging.info("Plotting EMD graph...")       
     try:
         self.plot_emd_graph(serializer, cart_coords) 
     except:
         logging.warn("EMD graphs could not be plotted")
     
     logging.info("Plotting histograms...") 
     try:            
         self.save_histogram_plots(serializer, cart_coords) 
     except:
         logging.warn("Histograms could not be plotted")  
开发者ID:hoergems,项目名称:abt_newt,代码行数:84,代码来源:plot_stats.py


注:本文中的serializer.Serializer.read_config方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。