Skip to content

Instantly share code, notes, and snippets.

@cswiercz
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cswiercz/13c55fd707248301e734 to your computer and use it in GitHub Desktop.
Save cswiercz/13c55fd707248301e734 to your computer and use it in GitHub Desktop.
abelfunctions Issue #51 - Simple Discriminant Path Construction Performance (Code)
import numpy
import sympy
import abelfunctions as ab
from sympy.abc import x,y
# construct a Riemann surface
f = -x**7 + 2*x**3*y + y**3
X = ab.RiemannSurface(f,x,y)
# get a discriminant place (the ones with x=0 are the current working
# ones in this example surface)
places = X(0)
for P in places:
print P
print
# output:
#
# x(t) = (1)t**1
# y(t) = + (1/2)t**4 + (-1/16)t**9+ O(t**10)
#
# x(t) = (-1/2)t**2
# y(t) = + (-1/2)t**3 + (-1/64)t**8+ O(t**9)
# compute the path and profile the stats
P = places[1]
import cProfile
import pstats
cProfile.run("gamma = X.path(P)",'path.profile')
p = pstats.Stats('path.profile')
p.strip_dirs()
p.sort_stats('time').print_stats(15)
p.sort_stats('cumulative').print_stats(15)
p.sort_stats('calls').print_stats(15)
Fri Oct 17 10:30:07 2014 path.profile
114480 function calls (110626 primitive calls) in 0.302 seconds
Ordered by: internal time
List reduced from 827 to 15 due to restriction <15>
ncalls tottime percall cumtime percall filename:lineno(function)
2285/1546 0.020 0.000 0.129 0.000 cache.py:78(wrapper)
15865 0.013 0.000 0.013 0.000 {isinstance}
251 0.010 0.000 0.022 0.000 facts.py:481(deduce_all_facts)
820 0.009 0.000 0.015 0.000 basic.py:333(__eq__)
4258/3875 0.009 0.000 0.030 0.000 sympify.py:52(sympify)
83/82 0.007 0.000 0.043 0.001 mul.py:95(flatten)
2938 0.006 0.000 0.011 0.000 numbers.py:400(__hash__)
4751/4531 0.005 0.000 0.007 0.000 basic.py:100(__hash__)
329/164 0.005 0.000 0.049 0.000 evalf.py:1180(evalf)
1643 0.005 0.000 0.007 0.000 numbers.py:1554(__new__)
3017 0.005 0.000 0.005 0.000 facts.py:464(_tell)
1715/916 0.005 0.000 0.118 0.000 decorators.py:70(__sympifyit_wrapper)
2197 0.004 0.000 0.011 0.000 numbers.py:1395(__hash__)
126/12 0.004 0.000 0.018 0.002 function.py:985(__new__)
4632 0.004 0.000 0.005 0.000 facts.py:515(<genexpr>)
Fri Oct 17 10:30:07 2014 path.profile
114480 function calls (110626 primitive calls) in 0.302 seconds
Ordered by: cumulative time
List reduced from 827 to 15 due to restriction <15>
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.302 0.302 <string>:1(<module>)
1 0.000 0.000 0.302 0.302 {method 'path' of 'abelfunctions.riemann_surface.RiemannSurface' objects}
1 0.000 0.000 0.302 0.302 riemann_surface_path_factory.py:186(path_to_place)
1 0.001 0.001 0.302 0.302 riemann_surface_path_factory.py:199(_path_to_discriminant_place)
2285/1546 0.020 0.000 0.129 0.000 cache.py:78(wrapper)
24 0.000 0.000 0.119 0.005 puiseux.py:1477(evalf)
1715/916 0.005 0.000 0.118 0.000 decorators.py:70(__sympifyit_wrapper)
526/493 0.001 0.000 0.079 0.000 decorators.py:108(binary_op_wrapper)
24 0.001 0.000 0.073 0.003 puiseux.py:1460(eval)
1 0.000 0.000 0.071 0.071 riemann_surface_path_factory.py:242(_path_to_regular_place)
1 0.003 0.003 0.066 0.066 riemann_surface_path_factory.py:456(RiemannSurfacePath_from_xpath)
173/164 0.002 0.000 0.053 0.000 evalf.py:1235(evalf)
146/116 0.002 0.000 0.053 0.000 operations.py:27(__new__)
3 0.001 0.000 0.052 0.017 puiseux.py:962(extend_to_t)
329/164 0.005 0.000 0.049 0.000 evalf.py:1180(evalf)
Fri Oct 17 10:30:07 2014 path.profile
114480 function calls (110626 primitive calls) in 0.302 seconds
Ordered by: call count
List reduced from 827 to 15 due to restriction <15>
ncalls tottime percall cumtime percall filename:lineno(function)
15865 0.013 0.000 0.013 0.000 {isinstance}
5046 0.002 0.000 0.002 0.000 {method 'get' of 'dict' objects}
4751/4531 0.005 0.000 0.007 0.000 basic.py:100(__hash__)
4632 0.004 0.000 0.005 0.000 facts.py:515(<genexpr>)
4258/3875 0.009 0.000 0.030 0.000 sympify.py:52(sympify)
3017 0.005 0.000 0.005 0.000 facts.py:464(_tell)
2938 0.006 0.000 0.011 0.000 numbers.py:400(__hash__)
2907 0.003 0.000 0.003 0.000 {hasattr}
2857/2800 0.001 0.000 0.001 0.000 {len}
2285/1546 0.020 0.000 0.129 0.000 cache.py:78(wrapper)
2197 0.004 0.000 0.011 0.000 numbers.py:1395(__hash__)
2067 0.003 0.000 0.009 0.000 sympify.py:320(_sympify)
2052 0.001 0.000 0.001 0.000 basic.py:700(args)
1717 0.001 0.000 0.001 0.000 {method 'items' of 'dict' objects}
1715/916 0.005 0.000 0.118 0.000 decorators.py:70(__sympifyit_wrapper)
This new performance data is from the same test above but where all of the
internal Puiseux data is first coerced to numerical (complex) types as
opposed to using "numpy.complex(sympy_expression.n())" with every
evaluation.
Fri Oct 17 11:16:20 2014 path.profile
81921 function calls (79472 primitive calls) in 0.212 seconds
Ordered by: internal time
List reduced from 822 to 15 due to restriction <15>
ncalls tottime percall cumtime percall filename:lineno(function)
1731/1478 0.014 0.000 0.068 0.000 cache.py:78(wrapper)
13091 0.010 0.000 0.011 0.000 {isinstance}
3444/3067 0.007 0.000 0.026 0.000 sympify.py:52(sympify)
568 0.006 0.000 0.010 0.000 basic.py:333(__eq__)
126/12 0.004 0.000 0.018 0.002 function.py:985(__new__)
83 0.004 0.000 0.010 0.000 polyoptions.py:126(__init__)
1750 0.004 0.000 0.006 0.000 numbers.py:400(__hash__)
3057/3001 0.003 0.000 0.004 0.000 basic.py:100(__hash__)
218/135 0.003 0.000 0.031 0.000 evalf.py:1180(evalf)
1 0.003 0.003 0.066 0.066 riemann_surface_path_factory.py:456(RiemannSurfacePath_from_xpath)
89 0.003 0.000 0.007 0.000 facts.py:481(deduce_all_facts)
1150/756 0.003 0.000 0.064 0.000 decorators.py:70(__sympifyit_wrapper)
50 0.003 0.000 0.011 0.000 polyutils.py:144(_parallel_dict_from_expr_if_gens)
1246 0.003 0.000 0.005 0.000 numbers.py:1554(__new__)
2202 0.003 0.000 0.003 0.000 {hasattr}
Fri Oct 17 11:16:20 2014 path.profile
81921 function calls (79472 primitive calls) in 0.212 seconds
Ordered by: cumulative time
List reduced from 822 to 15 due to restriction <15>
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.212 0.212 <string>:1(<module>)
1 0.000 0.000 0.212 0.212 {method 'path' of 'abelfunctions.riemann_surface.RiemannSurface' objects}
1 0.000 0.000 0.212 0.212 riemann_surface_path_factory.py:186(path_to_place)
1 0.001 0.001 0.212 0.212 riemann_surface_path_factory.py:199(_path_to_discriminant_place)
1 0.000 0.000 0.070 0.070 riemann_surface_path_factory.py:242(_path_to_regular_place)
1731/1478 0.014 0.000 0.068 0.000 cache.py:78(wrapper)
3 0.001 0.000 0.067 0.022 puiseux.py:967(extend_to_t)
1 0.003 0.003 0.066 0.066 riemann_surface_path_factory.py:456(RiemannSurfacePath_from_xpath)
1150/756 0.003 0.000 0.064 0.000 decorators.py:70(__sympifyit_wrapper)
56 0.001 0.000 0.041 0.001 polytools.py:69(__new__)
1 0.000 0.000 0.039 0.039 puiseux.py:619(puiseux)
144/135 0.001 0.000 0.036 0.000 evalf.py:1235(evalf)
52 0.000 0.000 0.032 0.001 polytools.py:194(_from_expr)
42 0.001 0.000 0.032 0.001 basic.py:758(as_poly)
218/135 0.003 0.000 0.031 0.000 evalf.py:1180(evalf)
Fri Oct 17 11:16:20 2014 path.profile
81921 function calls (79472 primitive calls) in 0.212 seconds
Ordered by: call count
List reduced from 822 to 15 due to restriction <15>
ncalls tottime percall cumtime percall filename:lineno(function)
13091 0.010 0.000 0.011 0.000 {isinstance}
3444/3067 0.007 0.000 0.026 0.000 sympify.py:52(sympify)
3057/3001 0.003 0.000 0.004 0.000 basic.py:100(__hash__)
2488 0.001 0.000 0.001 0.000 {method 'get' of 'dict' objects}
2202 0.003 0.000 0.003 0.000 {hasattr}
1940/1883 0.001 0.000 0.001 0.000 {len}
1750 0.004 0.000 0.006 0.000 numbers.py:400(__hash__)
1731/1478 0.014 0.000 0.068 0.000 cache.py:78(wrapper)
1590 0.001 0.000 0.001 0.000 basic.py:700(args)
1572 0.002 0.000 0.007 0.000 sympify.py:320(_sympify)
1566 0.001 0.000 0.002 0.000 facts.py:515(<genexpr>)
1494 0.000 0.000 0.000 0.000 polyoptions.py:38(postprocess)
1246 0.003 0.000 0.005 0.000 numbers.py:1554(__new__)
1243 0.002 0.000 0.006 0.000 numbers.py:1395(__hash__)
1222 0.001 0.000 0.001 0.000 {method 'append' of 'list' objects}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment