Skip to content

Commit

Permalink
Merge pull request #5715 from LMFDB/master
Browse files Browse the repository at this point in the history
master --> dev
  • Loading branch information
AndrewVSutherland authored Nov 3, 2023
2 parents 369d64c + dd388ff commit 87ebe9f
Show file tree
Hide file tree
Showing 74 changed files with 2,428 additions and 1,464 deletions.
4 changes: 4 additions & 0 deletions lmfdb/abvar/fq/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from lmfdb.utils import Downloader
from flask import abort
from lmfdb.backend.encoding import Json
from .isog_class import AbvarFq_isoclass

class AbvarFq_download(Downloader):
table = db.av_fq_isog
Expand All @@ -26,3 +27,6 @@ def download_curves(self, label, lang='text'):
label + '.curves',
lang=lang,
title='Curves in abelian variety isogeny class %s,'%(label))

def postprocess(self, rec, info, query):
return AbvarFq_isoclass(rec)
28 changes: 21 additions & 7 deletions lmfdb/abvar/fq/isog_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from sage.plot.all import line, points, circle, Graphics
from sage.misc import latex
from sage.misc.cachefunc import cached_method
from sage.misc.lazy_attribute import lazy_attribute

from lmfdb.utils import list_to_factored_poly_otherorder, coeff_to_poly, web_latex, integer_divisors
from lmfdb.number_fields.web_number_field import nf_display_knowl, field_pretty
Expand Down Expand Up @@ -79,7 +80,6 @@ def __init__(self, dbdata):
if "jacobian_count" not in dbdata:
dbdata["jacobian_count"] = None
self.__dict__.update(dbdata)
self.make_class()

@classmethod
def by_label(cls, label):
Expand All @@ -92,14 +92,28 @@ def by_label(cls, label):
except (AttributeError, TypeError):
raise ValueError("Label not found in database")

def make_class(self):
self.decompositioninfo = decomposition_display(list(zip(self.simple_distinct, self.simple_multiplicities)))
self.basechangeinfo = self.basechange_display()
self.formatted_polynomial = list_to_factored_poly_otherorder(self.polynomial, galois=False, vari="x")
@lazy_attribute
def decompositionraw(self):
return list(zip(self.simple_distinct, self.simple_multiplicities))

@lazy_attribute
def decompositioninfo(self):
return decomposition_display(self.decompositionraw)

@lazy_attribute
def basechangeinfo(self):
return self.basechange_display()

@lazy_attribute
def formatted_polynomial(self):
return list_to_factored_poly_otherorder(self.polynomial, galois=False, vari="x")

@lazy_attribute
def expanded_polynomial(self):
if self.is_simple and QQ['x'](self.polynomial).is_irreducible():
self.expanded_polynomial = ''
return ""
else:
self.expanded_polynomial = latex.latex(QQ[['x']](self.polynomial))
return latex.latex(QQ[['x']](self.polynomial))

@property
def p(self):
Expand Down
97 changes: 17 additions & 80 deletions lmfdb/abvar/fq/main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# -*- coding: utf-8 -*-

import ast
import re
from io import BytesIO
import time

from flask import abort, render_template, url_for, request, redirect, send_file
from sage.rings.all import PolynomialRing, ZZ
from flask import abort, render_template, url_for, request, redirect
from sage.rings.all import ZZ
from sage.databases.cremona import cremona_letter_code

from lmfdb import db
Expand Down Expand Up @@ -77,10 +74,10 @@ def abelian_varieties():
info = to_dict(request.args, search_array=AbvarSearchArray())
if request.args:
# hidden_search_type for prev/next buttons
info["search_type"] = search_type = info.get("search_type", info.get("hst", "List"))
info["search_type"] = search_type = info.get("search_type", info.get("hst", ""))
if search_type == "Counts":
return abelian_variety_count(info)
elif search_type in ['List', 'Random']:
elif search_type in ['List', '', 'Random']:
return abelian_variety_search(info)
else:
flash_error("Invalid search type; if you did not enter it in the URL please report")
Expand Down Expand Up @@ -155,66 +152,6 @@ def url_for_label(label):
g, q, iso = split_label(label)
return url_for(".abelian_varieties_by_gqi", g=g, q=q, iso=iso)

def download_search(info):
dltype = info["Submit"]
R = PolynomialRing(ZZ, "x")
delim = "bracket"
com = "" # single line comment start
com1 = "" # multiline comment start
com2 = "" # multiline comment end
eol = "" # line continuation (only needed for gp)
filename = "weil_polynomials.txt"
mydate = time.strftime("%d %B %Y")
if dltype == 'gp':
filename = 'weil_polynomials.gp'
com = r'\\'
eol = '\\'
if dltype == 'sage':
com = '#'
filename = 'weil_polynomials.sage'
if dltype == 'magma':
com1 = '/*'
com2 = '*/'
delim = 'magma'
filename = 'weil_polynomials.m'
elif dltype == 'oscar':
com1 = '#='
com2 = '=#'
filename = 'weil_polynomials.jl'
s = com1 + "\n"
s += com + " Weil polynomials downloaded from the LMFDB on %s.\n" % (mydate)
s += com + " Below is a list (called data), collecting the weight 1 L-polynomial\n"
s += com + " attached to each isogeny class of an abelian variety.\n"
s += "\n" + com2
s += "\n"

