def __init__(self, history_len=arg_or_default("--history-len", default=10), features=arg_or_default("--input-features", default="sent latency inflation," + "latency ratio," + "send ratio")): self.viewer = None self.rand = None self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock.setblocking(1) self.sock.bind(("localhost", 9787)) self.conn = None self.conn_addr = None self.features = features.split(",") self.history_len = history_len self.history = sender_obs.SenderHistory(history_len, self.features, 0) self.rate = STARTING_RATE single_obs_min_vec = sender_obs.get_min_obs_vector(self.features) single_obs_max_vec = sender_obs.get_max_obs_vector(self.features) self.observation_space = spaces.Box(np.tile(single_obs_min_vec, self.history_len), np.tile(single_obs_max_vec, self.history_len), dtype=np.float32) self.action_space = spaces.Box(np.array([-1e12]), np.array([1e12]), dtype=np.float32) self.steps_taken = 0 self.reward_sum = 0.0 self.reward_ewma = 0.0
def __init__(self, history_len=arg_or_default("--history-len", default=10), features=arg_or_default("--input-features", default="sent latency inflation," + "latency ratio," + "send ratio")): self.viewer = None self.rand = None self.min_bw, self.max_bw = (100, 500) # bandwidth self.min_lat, self.max_lat = (0.05, 0.5) # latency self.min_queue, self.max_queue = (0, 8) self.min_loss, self.max_loss = (0.0, 0.05) self.history_len = history_len print("History length: %d" % history_len) self.features = features.split(",") print("Features: %s" % str(self.features)) self.links = None self.senders = None self.create_new_links_and_senders() self.net = Network(self.senders, self.links) self.run_dur = None self.run_period = 0.1 self.steps_taken = 0 self.max_steps = MAX_STEPS self.debug_thpt_changes = False self.last_thpt = None self.last_rate = None # define action space if USE_CWND: self.action_space = spaces.Box(np.array([-1e12, -1e12]), np.array([1e12, 1e12]), dtype=np.float32) else: self.action_space = spaces.Box(np.array([-1e12]), np.array([1e12]), dtype=np.float32) # define observation space use_only_scale_free = True single_obs_min_vec = sender_obs.get_min_obs_vector(self.features) single_obs_max_vec = sender_obs.get_max_obs_vector(self.features) self.observation_space = spaces.Box(np.tile(single_obs_min_vec, self.history_len), np.tile(single_obs_max_vec, self.history_len), dtype=np.float32) self.reward_sum = 0.0 self.reward_ewma = 0.0 self.event_record = {"Events": []} self.episodes_run = -1
def __init__(self, flow_id): global RESET_RATE_MIN global RESET_RATE_MAX self.id = flow_id self.rate = random.uniform(RESET_RATE_MIN, RESET_RATE_MAX) self.history_len = arg_or_default("--history-len", 10) self.features = arg_or_default("--input-features", default="sent latency inflation," + "latency ratio," + "send ratio").split(",") self.history = sender_obs.SenderHistory(self.history_len, self.features, self.id) self.got_data = False self.agent = loaded_agent.LoadedModelAgent(MODEL_PATH) PccGymDriver.flow_lookup[flow_id] = self
#to try after LstmPolicy from stable_baselines.common.policies import MlpLstmPolicy, MlpLnLstmPolicy #from stable_baselines import PPO1 from stable_baselines import PPO2 import os import sys import inspect from stable_baselines.common.env_checker import check_env from common.simple_arg_parse import arg_or_default currentdir = os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))) parentdir = os.path.dirname(currentdir) sys.path.insert(0, parentdir) arch_str = arg_or_default("--arch", default="32,16") if arch_str == "": arch = [] else: arch = [int(layer_width) for layer_width in arch_str.split(",")] print("Architecture for vf and pi is: %s" % str(arch)) #64, 64 is (sort of) the default for the shared layers in LstmPolicy according to #https://stable-baselines.readthedocs.io/en/master/_modules/stable_baselines/common/policies.html#LstmPolicy #Also, LSTMs are not supported in the shared part shared_arch_str = arg_or_default("--shared_arch", default="64,64") if shared_arch_str == "": shared_arch = [] else: shared_arch = [ int(layer_width) for layer_width in shared_arch_str.split(",") ]
# Copyright 2019 Nathan Jay and Noga Rotman # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from common.simple_arg_parse import arg_or_default DELTA_SCALE = arg_or_default("--delta-scale", 0.05)
import tensorflow as tf from stable_baselines.common.policies import FeedForwardPolicy from stable_baselines import PPO1 import os from shutil import rmtree import sys import inspect currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) parentdir = os.path.dirname(currentdir) sys.path.insert(0, parentdir) from common.simple_arg_parse import arg_or_default # arch_str = arg_or_default("--arch", default="32,16") arch_str = arg_or_default("--arch", default="64,32") if arch_str == "": arch = [] else: arch = [int(layer_width) for layer_width in arch_str.split(",")] print("Architecture is: %s" % str(arch)) training_sess = None env = gym.make('PccNs-v0') # env = gym.make('CartPole-v0') gamma = arg_or_default("--gamma", default=0.99) print("gamma = %f" % gamma)
import network_sim import tensorflow as tf from stable_baselines.common.policies import MlpPolicy from stable_baselines.common.policies import FeedForwardPolicy from stable_baselines import PPO1 import os import sys import inspect currentdir = os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))) parentdir = os.path.dirname(currentdir) sys.path.insert(0, parentdir) from common.simple_arg_parse import arg_or_default arch_str = arg_or_default("--arch", default="32,16") if arch_str == "": arch = [] else: arch = [int(layer_width) for layer_width in arch_str.split(",")] print("Architecture is: %s" % str(arch)) training_sess = None class MyMlpPolicy(FeedForwardPolicy): def __init__(self, sess, ob_space, ac_space, n_env,
import loaded_agent if not hasattr(sys, 'argv'): sys.argv = [''] MIN_RATE = 0.5 MAX_RATE = 300.0 DELTA_SCALE = 0.05 RESET_RATE_MIN = 5.0 RESET_RATE_MAX = 100.0 RESET_RATE_MIN = 6.0 RESET_RATE_MAX = 6.0 MODEL_PATH = arg_or_default("--model-path", "/tmp/") for arg in sys.argv: arg_str = "NULL" try: arg_str = arg[arg.rfind("=") + 1:] except: pass if "--reset-target-rate=" in arg: RESET_RATE_MIN = float(arg_str) RESET_RATE_MAX = float(arg_str) class PccGymDriver():
from loaded_agent import LoadedModelAgent if not hasattr(sys, 'argv'): sys.argv = [''] MIN_RATE = 0.5 MAX_RATE = 300.0 DELTA_SCALE = 0.05 RESET_RATE_MIN = 5.0 RESET_RATE_MAX = 100.0 RESET_RATE_MIN = 6.0 RESET_RATE_MAX = 6.0 MODEL_PATH = arg_or_default( "--model-path", "/home/idoye/PycharmProjects/PCC-RL/icml_paper_model") for arg in sys.argv: arg_str = "NULL" try: arg_str = arg[arg.rfind("=") + 1:] except: pass if "--reset-target-rate=" in arg: RESET_RATE_MIN = float(arg_str) RESET_RATE_MAX = float(arg_str) class PccGymDriver(): flow_lookup = {}