Skip to content

Handle $mod operator in completeness checks#6853

Closed
Copilot wants to merge 5 commits intomainfrom
copilot/fix-ecq-conductor-search-error
Closed

Handle $mod operator in completeness checks#6853
Copilot wants to merge 5 commits intomainfrom
copilot/fix-ecq-conductor-search-error

Conversation

Copy link
Contributor

Copilot AI commented Feb 2, 2026

Searches for "multiple of" conductor/level crash with ValueError: Unsupported key $mod in completeness checking. The to_rset() function converts query operators to RealSets but lacks support for psycodict's $mod operator.

Changes

  • lmfdb/utils/completeness.py: Added $mod operator handling in to_rset(). Since $mod represents unbounded arithmetic progressions, treat as full real line, causing completeness checks to correctly return False.

  • lmfdb/tests/test_utils.py: Added unit tests for $mod operator and integration tests with elliptic curve/modular form queries.

Technical Notes

psycodict uses {'$mod': [remainder, divisor]} format (opposite of MongoDB). Example: {'$mod': [0, 7]} matches multiples of 7 (where value % 7 == 0).

# Before: ValueError when processing this query
query = {'conductor': {'$mod': [0, 7]}}

# After: Returns unbounded RealSet → completeness check returns False
rset = to_rset(query)  # Returns (-∞, +∞)

Affected searches:

  • /EllipticCurve/Q/?conductor_type=multiple&conductor=7
  • /ModularForm/GL2/Q/holomorphic/?level_type=multiple&level=23
Original prompt

This section details on the original issue you should resolve

<issue_title>Error searching for ECQ multiple of conductor</issue_title>
<issue_description>Searching for "multiple of" in the conductor field (e.g. take 7) in
https://www.lmfdb.org/EllipticCurve/Q/?search_type=
gives an error:
https://www.lmfdb.org/EllipticCurve/Q/?conductor_type=multiple&conductor=7

Image</issue_description>

Comments on the Issue (you are @copilot in this section)

@jenpaulhus This issue comes during the check for completeness of the particular search.

The feature on the ECQ pages requires $mod and that's where the error is coming from in utils/completeness.py

Traceback (most recent call last):
  File "/scratch/sage/sage-10.3/local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/flask/app.py", line 2091, in __call__
    return self.wsgi_app(environ, start_response)
  File "/scratch/home/jenpaulhus/lmfdb/lmfdb/app.py", line 42, in __call__
    return self.app(environ, start_response)
  File "/scratch/sage/sage-10.3/local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/flask/app.py", line 2076, in wsgi_app
    response = self.handle_exception(e)
  File "/scratch/sage/sage-10.3/local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/flask/app.py", line 2073, in wsgi_app
    response = self.full_dispatch_request()
  File "/scratch/sage/sage-10.3/local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/flask/app.py", line 1519, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/scratch/sage/sage-10.3/local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/flask/app.py", line 1517, in full_dispatch_request
    rv = self.dispatch_request()
  File "/scratch/sage/sage-10.3/local/var/lib/sage/venv-python3.10/lib/python3.10/site-packages/flask/app.py", line 1503, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/scratch/home/jenpaulhus/lmfdb/lmfdb/elliptic_curves/elliptic_curve.py", line 93, in rational_elliptic_curves
    return elliptic_curve_search(info)
  File "/scratch/home/jenpaulhus/lmfdb/lmfdb/utils/search_wrapper.py", line 274, in __call__
    complete, msg, caveat = results_complete(table.search_table, query, table._db, info.get("search_array"))
  File "/scratch/home/jenpaulhus/lmfdb/lmfdb/utils/completeness.py", line 49, in results_complete
    return lookup[table].check(query, db, search_array)
  File "/scratch/home/jenpaulhus/lmfdb/lmfdb/utils/completeness.py", line 678, in check
    if test(db, [query[col] for col in cols]):
  File "/scratch/home/jenpaulhus/lmfdb/lmfdb/utils/completeness.py", line 703, in __call__
    return all(self.cls(D).is_subset(B) for D, B in zip(Ds, self.bounds))
  File "/scratch/home/jenpaulhus/lmfdb/lmfdb/utils/completeness.py", line 703, in <genexpr>
    return all(self.cls(D).is_subset(B) for D, B in zip(Ds, self.bounds))
  File "/scratch/home/jenpaulhus/lmfdb/lmfdb/utils/completeness.py", line 438, in __init__
    self.rset = integer_normalize(to_rset(x))
  File "/scratch/home/jenpaulhus/lmfdb/lmfdb/utils/completeness.py", line 159, in to_rset
    raise ValueError(f"Unsupported key {k}")
