예제 #1
0
    def __init__(self, args, problem_source=None):
        super().__init__()
        self.args = args
        self.last_file = None

        self.action_space = spaces.Discrete(args.n_action_slots)
        if self.args.graph_embedding:
            assert self.args.graph_node_count == self.args.graph_embedding_size, "graph_node_count has to equal graph_embedding_size" # TODO
            # embS_space = spaces.Box(low=0.0, high=1.0, shape=(args.graph_node_count, args.graph_embedding_size), dtype=np.float32)
            # connS_space = spaces.Box(low=0.0, high=1.0, shape=(args.graph_node_count, args.graph_node_count), dtype=np.float32)
            # embAs_space = spaces.Box(low=0.0, high=1.0, shape=(args.n_action_slots, args.graph_node_count, args.graph_embedding_size), dtype=np.float32)
            # connAs_space = spaces.Box(low=0.0, high=1.0, shape=(args.n_action_slots, args.graph_node_count, args.graph_node_count), dtype=np.float32)
            # self.observation_space = spaces.Tuple((embS_space, connS_space, embAs_space, connAs_space))
            self.observation_space = spaces.Box(low=0.0, high=1.0, shape=(2, 1+ args.n_action_slots, args.graph_node_count, args.graph_node_count), dtype=np.float32)
        else:            
            self.observation_space = spaces.Box(low=-10.0, high=10.0, shape=(args.n_action_slots+args.state_dim, args.n_dim+1), dtype=np.float32)

        self.indexer = util.Indexer(args.n_dim, args.n_dim, feature_file=args.feature_file)
        self.n_dim = self.indexer.S_DIM

        if args.backend == "ocaml":
            import backend_ocaml
            self.backend = backend_ocaml.Backend(self.indexer, verbose=False,
                                                 fast_features=args.fast_features,
                                                 use_previous_state=args.use_previous_state,
                                                 use_previous_action=args.use_previous_action,
                                                 graph_embedding=args.graph_embedding,
                                                 graph_embedding_size=args.graph_embedding_size,
                                                 graph_node_count=args.graph_node_count,
                                                 det_steps=args.det_steps
            )
        elif args.backend == "prolog":
            import backend_prolog
            inner_dim = 10000
            self.backend = backend_prolog.Backend(inner_dim, self.indexer,
                                                  verbose=False,
                                                  print_proof=False
            )

        self.statistics = {} # we store history about the problems
        self.jackpots = []
        self.blacklist = [] # problems that we do not want to consider any more

        self.global_steps_to_remain = args.scheduler_starting_step
        self.global_episodes = 0
        self.global_success_ratio = 0

        self.global_step_counter = 0
        self.model=None

        if problem_source is not None:
            self.set_source(problem_source)
예제 #2
0
    def __init__(self, args, container):
        super().__init__()
        self.args = args
        self.container = container

        self.indexer = util.Indexer(args.n_dim,
                                    args.n_dim,
                                    feature_file=args.feature_file,
                                    embed_separately=True)
        self.n_dim = self.indexer.S_DIM
        self.backend = Backend(self.indexer,
                               verbose=False,
                               fast_features=args.fast_features,
                               use_previous_action=args.use_previous_action)
        self.action_space = spaces.Discrete(args.n_action_slots)
        self.observation_space = spaces.Box(low=-10.0,
                                            high=10.0,
                                            shape=(args.n_action_slots +
                                                   args.state_dim, self.n_dim),
                                            dtype=np.float32)

        self.last_file = None
예제 #3
0
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
session = tf.Session(config=config)
graph = Graph(args)

if modelfile is None:
    datadict = read_data(datafile, args)
    print("Size: ", len(datadict.rewards))
    print("Positive: ", np.sum(datadict.rewards > 0))
    train_model(session, graph, args, datadict)
else:
    saver = tf.train.Saver(max_to_keep=None)
    saver.restore(session, modelfile)
    print("Graph restored from ", modelfile)

indexer = util.Indexer(args.EMBEDDING_SIZE, args.EMBEDDING_SIZE)
backend = backend_ocaml.Backend(indexer,
                                verbose=False,
                                fast_features=False,
                                use_previous_action=False,
                                use_previous_state=False)


