-
Notifications
You must be signed in to change notification settings - Fork 0
/
prs.py
87 lines (66 loc) · 3.47 KB
/
prs.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
import os
from cdl import *
from utils import Search
from tools import get_unprocessed_fileid
import argparse
class ExhaustiveSearch(Search):
def __init__(self, cd, rules, lib_path, result_path):
super().__init__(cd, rules, lib_path, result_path)
def static_search(self,
cutoff=16,
threshold=0,
top_n=1000,
n_complete=5,
n_chunks=1000,
shuffle=False):
folder_name = f"{cutoff}_{threshold}_{top_n}_{n_chunks}_{n_complete}_{shuffle}_" + f"_".join(self.rules)
self.folder_path += folder_name
sub_folder_path = f"{self.folder_path}/{n_complete}_{self.cd.num_triples}/"
file_id = get_unprocessed_fileid(sub_folder_path)
while file_id is not None:
try:
os.rename(sub_folder_path+f"{file_id}.pkl",
sub_folder_path+f"{file_id}.processing")
trs_score_list = self.load_trs_score_list(f"{n_complete}_{self.cd.num_triples}",
f"{file_id}.processing")
for n_iter in range(n_complete+1, self.cd.num_triples+1):
next_trs_score_list = []
for trs, _ in trs_score_list:
trs_value_list = self.expand_trs(trs, cutoff, threshold)
next_trs_score_list.extend(trs_value_list)
trs_score_list.clear()
trs_score_list = next_trs_score_list
if top_n != -1:
trs_score_list.sort(key=lambda trs_score: trs_score[1])
trs_score_list = trs_score_list[-top_n:]
self.save_trs_score_list(trs_score_list,
f"{self.cd.num_triples}_{self.cd.num_triples}",
f"{file_id}.pkl")
os.remove(sub_folder_path+f"{file_id}.processing")
except FileNotFoundError as e:
print(e)
file_id = get_unprocessed_fileid(sub_folder_path)
parser = argparse.ArgumentParser(description="Run search on a single CPU core",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("-n", type=int, default=6)
parser.add_argument("-rules", nargs="*", type=str, default=["2N1", "2N3", "3N1", "1N3"])
parser.add_argument("-cutoff", type=int, default=16)
parser.add_argument("-threshold", type=float, default=0)
parser.add_argument("-top_n", type=int, default=1000)
parser.add_argument("-n_complete", type=int, default=10)
parser.add_argument("-n_chunks", type=int, default=10)
parser.add_argument("-shuffle", type=bool, default="")
parser.add_argument("-lib_path", type=str, default="/Users/bei/CLionProjects/cdl/")
parser.add_argument("-result_path", type=str, default="./results")
args = parser.parse_args()
config = vars(args)
print(config)
cd = CondorcetDomain(n=config['n'])
es = ExhaustiveSearch(cd, rules=config['rules'], lib_path=config['lib_path'], result_path=config['result_path'])
es.static_search(cutoff=config['cutoff'],
threshold=config['threshold'],
top_n=config['top_n'],
n_complete=config['n_complete'],
n_chunks=config['n_chunks'],
shuffle=config['shuffle'])
# python parallel_search.py -n 6 -cutoff 16 -threshold 0 -top_n 1000 -rules "2N3" "2N1" -triple_id 6 -core_id 2