if dltype == "magma":
s += "P<x> := PolynomialRing(Integers()); \n"
s += "data := ["
elif dltype == "sage":
s += "x = polygen(ZZ) \n"
s += "data = [ "
elif dltype == "oscar":
s += "Rx,x = PolynomialRing(QQ) \n"
s += "data = [ "
else:
s += "data = [ "

s += eol + "\n"
for f in db.av_fq_isog.search(ast.literal_eval(info["query"]), "poly"):
poly = R(f)
s += str(poly) + "," + eol + "\n"
s = s[:-2-len(eol)]
s += "]\n"
if delim == "magma":
s = s.replace("[", "[*")
s = s.replace("]", "*]")
s += ";"
strIO = BytesIO()
strIO.write(s.encode('utf-8'))
strIO.seek(0)
return send_file(strIO, download_name=filename, as_attachment=True)

@abvarfq_page.route("/data/<label>")
def AV_data(label):
if not lmfdb_label_regex.fullmatch(label):
Expand Down Expand Up @@ -579,7 +516,7 @@ def short_label(d):

def search_types(self, info):
return self._search_again(info, [
('List', 'List of isogeny classes'),
('', 'List of isogeny classes'),
('Counts', 'Counts table'),
('Random', 'Random isogeny class')])

Expand Down Expand Up @@ -685,16 +622,16 @@ def extended_code(c):
return by_label(jump_box)

abvar_columns = SearchColumns([
LinkCol("label", "ab.fq.lmfdb_label", "Label", url_for_label, default=True),
MathCol("g", "ag.dimension", "Dimension", default=True),
MathCol("field", "ag.base_field", "Base field", default=True),
MathCol("p", "ag.base_field", "Base char.", short_title="base characteristic"),
MathCol("formatted_polynomial", "av.fq.l-polynomial", "L-polynomial", short_title="L-polynomial", default=True),
MathCol("p_rank", "av.fq.p_rank", "$p$-rank", default=True),
MathCol("p_rank_deficit", "av.fq.p_rank", "$p$-rank deficit"),
MathCol("curve_count", "av.fq.curve_point_counts", "points on curve"),
MathCol("abvar_count", "ag.fq.point_counts", "points on variety"),
SearchCol("decomposition_display_search", "av.decomposition", "Isogeny factors", default=True)],
LinkCol("label", "ab.fq.lmfdb_label", "Label", url_for_label),
MathCol("g", "ag.dimension", "Dimension"),
MathCol("field", "ag.base_field", "Base field", download_col="q"),
MathCol("p", "ag.base_field", "Base char.", short_title="base characteristic", default=False),
MathCol("formatted_polynomial", "av.fq.l-polynomial", "L-polynomial", short_title="L-polynomial", download_col="polynomial"),
MathCol("p_rank", "av.fq.p_rank", "$p$-rank"),
MathCol("p_rank_deficit", "av.fq.p_rank", "$p$-rank deficit", default=False),
MathCol("curve_count", "av.fq.curve_point_counts", "points on curve", default=False),
MathCol("abvar_count", "ag.fq.point_counts", "points on variety", default=False),
SearchCol("decomposition_display_search", "av.decomposition", "Isogeny factors", download_col="decompositionraw")],
db_cols=["label", "g", "q", "poly", "p_rank", "p_rank_deficit", "is_simple", "simple_distinct", "simple_multiplicities", "is_primitive", "primitive_models", "curve_count", "abvar_count"])

