sagemath / sage

Main repository of SageMath
https://www.sagemath.org
Other
1.38k stars 470 forks source link

py3: errors with optional package CSDP #28371

Closed dcoudert closed 5 years ago

dcoudert commented 5 years ago
Using --optional=benzene,bliss,build,csdp,dochtml,dot2tex,gfortran,igraph,mpir,plantri,python2,python_igraph,sage,tdlib
Doctesting 1 file.
sage -t --long src/sage/graphs/lovasz_theta.py
**********************************************************************
File "src/sage/graphs/lovasz_theta.py", line 50, in sage.graphs.lovasz_theta.lovasz_theta
Failed example:
    C.lovasz_theta()                             # optional csdp
Exception raised:
    Traceback (most recent call last):
      File "/Users/dcoudert/sage3/sage/local/lib/python3.7/site-packages/sage/doctest/forker.py", line 681, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/Users/dcoudert/sage3/sage/local/lib/python3.7/site-packages/sage/doctest/forker.py", line 1105, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.graphs.lovasz_theta.lovasz_theta[1]>", line 1, in <module>
        C.lovasz_theta()                             # optional csdp
      File "/Users/dcoudert/sage3/sage/local/lib/python3.7/site-packages/sage/graphs/lovasz_theta.py", line 70, in lovasz_theta
        CSDP().require()
      File "/Users/dcoudert/sage3/sage/local/lib/python3.7/site-packages/sage/features/__init__.py", line 156, in require
        presence = self.is_present()
      File "sage/misc/cachefunc.pyx", line 2311, in sage.misc.cachefunc.CachedMethodCallerNoArgs.__call__ (build/cythonized/sage/misc/cachefunc.c:12712)
        self.cache = f(self._instance)
      File "/Users/dcoudert/sage3/sage/local/lib/python3.7/site-packages/sage/features/__init__.py", line 129, in is_present
        res = self._is_present()
      File "/Users/dcoudert/sage3/sage/local/lib/python3.7/site-packages/sage/features/__init__.py", line 353, in _is_present
        return self.is_functional()
      File "/Users/dcoudert/sage3/sage/local/lib/python3.7/site-packages/sage/features/csdp.py", line 47, in is_functional
        tf.write("2\n1\n1 1")
    TypeError: a bytes-like object is required, not 'str'
**********************************************************************
File "src/sage/graphs/lovasz_theta.py", line 52, in sage.graphs.lovasz_theta.lovasz_theta
Failed example:
    graphs.CycleGraph(5).lovasz_theta()          # optional csdp
Exception raised:
    Traceback (most recent call last):
      File "/Users/dcoudert/sage3/sage/local/lib/python3.7/site-packages/sage/doctest/forker.py", line 681, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/Users/dcoudert/sage3/sage/local/lib/python3.7/site-packages/sage/doctest/forker.py", line 1105, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.graphs.lovasz_theta.lovasz_theta[2]>", line 1, in <module>
        graphs.CycleGraph(Integer(5)).lovasz_theta()          # optional csdp
      File "/Users/dcoudert/sage3/sage/local/lib/python3.7/site-packages/sage/graphs/lovasz_theta.py", line 70, in lovasz_theta
        CSDP().require()
      File "/Users/dcoudert/sage3/sage/local/lib/python3.7/site-packages/sage/features/__init__.py", line 156, in require
        presence = self.is_present()
      File "sage/misc/cachefunc.pyx", line 2311, in sage.misc.cachefunc.CachedMethodCallerNoArgs.__call__ (build/cythonized/sage/misc/cachefunc.c:12712)
        self.cache = f(self._instance)
      File "/Users/dcoudert/sage3/sage/local/lib/python3.7/site-packages/sage/features/__init__.py", line 129, in is_present
        res = self._is_present()
      File "/Users/dcoudert/sage3/sage/local/lib/python3.7/site-packages/sage/features/__init__.py", line 353, in _is_present
        return self.is_functional()
      File "/Users/dcoudert/sage3/sage/local/lib/python3.7/site-packages/sage/features/csdp.py", line 47, in is_functional
        tf.write("2\n1\n1 1")
    TypeError: a bytes-like object is required, not 'str'
