diff --git a/src/sage/combinat/cluster_algebra_quiver/all.py b/src/sage/combinat/cluster_algebra_quiver/all.py index 40b86813ba0..5b28d09d1c6 100644 --- a/src/sage/combinat/cluster_algebra_quiver/all.py +++ b/src/sage/combinat/cluster_algebra_quiver/all.py @@ -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 diff --git a/src/sage/combinat/cluster_algebra_quiver/cluster_seed.py b/src/sage/combinat/cluster_algebra_quiver/cluster_seed.py index ae93b3e67af..3564594e370 100644 --- a/src/sage/combinat/cluster_algebra_quiver/cluster_seed.py +++ b/src/sage/combinat/cluster_algebra_quiver/cluster_seed.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: needs sage.graphs sage.modules r""" ClusterSeed @@ -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 @@ -57,6 +57,8 @@ from sage.combinat.cluster_algebra_quiver.interact import cluster_interact +lazy_import('sage.graphs.digraph', 'DiGraph') + class ClusterSeed(SageObject): r""" @@ -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 = [] @@ -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: @@ -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') @@ -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) diff --git a/src/sage/combinat/cluster_algebra_quiver/interact.py b/src/sage/combinat/cluster_algebra_quiver/interact.py index bf4bb87aba3..695e3d1d449 100644 --- a/src/sage/combinat/cluster_algebra_quiver/interact.py +++ b/src/sage/combinat/cluster_algebra_quiver/interact.py @@ -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']: diff --git a/src/sage/combinat/cluster_algebra_quiver/mutation_class.py b/src/sage/combinat/cluster_algebra_quiver/mutation_class.py index 78cf328747c..33b33087899 100644 --- a/src/sage/combinat/cluster_algebra_quiver/mutation_class.py +++ b/src/sage/combinat/cluster_algebra_quiver/mutation_class.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.graphs r""" mutation_class @@ -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] """ @@ -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() @@ -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] diff --git a/src/sage/combinat/cluster_algebra_quiver/mutation_type.py b/src/sage/combinat/cluster_algebra_quiver/mutation_type.py index ba4759f56ae..fc414b8f8fb 100644 --- a/src/sage/combinat/cluster_algebra_quiver/mutation_type.py +++ b/src/sage/combinat/cluster_algebra_quiver/mutation_type.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.graphs r""" Helper functions for mutation types of quivers @@ -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 @@ -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 diff --git a/src/sage/combinat/cluster_algebra_quiver/quiver.py b/src/sage/combinat/cluster_algebra_quiver/quiver.py index c02b38073ef..7b2ad09b1b2 100644 --- a/src/sage/combinat/cluster_algebra_quiver/quiver.py +++ b/src/sage/combinat/cluster_algebra_quiver/quiver.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: needs sage.graphs sage.modules r""" Quiver @@ -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 @@ -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): """ @@ -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 @@ -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 @@ -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") @@ -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) @@ -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`:: @@ -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() diff --git a/src/sage/combinat/cluster_algebra_quiver/quiver_mutation_type.py b/src/sage/combinat/cluster_algebra_quiver/quiver_mutation_type.py index 66b2385b3af..60e9e78c3bf 100644 --- a/src/sage/combinat/cluster_algebra_quiver/quiver_mutation_type.py +++ b/src/sage/combinat/cluster_algebra_quiver/quiver_mutation_type.py @@ -1,3 +1,4 @@ +# sage.doctest: needs sage.graphs r""" Quiver mutation types @@ -23,13 +24,15 @@ from copy import copy from sage.structure.unique_representation import UniqueRepresentation from sage.misc.cachefunc import cached_method +from sage.misc.lazy_import import lazy_import from sage.rings.integer_ring import ZZ from sage.rings.infinity import infinity from sage.graphs.digraph import DiGraph from sage.graphs.graph import Graph from sage.arith.misc import binomial, euler_phi from sage.misc.misc_c import prod -from sage.matrix.constructor import matrix + +lazy_import('sage.matrix.constructor', 'matrix') class QuiverMutationTypeFactory(SageObject): @@ -324,7 +327,7 @@ def _samples(self): replacing all positive entries by their negatives and adding `2`'s on the main diagonal. -``QuiverMutationType`` constructs a quiver mutation type object. For +:class:`QuiverMutationType` constructs a quiver mutation type object. For more detail on the possible different types, please see the compendium. @@ -686,8 +689,8 @@ def plot(self, circular=False, directed=True): EXAMPLES:: sage: QMT = QuiverMutationType(['A',5]) - sage: pl = QMT.plot() # optional - sage.plot sage.symbolic - sage: pl = QMT.plot(circular=True) # optional - sage.plot sage.symbolic + sage: pl = QMT.plot() # needs sage.plot sage.symbolic + sage: pl = QMT.plot(circular=True) # needs sage.plot sage.symbolic """ return self.standard_quiver().plot(circular=circular, directed=directed) @@ -706,7 +709,7 @@ def show(self, circular=False, directed=True): TESTS:: sage: QMT = QuiverMutationType(['A',5]) - sage: QMT.show() # long time + sage: QMT.show() # long time # needs sage.plot sage.symbolic """ self.plot(circular=circular, directed=directed).show() @@ -785,7 +788,7 @@ def b_matrix(self): sage: mut_type = QuiverMutationType(['A',5]); mut_type ['A', 5] - sage: mut_type.b_matrix() + sage: mut_type.b_matrix() # needs sage.modules [ 0 1 0 0 0] [-1 0 -1 0 0] [ 0 1 0 1 0] @@ -794,7 +797,7 @@ def b_matrix(self): sage: mut_type = QuiverMutationType(['A',3],['B',3]); mut_type [ ['A', 3], ['B', 3] ] - sage: mut_type.b_matrix() + sage: mut_type.b_matrix() # needs sage.modules [ 0 1 0 0 0 0] [-1 0 -1 0 0 0] [ 0 1 0 0 0 0] @@ -851,7 +854,7 @@ def cartan_matrix(self): sage: mut_type = QuiverMutationType(['A',5]); mut_type ['A', 5] - sage: mut_type.cartan_matrix() + sage: mut_type.cartan_matrix() # needs sage.modules [ 2 -1 0 0 0] [-1 2 -1 0 0] [ 0 -1 2 -1 0] @@ -860,7 +863,7 @@ def cartan_matrix(self): sage: mut_type = QuiverMutationType(['A',3],['B',3]); mut_type [ ['A', 3], ['B', 3] ] - sage: mut_type.cartan_matrix() + sage: mut_type.cartan_matrix() # needs sage.modules [ 2 -1 0 0 0 0] [-1 2 -1 0 0 0] [ 0 -1 2 0 0 0] @@ -1103,7 +1106,7 @@ def properties(self): class QuiverMutationType_Irreducible(QuiverMutationType_abstract): """ The mutation type for a cluster algebra or a quiver. Should not be - called directly, but through QuiverMutationType. + called directly, but through :class:`QuiverMutationType`. """ def __init__(self, letter, rank, twist=None): @@ -1692,7 +1695,7 @@ def class_size(self): which are mutation equivalent to the standard quiver of ``self`` (up to isomorphism) is returned. - Otherwise, ``NotImplemented`` is returned. + Otherwise, :obj:`NotImplemented` is returned. Formula for finite type A is taken from Torkildsen - Counting cluster-tilted algebras of type `A_n`. @@ -1896,7 +1899,7 @@ def class_size(self): def dual(self): """ - Return the QuiverMutationType which is dual to ``self``. + Return the :class:`QuiverMutationType` which is dual to ``self``. EXAMPLES:: @@ -1960,8 +1963,8 @@ def dual(self): class QuiverMutationType_Reducible(QuiverMutationType_abstract): """ The mutation type for a cluster algebra or a quiver. Should not be - called directly, but through QuiverMutationType. Inherits from - QuiverMutationType_abstract. + called directly, but through :class:`QuiverMutationType`. Inherits from + :class:`QuiverMutationType_abstract`. """ def __init__(self, *args): @@ -2054,7 +2057,7 @@ def class_size(self): which are mutation equivalent to the standard quiver of ``self`` (up to isomorphism) is returned. - Otherwise, ``NotImplemented`` is returned. + Otherwise, :obj:`NotImplemented` is returned. EXAMPLES:: @@ -2093,7 +2096,7 @@ def class_size(self): def dual(self): """ - Return the QuiverMutationType which is dual to ``self``. + Return the :class:`QuiverMutationType` which is dual to ``self``. EXAMPLES:: @@ -2294,7 +2297,7 @@ def save_quiver_data(n, up_to=True, types='ClassicalExceptional', verbose=True): INPUT: - - ``n``: the rank (or the upper limit on the rank) of the mutation + - ``n`` -- the rank (or the upper limit on the rank) of the mutation classes that are being saved. - ``up_to`` -- (default:``True``) if ``True``, saves data for @@ -2435,17 +2438,17 @@ def _edge_list_to_matrix(edges, nlist, mlist) -> matrix: sage: from sage.combinat.cluster_algebra_quiver.quiver_mutation_type import _edge_list_to_matrix sage: G = QuiverMutationType(['A', 2])._digraph - sage: _edge_list_to_matrix(G.edges(sort=True), [0, 1], []) + sage: _edge_list_to_matrix(G.edges(sort=True), [0, 1], []) # needs sage.modules [ 0 1] [-1 0] sage: G2 = DiGraph([('a', 'b', 1)]) - sage: _edge_list_to_matrix(G2.edges(sort=True), ['a', 'b'], []) + sage: _edge_list_to_matrix(G2.edges(sort=True), ['a', 'b'], []) # needs sage.modules [ 0 1] [-1 0] sage: G3 = DiGraph([('a', 'b', 1), ('b', 'c', 1)]) - sage: _edge_list_to_matrix(G3.edges(sort=True), ['a', 'b'], ['c']) + sage: _edge_list_to_matrix(G3.edges(sort=True), ['a', 'b'], ['c']) # needs sage.modules [ 0 1] [-1 0] [ 0 -1]