-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreset_framework.py
More file actions
133 lines (108 loc) · 3.59 KB
/
Copy pathreset_framework.py
File metadata and controls
133 lines (108 loc) · 3.59 KB
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
123
124
125
126
127
128
129
130
131
132
133
"""
Reset Framework Script
This script is created to easily reset the LEVER framework in case you want to use
different training data or start fresh. It will delete:
1. All data from the data/ folder
2. The trained regressor model (models/reward_regressor.pkl)
3. The Faiss vector database (faiss_index/ folder)
4. The successor feature models (psi_models/ folder)
WARNING: This will permanently delete all trained models and processed data.
Make sure you have backups if needed before running this script.
Usage:
python reset_framework.py
"""
import os
import shutil
from pathlib import Path
def delete_directory(path):
"""Delete a directory if it exists."""
if os.path.exists(path):
try:
shutil.rmtree(path)
print(f"✓ Deleted: {path}")
return True
except Exception as e:
print(f"✗ Error deleting {path}: {e}")
return False
else:
print(f"⚠️ Not found (skipping): {path}")
return False
def delete_file(path):
"""Delete a file if it exists."""
if os.path.exists(path):
try:
os.remove(path)
print(f"✓ Deleted: {path}")
return True
except Exception as e:
print(f"✗ Error deleting {path}: {e}")
return False
else:
print(f"⚠️ Not found (skipping): {path}")
return False
def delete_data_folder_contents():
"""Delete all contents of the data/ folder but keep the folder itself."""
data_dir = Path("data")
if not data_dir.exists():
print("⚠️ data/ folder does not exist (skipping)")
return False
deleted_any = False
for item in data_dir.iterdir():
try:
if item.is_file():
item.unlink()
print(f"✓ Deleted file: {item}")
deleted_any = True
elif item.is_dir():
shutil.rmtree(item)
print(f"✓ Deleted directory: {item}")
deleted_any = True
except Exception as e:
print(f"✗ Error deleting {item}: {e}")
if not deleted_any:
print("⚠️ data/ folder is empty (nothing to delete)")
return deleted_any
def main():
"""Main function to reset the framework."""
print("=" * 80)
print("LEVER Framework Reset")
print("=" * 80)
print()
print("This will delete:")
print(" 1. All data from data/ folder")
print(" 2. models/reward_regressor.pkl")
print(" 3. faiss_index/ folder")
print(" 4. psi_models/ folder")
print()
print("WARNING: This action cannot be undone!")
print()
# Ask for confirmation
response = input("Are you sure you want to continue? (yes/no): ").strip().lower()
if response not in ["yes", "y"]:
print("Reset cancelled.")
return
print()
print("Starting reset...")
print("-" * 80)
# 1. Delete all data from data/ folder
print("\n1. Deleting data/ folder contents...")
delete_data_folder_contents()
# 2. Delete regressor model
print("\n2. Deleting regressor model...")
delete_file("models/reward_regressor.pkl")
# 3. Delete faiss_index folder
print("\n3. Deleting Faiss index...")
delete_directory("faiss_index")
# 4. Delete psi_models folder
print("\n4. Deleting successor feature models...")
delete_directory("psi_models")
print()
print("=" * 80)
print("Reset complete!")
print("=" * 80)
print()
print("You can now run the framework preparation again:")
print(" python pi2vec_preparation.py")
print()
if __name__ == "__main__":
main()