Skip to content
3 changes: 3 additions & 0 deletions src/sage/combinat/cluster_algebra_quiver/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@
lazy_import("sage.combinat.cluster_algebra_quiver.quiver_mutation_type", "QuiverMutationType")
lazy_import("sage.combinat.cluster_algebra_quiver.quiver", "ClusterQuiver")
lazy_import("sage.combinat.cluster_algebra_quiver.cluster_seed", "ClusterSeed")

del install_doc
del lazy_import
18 changes: 10 additions & 8 deletions src/sage/combinat/cluster_algebra_quiver/cluster_seed.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
# sage.doctest: needs sage.graphs sage.modules
r"""
ClusterSeed

Expand Down Expand Up @@ -44,10 +44,10 @@
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.rings.fraction_field_element import FractionFieldElement
from sage.sets.set import Set
from sage.graphs.digraph import DiGraph
from sage.combinat.cluster_algebra_quiver.quiver_mutation_type import QuiverMutationType_Irreducible, QuiverMutationType_Reducible
from sage.combinat.cluster_algebra_quiver.mutation_type import is_mutation_finite
from random import randint
from sage.misc.lazy_import import lazy_import
from sage.misc.misc_c import prod
from sage.matrix.special import identity_matrix
from sage.matrix.constructor import matrix
Expand All @@ -57,6 +57,8 @@

from sage.combinat.cluster_algebra_quiver.interact import cluster_interact

lazy_import('sage.graphs.digraph', 'DiGraph')


class ClusterSeed(SageObject):
r"""
Expand Down Expand Up @@ -1040,11 +1042,11 @@ def plot(self, circular=False, mark=None, save_pos=False, force_c=False, with_gr
EXAMPLES::

sage: S = ClusterSeed(['A',5])
sage: S.plot() # optional - sage.plot sage.symbolic
sage: S.plot() # needs sage.plot sage.symbolic
Graphics object consisting of 15 graphics primitives
sage: S.plot(circular=True) # optional - sage.plot sage.symbolic
sage: S.plot(circular=True) # needs sage.plot sage.symbolic
Graphics object consisting of 15 graphics primitives
sage: S.plot(circular=True, mark=1) # optional - sage.plot sage.symbolic
sage: S.plot(circular=True, mark=1) # needs sage.plot sage.symbolic
Graphics object consisting of 15 graphics primitives
"""
greens = []
Expand Down Expand Up @@ -1086,7 +1088,7 @@ def show(self, fig_size=1, circular=False, mark=None, save_pos=False, force_c=Fa
TESTS::

sage: S = ClusterSeed(['A',5])
sage: S.show() # long time # optional - sage.plot sage.symbolic
sage: S.show() # long time # needs sage.plot sage.symbolic
"""
greens = []
if with_greens:
Expand Down Expand Up @@ -1120,7 +1122,7 @@ def interact(self, fig_size=1, circular=True):
TESTS::

sage: S = ClusterSeed(['A',4])
sage: S.interact() # optional - sage.plot sage.symbolic
sage: S.interact() # needs sage.plot sage.symbolic
...VBox(children=...
"""
return cluster_interact(self, fig_size, circular, kind='seed')
Expand All @@ -1142,7 +1144,7 @@ def save_image(self, filename, circular=False, mark=None, save_pos=False):

sage: S = ClusterSeed(['F',4,[1,2]])
sage: import tempfile
sage: with tempfile.NamedTemporaryFile(suffix=".png") as f: # optional - sage.plot sage.symbolic
sage: with tempfile.NamedTemporaryFile(suffix=".png") as f: # needs sage.plot sage.symbolic
....: S.save_image(f.name)
"""
graph_plot = self.plot(circular=circular, mark=mark, save_pos=save_pos)
Expand Down
4 changes: 2 additions & 2 deletions src/sage/combinat/cluster_algebra_quiver/interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def cluster_interact(self, fig_size=1, circular=True, kind='seed'):

TESTS::

sage: S = ClusterSeed(['A',4]) # optional - sage.graphs
sage: S.interact() # indirect doctest # optional - sage.graphs sage.symbolic
sage: S = ClusterSeed(['A',4]) # needs sage.graphs sage.modules
sage: S.interact() # indirect doctest # needs sage.graphs sage.modules sage.symbolic
...VBox(children=...
"""
if kind not in ['seed', 'quiver']:
Expand Down
9 changes: 5 additions & 4 deletions src/sage/combinat/cluster_algebra_quiver/mutation_class.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# sage.doctest: needs sage.graphs
r"""
mutation_class

Expand Down Expand Up @@ -41,11 +42,11 @@ def _principal_part(mat):
EXAMPLES::

sage: from sage.combinat.cluster_algebra_quiver.mutation_class import _principal_part
sage: M = Matrix([[1,2],[3,4],[5,6]]); M
sage: M = Matrix([[1,2],[3,4],[5,6]]); M # needs sage.modules
[1 2]
[3 4]
[5 6]
sage: _principal_part(M)
sage: _principal_part(M) # needs sage.modules
[1 2]
[3 4]
"""
Expand Down Expand Up @@ -159,7 +160,7 @@ def _matrix_to_digraph( M ):
EXAMPLES::

sage: from sage.combinat.cluster_algebra_quiver.mutation_class import _matrix_to_digraph
sage: _matrix_to_digraph(matrix(3,[0,1,0,-1,0,-1,0,1,0]))
sage: _matrix_to_digraph(matrix(3,[0,1,0,-1,0,-1,0,1,0])) # needs sage.modules
Digraph on 3 vertices
"""
n = M.ncols()
Expand Down Expand Up @@ -452,7 +453,7 @@ def _dig6_to_matrix( dig6 ):
sage: from sage.combinat.cluster_algebra_quiver.quiver import ClusterQuiver
sage: dg = ClusterQuiver(['A',4]).digraph()
sage: data = _digraph_to_dig6(dg)
sage: _dig6_to_matrix(data)
sage: _dig6_to_matrix(data) # needs sage.modules
[ 0 1 0 0]
[-1 0 -1 0]
[ 0 1 0 1]
Expand Down
15 changes: 8 additions & 7 deletions src/sage/combinat/cluster_algebra_quiver/mutation_type.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# sage.doctest: needs sage.graphs
r"""
Helper functions for mutation types of quivers

Expand Down Expand Up @@ -55,20 +56,20 @@ def is_mutation_finite(M, nr_of_checks=None):
sage: from sage.combinat.cluster_algebra_quiver.mutation_type import is_mutation_finite

sage: Q = ClusterQuiver(['A',10])
sage: M = Q.b_matrix()
sage: is_mutation_finite(M)
sage: M = Q.b_matrix() # needs sage.modules
sage: is_mutation_finite(M) # needs sage.modules
(True, None)

sage: Q = ClusterQuiver([(0,1),(1,2),(2,3),(3,4),(4,5),(5,6),(6,7),(7,8),(2,9)])
sage: M = Q.b_matrix()
sage: is_mutation_finite(M) # random
sage: M = Q.b_matrix() # needs sage.modules
sage: is_mutation_finite(M) # random # needs sage.modules
(False, [9, 6, 9, 8, 9, 4, 0, 4, 5, 2, 1, 0, 1, 0, 7, 1, 9, 2, 5, 7, 8, 6, 3, 0, 2, 5, 4, 2, 6, 9, 2, 7, 3, 5, 3, 7, 9, 5, 9, 0, 2, 7, 9, 2, 4, 2, 1, 6, 9, 4, 3, 5, 0, 8, 2, 9, 5, 3, 7, 0, 1, 8, 3, 7, 2, 7, 3, 4, 8, 0, 4, 9, 5, 2, 8, 4, 8, 1, 7, 8, 9, 1, 5, 0, 8, 7, 4, 8, 9, 8, 0, 7, 4, 7, 1, 2, 8, 6, 1, 3, 9, 3, 9, 1, 3, 2, 4, 9, 5, 1, 2, 9, 4, 8, 5, 3, 4, 6, 8, 9, 2, 5, 9, 4, 6, 2, 1, 4, 9, 6, 0, 9, 8, 0, 4, 7, 9, 2, 1, 6])

Check that :trac:`19495` is fixed::

sage: dg = DiGraph(); dg.add_vertex(0); S = ClusterSeed(dg); S
sage: dg = DiGraph(); dg.add_vertex(0); S = ClusterSeed(dg); S # needs sage.modules
A seed for a cluster algebra of rank 1
sage: S.is_mutation_finite()
sage: S.is_mutation_finite() # needs sage.modules
True
"""
import random
Expand Down Expand Up @@ -1428,7 +1429,7 @@ def _random_tests(mt, k, mut_class=None, nr_mut=5):
TESTS::

sage: from sage.combinat.cluster_algebra_quiver.mutation_type import _random_tests
sage: _random_tests( ['A',3], 1)
sage: _random_tests( ['A',3], 1) # needs sage.modules
testing ['A', 3]
"""
from sage.combinat.cluster_algebra_quiver.quiver import ClusterQuiver
Expand Down
41 changes: 22 additions & 19 deletions src/sage/combinat/cluster_algebra_quiver/quiver.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
# sage.doctest: needs sage.graphs sage.modules
r"""
Quiver

Expand Down Expand Up @@ -37,19 +37,18 @@
# https://www.gnu.org/licenses/
# ****************************************************************************

from sage.structure.sage_object import SageObject
from copy import copy

from sage.structure.sage_object import SageObject
from sage.rings.integer_ring import ZZ
from sage.rings.cc import CC
from sage.rings.infinity import infinity
from sage.graphs.digraph import DiGraph
from sage.graphs.graph import Graph
from sage.graphs.views import EdgesView
from sage.arith.misc import gcd
from sage.modules.free_module_element import vector
from sage.matrix.constructor import matrix
from sage.categories.cartesian_product import cartesian_product
from sage.misc.misc_c import prod
from sage.misc.lazy_import import lazy_import
from sage.rings.rational_field import QQ
from sage.rings.polynomial.polynomial_ring import polygen
from sage.combinat.cluster_algebra_quiver.quiver_mutation_type import QuiverMutationType, QuiverMutationType_Irreducible, QuiverMutationType_Reducible, _edge_list_to_matrix
Expand All @@ -58,6 +57,9 @@

from sage.combinat.cluster_algebra_quiver.interact import cluster_interact

lazy_import('sage.modules.free_module_element', 'vector')
lazy_import('sage.matrix.constructor', 'matrix')


class ClusterQuiver(SageObject):
"""
Expand All @@ -67,14 +69,14 @@ class ClusterQuiver(SageObject):

- ``data`` -- can be any of the following::

* QuiverMutationType
* str - a string representing a QuiverMutationType or a common quiver type (see Examples)
* ClusterQuiver
* Matrix - a skew-symmetrizable matrix
* DiGraph - must be the input data for a quiver
* List of edges - must be the edge list of a digraph for a quiver
* :class:`QuiverMutationType`
* :class:`str` -- a string representing a :class:`QuiverMutationType` or a common quiver type (see Examples)
* :class:`ClusterQuiver`
* :class:`Matrix` -- a skew-symmetrizable matrix
* :class:`DiGraph` -- must be the input data for a quiver
* List of edges -- must be the edge list of a digraph for a quiver

- ``frozen`` -- (default:``None``) sets the list of frozen variables
- ``frozen`` -- (default: ``None``) sets the list of frozen variables
if the input type is a :class:`DiGraph`, it is ignored otherwise

- ``user_labels`` -- (default:``None``) sets the names of the labels for
Expand Down Expand Up @@ -549,16 +551,17 @@ def plot(self, circular=True, center=(0, 0), directed=True, mark=None,
EXAMPLES::

sage: Q = ClusterQuiver(['A',5])
sage: Q.plot() # optional - sage.plot sage.symbolic
sage: Q.plot() # needs sage.plot sage.symbolic
Graphics object consisting of 15 graphics primitives
sage: Q.plot(circular=True) # optional - sage.plot sage.symbolic
sage: Q.plot(circular=True) # needs sage.plot sage.symbolic
Graphics object consisting of 15 graphics primitives
sage: Q.plot(circular=True, mark=1) # optional - sage.plot sage.symbolic
sage: Q.plot(circular=True, mark=1) # needs sage.plot sage.symbolic
Graphics object consisting of 15 graphics primitives
"""
from sage.plot.colors import rainbow
from sage.graphs.graph_generators import GraphGenerators
from sage.symbolic.constants import e, pi
from sage.rings.cc import CC
from sage.rings.imaginary_unit import I
graphs = GraphGenerators()
# returns positions for graph vertices on two concentric cycles with radius 1 and 2
Expand Down Expand Up @@ -699,7 +702,7 @@ def interact(self, fig_size=1, circular=True):
TESTS::

sage: S = ClusterQuiver(['A',4])
sage: S.interact() # optional - sage.plot sage.symbolic
sage: S.interact() # needs sage.plot sage.symbolic
...VBox(children=...
"""
return cluster_interact(self, fig_size, circular, kind="quiver")
Expand All @@ -717,7 +720,7 @@ def save_image(self, filename, circular=False):

sage: Q = ClusterQuiver(['F',4,[1,2]])
sage: import tempfile
sage: with tempfile.NamedTemporaryFile(suffix=".png") as f: # optional - sage.plot sage.symbolic
sage: with tempfile.NamedTemporaryFile(suffix=".png") as f: # needs sage.plot sage.symbolic
....: Q.save_image(f.name)
"""
graph_plot = self.plot(circular=circular)
Expand All @@ -742,7 +745,7 @@ def qmu_save(self, filename=None):

sage: Q = ClusterQuiver(['F',4,[1,2]])
sage: import tempfile
sage: with tempfile.NamedTemporaryFile(suffix=".qmu") as f: # optional - sage.plot sage.symbolic
sage: with tempfile.NamedTemporaryFile(suffix=".qmu") as f: # needs sage.plot sage.symbolic
....: Q.qmu_save(f.name)

Make sure we can save quivers with `m != n` frozen variables, see :trac:`14851`::
Expand All @@ -751,7 +754,7 @@ def qmu_save(self, filename=None):
sage: T1 = S.principal_extension()
sage: Q = T1.quiver()
sage: import tempfile
sage: with tempfile.NamedTemporaryFile(suffix=".qmu") as f: # optional - sage.plot sage.symbolic
sage: with tempfile.NamedTemporaryFile(suffix=".qmu") as f: # needs sage.plot sage.symbolic
....: Q.qmu_save(f.name)
"""
M = self.b_matrix()
Expand Down
Loading