sagemath / sagecell

The Sage Cell Server---providing a way to embed Sage computations into any web page.
Other
203 stars 68 forks source link

Error in the sage online cell related to GAP #560

Closed Nakayamaalgebra closed 2 years ago

Nakayamaalgebra commented 2 years ago

Typing this into the online sage cell (https://sagecell.sagemath.org/) gives an error (using the GAP language):

LoadPackage("qpa"); Q:=Quiver(3,[[1,2,"a"],[2,3,"b"]]);KQ:=PathAlgebra(GF(3),Q);AssignGeneratorVariables(KQ);rel:=[a*b];A:=KQ/rel;

But this error doesnt occur when opening GAP in a terminal and entering the code. So my question is whether there is a problem in the sage online cell related to GAP or how I can fix this.

(Is there by the way another site offering to use GAP online?)

novoselt commented 2 years ago

GAP code in SageMathCell is evaluated by feeding it into gap.eval(...) in Sage. When I do it in a terminal session of Sage, I get exactly the same error. I have no idea what is happening and how to fix it, but it has nothing to do with SageMathCell processing.

Nakayamaalgebra commented 2 years ago

Thank you for your reply. I also asked this here: https://ask.sagemath.org/question/62033/error-in-the-sage-online-cell-related-to-gap/ . A user said he doesnt get this error using Sage in a terminal and I also dont.

novoselt commented 2 years ago

To be clear who is trying what, this is from a terminal Sage session in CoCalc:

sage: gap.eval("""
....: LoadPackage("qpa");
....: Q:=Quiver(3,[[1,2,"a"],[2,3,"b"]]);KQ:=PathAlgebra(GF(3),Q);AssignGeneratorVariables(KQ);rel:=[a*b];A:=KQ/rel;
....: """)
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
/ext/sage/9.5/local/var/lib/sage/venv-python3.9.9/lib/python3.9/site-packages/sage/interfaces/gap.py in _eval_line(self, line, allow_use_file, wait_for_prompt, restart_if_needed)
    672                 error = error.replace('\r','')
--> 673                 raise RuntimeError("%s produced error output\n%s\n   executing %s"%(self, error,line))
    674             if not len(normal):

RuntimeError: Gap produced error output
Syntax error: ) expected in /home/user/.sage/temp/project-228cc874-e816-4800-9\
bab-ca59ace3c060/925/interface/tmp1059:1
Print( LoadPackage("qpa"); Q:=Quiver(3,[[1,2,"a"],[2,3,"b"]]);KQ:=PathAlgebra(\
GF(3),Q);AssignGeneratorVariables(KQ);rel:=[a*b];A:=KQ/rel );
                         ^

   executing Read("/home/user/.sage/temp/project-228cc874-e816-4800-9bab-ca59ace3c060/925/interface/tmp1059");

During handling of the above exception, another exception occurred:

RuntimeError                              Traceback (most recent call last)
/ext/sage/9.5/local/var/lib/sage/venv-python3.9.9/lib/python3.9/site-packages/sage/interfaces/expect.py in _eval_line_using_file(self, line, restart_if_needed)
    820         try:
--> 821             s = self._eval_line(self._read_in_file_command(tmp_to_use), allow_use_file=False, restart_if_needed=False)
    822         except pexpect.EOF:

/ext/sage/9.5/local/var/lib/sage/venv-python3.9.9/lib/python3.9/site-packages/sage/interfaces/gap.py in _eval_line(self, line, allow_use_file, wait_for_prompt, restart_if_needed)
    706             else:
--> 707                 raise RuntimeError(exc)
    708 

RuntimeError: Gap produced error output
Syntax error: ) expected in /home/user/.sage/temp/project-228cc874-e816-4800-9\
bab-ca59ace3c060/925/interface/tmp1059:1
Print( LoadPackage("qpa"); Q:=Quiver(3,[[1,2,"a"],[2,3,"b"]]);KQ:=PathAlgebra(\
GF(3),Q);AssignGeneratorVariables(KQ);rel:=[a*b];A:=KQ/rel );
                         ^

   executing Read("/home/user/.sage/temp/project-228cc874-e816-4800-9bab-ca59ace3c060/925/interface/tmp1059");

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
/ext/sage/9.5/local/var/lib/sage/venv-python3.9.9/lib/python3.9/site-packages/sage/interfaces/expect.py in eval(self, code, strip, synchronize, locals, allow_use_file, split_lines, **kwds)
   1379                         self._eval_using_file_cutoff and len(code) > self._eval_using_file_cutoff):
