-
Notifications
You must be signed in to change notification settings - Fork 12
/
test_b-oracle.py
122 lines (104 loc) · 4.12 KB
/
test_b-oracle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
'''
UFPA - LASSE - Telecommunications, Automation and Electronics Research and Development Center - www.lasse.ufpa.br
CAVIAR - Communication Networks and Artificial Intelligence Immersed in Virtual or Augmented Reality
Ailton Oliveira, Felipe Bastos, João Borges, Emerson Oliveira, Daniel Suzuki, Lucas Matni, Rebecca Aben-Athar, Aldebaro Klautau (UFPA): [email protected]
CAVIAR: https://github.com/lasseufpa/ITU-Challenge-ML5G-PHY-RL.git
Script to create BeamOracle agent for baseline
V1.0
'''
import os
import csv
import argparse
import caviar_tools
from beamselect_env import BeamSelectionEnv
# Create the folder
try:
os.mkdir('./data/beamoracle')
except OSError as error:
print(error)
'''
Creates a BeamOracle agent and saves the output in a file
'''
def beam_oracle(test_ep, full_output, dummy_type='random'):
# Set the range of episodes that dummy will work on
if len(test_ep) >= 2:
test_ep = range(test_ep[0], test_ep[1]+1)
for ep in test_ep:
# Get total number of steps based on the timestamps for a specific UE
n_steps = caviar_tools.linecount([ep])
env = BeamSelectionEnv(ep=[ep])
if full_output == True:
output_file = './data/beamoracle/'+'output_b_beam_oracle_ep'+ str(ep)+ '.csv'
with open(output_file, 'w', newline="") as csvfile:
writer = csv.writer(csvfile)
writer.writerow(
['chosen_ue']+
['ue_index']+
['beam_index']+
['x']+
['y']+
['z']+
['pkts_dropped']+
['pkts_transmitted']+
['pkts_buffered']+
['bit_rate_gbps']+
['channel_mag']+
['reward'])
for i in range(n_steps):
action = user(i)
obs, reward, done, info = env.best_beam_step(action)
writer.writerow(
[info['chosen_ue']]+
[action]+
[info['best_beam']]+
[obs[0]]+
[obs[1]]+
[obs[2]]+
[info['pkts_dropped']]+
[info['pkts_transmitted']]+
[info['pkts_buffered']]+
[info['bit_rate']/1e+9]+
[info['channel_mag']]+
[float(reward)])
else:
output_file = './data/beamoracle/'+'actions_b_beam_oracle_ep'+ str(ep)+ '.csv'
with open(output_file, 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(['chosen_ue']+
['ue_number']+
['beam_index'])
for i in range(n_steps):
action = user(i)
obs, reward, done, info = env.best_beam_step(action)
writer.writerow([info['chosen_ue']]+
[action]+
[info['best_beam']])
# Free memory
del env
def user(step):
# 3 is the total number of users
# user is chosen with the following pattern 0,1,2,0...
user = step % 3
return user
'''
Usage:
$ python3 test_b-oracle.py -ep <test_ep_id#1> <test_ep_id#n> --full-output <if not then only actions>
Example:
$ python3 test_b-oracle.py -ep 0 1 --full-output
'''
parser = argparse.ArgumentParser()
parser.add_argument("--episode", "-ep",
nargs='+',
help="ID of the episodes to test",
action="store",
dest="episode",
type=int)
parser.add_argument("--full-output", "-f",
help="If activated yields all info " +
"regarding the agent performance " +
"in each step, if not, only actions",
action="store_true",
dest="full_output")
args = parser.parse_args()
beam_oracle(test_ep=args.episode,
full_output=args.full_output)