Skip to content

Commit 2af72f6

Browse files
authored
Merge pull request #2 from polixir/dev
Dev
2 parents 1650c94 + 085fd71 commit 2af72f6

10 files changed

Lines changed: 26 additions & 39 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ RLA.egg-info**
88
**/code/**
99
**/results/**
1010
**/log/**
11+
**/arc/**
1112
**/.ipynb_checkpoints/*
1213
**/.DS_Store
1314
test/target_data_root/*

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ RLA has decoupled to the training code and only some additional configuration ar
77

88
The project is still in developing. Welcome to join us. :)
99

10+
We maintain an RLA in https://github.com/polixir/RLAssistant in the future which will consider extra requirements needed in the team cooperation scenario.
11+
1012

1113

1214
## Design Principles of RLA
@@ -114,6 +116,7 @@ We build an example project for integrating RLA, which can be seen in ./example/
114116
**/code/**
115117
**/results/**
116118
**/log/**
119+
**/arc/**
117120
```
118121
### Step2: record intermediate variables/checkpoints/other types of data.
119122

@@ -206,7 +209,7 @@ Usually, it is unnecessary to change the content of experiment logs. In our prac
206209
**Batch Management**
207210

208211
We manage the items in the database via toolkits in rla_scripts. Currently, the rla_scripts includes
209-
1. Archive: archive some important results into another table.
212+
1. Archive: archive important experiments into an archived database, which will be saved in DATA_ROOT/arc.
210213
2. Delete: delete all useless experiments at once.
211214
3. Send to remote [TODO]
212215
4. Download from remote [TODO]
@@ -239,7 +242,8 @@ PS:
239242
2. An alternative way is building your own NFS for your physical machines and locate data_root to the NFS.
240243

241244
# TODO
245+
- [ ] video visualization.
242246
- [ ] add comments and documents to the functions.
243247
- [ ] add an auto integration script.
244-
- [ ] download / upload experiment logs through timestamp;
248+
- [ ] download / upload experiment logs through timestamp.
245249

RLA/easy_log/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
CHECKPOINT = 'checkpoint'
44
ARCHIVE_TESTER = 'archive_tester'
55
OTHER_RESULTS = 'results'
6-
6+
ARCHIVED_TABLE = 'arc'
77
default_log_types = [LOG, CODE, CHECKPOINT, ARCHIVE_TESTER, OTHER_RESULTS]
88

99
class LOAD_TESTER_MODE:

RLA/easy_log/log_tools.py

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def _delete_related_log(self, regex, show=False):
140140
os.remove(root_dir)
141141
print("--- delete root file {} ---".format(root_dir))
142142
else:
143-
print("not dir {}".format(root_dir))
143+
print("no dir {}".format(root_dir))
144144
if empty: print("empty regex {}".format(root_dir_regex))
145145
return log_found
146146

@@ -180,46 +180,39 @@ def delete_small_timestep_log(self, skip_ask=False):
180180
return log_found
181181

182182
class ArchiveLogTool(BasicLogTool):
183-
def __init__(self, proj_root, task_table_name, regex, archive_table_name, remove, *args, **kwargs):
183+
def __init__(self, proj_root, task_table_name, regex, archive_table_name=ARCHIVED_TABLE, *args, **kwargs):
184184
self.proj_root = proj_root
185185
self.task_table_name = task_table_name
186186
self.regex = regex
187-
self.remove = remove
188187
self.archive_table_name = archive_table_name
189188
super(ArchiveLogTool, self).__init__(*args, **kwargs)
190189

191190
def _archive_log(self, show=False):
192191
for log_type in self.log_types:
193192
root_dir_regex = osp.join(self.proj_root, log_type, self.task_table_name, self.regex)
194-
archive_root_dir = osp.join(self.proj_root, log_type, self.archive_table_name)
195-
prefix_dir = osp.join(self.proj_root, log_type, self.task_table_name)
193+
archive_root_dir = osp.join(self.proj_root, self.archive_table_name, log_type)
194+
prefix_dir = osp.join(self.proj_root, log_type)
196195
prefix_len = len(prefix_dir)
197196
empty = True
198197
# os.system("chmod +x -R \"{}\"".format(prefix_dir))
199198
for root_dir in glob.glob(root_dir_regex):
200199
empty = False
201200
if os.path.exists(root_dir):
201+
# remove the overlapped path.
202202
archiving_target = osp.join(archive_root_dir, root_dir[prefix_len+1:])
203203
archiving_target_dir = '/'.join(archiving_target.split('/')[:-1])
204204
os.makedirs(archiving_target_dir, exist_ok=True)
205205
if os.path.isdir(root_dir):
206206
if not show:
207207
# os.makedirs(archiving_target, exist_ok=True)
208208
shutil.copytree(root_dir, archiving_target)
209-
if self.remove:
210-
try:
211-
shutil.rmtree(root_dir)
212-
except PermissionError as e:
213-
print("skip the permission error file")
214-
print("move dir {}, to {}".format(root_dir, archiving_target))
209+
print("copy dir {}, to {}".format(root_dir, archiving_target))
215210
else:
216211
if not show:
217212
shutil.copy(root_dir, archiving_target)
218-
if self.remove:
219-
os.remove(root_dir)
220-
print("move file {}, to {}".format(root_dir, archiving_target))
213+
print("copy file {}, to {}".format(root_dir, archiving_target))
221214
else:
222-
print("not dir {}".format(root_dir))
215+
print("no dir {}".format(root_dir))
223216
if empty: print("empty regex {}".format(root_dir_regex))
224217
pass
225218

@@ -265,12 +258,3 @@ def view_log(self, skip_ask=False):
265258
s = input("press y to view \n ")
266259
if s == 'y':
267260
self._view_log(regex=res[0] + '*')
268-
269-
270-
271-
272-
273-
274-
# if __name__ == '__main__':
275-
# dlt = DeleteLogTool("../", "var_seq_imitation", "self-transfer", "2019/11/29/01-11*")
276-
# dlt.delete_related_log()

rla_scripts/archive_expt.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,12 @@ def argsparser():
1515
parser = argparse.ArgumentParser("Archive Log")
1616
# reduce setting
1717
parser.add_argument('--task_table_name', type=str)
18-
parser.add_argument('--archive_table_name', type=str, default=ARCHIVED_TABLE)
1918
parser.add_argument('--regex', type=str)
20-
parser.add_argument('--remove', action='store_true')
21-
2219

2320
args = parser.parse_args()
2421
return args
2522

2623
if __name__=='__main__':
2724
args = argsparser()
28-
dlt = ArchiveLogTool(proj_root=DATA_ROOT, task_table_name=args.task_table_name, regex=args.regex,
29-
archive_table_name=args.archive_table_name, remove=args.remove)
25+
dlt = ArchiveLogTool(proj_root=DATA_ROOT, task_table_name=args.task_table_name, regex=args.regex)
3026
dlt.archive_log()

rla_scripts/config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
DATA_ROOT = '../example/simplest_code/'
2-
ARCHIVED_TABLE = 'archived'

rla_scripts/delete_expt.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ def argsparser():
1212
parser.add_argument('--task_table_name', type=str, default="")
1313
parser.add_argument('--regex', type=str)
1414
parser.add_argument('--timestep_bound', type=int, default=100)
15+
# Filter.ALL: delete all experiments satisfied regex
16+
# Filter.SMALL_TIMESTEP: delete all experiments that the names satisfy regex
17+
# and the recorded timesteps are less than args.timestep_bound.
1518
parser.add_argument('--delete_type', type=str, default=Filter.ALL)
1619

1720
args = parser.parse_args()

rla_scripts/view_expt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from config import *
88

99
def argsparser():
10-
parser = argparse.ArgumentParser("Archive Log")
10+
parser = argparse.ArgumentParser("View Log")
1111
parser.add_argument('--task_table_name', type=str)
1212
parser.add_argument('--regex', type=str)
1313
args = parser.parse_args()

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name='RLA',
8-
version="0.5.2",
8+
version="0.5.3",
99
description=(
1010
'RL assistant'
1111
),
@@ -20,6 +20,7 @@
2020
"argparse",
2121
"dill",
2222
"seaborn",
23-
"pathspec"
23+
"pathspec",
24+
'tensorboardX'
2425
]
2526
)

test/test_scripts.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,12 @@ def test_delete_reg_small_ts(self):
4343
def test_archive(self):
4444
self.remove_and_copy_data()
4545
# archive experiments.
46-
dlt = ArchiveLogTool(proj_root=self.TARGET_DATA_ROOT, task_table_name=self.TASK_NAME, regex='2022/03/01/21-13*',
47-
archive_table_name='archived', remove=False)
46+
dlt = ArchiveLogTool(proj_root=self.TARGET_DATA_ROOT, task_table_name=self.TASK_NAME, regex='2022/03/01/21-13*')
4847
dlt.archive_log(skip_ask=True)
4948
# remove the archived experiments.
5049
filter = Filter()
5150
filter.config(type=Filter.ALL, timstep_bound=1)
52-
dlt = DeleteLogTool(proj_root=self.TARGET_DATA_ROOT, task_table_name='archived', regex='2022/03/01/21-13*', filter=filter)
51+
dlt = DeleteLogTool(proj_root=self.TARGET_DATA_ROOT + '/arc', regex='2022/03/01/21-13*', filter=filter, task_table_name=self.TASK_NAME)
5352
log_found = dlt.delete_related_log(skip_ask=True)
5453
assert log_found == 10
5554

0 commit comments

Comments
 (0)