def test_send(self):
        adjacency_matrix = [
            [0, 1],
            [1, 0]
        ]

        nodes = create_network(adjacency_matrix, self.stack_class_list, self.stack_args)

        data = nodes[0][self.TEST_LAYER].get_data(1, timeout=TIMEOUT)
        self.assertIsNotNone(data, "Application did not respond with data")
Esempio n. 2
0
def create_workers(config, logger):
    counter = mp.Value('i', 0)

    learning_network = network_factory.create_network(
        num_layers=config["num_layers"], hidden_size=config["hidden_size"])
    target_network = network_factory.create_network(
        num_layers=config["num_layers"], hidden_size=config["hidden_size"])
    learning_network.load_state_dict(target_network.state_dict())

    optimizer = SharedAdam(learning_network.parameters(),
                           lr=config["learning_rate"])
    optimizer.share_memory()

    workers = []
    for idx in range(0, config["n_workers"]):
        networks = {"learning": learning_network, "target": target_network}

        # environment = create_environment(idx)
        policy = Policy(epsilon=config["startingEpsilons"][idx],
                        numUpdates=config["numPolicyUpdates"],
                        minEpsilon=config["minEpsilons"][idx],
                        logger=logger)
        trainingArgs = (idx, networks, optimizer, counter, policy, config,
                        logger)
        p = mp.Process(target=Worker.train, args=trainingArgs)

        logger.log("Starting process: {0}".format(idx))

        p.start()

        logger.log("Process started: {0}".format(idx))
        workers.append(p)
        logger.log("Worker Appended: {0}".format(idx))

    logger.log("Creating the greedy worker")
    p = create_greedy_worker(networks, counter, config)
    p.start()
    workers.append(p)
    logger.log("Greedy worker started and appended")

    return workers, target_network
Esempio n. 3
0
    def test_send_no_connection(self):
        adjacency_matrix = [[0, 0], [0, 0]]

        nodes = create_network(adjacency_matrix, self.stack_class_list,
                               self.stack_args)

        pckt = packet.Packet()
        pckt.network = packet.NetworkingPacket(0, 1)
        nodes[0][self.TEST_LAYER].send_buffer.put(pckt)

        resp = nodes[1][self.TEST_LAYER].get_response(timeout=TIMEOUT)
        self.assertIsNone(
            resp, "Network layer was able to send across a disconnected link")
Esempio n. 4
0
    def test_send(self):
        adjacency_matrix = [[0, 1], [1, 0]]

        nodes = create_network(adjacency_matrix, self.stack_class_list,
                               self.stack_args)

        pckt = packet.Packet()
        pckt.network = packet.NetworkingPacket(0, 1)
        nodes[0][self.TEST_LAYER].send_buffer.put(pckt)

        resp = nodes[1][self.TEST_LAYER].get_response(timeout=TIMEOUT)
        self.assertEqual(resp, pckt,
                         "Networking layer was not able to send packet")
Esempio n. 5
0
    def test_send(self):
        adjacency_matrix = [[0, 1], [1, 0]]

        nodes = create_network(adjacency_matrix, self.stack_class_list,
                               self.stack_args)

        pckt = packet.Packet()

        # Send request to node 1
        pckt.app = packet.AppPacket(0, 1, 0, 0)
        # Transport 0 is TCP
        pckt.transport = packet.TransportPacket(0)
        nodes[0][self.TEST_LAYER].send_buffer.put(pckt)
        time.sleep(TIMEOUT)

        # Transport layer has sent packet
        self.assertEqual(
            nodes[0][self.TEST_LAYER - 1].current_seq, 1,
            "TCP sequence number not incremented after sending TCP packet")

        # ACK has been received and removed from ack buffer
        self.assertEqual(len(nodes[0][self.TEST_LAYER - 1].ack_buffer), 0,
                         "TCP still waiting on TCP packet ACK")
Esempio n. 6
0
import policy_worker
from Environment import HFOEnv
import network_factory
import torch
from Policy import Policy
from logger import Logger

os.environ['OMP_NUM_THREADS'] = '1'

# Use this script to handle arguments and
# initialize important components of your experiment.
# These might include important parameters for your experiment,
# your models, torch's multiprocessing methods, etc.
if __name__ == "__main__":

    value_network = network_factory.create_network()
    weights_path = "model_weights/exp4/weights_final.out"
    value_network.load_state_dict(torch.load(weights_path))

    logger = Logger("output.out")

    rnd_seed = 11111 + 111
    environment = HFOEnv(port=6011, seed=rnd_seed, numOpponents=1)
    environment.connectToServer()

    policy_worker.run(num_episodes=1000,
                      network=value_network,
                      environment=environment,
                      policy=Policy(logger=logger),
                      logger=logger,
                      counter=None)