@search_wrap(
Expand All @@ -704,7 +641,7 @@ def extended_code(c):
columns=abvar_columns,
shortcuts={
"jump": jump,
"download": download_search,
"download": AbvarFq_download(),
},
postprocess=lambda res, info, query: [AbvarFq_isoclass(x) for x in res],
url_for_label=url_for_label,
Expand All @@ -731,7 +668,7 @@ def abelian_variety_count(info, query):
def url_generator(g, q):
info_copy = dict(urlgen_info)
info_copy.pop("search_array", None)
info_copy["search_type"] = "List"
info_copy.pop("search_type", None)
info_copy["g"] = g
info_copy["q"] = q
return url_for("abvarfq.abelian_varieties", **info_copy)
Expand Down
14 changes: 7 additions & 7 deletions lmfdb/abvar/fq/test_av.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ def test_av_download(self):
r"""
Test downloading on search results page.
"""
response = self.tc.get("Variety/Abelian/Fq/5/2/?Submit=sage&download=1&query=%7B%27q%27%3A+2%2C+%27g%27%3A+5%7D")
self.assertTrue("Below is a list" in response.get_data(as_text=True))
self.assertTrue("32*x^10" in response.get_data(as_text=True))
data = self.tc.get("Variety/Abelian/Fq/5/2/?Submit=sage&download=1&query=%7B%27q%27%3A+2%2C+%27g%27%3A+5%7D").get_data(as_text=True)
self.assertTrue("Each entry in the following data list" in data)
self.assertTrue("[1, -10, 50, -160, 360, -592, 720, -640, 400, -160, 32]" in data)
response = self.tc.get("Variety/Abelian/Fq/5/2/?Submit=gp&download=1&query=%7B%27q%27%3A+2%2C+%27g%27%3A+5%7D")
self.assertTrue("Below is a list" in response.get_data(as_text=True))
self.assertTrue("32*x^10" in response.get_data(as_text=True))
self.assertTrue("Each entry in the following data list" in response.get_data(as_text=True))
self.assertTrue("[1, -10, 50, -160, 360, -592, 720, -640, 400, -160, 32]" in response.get_data(as_text=True))
response = self.tc.get("Variety/Abelian/Fq/5/2/?Submit=magma&download=1&query=%7B%27q%27%3A+2%2C+%27g%27%3A+5%7D")
self.assertTrue("Below is a list" in response.get_data(as_text=True))
self.assertTrue("32*x^10" in response.get_data(as_text=True))
self.assertTrue("Each entry in the following data list" in response.get_data(as_text=True))
self.assertTrue("[1, -10, 50, -160, 360, -592, 720, -640, 400, -160, 32]" in response.get_data(as_text=True))

def test_download_all(self):
r"""
Expand Down
2 changes: 1 addition & 1 deletion lmfdb/abvar/fq/test_browse_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_count_table(self):
self.check_args("/Variety/Abelian/Fq/?search_type=Counts&q=4..7&g=2..4", "2953")
self.check_args("/Variety/Abelian/Fq/?search_type=Counts&q=2-27&g=1%2C3%2C5", "30543")
# check that the links are functional
self.check_args("/Variety/Abelian/Fq/?search_type=Counts", "/Variety/Abelian/Fq/?search_type=List&amp;g=5&amp;q=3")
self.check_args("/Variety/Abelian/Fq/?search_type=Counts", "/Variety/Abelian/Fq/?g=5&amp;q=3")
# and that it deals with invalid input
self.check_args("/Variety/Abelian/Fq/?search_type=Counts&q=2-27&g=x", "not a valid input")

Expand Down
2 changes: 1 addition & 1 deletion lmfdb/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def quote_string(value):

def pretty_document(rec, sep=", ", id=True):
# sort keys and remove _id for html display
attrs = sorted([(key, quote_string(rec[key])) for key in rec.keys() if (id or key != 'id')])
attrs = sorted([(key, quote_string(rec[key])) for key in rec if (id or key != 'id')])
return "{" + sep.join("'%s': %s" % attr for attr in attrs) + "}"


Expand Down
31 changes: 25 additions & 6 deletions lmfdb/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ def is_running():
# * meta_description, shortthanks, feedbackpage
# * DEBUG and BETA variables storing whether running in each mode

# try:
# # In order to support running under gunicorn with gevent workers,
# # we try to patch psycopg2 to add an appropriate callback function
# from psycogreen.gevent import patch_psycopg
# patch_psycopg()
# except Exception:
# app.logger.info("Exception in psycogreen; not running with gevent support")
# else:
# app.logger.info("Gevent support enabled")

@app.context_processor
def ctx_proc_userdata():
Expand Down Expand Up @@ -141,7 +150,17 @@ def ctx_proc_userdata():
#vars['ALPHA'] = True # hardwired for alpha branch

def modify_url(**replace):
urlparts = urlparse(request.url)
url = request.url
if url.startswith("https, "):
# Cocalc weirdness that lets them serve pages on https from within a project
url = url[7:]
urlparts = urlparse(url)
if "query_add" in replace:
assert "query" not in replace
if urlparts.query:
replace["query"] = replace.pop("query_add") + "&" + urlparts.query
else:
replace["query"] = replace.pop("query_add")
urlparts = urlparts._replace(**replace)
return urlunparse(urlparts)
vars['modify_url'] = modify_url
Expand Down Expand Up @@ -249,10 +268,10 @@ def urlencode(kwargs):
# Redirects and errors #
##############################

@app.after_request
def print_done(T):
app.logger.info(f"done with = {request.url}")
return T
# @app.after_request
# def print_done(T):
# app.logger.info(f"done with = {request.url}")
# return T

@app.before_request
def netloc_redirect():
Expand All @@ -265,7 +284,7 @@ def netloc_redirect():
from urllib.parse import urlparse, urlunparse

urlparts = urlparse(request.url)
app.logger.info(f"Requested url = {request.url}")
# app.logger.info(f"Requested url = {request.url}")

if urlparts.netloc in ["lmfdb.org", "lmfdb.com", "www.lmfdb.com"]:
replaced = urlparts._replace(netloc="www.lmfdb.org", scheme="https")
Expand Down
Loading

0 comments on commit 87ebe9f

Please sign in to comment.