def start():
    global steps
    _, _, action_list, _, done = backend.start(problem)
    action_count = len(action_list)
    best_action = print_state(action_count)
    steps = []
    return action_count, done, best_action
예제 #4
0
import argparse
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--backend', help='ocaml/prolog', type=str, default='prolog')
parser.add_argument('--ocaml_version', help='hash/literal', type=str, default='literal')
parser.add_argument('--time', help='time in seconds, floats are OK', type=float, default=10.)
parser.add_argument('--file', help='file name with the theorem to be proved', type=str, default='theorems/a.p')
args = parser.parse_args()

import util
import backend_ocaml
import env_prolog

S_DIM = 60
A_DIM = 30

indexer = util.Indexer(S_DIM, A_DIM)
cp = util.ClausePrinter()

if args.backend == "ocaml":
    env = backend_ocaml.Backend(indexer, verbose=False)
elif args.backend == "prolog":
    env = env_prolog.Env(indexer, backtrack=True, verbose=False, print_proof=True)

t0 = time.time()
def getTime():
    return time.time() - t0

pathLim = 1
while getTime() < args.time:
    state, state_id, action_list, action_ids, done = env.start(args.file, pathLim)
예제 #5
0
def main():
    from backend_ocaml import Backend
    import util

    N_DIM = 100
    FEATURE_FILE = None
    FAST_FEATURES = False
    USE_PREVIOUS_ACTION = False
    USE_PREVIOUS_STATE = False
    FILE = "a.p"  #"theorems/robinson/simple/final/robinson_1m1__1.p"

    indexer = util.Indexer(N_DIM, N_DIM, feature_file=FEATURE_FILE)
    backend = Backend(indexer,
                      verbose=False,
                      fast_features=FAST_FEATURES,
                      use_previous_action=USE_PREVIOUS_ACTION,
                      use_previous_state=USE_PREVIOUS_STATE)
    backend.start(FILE)
    # state, state_id, embedded_action_list, embedded_action_ids, done = backend.start(FILE)
    # action_count = len(embedded_action_list)
    done, action_count = backend.step_fast(0)

    state = backend.get_holstep_state()
    goal = state[0]
    action = backend.get_holstep_action(0)
    action = add_or_node(action)

    print("action:", action),
    print("var_node_added:", add_var_nodes(action))

    for i in range(1, 10):
        print(i, " truncated action ", truncate_clause(action, i))

    print("state embedding: \n", clause2embedding(goal, 5))
    print("action embedding: \n", clause2embedding(action, 5))
    print("\n\n\n")

    print("State: {}, count {}".format(state, count_nodes(goal)))
    print("State types: {}".format(collect_types(goal)))
    print("State vars: {}".format(collect_vars(goal, 0)))
    VarConn = build_varconn(goal, 5)
    goal = collapse_vars(goal)

    print("Vars collapsed: {}".format(goal))
    print("VarConn: ")
    print(VarConn)

    ConnGoal = build_connections(goal)
    ConnAction = build_connections(action)

    print("ConnG\n", ConnGoal)
    print("ConnA\n", ConnAction)

    print("\n\n")
    backend.print_state()
    for a in range(action_count):
        action = backend.get_holstep_action(a)
        print("Action {}: {}, count {}, literals {}".format(
            a, add_or_node(action), count_nodes(action),
            count_literals(action)))
        backend.print_action(a)
예제 #6
0
# import backend_prolog
import util
import sys

if len(sys.argv) < 2:
    assert False, "Need to provide at least one argument: \nshow_proof_states.py <problemfile> [<proofsteps>]"

problem = sys.argv[1]
if len(sys.argv) >= 3:
    proof = [int(x) for x in (sys.argv[2].split(','))]
else:
    proof = []

N_DIM = 100

indexer = util.Indexer(N_DIM, N_DIM)
backend = backend_ocaml.Backend(indexer,
                                verbose=False,
                                fast_features=False,
                                use_previous_action=False,
                                use_previous_state=False,
                                det_steps=False)


def start():
    global steps, hashes, states, actions
    state, action_list, done = backend.start(problem)
    # print("State: ", state)
    backend.print_state()
    #    for i, _ in enumerate(action_list):
    #        backend.print_action(i)