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

Save and load a finitely presented group #37061

Closed
2 tasks done
enriqueartal opened this issue Jan 14, 2024 · 1 comment · Fixed by #37128
Closed
2 tasks done

Save and load a finitely presented group #37061

enriqueartal opened this issue Jan 14, 2024 · 1 comment · Fixed by #37128

Comments

@enriqueartal
Copy link
Contributor

Steps To Reproduce

Run the following code:

sage: save(FreeGroup(1)/[], 'ab')
sage: load('ab.sobj')
Finitely presented group < x |  >
sage: from sage.groups.finitely_presented import wrap_FpGroup
sage: save(wrap_FpGroup(libgap(FreeGroup(1)/[])), 'ab')
sage: load('ab.sobj')
---------------------------------------------------------------------------
GAPError                                  Traceback (most recent call last)
Cell In[20], line 1
----> 1 load('ab.sobj')

File /usr/local/sage-310/src/sage/misc/persist.pyx:189, in sage.misc.persist.load()
    187 
    188     ## Load file by absolute filename
--> 189     with open(filename, 'rb') as fobj:
    190         X = loads(fobj.read(), compress=compress, **kwargs)
    191     try:

File /usr/local/sage-310/src/sage/misc/persist.pyx:190, in sage.misc.persist.load()
    188 ## Load file by absolute filename
    189 with open(filename, 'rb') as fobj:
--> 190     X = loads(fobj.read(), compress=compress, **kwargs)
    191 try:
    192     X._default_filename = os.path.abspath(filename)

File /usr/local/sage-310/src/sage/misc/persist.pyx:995, in sage.misc.persist.loads()
    993 unpickler = SageUnpickler(io.BytesIO(s), **kwargs)
    994 global already_unpickled
--> 995 ans = unpickler.load()
    996 already_unpickled = { }
    997 return ans

File /usr/local/sage-310/src/sage/libs/gap/element.pyx:390, in sage.libs.gap.element._from_sage()
    388 
    389 
--> 390 cpdef _from_sage(elem) noexcept:
    391     """
    392     Currently just used for unpickling; equivalent to calling ``libgap(elem)``

File /usr/local/sage-310/src/sage/libs/gap/element.pyx:396, in sage.libs.gap.element._from_sage()
    394 """
    395 if isinstance(elem, str):
--> 396     return libgap.eval(elem)
    397 
    398 return libgap(elem)

File /usr/local/sage-310/src/sage/libs/gap/libgap.pyx:406, in sage.libs.gap.libgap.Gap.eval()
    404 
    405         initialize()
--> 406         elem = make_any_gap_element(self, gap_eval(gap_command))
    407 
    408         # If the element is NULL just return None instead

File /usr/local/sage-310/src/sage/libs/gap/util.pyx:364, in sage.libs.gap.util.gap_eval()
    362 try:
    363     GAP_Enter()
--> 364     result = GAP_EvalString(cmd)
    365     # We can assume that the result object is a GAP PList (plain list)
    366     # and we should use functions for PLists directly for now; see

GAPError: Error, Variable: 'x' must have a value

Expected Behavior

It should be possible to save and load any finitely presented group. It is possible if it is created directly.

Actual Behavior

If the group comes from wrap_FpGroup a libgap group, the above error happens.

Additional Information

No response

Environment

- **Fedora 39**:
- **Sage Version*: 10.2*:

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
@enriqueartal enriqueartal changed the title Save and load a finitely presented grup<title> Save and load a finitely presented grup Jan 14, 2024
@enriqueartal enriqueartal changed the title Save and load a finitely presented grup Save and load a finitely presented group Jan 15, 2024
@enriqueartal
Copy link
Contributor Author

I got a way for the following feature: if G is a libgap group and G1 = G.sage(), then G and G1.gap() coincide. Likely it is not optimal and instead of changing this branch I created a fake PR enriqueartal#8 to track the changed files.
I created reduce methods for several classes.

vbraun pushed a commit to vbraun/sage that referenced this issue Sep 27, 2024
… libgap groups

    
<!-- Describe your changes here in detail -->
At this point it is not possible to load a saved finitely presented
group that comes from a libgap group, see an example in
sagemath#37061

One possible cause is the use of a general `__reduce__` method for free
groups. At least, adding such a method allows to load free groups or
finitely presented groups obtained from a libgap group using
`wrapFreeGroup` or `wrapFpGroup`. It fixes sagemath#37061 and it would simplify
some code in sagemath#36768

With these changes, free and finitely presented groups, included libgap
groups, can be pickled.

### 📝 Checklist



- [X] The title is concise, informative, and self-explanatory.
- [X] The description explains in detail what this PR is about.
- [X] I have linked a relevant issue or discussion.
- [X] I have created tests covering the changes.
- [X] I have updated the documentation accordingly.
    
URL: sagemath#37128
Reported by: Enrique Manuel Artal Bartolo
Reviewer(s): Enrique Manuel Artal Bartolo, Travis Scrimshaw
@vbraun vbraun closed this as completed in d593324 Sep 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants