def get_proof(args): coq_filename = os.path.splitext(args.file)[0] + '.v' fields = coq_filename.split(os.path.sep) loc2code = get_code(open(coq_filename, 'rb').read()) meta = open(args.file).read() coq_code = extract_code(meta, loc2code) with open(os.path.join(args.data_path, args.file[13:-5] + '.json'), "r") as json_data: file_data = json.load(json_data) with open(args.file0, "r") as json_data: proof_data0 = json.load(json_data) proof_data0 = [tempdic['name'] for tempdic in proof_data0['proofs']] for tempproof in file_data['proofs']: args.proof = tempproof if tempproof not in proof_data0: continue if os.path.isfile(os.path.join( dirname, args.proof + '.json')): # tempproof != 'loc_unconstrained_satisf': continue db_path = os.path.join(dirname, args.proof + '-sexp_cache') sexp_cache = SexpCache(db_path) with SerAPI(args.timeout, args.debug) as serapi: num_extra_cmds = len(set_paths(meta, serapi, sexp_cache)) # process the coq code proof_start_lines = [] in_proof = False for num_executed, (code_line, tags) in enumerate(coq_code): assert code_line == file_data['vernac_cmds'][num_extra_cmds + num_executed][0] if 'PROOF_NAME' in tags and tags[ 'PROOF_NAME'] == args.proof: # the proof ends serapi.pop() line_nb = proof_start_lines[-1] proof_data = record_proof(num_extra_cmds, line_nb, coq_code[line_nb + 1:], sexp_cache, serapi, args) if proof_data is not None: dump(proof_data, args) break # execute the code if args.debug: print('%d: %s' % (num_executed, code_line)) serapi.execute(code_line) if serapi.has_open_goals(): if not in_proof: # the proof starts in_proof = True proof_start_lines.append(num_executed) serapi.push() else: in_proof = False return
def process_file(filename): # extract a Coq file db_path = dst_filename(filename, args.data_path) + "-sexp_cache" try: os.makedirs(os.path.split(db_path)[0]) except os.error: pass sexp_cache = SexpCache(db_path) file_data = check_file(filename, sexp_cache, args) dump(file_data, args)
def process_file(filename): # extract a Coq file coq_filename = os.path.splitext(filename)[0] + '.v' fields = coq_filename.split(os.path.sep) file_data_filename = os.path.sep.join(fields[2:]) file_data_coq_project = fields[1] path = os.path.join(args.data_path, file_data_coq_project, file_data_filename)[:-2] if os.path.isfile(path + '.json'): return db_path = dst_filename(filename, args.data_path) + '-sexp_cache' try: os.makedirs(os.path.split(db_path)[0]) except os.error: pass sexp_cache = SexpCache(db_path) try: file_data = check_file(filename, sexp_cache, args) except: print(path + ' failed') return dump(file_data, args)
type=int, default=4, help="The maximum length for synthetic proofs", ) arg_parser.add_argument("--timeout", type=int, default=3600, help="Timeout for SerAPI") arg_parser.add_argument("--data_path", type=str, default="./data") args = arg_parser.parse_args() print(args) human_proof_file = (dst_filename(args.file, args.data_path) + "-PROOFS/" + args.proof + ".json") if not os.path.exists(human_proof_file): print("%s does not exist. Exiting.." % human_proof_file) sys.exit(0) dirname = dst_filename(args.file, args.data_path) + "-SUBPROOFS/" try: os.makedirs(dirname) except os.error: pass db_path = os.path.join(dirname, args.proof + "_sexp_cache") sexp_cache = SexpCache(db_path) file_data = json.load( open(dst_filename(args.file, args.data_path) + ".json")) subproofs_data = get_subproofs(human_proof_file, file_data["vernac_cmds"], sexp_cache, args) dump(subproofs_data, args)
import pickle from tac_grammar import CFG, TreeBuilder, NonterminalNode, TerminalNode import sys sys.setrecursionlimit(100000) sys.path.append(os.path.normpath(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../'))) from gallina import GallinaTermParser from lark.exceptions import UnexpectedCharacters, ParseError from utils import iter_proofs, SexpCache import argparse from hashlib import md5 from agent import filter_env import pdb term_parser = GallinaTermParser(caching=True) sexp_cache = SexpCache('../sexp_cache', readonly=True) def parse_goal(g): goal = {'id': g['id'], 'text': g['type'], 'ast': term_parser.parse(sexp_cache[g['sexp']])} local_context = [] for i, h in enumerate(g['hypotheses']): for ident in h['idents']: local_context.append({'ident': ident, 'text': h['type'], 'ast': term_parser.parse(sexp_cache[h['sexp']])}) return local_context, goal grammar = CFG('tactics.ebnf', 'tactic_expr') tree_builder = TreeBuilder(grammar) def tactic2actions(tac_str): tree = tree_builder.transform(grammar.parser.parse(tac_str))
from time import time def action_seq_loss(logits_batch, actions_batch, opts): assert len(logits_batch) == len(actions_batch) loss = 0 for logits, actions in zip(logits_batch, actions_batch): length = min(logits.shape[0], actions.shape[0]) loss += F.cross_entropy(logits[:length], actions[:length].to(opts.device)) loss /= len(logits_batch) return loss # merge this with extract_proof_steps.py term_parser = GallinaTermParser(caching=True) sexp_cache = SexpCache("../sexp_cache", readonly=True) def filter_env(env): "Get the last 10 toplevel constants" filtered_env = [] toplevel_consts = [ const for const in env["constants"] if const["qualid"].startswith("SerTop") ] for const in toplevel_consts[-10:]: ast = sexp_cache[const["sexp"]] filtered_env.append({"qualid": const["qualid"], "ast": term_parser.parse(ast)}) return filtered_env def parse_goal(g):