Issue with GAP in SageMath 10.3 when using PyCharm, but no issue in JupyterLab

asked 2024-04-08 14:54:53 +0200

updated 2024-04-09 02:08:31 +0200

Max Alekseyev gravatar image

Hi, I've been struggling for the past few days to figure out why my code is unable to run in PyCharm. I would really appreciate any guidance to resolve this.

I've changed my System Interpreter in PyCharm to SageMath's, defining the path

/private/var/tmp/sage-10.3-current/local/var/lib/sage/venv-python3.11.1/bin/python3

Below is a sample test code I use:

from sage.all import *
B = matrix(GF(3), [
    [2, 2, 1, 2, 1, 1, 0, 1, 0, 1],
    [2, 0, 1, 1, 2, 1, 2, 2, 0, 0],
    [0, 0, 1, 1, 0, 1, 0, 2, 2, 1],
    [2, 2, 0, 2, 0, 2, 1, 0, 1, 1],
    [1, 0, 2, 2, 2, 1, 1, 2, 1, 2],
    [2, 2, 2, 0, 2, 0, 2, 1, 1, 2],
    [0, 2, 1, 0, 1, 2, 2, 2, 2, 0],
    [0, 0, 1, 2, 2, 1, 0, 0, 0, 1],
    [2, 2, 1, 0, 0, 1, 0, 2, 0, 0],
    [0, 2, 1, 0, 1, 1, 2, 2, 0, 0]
])
print('Rank')
print(B.rank())

C = codes.LinearCode(B)
#below is problematic
C.minimum_distance()

In PyCharm, I am able to find the rank, and also construct the LinearCode object. But I can't seem to use the minimum_distance function.

I run into an error suggesting I can't access the GAP functionalities

TypeError: unable to start gap because the command 'gap -A -l "/private/var/tmp/sage-10.3-current/local/lib/gap;/private/var/tmp/sage-10.3-current/local/share/gap" -b -p -T -E -m 64m  /private/var/tmp/sage-10.3-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/sage/ext_data/gap/sage.g' failed: The command was not found or was not executable: gap.

For completeness, the full error message is below:

Traceback (most recent call last):
  File "/Users/jianxiansim/PycharmProjects/qLDPC Codes/TEST.py", line 20, in <module>
    C.minimum_distance()
  File "sage/misc/cachefunc.pyx", line 1967, in sage.misc.cachefunc.CachedMethodCaller.__call__ (build/cythonized/sage/misc/cachefunc.c:13535)
  File "sage/misc/cachefunc.pyx", line 1842, in sage.misc.cachefunc.CachedMethodCaller._instance_call (build/cythonized/sage/misc/cachefunc.c:12984)
  File "/private/var/tmp/sage-10.3-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/sage/coding/linear_code.py", line 1420, in minimum_distance
    return self._minimum_weight_codeword(algorithm).hamming_weight()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/private/var/tmp/sage-10.3-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/sage/coding/linear_code.py", line 1465, in _minimum_weight_codeword
    current_randstate().set_seed_gap()
  File "sage/misc/randstate.pyx", line 721, in sage.misc.randstate.randstate.set_seed_gap (build/cythonized/sage/misc/randstate.c:5339)
  File "/private/var/tmp/sage-10.3-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/sage/interfaces/interface.py", line 671, in __call__
    return self._parent.function_call(self._name, list(args), kwds)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/private/var/tmp/sage-10.3-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/sage/interfaces/gap.py", line 867, in function_call
    args, kwds = self._convert_args_kwds(args, kwds)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/private/var/tmp/sage-10.3-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/sage/interfaces/interface.py", line 573, in _convert_args_kwds
    args[i] = self(arg)
              ^^^^^^^^^
  File "/private/var/tmp/sage-10.3-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/sage/interfaces/interface.py", line 306, in __call__
    result = self._coerce_from_special_method(x)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/private/var/tmp/sage-10.3-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/sage/interfaces/interface.py", line 334, in _coerce_from_special_method
    return (x.__getattribute__(s))(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "sage/structure/sage_object.pyx", line 749, in sage.structure.sage_object.SageObject._gap_ (build/cythonized/sage/structure/sage_object.c:8741)
  File "sage/structure/sage_object.pyx", line 725, in sage.structure.sage_object.SageObject._interface_ (build/cythonized/sage/structure/sage_object.c:8164)
  File "/private/var/tmp/sage-10.3-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/sage/interfaces/interface.py", line 299, in __call__
    return cls(self, x, name=name)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/private/var/tmp/sage-10.3-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/sage/interfaces/expect.py", line 1525, in __init__
    raise TypeError(*x.args)
TypeError: unable to start gap because the command 'gap -A -l "/private/var/tmp/sage-10.3-current/local/lib/gap;/private/var/tmp/sage-10.3-current/local/share/gap" -b -p -T -E -m 64m  /private/var/tmp/sage-10.3-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/sage/ext_data/gap/sage.g' failed: The command was not found or was not executable: gap.

I encounter no such issue in JupyterLab when I open it directly from the SageMath Launcher, and run the same code. How should I configure my PyCharm for this? Thank you!

edit retag flag offensive close merge delete

Comments

Perhaps you need to set up SAGE_GAP_COMMAND environment variable as described at https://www.jetbrains.com/help/pychar...

Max Alekseyev gravatar imageMax Alekseyev ( 2024-04-09 06:26:27 +0200 )edit

Hey Max, thanks for the advice, but I'm still encountering the same issue.

I added a path variable with

Name: SAGE_GAP_COMMAND

Value: /Volumes/SageMath-10.3/SageMath-10-3.app/Contents/Frameworks/Sage.framework/Versions/10.3/local/bin/gap

I believe the above Value provides the file path to the gap executable.

However, it gives the exact same error message as above, but now additionally has this at the end:

* Gap crashed or quit executing 'SaveWorkspace("/Users/jianxiansim/.sage/gap/tmpopr4mbin");' * Restarting Gap and trying again * Gap crashed or quit executing '\$sage1:=GlobalMersenneTwister;;' * Restarting Gap and trying again

simjianxian gravatar imagesimjianxian ( 2024-04-09 10:57:15 +0200 )edit

You may like to check out this Q&A: https://ask.sagemath.org/question/38750

Max Alekseyev gravatar imageMax Alekseyev ( 2024-04-09 22:36:52 +0200 )edit