**********************************************************************
1 item had failures:
   2 of   6 in sage.graphs.lovasz_theta.lovasz_theta
    [5 tests, 2 failures, 0.49 s]
----------------------------------------------------------------------
sage -t --long src/sage/graphs/lovasz_theta.py  # 2 doctests failed
----------------------------------------------------------------------
sage -t --long src/sage/features/csdp.py
**********************************************************************
File "src/sage/features/csdp.py", line 21, in sage.features.csdp.CSDP
Failed example:
    CSDP().is_present()  # optional: csdp
Exception raised:
    Traceback (most recent call last):
      File "/Users/dcoudert/sage3/sage/local/lib/python3.7/site-packages/sage/doctest/forker.py", line 681, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/Users/dcoudert/sage3/sage/local/lib/python3.7/site-packages/sage/doctest/forker.py", line 1105, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.features.csdp.CSDP[1]>", line 1, in <module>
        CSDP().is_present()  # optional: csdp
      File "sage/misc/cachefunc.pyx", line 2311, in sage.misc.cachefunc.CachedMethodCallerNoArgs.__call__ (build/cythonized/sage/misc/cachefunc.c:12712)
        self.cache = f(self._instance)
      File "/Users/dcoudert/sage3/sage/local/lib/python3.7/site-packages/sage/features/__init__.py", line 129, in is_present
        res = self._is_present()
      File "/Users/dcoudert/sage3/sage/local/lib/python3.7/site-packages/sage/features/__init__.py", line 353, in _is_present
        return self.is_functional()
      File "/Users/dcoudert/sage3/sage/local/lib/python3.7/site-packages/sage/features/csdp.py", line 47, in is_functional
        tf.write("2\n1\n1 1")
    TypeError: a bytes-like object is required, not 'str'
**********************************************************************
File "src/sage/features/csdp.py", line 41, in sage.features.csdp.CSDP.is_functional
Failed example:
    CSDP().is_functional()  # optional: csdp
Exception raised:
    Traceback (most recent call last):
      File "/Users/dcoudert/sage3/sage/local/lib/python3.7/site-packages/sage/doctest/forker.py", line 681, in _run
        self.compile_and_execute(example, compiler, test.globs)
      File "/Users/dcoudert/sage3/sage/local/lib/python3.7/site-packages/sage/doctest/forker.py", line 1105, in compile_and_execute
        exec(compiled, globs)
      File "<doctest sage.features.csdp.CSDP.is_functional[1]>", line 1, in <module>
        CSDP().is_functional()  # optional: csdp
      File "/Users/dcoudert/sage3/sage/local/lib/python3.7/site-packages/sage/features/csdp.py", line 47, in is_functional
        tf.write("2\n1\n1 1")
    TypeError: a bytes-like object is required, not 'str'
**********************************************************************
2 items had failures:
   1 of   3 in sage.features.csdp.CSDP
   1 of   3 in sage.features.csdp.CSDP.is_functional
    [6 tests, 2 failures, 0.02 s]
----------------------------------------------------------------------
sage -t --long src/sage/features/csdp.py  # 2 doctests failed

CC: @dimpase @vinklein

Component: graph theory

Author: David Coudert

Branch/Commit: 27a9342

Reviewer: Vincent Klein

Issue created by migration from https://trac.sagemath.org/ticket/28371

dcoudert commented 5 years ago
comment:1

So far I'm unable to fix the issues.

dcoudert commented 5 years ago
comment:2

Got it: it suffices too .encode() and .decode() strings in right places.


New commits:

764ce70trac #28371: fix features/csdp.py
8faca3ctrac #28371: fix graphs/lovasz_theta.py
dcoudert commented 5 years ago

Branch: public/graphs/28371_csdp

dcoudert commented 5 years ago

Author: David Coudert

dcoudert commented 5 years ago

Commit: 8faca3c

4a781b2b-eada-4ae4-9b46-f6cbb63459b9 commented 5 years ago
comment:3

