-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_lmfdb_raw.py
More file actions
74 lines (63 loc) · 2.41 KB
/
Copy pathparse_lmfdb_raw.py
File metadata and controls
74 lines (63 loc) · 2.41 KB
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
import pandas as pd
from sage.databases.cremona import CremonaDatabase
from tqdm import tqdm
import multiprocessing as mp
import os
# ========================= CONFIG =========================
NUM_CORES = 4
CHUNK_SIZE = 400
OUTPUT_CREMONA = "cremona_raw_parsed.csv"
OUTPUT_LMFDB = "lmfdb_raw_parsed.csv"
# ======================================================
print("=== CREMONA (already done) ===")
if os.path.exists(OUTPUT_CREMONA):
n_cremona = sum(1 for _ in open(OUTPUT_CREMONA)) - 1
print(f" {OUTPUT_CREMONA} already exists ({n_cremona:,} curves)")
else:
print("Cremona file not found.")
# ====================== LMFDB (lmfdb-lite) ======================
print("\n=== LMFDB EXTRACTION (lmfdb-lite) ===")
from lmf import db as lmfdb_db
def lmfdb_batch(start, batch_size=10000):
query = {"conductor": {"$gte": start, "$lt": start + batch_size}}
results = list(
lmfdb_db.ec_curvedata.search(
query,
[
"lmfdb_label",
"conductor",
"absD",
"rank",
"ainvs",
], # ← exact column names from your list
)
)
rows = []
for r in results:
rows.append(
{
"label": r.get("lmfdb_label"),
"conductor": int(r.get("conductor", 0)),
"delta": int(r.get("absD", 0)), # absolute discriminant = |Δ|
"rank": int(r.get("rank", -1)),
"a_invariants_raw": str(r.get("ainvs", [])),
}
)
return rows
all_lmfdb = []
BATCH_SIZE = 10000
max_cond = 500000 # increase to 1_000_000+ if you want more curves
for start in tqdm(range(1, max_cond, BATCH_SIZE), desc="LMFDB batches"):
batch = lmfdb_batch(start, BATCH_SIZE)
all_lmfdb.extend(batch)
df_lmfdb = pd.DataFrame(all_lmfdb)
df_lmfdb.to_csv(OUTPUT_LMFDB, index=False)
print(f"\n LMFDB raw parsed saved: {OUTPUT_LMFDB} ({len(df_lmfdb):,} curves)")
print("\n DONE! BOTH RAW CSVs ARE READY")
print(f" cremona_raw_parsed.csv → {n_cremona:,} curves (local Cremona)")
print(f" lmfdb_raw_parsed.csv → {len(df_lmfdb):,} curves (LMFDB)")
print("\nNext step:")
print(" python compute_3selmer_from_raw.py")
print(" (it will use cremona_raw_parsed.csv by default)")
print(" To use LMFDB instead, change the line:")
print(" IN = 'lmfdb_raw_parsed.csv'")