#15206: Poset show should accept non-hashable or non-injective element labels
------------------------------------------------+------------------------
       Reporter:  darij                         |        Owner:
           Type:  task                          |       Status:  new
       Priority:  major                         |    Milestone:  sage-6.4
      Component:  combinatorics                 |   Resolution:
       Keywords:  combinat, show, plot, posets  |    Merged in:
        Authors:                                |    Reviewers:
Report Upstream:  N/A                           |  Work issues:
         Branch:                                |       Commit:
   Dependencies:                                |     Stopgaps:
------------------------------------------------+------------------------
Description changed by jmantysalo:

Old description:

> {{{
> sage: P = Poset({1: [2,3]})
> sage: labs = {i: P.rank(i) for i in range(1, 4)}
> sage: labs
> {1: 0, 2: 1, 3: 1}
> sage: P.show(element_labels=labs)
> ---------------------------------------------------------------------------
> NotImplementedError                       Traceback (most recent call
> last)
> <ipython-input-38-dfd00191eb55> in <module>()
> ----> 1 P.show(element_labels=labs)
>
> /home/darij/sage-5.12.beta5/local/lib/python2.7/site-
> packages/sage/combinat/posets/posets.pyc in show(self, label_elements,
> element_labels, vertex_size, vertex_colors, layout, **kwds)
>    1440         """
>    1441         self.plot(label_elements=label_elements,
> element_labels=element_labels,
> -> 1442             vertex_size=vertex_size, vertex_colors=vertex_colors,
> layout=layout).show(**kwds)
>    1443
>    1444     @combinatorial_map(name="to graph")
>
> /home/darij/sage-5.12.beta5/local/lib/python2.7/site-
> packages/sage/combinat/posets/posets.pyc in plot(self, label_elements,
> element_labels, vertex_size, vertex_colors, layout, **kwds)
>    1402             relabelling = dict((self(element), label)
>    1403                                for (element, label) in
> element_labels.items())
> -> 1404             graph = graph.relabel(relabelling, inplace = False)
>    1405             if rank_function: # use the rank function to set the
> heights
>    1406                 for i in self:
>
> /home/darij/sage-5.12.beta5/local/lib/python2.7/site-
> packages/sage/graphs/generic_graph.pyc in relabel(self, perm, inplace,
> return_map, check_input, complete_partial_function)
>   16208                               return_map= return_map,
>   16209                               check_input = check_input,
> > 16210                               complete_partial_function =
> complete_partial_function)
>   16211
>   16212             if return_map:
>
> /home/darij/sage-5.12.beta5/local/lib/python2.7/site-
> packages/sage/graphs/generic_graph.pyc in relabel(self, perm, inplace,
> return_map, check_input, complete_partial_function)
>   16263         if check_input:
>   16264             if len(set(perm.values())) < len(perm):
> > 16265                 raise NotImplementedError("Non injective
> relabeling")
>   16266
>   16267             for v in perm.iterkeys():
>
> NotImplementedError: Non injective relabeling
> }}}
>
> I understand that this, along with the lack of support for non-hashable
> labels, is owed to the implementation, but IMHO this means that the
> implementation (via relabelling the poset before plotting it, rather than
> as one would expect via doing everything as if the labels weren't there
> and then introducing them at the very end) is bad. (Incidentally, I'm not
> even sure that the shape of the image doesn't depend on the labels -- in
> the examples I've checked it seems to not depend on them, but I don't
> trust the code very much.)
>
> I am not the type of mathematician who gets any enlightenment out of
> pictures, but even I do need to use {{{show()}}} when I'm making a
> presentation. Issues like this harm the presentability of Sage code.

New description:

 {{{
 sage: P = Poset({1: [2,3]})
 sage: labs = {i: P.rank(i) for i in range(1, 4)}
 sage: labs
 {1: 0, 2: 1, 3: 1}
 sage: P.show(element_labels=labs)
 ---------------------------------------------------------------------------
 NotImplementedError                       Traceback (most recent call
 last)
 <ipython-input-38-dfd00191eb55> in <module>()
 ----> 1 P.show(element_labels=labs)

 /home/darij/sage-5.12.beta5/local/lib/python2.7/site-
 packages/sage/combinat/posets/posets.pyc in show(self, label_elements,
 element_labels, vertex_size, vertex_colors, layout, **kwds)
    1440         """
    1441         self.plot(label_elements=label_elements,
 element_labels=element_labels,
 -> 1442             vertex_size=vertex_size, vertex_colors=vertex_colors,
 layout=layout).show(**kwds)
    1443
    1444     @combinatorial_map(name="to graph")

 /home/darij/sage-5.12.beta5/local/lib/python2.7/site-
 packages/sage/combinat/posets/posets.pyc in plot(self, label_elements,
 element_labels, vertex_size, vertex_colors, layout, **kwds)
    1402             relabelling = dict((self(element), label)
    1403                                for (element, label) in
 element_labels.items())
 -> 1404             graph = graph.relabel(relabelling, inplace = False)
    1405             if rank_function: # use the rank function to set the
 heights
    1406                 for i in self:

 /home/darij/sage-5.12.beta5/local/lib/python2.7/site-
 packages/sage/graphs/generic_graph.pyc in relabel(self, perm, inplace,
 return_map, check_input, complete_partial_function)
   16208                               return_map= return_map,
   16209                               check_input = check_input,
 > 16210                               complete_partial_function =
 complete_partial_function)
   16211
   16212             if return_map:

 /home/darij/sage-5.12.beta5/local/lib/python2.7/site-
 packages/sage/graphs/generic_graph.pyc in relabel(self, perm, inplace,
 return_map, check_input, complete_partial_function)
   16263         if check_input:
   16264             if len(set(perm.values())) < len(perm):
 > 16265                 raise NotImplementedError("Non injective
 relabeling")
   16266
   16267             for v in perm.iterkeys():

 NotImplementedError: Non injective relabeling
 }}}

 I understand that this, along with the lack of support for non-hashable
 labels, is owed to the implementation, but IMHO this means that the
 implementation (via relabelling the poset before plotting it, rather than
 as one would expect via doing everything as if the labels weren't there
 and then introducing them at the very end) is bad. (Incidentally, I'm not
 even sure that the shape of the image doesn't depend on the labels -- in
 the examples I've checked it seems to not depend on them, but I don't
 trust the code very much.)

 I am not the type of mathematician who gets any enlightenment out of
 pictures, but even I do need to use {{{show()}}} when I'm making a
 presentation. Issues like this harm the presentability of Sage code.

 Fixing this would also help with problem when combining `vertex_colors`
 and `element_labels`. See for example

 {{{
 Poset({1:[]}).plot(vertex_colors={'red':[1]}, element_labels={1: 2})
 }}}

--

--
Ticket URL: <http://trac.sagemath.org/ticket/15206#comment:5>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to