Running 'python bin/sympy_time.py', I realised that importing sympy
pulls in a lot of stuff that are irrelevant to an end user, like pdb,
doctest or py.test. Fixing this simply requires removing the imports of
runtests and pytest from sympy/utilities/__init.py and importing those
modules explicitly where they are required.
More generally, I've often been annoyed by the fact that it's impossible
to import only part of sympy and by the sheer amount of bloat in the
sympy namespace (len(dir(sympy)) == 497), so I'd rather like that we
start exercising some restraint in what we put in the "__init__.py"s.
What do you think?
Ronan
This should be done.
>
> More generally, I've often been annoyed by the fact that it's impossible
> to import only part of sympy and by the sheer amount of bloat in the
> sympy namespace (len(dir(sympy)) == 497), so I'd rather like that we
> start exercising some restraint in what we put in the "__init__.py"s.
Yes, definitely.
>
> What do you think?
I think that the main "sympy" module should provide some reasonable
set of tools, right away. Maybe we can remove some things from the
global namespace into modules.
For specialized things, one should import things explicitly. For
example the physics quantum code needs to be imported from
sympy.physics.hydrogen and so on.
Ondrej
Or another idea would be to just import ode (the module) into the
namespace, and then you just use ode.classify_ode(), or from ode
import classify_ode if you are going to use it a lot. Or does this
take just as much time as importing into the global namespace in the
first place?
Also, I have heard that it might be possible to do lazy importing, so
for example, you don't actually import all the internal functions in
ode.py until someone calls dsolve(). You should be able to do some
magic using __import__() in either case, right?
Can we do more advanced benchmarks to see which modules are slowing
the import time down the most?
Aaron Meurer
> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To post to this group, send email to sy...@googlegroups.com.
> To unsubscribe from this group, send email to sympy+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
>
>
Aaron Meurer
We need to experiment. I think we all agree that something like you
describe is desirable to do.
I think that basic "import sympy" should only import the core, plus
some basic functions, and then limits, integrals, solve, dsolve. Maybe
some more things.
And the rest should simply by not imported at all, and the user has to
import it by hand. That means, that dsolve() has to import the stuff
from withing the function itself, so that it gets "lazy imported".
>
> Or another idea would be to just import ode (the module) into the
> namespace, and then you just use ode.classify_ode(), or from ode
> import classify_ode if you are going to use it a lot. Or does this
> take just as much time as importing into the global namespace in the
> first place?
>
> Also, I have heard that it might be possible to do lazy importing, so
> for example, you don't actually import all the internal functions in
> ode.py until someone calls dsolve(). You should be able to do some
> magic using __import__() in either case, right?
>
> Can we do more advanced benchmarks to see which modules are slowing
> the import time down the most?
I do that usually by commenting out things in the sympy/__init__.py.
The problem is that sometimes things are interrelated, so one needs to
be a bit careful.
Ondrej
For example the special functions should *not* be imported by default,
as there will be tons of them. And one will just do:
from sympy.special import Ylm
and so on. That should be easy to do.
Ondrej
https://github.com/sympy/sympy/pull/30
> >
> > What do you think?
>
> I think that the main "sympy" module should provide some reasonable
> set of tools, right away. Maybe we can remove some things from the
> global namespace into modules.
>
+1
> For specialized things, one should import things explicitly. For
> example the physics quantum code needs to be imported from
> sympy.physics.hydrogen and so on.
>
> Ondrej
>
There a few rather self-contained subpackages that shouldn't be
imported, then. These are physics, geometry and galgebra. It seems more
difficult to compartmentise all the mathematical stuff (e.g. N-theory
might seem to be an advanced and specialised topic but we certainly need
primality testing everywhere).
It sounds like we need one of those packages that draws an
interrelationship graph of all the modules.
Aaron Meurer
Aaron Meurer