Skip to content

Commit a2dac75

Browse files
committed
Comment out dead code.
`find_redundant_rules()` is never called. Commented it out and its helper method `find_redundant_rule_`
1 parent 6a1b2e5 commit a2dac75

File tree

1 file changed

+39
-31
lines changed

1 file changed

+39
-31
lines changed

popper/tester.py

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import os
22
import time
3+
from typing import AnyStr, Any, Dict
4+
35
import pkg_resources
46
from janus_swi import query_once, consult
57
from functools import cache
68
from contextlib import contextmanager
7-
from . util import order_prog, prog_is_recursive, rule_is_recursive, calc_rule_size, calc_prog_size, prog_hash, format_rule, format_literal, Literal
9+
from .util import order_prog, prog_is_recursive, rule_is_recursive, calc_rule_size, calc_prog_size, prog_hash, \
10+
format_rule, format_literal, Literal, Settings
811
from bitarray import bitarray, frozenbitarray
912
from bitarray.util import ones
1013
from collections import defaultdict
@@ -19,6 +22,11 @@ def bool_query(query):
1922

2023
class Tester():
2124

25+
settings: Settings
26+
cached_pos_covered: Dict[int, frozenbitarray]
27+
neg_fact_str: str
28+
neg_literal_set: frozenset
29+
2230
def __init__(self, settings):
2331
self.settings = settings
2432

@@ -59,7 +67,7 @@ def __init__(self, settings):
5967
self.pos_examples_ = ones(self.num_pos)
6068

6169
self.cached_pos_covered = {}
62-
self.cached_inconsistent = {}
70+
# self.cached_inconsistent = {} -- never set or referenced.
6371

6472
if self.settings.recursion_enabled:
6573
query_once(f'assert(timeout({self.settings.eval_timeout})), fail')
@@ -374,35 +382,35 @@ def has_redundant_literal(self, prog):
374382
# print(q, False)
375383
return False
376384

377-
# # WE ASSUME THAT THERE IS A REUNDANT RULE
378-
def find_redundant_rule_(self, prog):
379-
prog_ = []
380-
for i, (head, body) in enumerate(prog):
381-
c = f"{i}-[{','.join(('not_'+ format_literal(head),) + tuple(format_literal(lit) for lit in body))}]"
382-
prog_.append(c)
383-
prog_ = f"[{','.join(prog_)}]"
384-
prog_ = janus_format_rule(prog_)
385-
q = f'find_redundant_rule({prog_}, K1, K2)'
386-
res = query_once(q)
387-
k1 = res['K1']
388-
k2 = res['K2']
389-
return prog[k1], prog[k2]
390-
391-
def find_redundant_rules(self, prog):
392-
# assert(False)
393-
# AC: if the overhead of this call becomes too high, such as when learning programs with lots of clauses, we can improve it by not comparing already compared clauses
394-
base = []
395-
step = []
396-
for rule in prog:
397-
if rule_is_recursive(rule):
398-
step.append(rule)
399-
else:
400-
base.append(rule)
401-
if len(base) > 1 and self.has_redundant_rule(base):
402-
return self.find_redundant_rule_(base)
403-
if len(step) > 1 and self.has_redundant_rule(step):
404-
return self.find_redundant_rule_(step)
405-
return None
385+
# # WE ASSUME THAT THERE IS A REDUNDANT RULE
386+
# def find_redundant_rule_(self, prog):
387+
# prog_ = []
388+
# for i, (head, body) in enumerate(prog):
389+
# c = f"{i}-[{','.join(('not_'+ format_literal(head),) + tuple(format_literal(lit) for lit in body))}]"
390+
# prog_.append(c)
391+
# prog_ = f"[{','.join(prog_)}]"
392+
# prog_ = janus_format_rule(prog_)
393+
# q = f'find_redundant_rule({prog_}, K1, K2)'
394+
# res = query_once(q)
395+
# k1 = res['K1']
396+
# k2 = res['K2']
397+
# return prog[k1], prog[k2]
398+
#
399+
# def find_redundant_rules(self, prog):
400+
# # assert(False)
401+
# # AC: if the overhead of this call becomes too high, such as when learning programs with lots of clauses, we can improve it by not comparing already compared clauses
402+
# base = []
403+
# step = []
404+
# for rule in prog:
405+
# if rule_is_recursive(rule):
406+
# step.append(rule)
407+
# else:
408+
# base.append(rule)
409+
# if len(base) > 1 and self.has_redundant_rule(base):
410+
# return self.find_redundant_rule_(base)
411+
# if len(step) > 1 and self.has_redundant_rule(step):
412+
# return self.find_redundant_rule_(step)
413+
# return None
406414

407415
def find_pointless_relations(self):
408416
settings = self.settings

0 commit comments

Comments
 (0)