Opened 2 months ago

Closed 2 months ago

#28371 closed defect (fixed)

py3: errors with optional package CSDP

Reported by: dcoudert Owned by:
Priority: major Milestone: sage-8.9
Component: graph theory Keywords:
Cc: dimpase, vklein Merged in:
Authors: David Coudert Reviewers: Vincent Klein
Report Upstream: N/A Work issues:
Branch: 27a9342 (Commits) Commit: 27a934225f761f72a90a18e3a91628133cf839b6
Dependencies: Stopgaps:

Description

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

Change History (11)

comment:1 Changed 2 months ago by dcoudert

So far I'm unable to fix the issues.

comment:2 Changed 2 months ago by dcoudert

  • Authors set to David Coudert
  • Branch set to public/graphs/28371_csdp
  • Cc vklein added
  • Commit set to 8faca3c729ba49d4236dd8b80c85738b01dfd4e6
  • Status changed from new to needs_review

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

comment:3 Changed 2 months ago by vklein

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
Last edited 2 months ago by vklein (previous) (diff)

comment:4 Changed 2 months ago by git

  • Commit changed from 8faca3c729ba49d4236dd8b80c85738b01dfd4e6 to 04ff9b4a6025165390e2b5f82a36546bffea4a40

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

04ff9b4trac #28371: compatibility with Python 2

comment:5 Changed 2 months ago by dcoudert

Sorry, fixed.

comment:6 Changed 2 months ago by vklein

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.

Last edited 2 months ago by vklein (previous) (diff)

comment:7 Changed 2 months ago by git

  • Commit changed from 04ff9b4a6025165390e2b5f82a36546bffea4a40 to 27a934225f761f72a90a18e3a91628133cf839b6

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

27a9342trac #28371: use bytes_to_str instead of .decode() in features/csdp.py

comment:8 Changed 2 months ago by dcoudert

It is ok like that?

comment:9 Changed 2 months ago by vklein

  • Reviewers set to Vincent Klein
  • Status changed from needs_review to positive_review

Yes ! Thanks !

comment:10 Changed 2 months ago by dcoudert

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

comment:11 Changed 2 months ago by vbraun

  • Branch changed from public/graphs/28371_csdp to 27a934225f761f72a90a18e3a91628133cf839b6
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.