Datasets:
Download tools/compiler/package.py from ego0op/ingot-lean-zig: direct link, hf CLI and curl.
- Browser
- Download file 2.37 kB
-
https://huggingface.co/datasets/ego0op/ingot-lean-zig/resolve/main/tools/compiler/package.py
- Command line
-
hf download hf://datasets/ego0op/ingot-lean-zig/tools/compiler/package.py
-
curl -L -o package.py https://huggingface.co/datasets/ego0op/ingot-lean-zig/resolve/main/tools/compiler/package.py
2.37 kB
| # package.py HFC_DIR : the `compiler` config of ingot-lean-zig, one row per standalone file that passed zig test | |
| # alone and is not contaminated. | |
| import sys, json, hashlib, re, pyarrow as pa, pyarrow.parquet as pq | |
| H = sys.argv[1] | |
| lic = pq.read_table(H + '/../hfl/data/train/train-00000-of-00001.parquet').slice(0, 1).to_pylist()[0]['license_text'] | |
| dc = json.load(open(H + '/decontam.json')) | |
| # (each function's body names the Lean declaration it was translated from, `// Lean: <name>`, from cycle 177) | |
| decl = dict(l.rstrip('\n').split('\t') for l in open(H + '/declnames.tsv')) | |
| mods = dict(l.rstrip('\n').split('\t') for l in open(H + '/declmods.tsv')) | |
| dropped_ref = [] | |
| rows = [] | |
| for z in [l.strip() for l in open(H + '/pass.txt') if l.strip()]: | |
| if z in dc['contaminated']: continue | |
| text = open(f'{H}/files/{z}.zig').read() | |
| d = decl.get(z) or None | |
| # (lean2zig's own reference implementations, `Lean2Zig.Ref.*`, are not Lean's code: left out) | |
| if d and d.startswith('Lean2Zig.Ref.'): | |
| dropped_ref.append(z); continue | |
| mod = mods.get(d) if d else None | |
| if mod == '?': mod = None | |
| src = None | |
| if mod and mod != '?': src = 'src/' + mod.replace('.', '/') + '.lean' | |
| nv = len(re.findall(r'(?m)^ try (?:std\.testing\.expect|leanExpect)', text)) | |
| rows.append(dict(id=f'ilzc-{len(rows):05d}', family=(mod.split('.')[0] if mod else z.split('_')[0]), kind='compiler', | |
| lean_decl=d, zig_name=z, | |
| source_repo='leanprover/lean4', source_commit='f72c35b3f637c8c6571d353742168ab66cc22c00', source_file=src, | |
| license='Apache-2.0', license_text=lic, zig_version='0.17.0', text=text, n_vectors=nv, | |
| bytes=len(text.encode()), sha256=hashlib.sha256(text.encode()).hexdigest(), | |
| verify=f'zig 0.17.0 test of this file alone: {nv} vectors computed by Lean 4.29.1 (v4.29.1, f72c35b), all pass (x86_64-linux, Debug)', | |
| generator='lean2zig cycle 177 (gke0op/babel 293cdbd7, tools/lean2zig/compiler)')) | |
| import os; os.makedirs(H + '/out/data/compiler', exist_ok=True) | |
| pq.write_table(pa.Table.from_pylist(rows), H + '/out/data/compiler/compiler-00000-of-00001.parquet', compression='zstd') | |
| print(len(dropped_ref), 'reference implementations left out:', dropped_ref) | |
| print(len(rows), 'rows;', sum(r['lean_decl'] is not None for r in rows), 'with one Lean declaration;', sum(r['bytes'] for r in rows), 'bytes') | |