The current fix is not compatible with python2.

f-strings only appears with python3.6.

sage -t --long src/sage/graphs/lovasz_theta.py 
Traceback (most recent call last):
  File "/home/vklein/odk/sage/src/bin/sage-runtests", line 177, in <module>
    from sage.doctest.control import DocTestController
  File "/home/vklein/odk/sage/local/lib/python2.7/site-packages/sage/doctest/control.py", line 33, in <module>
    from .sources import FileDocTestSource, DictAsObject
  File "/home/vklein/odk/sage/local/lib/python2.7/site-packages/sage/doctest/sources.py", line 33, in <module>
    from .parsing import SageDocTestParser
  File "/home/vklein/odk/sage/local/lib/python2.7/site-packages/sage/doctest/parsing.py", line 66, in <module>
    from sage.all import RealIntervalField
  File "/home/vklein/odk/sage/local/lib/python2.7/site-packages/sage/all.py", line 103, in <module>
    from sage.modular.all    import *
  File "/home/vklein/odk/sage/local/lib/python2.7/site-packages/sage/modular/all.py", line 54, in <module>
    from .btquotients.all import *
  File "/home/vklein/odk/sage/local/lib/python2.7/site-packages/sage/modular/btquotients/all.py", line 2, in <module>
    from .btquotient import BruhatTitsQuotient
  File "/home/vklein/odk/sage/local/lib/python2.7/site-packages/sage/modular/btquotients/btquotient.py", line 51, in <module>
    from sage.graphs.all import Graph
  File "/home/vklein/odk/sage/local/lib/python2.7/site-packages/sage/graphs/all.py", line 8, in <module>
    from .graph_database import GraphDatabase, GenericGraphQuery, GraphQuery
  File "/home/vklein/odk/sage/local/lib/python2.7/site-packages/sage/graphs/graph_database.py", line 48, in <module>
    from . import graph
  File "/home/vklein/odk/sage/local/lib/python2.7/site-packages/sage/graphs/graph.py", line 425, in <module>
    class Graph(GenericGraph):
  File "/home/vklein/odk/sage/local/lib/python2.7/site-packages/sage/graphs/graph.py", line 8650, in Graph
    from sage.graphs.lovasz_theta import lovasz_theta
  File "/home/vklein/odk/sage/local/lib/python2.7/site-packages/sage/graphs/lovasz_theta.py", line 75
    tf.write(f"{n}\n{g.number_of_edges()}\n".encode())
                                           ^
SyntaxError: invalid syntax
7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 5 years ago

Changed commit from 8faca3c to 04ff9b4

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 5 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

04ff9b4trac #28371: compatibility with Python 2
dcoudert commented 5 years ago
comment:5

Sorry, fixed.

4a781b2b-eada-4ae4-9b46-f6cbb63459b9 commented 5 years ago
comment:6

I have another slight (non blocking) concern with result = lines.decode().strip().split('\n')[-1] and python2.

With this code in python2 result is in unicode and the other string used .split('\n') and re.match("^The Lovasz Theta Number is (.*)$", result) are in bytes.

It works as it is but i think it would be cleaner to use bytes_to_str from sage.cpython.string instead of decode.

That way result will be of type str in both py2 and py3.

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 5 years ago

Changed commit from 04ff9b4 to 27a9342

7ed8c4ca-6d56-4ae9-953a-41e42b4ed313 commented 5 years ago

Branch pushed to git repo; I updated commit sha1. New commits:

27a9342trac #28371: use bytes_to_str instead of .decode() in features/csdp.py
dcoudert commented 5 years ago
comment:8

It is ok like that?

4a781b2b-eada-4ae4-9b46-f6cbb63459b9 commented 5 years ago
comment:9

Yes ! Thanks !

4a781b2b-eada-4ae4-9b46-f6cbb63459b9 commented 5 years ago

Reviewer: Vincent Klein

dcoudert commented 5 years ago
comment:10

Thank you. These were the last known Py3 failing doctests in the graph module ;)

vbraun commented 5 years ago

Changed branch from public/graphs/28371_csdp to 27a9342