Closed eulerreich closed 4 years ago
Changed keywords from none to Macaulay2, interface
See also:
This happens when the input string sent to eval is longer than 500 characters, as the Macaulay2-Expect interface is configured with the option eval_using_file_cutoff=500
. This option determines whether the input is pasted into the Macaulay2 REPL directly for short input, or whether it is first written to a file and then loaded into Macaulay2. Loading the file is implemented using the load
command, which exectues the code, but does not echo the output values in Macaulay2, so this results in an empty string returned by eval.
I tried to replace the load
command by the input
command which does echo the output values – however, it also echoes the input on additional input lines. This makes it rather difficult to handle using the Expect interface as parsing the output stops once it reaches the first input prompt. I could not figure out how to solve this.
The only way to fix this I can think of would be to add a function to Macaulay2 that just echoes the output of a file.
As a workaround, you can call macaulay2("res111")
or call print at the end of your Macaulay2 code like print res idl111
.
Branch: u/gh-mwageringel/25903
Changed keywords from Macaulay2, interface to Macaulay2, interface, IMA Coding Sprint
Commit: 496ea55
Author: Markus Wageringel
Here is a branch solving this by using the Macaulay2 function input
instead of load
to read in files. With input
, the results are echoed as desired. However, input
also echoes the input lines. These echoed input lines need to be stripped from the output – this is accomplished by setting a custom input prompt while reading from a file. The input lines are then stripped in _post_process_from_file
.
Note that this is only necessary because the Macaulay2 interface in Sage overwrites the prompts, in the first place. In a usual Macaulay2 session, echoed input lines start with ii
rather than a single i
:
i1 : input "testfile.m2"
ii2 : a = 7
oo2 = 7
ii3 :
i4 :
However, in the current interface, the prompt is overwritten to _EGAS_
in either case, so it confuses echoed input lines and actual input lines. With this branch, the echoed input lines start with _EGAS_LOAD_
and get stripped.
New commits:
496ea55 | 25903: make macaulay2 echo output when evaluating using file |
looks good. Sorry for sitting on it for such a long time.
Reviewer: Dima Pasechnik
Description changed:
---
+++
@@ -1,3 +1,9 @@
+This ticket solves the discrepancy between evaluating Macaulay2 input using a file vs directly as follows:
+
+It is solved by using the Macaulay2 function `input` instead of `load` to read in files. With `input`, the results are echoed as desired. However, `input` also echoes the input lines. These echoed input lines need to be stripped from the output – this is accomplished by setting a custom input prompt while reading from a file. The input lines are then stripped in `_post_process_from_file`.
+
+---
+
If I run
```python
No problem. Thank you.
Changed branch from u/gh-mwageringel/25903 to 496ea55
This ticket solves the discrepancy between evaluating Macaulay2 input using a file vs directly as follows:
It is solved by using the Macaulay2 function
input
instead ofload
to read in files. Withinput
, the results are echoed as desired. However,input
also echoes the input lines. These echoed input lines need to be stripped from the output – this is accomplished by setting a custom input prompt while reading from a file. The input lines are then stripped in_post_process_from_file
.If I run
I get back the correct answer in sage.
However if I try a larger ring and ideal,
then I get back an empty string. However, if I rerun
in the second case I'll get back the right answer.
I checked that both commands give the correct answers inside macaulay2, so it must be a bug in the bridge.
CC: @mwageringel @slel @dimpase @saliola @antonleykin
Component: interfaces: optional
Keywords: Macaulay2, interface, IMA Coding Sprint
Author: Markus Wageringel
Branch/Commit:
496ea55
Reviewer: Dima Pasechnik
Issue created by migration from https://trac.sagemath.org/ticket/25903