ValueError: Unsupported key $mod
```</body></comment_new>
<comment_new><author>@jenpaulhus</author><body>
Someone also just reported this on the bugreport so I'm adding the production issue label.</body></comment_new>
<comment_new><author>@edgarcosta</author><body>
Another one:

Exception on /ModularForm/GL2/Q/holomorphic/ [GET]
Traceback (most recent call last):
File "/home/sage/sage-10.5/local/var/lib/sage/venv-python3.12/lib/python3.12/site-packages/flask/app.py", line 1511, in wsgi_app
response = self.full_dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/sage/sage-10.5/local/var/lib/sage/venv-python3.12/lib/python3.12/site-packages/flask/app.py", line 919, in full_dispatch_request
rv = self.handle_user_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/sage/sage-10.5/local/var/lib/sage/venv-python3.12/lib/python3.12/site-packages/flask/app.py", line 917, in full_dispatch_request
rv = self.dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^
File "/home/sage/sage-10.5/local/var/lib/sage/venv-python3.12/lib/python3.12/site-packages/flask/app.py", line 902, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/lmfdb/lmfdb-git-web/lmfdb/classical_modular_forms/main.py", line 172, in index
return newform_search(info)
^^^^^^^^^^^^^^^^^^^^
File "/home/lmfdb/lmfdb-git-web/lmfdb/utils/search_wrapper.py", line 274, in call
complete, msg, caveat = result...


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 4 commits February 2, 2026 00:35
Co-authored-by: edgarcosta <322822+edgarcosta@users.noreply.github.com>
Co-authored-by: edgarcosta <322822+edgarcosta@users.noreply.github.com>
Co-authored-by: edgarcosta <322822+edgarcosta@users.noreply.github.com>
Co-authored-by: edgarcosta <322822+edgarcosta@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix error searching for ECQ multiple of conductor Handle $mod operator in completeness checks Feb 2, 2026
Copilot AI requested a review from edgarcosta February 2, 2026 00:45
@edgarcosta edgarcosta requested a review from roed314 February 2, 2026 12:29
@edgarcosta edgarcosta marked this pull request as ready for review February 2, 2026 12:29
@jenpaulhus
Copy link
Contributor

What's the status of this PR? There's now yet another bugreport about someone trying to search with $mod and an error coming up.

@roed314
Copy link
Member

roed314 commented Feb 14, 2026

I'm not thrilled with this solution, which is why I didn't initially approve it. Then I got distracted. Here's an example of the kind of output that I think may end up biting us in the future:

mod_query = {'$mod': [0, 7]}
rset = to_rset(mod_query)
self.assertEqual(str(rset), "(-oo, +oo)")
        
# Test that IntegerSet can be created from $mod query without error
iset = IntegerSet(mod_query)
self.assertEqual(str(iset.rset), "(-oo, +oo)")
        
bounded = IntegerSet([1, 500000])
self.assertEqual(bounded.is_subset(iset), True)

I'll try to think of a different way to solve this issue.

@roed314
Copy link
Member

roed314 commented Feb 14, 2026

I'm closing this in favor of #6879, with more discussion on #6822 for solving the underlying problem.

@roed314 roed314 closed this Feb 14, 2026
@edgarcosta edgarcosta deleted the copilot/fix-ecq-conductor-search-error branch February 16, 2026 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error searching for ECQ multiple of conductor

4 participants