Path: blob/main/scripts/genus2_curves/load_ratpts.py
1127 views
# -*- coding: utf-8 -*-12import lmfdb3import ast4import pymongo5from data_mgt.utilities.rewrite import rewrite_collection67# expected input file format is8# label:eqn:rank:ratpts:ratpts-verified:mwgroup:mwgens:mwgroup-verified:rank-verified9# ratpts contains a list of triples of ints representing projective points10# mwgroup is a list of invariants for finitely generated abelian group (0 means Z/0 = Z)11# mwgens is a list of degree 0 divisors on the Jacobian in Magma's Mumford representation1213def load_ratpts_data(filename):14db = lmfdb.base.getDBConnection().genus2_curves15with open(filename,'r') as input_file:16data = input_file.read()17outrecs = []18for inrec in data.split('\n'):19if not inrec:20break21items = inrec.split(':')22# assert len(items) == 923assert len(items) == 524label = items[0]25# Lrank = int(items[2])26ratpts = ast.literal_eval(items[3])27ratpts_v = True if int(items[4]) == 1 else False28# mwgroup = ast.literal_eval(items[5])29# mwrank = len([n for n in mwgroup if n == 0])30# mwgens = ast.literal_eval(items[6])31# mwgroup_v = True if int(items[7]) == 1 else False32# mwrank_v = True if int(items[8]) == 1 else False33# if mwrank < Lrank and not mwrank_v:34# print "Skipping record for %s with unverified mwrank %d < Lrank %d"%(label,mwrank,Lrank)35# continue36# if mwrank != Lrank:37# "Hooray you have found a counterexample to BSD! Or your data is wrong/incomplete :("38# print inrec39# return40rec = { 'label': label,41'num_rat_pts': int(len(ratpts)),42'rat_pts': [[str(c) for c in p] for p in ratpts],43'rat_pts_v': bool(ratpts_v) }44# 'mw_group' : [int(a) for a in mwgroup],45# 'mw_rank' : int(mwrank),46# 'mw_gens' : mwgens, # divisor coefficients should already be encoded as strings47# 'mw_group_v': bool(mwgroup_v),48# 'mw_rank_v': bool(mwrank_v) }49outrecs.append(rec)50if db.ratpts.new.count() > 0:51print("overwriting existing ratpts.new")52db.ratpts.new.drop()53db.ratpts.new.insert_many(outrecs)54assert db.ratpts.new.count() == len(outrecs)55db.ratpts.new.create_index([('label',pymongo.ASCENDING)])56if db.ratpts.old.count() > 0:57db.ratpts.old.drop()58if db.ratpts.count() > 0:59db.ratpts.rename('ratpts.old')60db.ratpts.new.rename('ratpts')6162# function to be passed to rewrite_collection63def ratpts_update(rec):64db = lmfdb.base.getDBConnection().genus2_curves65r = db.ratpts.find_one({'label':rec['label']})66rec['num_rat_pts'] = r['num_rat_pts']67return rec68print("Updating num_rat_pts in curves collection")69rewrite_collection(db, "curves","curves.new", ratpts_update)70print("renaming curves.new to curves")71db.curves.old.drop()72db.curves.rename("curves.old")73db.curves.new.rename("curves")74db.curves.create_index([('num_rat_pts',int(1))])75print("Done!")767778