Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
AndrewVSutherland
GitHub Repository: AndrewVSutherland/lmfdb
Path: blob/main/scripts/hecke_algebras/hecke_algebras_l_adic.py
1128 views
1
# -*- coding: utf-8 -*-
2
r""" Import Hecke algebras.
3
4
Note: This code can be run on all files in any order. Even if you
5
rerun this code on previously entered files, it should have no affect.
6
This code checks if the entry exists, if so returns that and updates
7
with new information. If the entry does not exist then it creates it
8
and returns that.
9
10
"""
11
12
import sys
13
import re
14
import json
15
import os
16
import gzip
17
18
from lmfdb.base import getDBConnection
19
20
C= getDBConnection()
21
import yaml
22
pw_dict = yaml.load(open(os.path.join(os.getcwd(), "passwords.yaml")))
23
username = pw_dict['data']['username']
24
password = pw_dict['data']['password']
25
C['hecke_algebras'].authenticate('editor', password)
26
hecke_orb_l = C['hecke_algebras'].hecke_algebras_l_adic
27
28
saving = True
29
30
def sd(f):
31
for k in f.keys():
32
print('%s ---> %s'%(k, f[k]))
33
34
def makels(li):
35
li2 = [str(x) for x in li]
36
return ','.join(li2)
37
38
def string2list(s):
39
s = str(s)
40
if s=='': return []
41
return [int(a) for a in s.split(',')]
42
43
44
45
# The following create_index command checks if there is an index on
46
# label, dimension, determinant and level.
47
48
hecke_orb_l.create_index('level')
49
hecke_orb_l.create_index('weight')
50
hecke_orb_l.create_index('ell')
51
52
print("finished indices")
53
54
55
## Main importing function
56
57
def do_import(ll):
58
level,weight,orbit_label,ell,index,idempotent,gen_l,num_gen_l,rel_l,num_charpoly,charpoly_ql= ll
59
mykeys = ['level','weight','orbit_label','ell','index','idempotent','gen_l','num_gen_l','rel_l','num_charpoly_ql','charpoly_ql']
60
data = {}
61
for j in range(len(mykeys)):
62
data[mykeys[j]] = ll[j]
63
64
label=".".join([str(data['orbit_label']),str(data['ell']), str(data['index'])])
65
data['label_l'] = label
66
67
alg_orb_l = hecke_orb_l.find_one({'label_l': label})
68
69
if alg_orb_l is None:
70
print("new l adic information")
71
alg_orb_l = data
72
else:
73
print("algebra in the database")
74
alg_orb_l.update(data)
75
if saving:
76
hecke_orb_l.update({'label_l': label} , {"$set": alg_orb_l}, upsert=True)
77
78
79
80
# Loop over files
81
82
for path in sys.argv[1:]:
83
print(path)
84
filename = os.path.basename(path)
85
fn = gzip.open(path) if filename[-3:] == '.gz' else open(path)
86
for line in fn.readlines():
87
line.strip()
88
if re.match(r'\S',line):
89
l = json.loads(line)
90
do_import(l)
91
92