def load_config(self, config_file, updated_settings): with open(config_file, 'r') as config_io: try: self.config = yaml.load(config_io) self.config.update(self.__filter_nonetypes(updated_settings)) except yaml.YAMLError as exc: log.error("Load config failed: {}".format(exc)) log.debug("Load config: {}".format(self.config)) if 'log-file' in self.config: logger.set_log_file(self.config['log-file'])
def __init__(self, policy, model, env, train_model=True, calc_inf_gain=True, exp_name="_exp", start_itr=0, n_itr=500, n_paths=25, max_path_length=200, action_repeat=1, n_train_batches=100, train_batch_size=10, inf_gain_itr=5, inf_gain_batch_size=1, inf_factor=1, min_pool_size=200, max_pool_size=100000): self.policy = policy self.model = model self.env = env self.policy_opt = PolicyOptimizer(self.policy) self.exp_name = exp_name self.calc_inf_gain = calc_inf_gain self.train_model = train_model self.start_itr = start_itr self.n_itr = n_itr self.n_paths = n_paths self.max_path_length = max_path_length self.action_repeat = action_repeat self.n_train_batches = n_train_batches self.train_batch_size = train_batch_size self.inf_gain_itr = inf_gain_itr self.inf_gain_batch_size = inf_gain_batch_size self.inf_factor = inf_factor self.min_pool_size = min_pool_size self.max_pool_size = max_pool_size self.obs_dim = np.prod(self.env.observation_space.shape) self.act_dim = np.prod(self.env.action_space.shape) self.pool = ReplayPool(self.max_pool_size, observation_shape=self.obs_dim, action_dim=self.act_dim) logger.set_log_file(self.exp_name)
'for delayed packets', default=1000) parser.add_argument('seed', type=int, help='RNG seed', default=0) parser.add_argument('-p', '--receiver_port', type=int,\ help='The receiver\'s port', default=None) args = parser.parse_args() try: os.remove(args.filename) except OSError: pass def data_proc(data: bytes): with open(args.filename, 'ab') as f: f.write(data) log_file = 'Client_log.txt' if args.receiver_port else 'Server_log.txt' logger.set_log_file(log_file) sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.bind(('127.0.0.1', args.port)) print('Binding to {}'.format(('127.0.0.1', args.port))) PLD.init(args, sock=sock) addr = None if args.receiver_port: addr = ('127.0.0.1', args.receiver_port) stp = STP(PLD.send, PLD._sock, data_proc, MSS=args.MSS, MWS=args.MWS,
parser.add_argument('port', type=int, help='The port number to listen on') parser.add_argument('filename', type=str, help='The file to store the received data in') parser.add_argument('--logfile', type=str, help='The log file', default='receiver_log.txt') args = parser.parse_args() try: os.remove(args.filename) except OSError: pass def data_proc(d: bytes): global data data += d logger.set_log_file(args.logfile) sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.bind(('localhost', args.port)) stp = STP(send, sock, data_proc) stp.listen() logger.write(receiver=True) with open(args.filename, 'ab') as f: f.write(data) logger.w('done receiving')