-> 1380                     return self._eval_line_using_file(code)
   1381                 elif split_lines:

/ext/sage/9.5/local/var/lib/sage/venv-python3.9.9/lib/python3.9/site-packages/sage/interfaces/gap.py in _eval_line_using_file(self, line)
   1379             try:  # this is necessary, since Print requires something as input, and some functions (e.g., Read) return nothing.
-> 1380                 return Expect._eval_line_using_file(self, line0)
   1381             except RuntimeError:

/ext/sage/9.5/local/var/lib/sage/venv-python3.9.9/lib/python3.9/site-packages/sage/interfaces/expect.py in _eval_line_using_file(self, line, restart_if_needed)
    847                     raise RuntimeError('%s terminated unexpectedly while reading in a large line' % self)
--> 848             if "Input/output error" in msg.args[0]:
    849                 # This occurs on non-linux machines

TypeError: argument of type 'RuntimeError' is not iterable

During handling of the above exception, another exception occurred:

TypeError                                 Traceback (most recent call last)
<ipython-input-7-53ef1a464ffa> in <module>
----> 1 gap.eval("""
      2 LoadPackage("qpa");
      3 Q:=Quiver(3,[[1,2,"a"],[2,3,"b"]]);KQ:=PathAlgebra(GF(3),Q);AssignGeneratorVariables(KQ);rel:=[a*b];A:=KQ/rel;
      4 """)

/ext/sage/9.5/local/var/lib/sage/venv-python3.9.9/lib/python3.9/site-packages/sage/interfaces/gap.py in eval(self, x, newlines, strip, split_lines, **kwds)
    496             if not input_line.endswith(';'):
    497                 input_line += ';'
--> 498         result = Expect.eval(self, input_line, **kwds)
    499         if not newlines:
    500             result = result.replace("\\\n","")

/ext/sage/9.5/local/var/lib/sage/venv-python3.9.9/lib/python3.9/site-packages/sage/interfaces/expect.py in eval(self, code, strip, synchronize, locals, allow_use_file, split_lines, **kwds)
   1388         # In particular, do NOT call self._keyboard_interrupt()
   1389         except TypeError as s:
-> 1390             raise TypeError('error evaluating "%s":\n%s'%(code,s))
   1391 
   1392     ############################################################

TypeError: error evaluating "LoadPackage("qpa"); Q:=Quiver(3,[[1,2,"a"],[2,3,"b"]]);KQ:=PathAlgebra(GF(3),Q);AssignGeneratorVariables(KQ);rel:=[a*b];A:=KQ/rel;":
argument of type 'RuntimeError' is not iterable
dimpase commented 2 years ago

In case, one can in fact do this computation in Sage, without swithing to GAP interface, as follows:

libgap.LoadPackage("qpa")
Q=libgap.Quiver(3,[[1,2,"a"],[2,3,"b"]])
KQ=libgap.PathAlgebra(libgap.GF(3),Q)
KQ.AssignGeneratorVariables()
a=libgap.eval('a')
b=libgap.eval('b')
rel=[a*b]
A=KQ/rel
dimpase commented 2 years ago

sagecell could do sage: gap._eval_using_file_cutoff=2000 (or more?) before calling gap.eval().

(see more details in my answer to https://ask.sagemath.org/question/62033/error-in-the-sage-online-cell-related-to-gap/ )

novoselt commented 2 years ago

That would be language specific so not quite desirable. But if this is a better approach for GAP, shouldn't gap.eval() itself call that better command internally?

dimpase commented 2 years ago

all that dance around pexpect using files to communicate in case of "too much" to communicate is platform-specific; on some Linuxes pipes are very slow. As an experiment you can increase gap._eval_using_file_cutoff either by patching sagecell, or by

--- a/src/sage/interfaces/gap.py
+++ b/src/sage/interfaces/gap.py
@@ -1069,7 +1069,7 @@ class Gap(Gap_generic):
                         restart_on_ctrlc=True,
                         verbose_start=False,
                         logfile=logfile,
-                        eval_using_file_cutoff=100,
+                        eval_using_file_cutoff=2000,
                         env=env)
         self.__seq = 0
         self._seed = seed

or even a bigger than 2000 value, and see if users start complaining.