From 38f330a9919a78000326fd3a5e9ed59830262901 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 14 Jan 2025 12:01:13 -0800 Subject: [PATCH 1/8] tox.ini: New --- tox.ini | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tox.ini diff --git a/tox.ini b/tox.ini new file mode 100644 index 000000000..ea3524c2c --- /dev/null +++ b/tox.ini @@ -0,0 +1,15 @@ +[tox] +envlist = passagemath + +[testenv:passagemath] +deps = + passagemath-combinat # sage.algebras.free_algebra + passagemath-flint # for sage.rings.imaginary_unit + passagemath-repl # --> sage_eval + passagemath-groups + passagemath-symbolics # for sage.symbolic.constants + passagemath-plot + passagemath-graphs + +commands = + python -m snappy.test From b19b56564c6549abe28543bb61542936b7b8a404 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 14 Jan 2025 13:59:53 -0800 Subject: [PATCH 2/8] python/sage_helper.py: Initialize sagemath_modules --- python/sage_helper.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/python/sage_helper.py b/python/sage_helper.py index 95aa78549..5a643b79c 100644 --- a/python/sage_helper.py +++ b/python/sage_helper.py @@ -40,6 +40,10 @@ def sage_method(function): from sage.all import is_prime except ImportError: # Modularized Sage library + try: + import sage.all__sagemath_modules + except ImportError: + pass from sage.algebras.group_algebra import GroupAlgebra from sage.arith.misc import gcd, xgcd, is_prime from sage.combinat.subset import powerset From 9bacd82d23ca483b3327e6a6818e0ccca84a4ea3 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 14 Jan 2025 14:00:12 -0800 Subject: [PATCH 3/8] tox.ini: Add fpylll to deps --- tox.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/tox.ini b/tox.ini index ea3524c2c..6a134ce62 100644 --- a/tox.ini +++ b/tox.ini @@ -3,6 +3,7 @@ envlist = passagemath [testenv:passagemath] deps = + fpylll passagemath-combinat # sage.algebras.free_algebra passagemath-flint # for sage.rings.imaginary_unit passagemath-repl # --> sage_eval From 15adf05b9a730ebb0f12b319c331d1b2637da4cd Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 14 Jan 2025 14:57:39 -0800 Subject: [PATCH 4/8] setup.py: Declare extra 'passagemath' --- setup.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/setup.py b/setup.py index 42bb21e0f..01a1204dd 100644 --- a/setup.py +++ b/setup.py @@ -533,6 +533,18 @@ def add(self, source_file, dependency_mod_time=0.0): zip_safe = False, python_requires = '>=3.8', install_requires = install_requires, + extras_require = { + "passagemath": [ + "fpylll", + "passagemath-combinat", # sage.algebras.free_algebra + "passagemath-flint", # for sage.rings.imaginary_unit + "passagemath-repl", # --> sage_eval + "passagemath-groups", + "passagemath-symbolics", # for sage.symbolic.constants + "passagemath-plot", + "passagemath-graphs", + ], + }, packages = ['snappy', 'snappy/manifolds', 'snappy/twister', 'snappy/snap', 'snappy/snap/t3mlite', 'snappy/snap/peripheral', 'snappy/ptolemy', From ef8fb9861a489204563d5fcd048a8a1d68656658 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 14 Jan 2025 14:57:54 -0800 Subject: [PATCH 5/8] tox.ini: Use extra 'passagemath' --- tox.ini | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/tox.ini b/tox.ini index 6a134ce62..6e1d75c65 100644 --- a/tox.ini +++ b/tox.ini @@ -2,15 +2,7 @@ envlist = passagemath [testenv:passagemath] -deps = - fpylll - passagemath-combinat # sage.algebras.free_algebra - passagemath-flint # for sage.rings.imaginary_unit - passagemath-repl # --> sage_eval - passagemath-groups - passagemath-symbolics # for sage.symbolic.constants - passagemath-plot - passagemath-graphs +extras = passagemath commands = python -m snappy.test From 74d833c1093427d538caa0cb997f1e9a7a4292a1 Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 14 Jan 2025 14:58:20 -0800 Subject: [PATCH 6/8] Replace .all imports in doctests --- doc_src/verify.rst | 2 +- python/__init__.py | 2 +- python/cusps/cusp_areas_from_matrix.py | 4 ++-- python/math_basics.py | 2 +- python/matrix.py | 2 +- python/tiling/floor.py | 2 +- python/tiling/real_hash_dict.py | 2 +- python/verify/interval_newton_shapes_engine.py | 4 ++-- python/verify/interval_tree.py | 2 +- python/verify/krawczyk_shapes_engine.py | 2 +- .../cusp_translate_engine.py | 4 ++-- python/verify/short_slopes.py | 2 +- python/verify/upper_halfspace/extended_matrix.py | 2 +- python/verify/upper_halfspace/finite_point.py | 12 ++++++------ python/verify/upper_halfspace/ideal_point.py | 12 ++++++------ 15 files changed, 28 insertions(+), 28 deletions(-) diff --git a/doc_src/verify.rst b/doc_src/verify.rst index 04fc2c463..241a62d7d 100644 --- a/doc_src/verify.rst +++ b/doc_src/verify.rst @@ -164,7 +164,7 @@ Some examples of verified computations are: * An example of finding all geodesics up to length 1:: - sage: from sage.all import RIF + sage: from snappy.sage_helper import RIF sage: L = RIF(1) sage: M = Manifold("m003") sage: spec = M.length_spectrum_alt_gen(verified=True) diff --git a/python/__init__.py b/python/__init__.py index 27f89e2e5..63f00feb8 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -435,7 +435,7 @@ def short_slopes(manifold, The given :attr:`length` is cast to a SageMath ``RealIntervalField`` of the given precision if :attr:`verified = True`:: - sage: from sage.all import pi + sage: from sage.symbolic.constants import pi sage: M.short_slopes(length = 2 * pi, verified = True, bits_prec = 100) [[(1, 0), (-5, 1), (-4, 1), (-3, 1), (-2, 1), (-1, 1), (0, 1), (1, 1), (2, 1), (3, 1), (4, 1), (5, 1)]] diff --git a/python/cusps/cusp_areas_from_matrix.py b/python/cusps/cusp_areas_from_matrix.py index bf53d58ed..21627dce3 100644 --- a/python/cusps/cusp_areas_from_matrix.py +++ b/python/cusps/cusp_areas_from_matrix.py @@ -8,7 +8,7 @@ def unbiased_cusp_areas_from_cusp_area_matrix(cusp_area_matrix): Examples:: - sage: from sage.all import matrix, RIF + sage: from snappy.sage_helper import matrix, RIF sage: unbiased_cusp_areas_from_cusp_area_matrix( ... matrix([[RIF(9.0,9.0005),RIF(6.0, 6.001)], ... [RIF(6.0,6.001 ),RIF(4.0, 4.001)]])) @@ -35,7 +35,7 @@ def unbiased_cusp_areas_from_cusp_area_matrix(cusp_area_matrix): def greedy_cusp_areas_from_cusp_area_matrix(cusp_area_matrix, first_cusps=[]): """ - sage: from sage.all import matrix, RIF + sage: from snappy.sage_helper import matrix, RIF sage: greedy_cusp_areas_from_cusp_area_matrix( ... matrix([[RIF(9.0,9.0005),RIF(6.0, 6.001)], ... [RIF(6.0,6.001 ),RIF(10.0, 10.001)]])) diff --git a/python/math_basics.py b/python/math_basics.py index bdcdf72f0..0f013617c 100644 --- a/python/math_basics.py +++ b/python/math_basics.py @@ -103,7 +103,7 @@ def correct_min(l): This is needed because python's min returns the wrong result for intervals, for example: - sage: from sage.all import RIF + sage: from snappy.sage_helper import RIF sage: min(RIF(4,5), RIF(3,6)).endpoints() (4.00000000000000, 5.00000000000000) diff --git a/python/matrix.py b/python/matrix.py index 8ef883a29..0bc16bcd2 100644 --- a/python/matrix.py +++ b/python/matrix.py @@ -373,7 +373,7 @@ def mat_solve(m, v, epsilon=0): Setup a complex interval for example:: - sage: from sage.all import RealIntervalField, ComplexIntervalField + sage: from snappy.sage_helper import RealIntervalField, ComplexIntervalField sage: RIF = RealIntervalField(80) sage: CIF = ComplexIntervalField(80) sage: fuzzy_four = CIF(RIF(3.9999,4.0001),RIF(-0.0001,0.0001)) diff --git a/python/tiling/floor.py b/python/tiling/floor.py index 05928b230..67ef6fe09 100644 --- a/python/tiling/floor.py +++ b/python/tiling/floor.py @@ -8,7 +8,7 @@ def floor_as_integers(x) -> Sequence[int]: Computes floor of a number or interval, returning a list of integers if evaluating floor is ambiguous. - sage: from sage.all import RIF + sage: from snappy.sage_helper import RIF sage: floor_as_integers(RIF(1.8, 1.9)) [1] sage: floor_as_integers(RIF(1.9, 2.1)) diff --git a/python/tiling/real_hash_dict.py b/python/tiling/real_hash_dict.py index ecb7da9c4..ae46edb96 100644 --- a/python/tiling/real_hash_dict.py +++ b/python/tiling/real_hash_dict.py @@ -58,7 +58,7 @@ class RealHashDict: >>> d.get(to_number(10.0000001)) ['A', 'B'] - sage: from sage.all import RIF + sage: from snappy.sage_helper import RIF sage: def equality_predicate(x, y): ... d = abs(x - y) ... if d < RIF(0.1): diff --git a/python/verify/interval_newton_shapes_engine.py b/python/verify/interval_newton_shapes_engine.py index f635f4f2e..f06cca7cb 100644 --- a/python/verify/interval_newton_shapes_engine.py +++ b/python/verify/interval_newton_shapes_engine.py @@ -350,7 +350,7 @@ def certified_newton_iteration(equations, shape_intervals, Intervals containing the true solution:: - sage: from sage.all import vector + sage: from snappy.sage_helper import vector sage: good_shapes = vector([ ... C.CIF(C.RIF(0.78055, 0.78056), C.RIF(0.91447, 0.91448)), ... C.CIF(C.RIF(0.78055, 0.78056), C.RIF(0.91447, 0.91448)), @@ -368,7 +368,7 @@ def certified_newton_iteration(equations, shape_intervals, Intervals not containing a true solution:: - sage: from sage.all import vector + sage: from snappy.sage_helper import vector sage: bad_shapes = vector([ ... C.CIF(C.RIF(0.78054, 0.78055), C.RIF(0.91447, 0.91448)), ... C.CIF(C.RIF(0.78055, 0.78056), C.RIF(0.91447, 0.91448)), diff --git a/python/verify/interval_tree.py b/python/verify/interval_tree.py index 08ae51dd9..b57dbda81 100644 --- a/python/verify/interval_tree.py +++ b/python/verify/interval_tree.py @@ -12,7 +12,7 @@ class IntervalTree(): Create an interval tree and add pairs to it:: - sage: from sage.all import RIF + sage: from snappy.sage_helper import RIF sage: t = IntervalTree() sage: t.insert(RIF(1.01,1.02),'1') sage: t.insert(RIF(3.01,3.02),'3') diff --git a/python/verify/krawczyk_shapes_engine.py b/python/verify/krawczyk_shapes_engine.py index 1313a3db6..5843a4017 100644 --- a/python/verify/krawczyk_shapes_engine.py +++ b/python/verify/krawczyk_shapes_engine.py @@ -288,7 +288,7 @@ def krawczyk_interval(self, shape_intervals): Do several Krawczyk operations to get a better solution:: - sage: from sage.all import vector + sage: from snappy.sage_helper import vector sage: M = Manifold("m019") sage: shapes = vector(ComplexIntervalField(53), [ 0.5+0.8j, 0.5+0.8j, 0.5+0.8j]) sage: for i in range(15): diff --git a/python/verify/maximal_cusp_area_matrix/cusp_translate_engine.py b/python/verify/maximal_cusp_area_matrix/cusp_translate_engine.py index 15a390c06..dec41493c 100644 --- a/python/verify/maximal_cusp_area_matrix/cusp_translate_engine.py +++ b/python/verify/maximal_cusp_area_matrix/cusp_translate_engine.py @@ -46,7 +46,7 @@ def canonical_translates(self, finitePoint): """ TESTS:: - sage: from sage.all import * + sage: from snappy.sage_helper import * sage: t0 = CIF(RIF(2.3, 2.30000000001), 3.4) sage: t1 = CIF(4.32, RIF(5.43, 5.4300000001)) sage: c = CuspTranslateEngine(t0, t1) @@ -106,7 +106,7 @@ def _translate_to_match(self, z, targetZ): def translate_to_match(self, finitePoint, targetFinitePoint): """ - sage: from sage.all import * + sage: from snappy.sage_helper import * sage: t0 = CIF(RIF(2.3, 2.30000000001), 3.4) sage: t1 = CIF(4.32, RIF(5.43, 5.4300000001)) sage: c = CuspTranslateEngine(t0, t1) diff --git a/python/verify/short_slopes.py b/python/verify/short_slopes.py index 3ecfd31d9..0760b50ea 100644 --- a/python/verify/short_slopes.py +++ b/python/verify/short_slopes.py @@ -20,7 +20,7 @@ def short_slopes_from_cusp_shape_and_area( cusp_shape is longitude over meridian (conjugate). l/m - sage: from sage.all import RIF, CIF + sage: from snappy.sage_helper import RIF, CIF sage: short_slopes_from_cusp_shape_and_area(CIF(RIF(1.0),RIF(1.3333,1.3334)), RIF(12.0)) [(1, 0), (-2, 1), (-1, 1), (0, 1)] diff --git a/python/verify/upper_halfspace/extended_matrix.py b/python/verify/upper_halfspace/extended_matrix.py index 2997069e9..43cae35ad 100644 --- a/python/verify/upper_halfspace/extended_matrix.py +++ b/python/verify/upper_halfspace/extended_matrix.py @@ -15,7 +15,7 @@ class ExtendedMatrix(): Multiply two extended matrix:: - sage: from sage.all import matrix, CIF + sage: from snappy.sage_helper import matrix, CIF sage: m = ExtendedMatrix(matrix([[CIF(2), CIF(0,2)],[CIF(1,2), CIF(3,4)]])) sage: m2 = ExtendedMatrix(matrix.identity(CIF, 2), isOrientationReversing = True) sage: m * m2 diff --git a/python/verify/upper_halfspace/finite_point.py b/python/verify/upper_halfspace/finite_point.py index 0920b4c5f..8a90faf05 100644 --- a/python/verify/upper_halfspace/finite_point.py +++ b/python/verify/upper_halfspace/finite_point.py @@ -14,7 +14,7 @@ class FinitePoint(): A point in the upper half space model represented by the quaternion z + t * j with t > 0. For example, the point (1 + 2 * i) + 3 * j is:: - sage: from sage.all import * + sage: from snappy.sage_helper import * sage: FinitePoint(CIF(1,2),RIF(3)) FinitePoint(1 + 2*I, 3) @@ -32,7 +32,7 @@ def key_interval(self): Returns an element in ``RealIntervalField`` which can be used as key for an interval tree to implement a mapping from :class:`FinitePoint`:: - sage: from sage.all import * + sage: from snappy.sage_helper import * sage: FinitePoint(CIF(1,2),RIF(3)).key_interval() # doctest: +NUMERIC12 36.8919985104477? @@ -52,7 +52,7 @@ def translate_PSL(self, m): with coefficients in SageMath's ``ComplexIntervalField`` and have determinant 1:: - sage: from sage.all import * + sage: from snappy.sage_helper import * sage: pt = FinitePoint(CIF(1,2),RIF(3)) sage: m = matrix([[CIF(0.5), CIF(2.4, 2)],[CIF(0.0), CIF(2.0)]]) sage: pt.translate_PSL(m) # doctest: +NUMERIC12 @@ -72,7 +72,7 @@ def translate_PGL(self, m): The matrix m should be an :class:`ExtendedMatrix` or a SageMath ``Matrix`` with coefficients in SageMath's ``ComplexIntervalField``:: - sage: from sage.all import * + sage: from snappy.sage_helper import * sage: pt = FinitePoint(CIF(1,2),RIF(3)) sage: m = matrix([[CIF(0.25), CIF(1.2, 1)],[CIF(0.0), CIF(1.0)]]) sage: pt.translate_PGL(m) # doctest: +NUMERIC12 @@ -132,7 +132,7 @@ def cosh_dist(self, other): Returns cosh of the distance of this finite point to another finite point:: - sage: from sage.all import * + sage: from snappy.sage_helper import * sage: a = FinitePoint(CIF(1,2),RIF(3)) sage: b = FinitePoint(CIF(4,5),RIF(6)) sage: a.cosh_dist(b) # doctest: +NUMERIC12 @@ -177,7 +177,7 @@ def dist(self, other): """ Returns the distance of this finite point to another finite point:: - sage: from sage.all import * + sage: from snappy.sage_helper import * sage: a = FinitePoint(CIF(1,2),RIF(3)) sage: b = FinitePoint(CIF(4,5),RIF(6)) sage: a.dist(b) # doctest: +NUMERIC12 diff --git a/python/verify/upper_halfspace/ideal_point.py b/python/verify/upper_halfspace/ideal_point.py index 3d6cbb7fa..b76461aa2 100644 --- a/python/verify/upper_halfspace/ideal_point.py +++ b/python/verify/upper_halfspace/ideal_point.py @@ -42,7 +42,7 @@ def apply_Moebius(m, z): """ Applies the matrix m to the ideal point z:: - sage: from sage.all import matrix, CIF, RIF + sage: from snappy.sage_helper import matrix, CIF, RIF sage: m = matrix([[CIF(2,1), CIF(4,2)], [CIF(2,3), CIF(4,2)]]) sage: apply_Moebius(m, CIF(3,4)) # doctest: +NUMERIC12 0.643835616438356? - 0.383561643835617?*I @@ -68,7 +68,7 @@ def cross_ratio(z0, z1, z2, z3): Computes the cross ratio (according to SnapPea conventions) of four ideal points:: - sage: from sage.all import CIF + sage: from snappy.sage_helper import CIF sage: cross_ratio(Infinity, CIF(0), CIF(1), CIF(1.2, 1.3)) # doctest: +NUMERIC12 1.2000000000000000? + 1.300000000000000?*I @@ -88,7 +88,7 @@ def compute_midpoint_of_triangle_edge_with_offset(idealPoints, offset): with the side a b the midpoint. This function returns this point moved towards a by hyperbolic distance log(offset):: - sage: from sage.all import CIF, RIF + sage: from snappy.sage_helper import CIF, RIF sage: compute_midpoint_of_triangle_edge_with_offset( # doctest: +NUMERIC12 ... [ CIF(0), Infinity, CIF(1) ], RIF(5.0)) FinitePoint(0, 0.2000000000000000?) @@ -138,7 +138,7 @@ def compute_incenter_of_triangle(idealPoints): """ Computes incenter of the triangle spanned by three ideal points:: - sage: from sage.all import CIF + sage: from snappy.sage_helper import CIF sage: z0 = Infinity sage: z1 = CIF(0) sage: z2 = CIF(1) @@ -164,7 +164,7 @@ def compute_inradius_and_incenter(idealPoints): Computes inradius and incenter of the tetrahedron spanned by four ideal points:: - sage: from sage.all import CIF + sage: from snappy.sage_helper import CIF sage: z0 = Infinity sage: z1 = CIF(0) sage: z2 = CIF(1) @@ -193,7 +193,7 @@ def Euclidean_height_of_hyperbolic_triangle(idealPoints): containing the triangle or the Euclidean radius of one of its hyperbolic sides (if the projection onto the boundary is an obtuse triangle):: - sage: from sage.all import CIF + sage: from snappy.sage_helper import CIF sage: z0 = CIF(0) sage: z1 = CIF(1) sage: Euclidean_height_of_hyperbolic_triangle([z0, z1, Infinity]) From f066c7eec92c1b0fad3c9f79b396fbd87b380e2d Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Tue, 14 Jan 2025 16:26:19 -0800 Subject: [PATCH 7/8] python/verify/upper_halfspace/finite_point.py: Replace .all imports --- python/verify/upper_halfspace/finite_point.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python/verify/upper_halfspace/finite_point.py b/python/verify/upper_halfspace/finite_point.py index 8a90faf05..ed31e5eb8 100644 --- a/python/verify/upper_halfspace/finite_point.py +++ b/python/verify/upper_halfspace/finite_point.py @@ -214,7 +214,7 @@ class _FinitePointTester(): """ def matrix1(self): - from sage.all import RIF, CIF, matrix + from ...sage_helper import RIF, CIF, matrix return matrix( [[CIF(RIF(1.3), RIF(-0.4)), CIF(RIF(5.6), RIF(2.3))], [CIF(RIF(-0.3), RIF(0.1)), CIF(1)]]) @@ -223,7 +223,7 @@ def extended_matrix1(self, isOrientationReversing): return ExtendedMatrix(self.matrix1(), isOrientationReversing) def matrix2(self): - from sage.all import RIF, CIF, matrix + from ...sage_helper import RIF, CIF, matrix return matrix( [[CIF(RIF(0.3), RIF(-1.4)), CIF(RIF(3.6), RIF(6.3))], [CIF(RIF(-0.3), RIF(1.1)), CIF(1)]]) @@ -234,7 +234,7 @@ def extended_matrix2(self, isOrientationReversing): def images_have_same_distance(self, m): from sage.rings.real_mpfi import RealIntervalFieldElement - from sage.all import RIF, CIF + from ...sage_helper import RIF, CIF a = FinitePoint(CIF(RIF(3.5),RIF(-3.0)), RIF(8.5)) b = FinitePoint(CIF(RIF(4.5),RIF(-4.5)), RIF(9.6)) @@ -254,7 +254,7 @@ def images_have_same_distance(self, m): raise Exception("Distance changed %r %r" % (d_before, d_after)) def matrix_multiplication_works(self, matrices): - from sage.all import RIF, CIF, prod + from ...sage_helper import RIF, CIF, prod a = FinitePoint(CIF(RIF(3.5),RIF(-3.0)), RIF(8.5)) From 72d2904d6c9140d31ada67312735b930c1519eab Mon Sep 17 00:00:00 2001 From: Matthias Koeppe Date: Sun, 23 Nov 2025 19:57:20 -0800 Subject: [PATCH 8/8] setup.py: Declare extra 'cypari' --- setup.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/setup.py b/setup.py index 3c2ec9eab..f1a8fe213 100644 --- a/setup.py +++ b/setup.py @@ -562,12 +562,8 @@ def split_version(s : str): 'pypng', # Used to save OpenGL images. 'PyX', # Used to save PDF images of links. 'pickleshare', # To avoid https://github.com/ipython/ipython/issues/14416 + 'ipython>=5.0', ] -try: - import sage -except ImportError: - install_requires.append('cypari>=2.3') - install_requires.append('ipython>=5.0') # Get version number: exec(open('python/version.py').read()) @@ -584,8 +580,12 @@ def split_version(s : str): python_requires = '>=3.8', install_requires = install_requires, extras_require = { + "cypari": [ + "cypari>=2.3", + ], "passagemath": [ "fpylll", + "passagemath-pari", # provides cypari2 "passagemath-combinat", # sage.algebras.free_algebra "passagemath-flint", # for sage.rings.imaginary_unit "passagemath-repl", # --> sage_eval