Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The CremonaDatabase class does not work correctly. #39072

Open
2 tasks done
culler opened this issue Dec 2, 2024 · 4 comments · May be fixed by #39116 or #39179
Open
2 tasks done

The CremonaDatabase class does not work correctly. #39072

culler opened this issue Dec 2, 2024 · 4 comments · May be fixed by #39116 or #39179
Labels

Comments

@culler
Copy link
Contributor

culler commented Dec 2, 2024

Steps To Reproduce

  • build sage without the spkg database_cremona_ellcurve installed
  • start sage
  • Instantiate an object of class CremonaDatabase using the option mini=False

Expected Behavior

Sage should report that the database_cremona_ellcurve spkg is not installed and advise using mini=True.

Sage should not silently replace the large database by the mini database when the large database was specifically requested.

Actual Behavior

% venv/bin/sage
┌────────────────────────────────────────────────────────────────────┐
│ SageMath version 10.5.rc2, Release Date: 2024-11-30                │
│ Using Python 3.12.5. Type "help()" for help.                       │
└────────────────────────────────────────────────────────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Warning: this is a prerelease version, and it may be unstable.     ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
sage: C = CremonaDatabase(mini=False)
sage: isinstance(C, sage.databases.cremona.MiniCremonaDatabase)
True

Additional Information

No response

Environment

  • macOS (and surely all other OS's):
  • 10.5:

Checklist

  • I have searched the existing issues for a bug report that matches the one I want to file, without success.
  • I have read the documentation and troubleshoot guide
@culler culler added the t: bug label Dec 2, 2024
@culler
Copy link
Contributor Author

culler commented Dec 2, 2024

Since LargeCremonaDatabase is a subclass of MiniCremonaDatabase, I should have added one more test:

sage: C = CremonaDatabase(mini=False)
sage: isinstance(C, sage.databases.cremona.MiniCremonaDatabase)
True
sage: isinstance(C, sage.databases.cremona.LargeCremonaDatabase)
False

@user202729
Copy link
Contributor

user202729 commented Dec 3, 2024

The fix is pretty simple…

     if set_global is not None:
         from sage.misc.superseded import deprecation
         deprecation(25825, "the set_global argument for CremonaDatabase is deprecated and ignored")
+    input_mini = mini
     if name is None:
         if DatabaseCremona().is_present():
             name = 'cremona'
@@ -1697,6 +1731,8 @@ def CremonaDatabase(name=None, mini=None, set_global=None):
         mini = True
     if mini is None:
         raise ValueError('mini must be set as either True or False')
+    if (name == 'cremona' and input_mini is True) or (name == 'cremona mini' and input_mini is False):
+        raise ValueError(f'wrong value of mini, database {name!r} must have mini={mini}')
 
     if mini:
         return MiniCremonaDatabase(name)

but the doctest is difficult to implement.

+
+    Verify that :issue:`39072` has been resolved::
+
+        sage: # optional - NOT database_cremona_ellcurve
+        sage: c = CremonaDatabase(mini=True)  # without database_cremona_ellcurve, this will select name = 'cremona mini'
+        sage: isinstance(c, sage.databases.cremona.MiniCremonaDatabase)
+        True
+        sage: c = CremonaDatabase(mini=False)  # same as above but invalid value of ``mini`` raises error
+        Traceback (most recent call last):
+        ...
+        ValueError: wrong value of mini, database 'cremona mini' must have mini=True
+        sage: c = CremonaDatabase(name='cremona mini', mini=False)
+        Traceback (most recent call last):
+        ...
+        ValueError: wrong value of mini, database 'cremona mini' must have mini=True
+
+    ::
+
+        sage: # optional - database_cremona_ellcurve
+        sage: c = CremonaDatabase(mini=False)
+        sage: isinstance(c, sage.databases.cremona.LargeCremonaDatabase)
+        True
+        sage: c = CremonaDatabase(mini=True)  # with database_cremona_ellcurve, this will select name = 'cremona'
+        Traceback (most recent call last):
+        ...
+        ValueError: wrong value of mini, database 'cremona' must have mini=False
+        sage: c = CremonaDatabase(name='cremona', mini=True)
+        Traceback (most recent call last):
+        ...
+        ValueError: wrong value of mini, database 'cremona' must have mini=False
+        sage: c = CremonaDatabase(name='cremona', mini=False)
+        sage: isinstance(c, sage.databases.cremona.LargeCremonaDatabase)
+        True

the current doctest framework does not support # optional - NOT database_cremona_ellcurve yet (read: this test is only expected to pass if optional feature database_cremona_ellcurve is not available)

Opinion: what should the doctest format be? Is # needs database_cremona_ellcurve uninstalled good? Problem is # needs takes multiple space-separated arguments, so we may get confusing situation like #needs a b uninstalled (read: a must be installed, b must be uninstalled) etc.?

@culler
Copy link
Contributor Author

culler commented Dec 3, 2024

That's great that there is a simple fix.

I do wonder, however, why it is considered a good idea to make the user jump through these hoops, i.e. to be forced to provide redundant information and to be punished for doing so in an inconsistent way.

A more straightforward design would drop the name and mini arguments altogether and have one keyword option "size" which defaults to "auto" but can also be "large" or "mini". Then the CremonaDatabase function would return an instance of MiniCremonaDatabase if the "size" option is "mini", and either return an instance of LargeCremonaDatabase or raise a FeatureNotPresentError if the option is "large" . The default would be to provide the best available. A doctest should be able to test if the feature exists in order to know which result is expected.

This would differ from the current implementation and would therefore create a backwards incompatibility. But the current implementation is broken. A partial remedy would be to generate a deprecation warning if the keywords "name", "mini" or "setglobal" are used and to return a MiniCremonaDatabase in those cases unless mini is False and the large database is installed.

@user202729 user202729 linked a pull request Dec 10, 2024 that will close this issue
5 tasks
@kwankyu kwankyu linked a pull request Dec 21, 2024 that will close this issue
5 tasks
@kwankyu
Copy link
Collaborator

kwankyu commented Dec 21, 2024

#39179 fixes the issue as expected, keeping the original semantics of arguments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants