This is with python 2.5.1, numpy 1.5.0, no scipy, no gmpy on OSX
10.5.8 PPC (big endian).
I can get the error from just importing
sympy.physics.quantum.matrixcache. It makes sense because we are
passing sympy.I with dtype 'complex' to numpy.
Ted
Traceback (most recent call last):
File "setup.py", line 269, in <module>
'audit' : audit,
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/distutils/core.py", line 151, in setup
dist.run_commands()
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/distutils/dist.py", line 974, in run_commands
self.run_command(cmd)
File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/distutils/dist.py", line 994, in run_command
cmd_obj.run()
File "setup.py", line 161, in run
if sympy.test():
File "sympy/utilities/runtests.py", line 181, in test
return t.test(sort=sort)
File "sympy/utilities/runtests.py", line 487, in test
self.test_file(f)
File "sympy/utilities/runtests.py", line 499, in test_file
execfile(filename, gl)
File "/users/ted/developer/opensource/sympy/sympy_github2/sympy/
physics/quantum/tests/test_gate.py", line 4, in <module>
from sympy.physics.quantum.gate import (XGate, YGate, ZGate,
random_circuit,
File "sympy/physics/quantum/gate.py", line 31, in <module>
from sympy.physics.quantum.matrixcache import matrix_cache
File "sympy/physics/quantum/matrixcache.py", line 92, in <module>
matrix_cache.cache_matrix('Y', Matrix([[0, -I], [I, 0]]))
File "sympy/physics/quantum/matrixcache.py", line 38, in cache_matrix
self._numpy_matrix(name, m)
File "sympy/physics/quantum/matrixcache.py", line 72, in
_numpy_matrix
m = to_numpy(m, dtype=self.dtype)
File "sympy/physics/quantum/matrixutils.py", line 99, in to_numpy
return sympy_to_numpy(m, dtype=dtype)
File "sympy/physics/quantum/matrixutils.py", line 53, in
sympy_to_numpy
return np.matrix(m.tolist(), dtype=dtype)
File "numpy/matrixlib/defmatrix.py", line 257, in __new__
TypeError: a float is required
I'll see if I can figure out how to fix at least the numpy one for the
release. Do you know how to fix it? If so, please send a pull
request.
Aaron Meurer
On Sat, Jun 18, 2011 at 1:03 PM, Ted Horst <ted....@earthlink.net> wrote:
> I'm a little late to the party, but I just tested 0.7.0 tip and got this
> error (stopped testing):
>
> This is with python 2.5.1, numpy 1.5.0, no scipy, no gmpy on OSX 10.5.8 PPC
> (big endian).
>
> I can get the error from just importing sympy.physics.quantum.matrixcache.
> It makes sense because we are passing sympy.I with dtype 'complex' to
> numpy.
>
> Ted
>
> Traceback (most recent call last):
> File "setup.py", line 269, in <module>
> 'audit' : audit,
> File
> "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/distutils/core.py",
> line 151, in setup
> dist.run_commands()
> File
> "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/distutils/dist.py",
> line 974, in run_commands
> self.run_command(cmd)
> File
> "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/distutils/dist.py",
> line 994, in run_command
> cmd_obj.run()
> File "setup.py", line 161, in run
> if sympy.test():
> File "sympy/utilities/runtests.py", line 181, in test
> return t.test(sort=sort)
> File "sympy/utilities/runtests.py", line 487, in test
> self.test_file(f)
> File "sympy/utilities/runtests.py", line 499, in test_file
> execfile(filename, gl)
> File
> "/users/ted/developer/opensource/sympy/sympy_github2/sympy/physics/quantum/tests/test_gate.py",
> line 4, in <module>
> from sympy.physics.quantum.gate import (XGate, YGate, ZGate,
> random_circuit,
> File "sympy/physics/quantum/gate.py", line 31, in <module>
> from sympy.physics.quantum.matrixcache import matrix_cache
> File "sympy/physics/quantum/matrixcache.py", line 92, in <module>
> matrix_cache.cache_matrix('Y', Matrix([[0, -I], [I, 0]]))
> File "sympy/physics/quantum/matrixcache.py", line 38, in cache_matrix
> self._numpy_matrix(name, m)
> File "sympy/physics/quantum/matrixcache.py", line 72, in _numpy_matrix
> m = to_numpy(m, dtype=self.dtype)
> File "sympy/physics/quantum/matrixutils.py", line 99, in to_numpy
> return sympy_to_numpy(m, dtype=dtype)
> File "sympy/physics/quantum/matrixutils.py", line 53, in sympy_to_numpy
> return np.matrix(m.tolist(), dtype=dtype)
> File "numpy/matrixlib/defmatrix.py", line 257, in __new__
> TypeError: a float is required
>
> --
> 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.
>
>
Can someone with numpy knowledge give any insight here? Otherwise, I
think the solution might have to be to disable numpy support in the
quantum code in Python 2.5.
I haven't looked at why it kills the test runner yet. I'll look at that now.
By the way, a workaround might be to do np.matrix([map(complex, i) for
i in m.tolist()], dtype=complex), i.e., manually convert the elements
of the Matrix to complex, but this is rather hackish and I would
prefer to aviod it if possible.
Aaron Meurer
Oh, this is rather obvious. It's because the exception is raised at
import time. If it were raised when running an actual test, it would
be caught by the test runner. This is probably OK behavior (anyway,
it's not top priority to change it).
Aaron Meurer
>>> numpy.matrix([[0, I]], dtype='complex')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/numpy/matrixlib/defmatrix.py",
line 257, in __new__
arr = N.array(data, dtype=dtype, copy=copy)
File "sympy/core/expr.py", line 129, in __float__
raise ValueError("Symbolic value, can't compute")
ValueError: Symbolic value, can't compute
in Python 2.5 (and it works in Python 2.6 and 2.7). So I guess the
bug is in SymPy somewhere, and numpy 1.5 was catching that ValueError
and re-throwing it as a TypeError.
Aaron Meurer
import numpy
class A(object):
def __float__(self):
return 2.0
def __complex__(self):
return 5.0j
a = A()
print numpy.matrix([[a]], dtype='complex')
And ran:
Aaron-Meurer:sympy aaronmeurer(0.7.0$%)$python2.5 numpyfloattest.py
[[ 2.+0.j]]
Aaron-Meurer:sympy aaronmeurer(0.7.0$%)$python2.7 numpyfloattest.py
[[ 0.+5.j]]
So for some reason, in Python 2.5, it runs complex(float()) on the
data. Of course, this doesn't work very well if the numbers are
complex, like sympy.I.
I have created http://projects.scipy.org/numpy/ticket/1872 for this.
In the meanwhile, I will just disable numpy in the quantum code in
Python 2.5.
Aaron Meurer
So, to fix this right, I need advice from Brian and others who know
the quantum code. Where would be the best place to put some kind of
global parameter defining if numpy is supported for the quantum code
(similar to what the polys use for gmpy)?
Aaron Meurer
Ted
Aaron Meurer
>>>> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/numpy/matrixlib/defmatrix.py",
>>>>>>>> "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/distutils/core.py",
>>>>>>>> line 151, in setup
>>>>>>>> dist.run_commands()
>>>>>>>> File
>>>>>>>>
>>>>>>>> "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/distutils/dist.py",
>>>>>>>> line 974, in run_commands
>>>>>>>> self.run_command(cmd)
>>>>>>>> File
>>>>>>>>
>>>>>>>> "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/distutils/dist.py",
>>>>>>>> line 994, in run_command
>>>>>>>> cmd_obj.run()
>>>>>>>> File "setup.py", line 161, in run
>>>>>>>> if sympy.test():
>>>>>>>> File "sympy/utilities/runtests.py", line 181, in test
>>>>>>>> return t.test(sort=sort)
>>>>>>>> File "sympy/utilities/runtests.py", line 487, in test
>>>>>>>> self.test_file(f)
>>>>>>>> File "sympy/utilities/runtests.py", line 499, in test_file
>>>>>>>> execfile(filename, gl)
>>>>>>>> File
>>>>>>>>
>>>>>>>> "/users/ted/developer/opensource/sympy/sympy_github2/sympy/physics/quantum/tests/test_gate.py",
I've yet to apply this everywhere in SymPy (I will do it tomorrow). I
still need to decide if it will be good enough to use
import_module('numpy', min_python_version=(2, 6)) everywhere in the
quantum module, or if I should centralize numpy importing in that
module even further.
But it should a *lot* less code, i.e., instead of
import sys
import warnings
try:
if sys.version_info < (2, 6):
warnings.warn("Python version too old to use numpy")
raise ImportError
import numpy
except ImportError:
<do numpy not supported stuff>
in every single quantum file that uses numpy (including the tests), we
would just have
from sympy.external import import_module
numpy = import_module('numpy', min_python_version=(2, 6))
if not numpy:
<do numpy not supported stuff>
Aaron Meurer
Ted
So numpy is optionally imported in the quantum module, and sympy fails
to import with a particular version of numpy and python2.5?
If it's just a test failure on a particular combination of
numpy/python and it's not easy for us to fix currently, I would just
document it in the release notes and release.
Ondrej
> Seem like it would be more consistent to raise an ImportError rather than return None. That would also mean less change to existing code.
That would defeat the whole purpose of the function, except when we need to check for versions or you want to emit a warning. Remember that this is for *optional* dependencies, so it will always be used in the case where we catch the ImportError and do some handling.
> Thinking a bit further, could this be done in an import hook (I haven't done one myself, so not sure)?
I've never heard of those. I'll check it out and see if it's any better.
Aaron Meurer
>>>>>>> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/numpy/matrixlib/defmatrix.py",
>>>>>>>>>>> "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/distutils/core.py",
>>>>>>>>>>> line 151, in setup
>>>>>>>>>>> dist.run_commands()
>>>>>>>>>>> File
>>>>>>>>>>>
>>>>>>>>>>> "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/distutils/dist.py",
>>>>>>>>>>> line 974, in run_commands
>>>>>>>>>>> self.run_command(cmd)
>>>>>>>>>>> File
>>>>>>>>>>>
>>>>>>>>>>> "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/distutils/dist.py",
>>>>>>>>>>> line 994, in run_command
>>>>>>>>>>> cmd_obj.run()
>>>>>>>>>>> File "setup.py", line 161, in run
>>>>>>>>>>> if sympy.test():
>>>>>>>>>>> File "sympy/utilities/runtests.py", line 181, in test
>>>>>>>>>>> return t.test(sort=sort)
>>>>>>>>>>> File "sympy/utilities/runtests.py", line 487, in test
>>>>>>>>>>> self.test_file(f)
>>>>>>>>>>> File "sympy/utilities/runtests.py", line 499, in test_file
>>>>>>>>>>> execfile(filename, gl)
>>>>>>>>>>> File
>>>>>>>>>>>
>>>>>>>>>>> "/users/ted/developer/opensource/sympy/sympy_github2/sympy/physics/quantum/tests/test_gate.py",
>> To unsubscribe from this group, send email to sympy+un...@googlegroups.com.
Just returned from being out of town for 4 days. I will try to get
caught up on sympy things tomorrow.
Brian
--
Brian E. Granger
Cal Poly State University, San Luis Obispo
bgra...@calpoly.edu and elli...@gmail.com
Another question that came up when doing this: how do I test the
circuitplot module to make sure it works? I didn't see any tests or
examples that used it anywhere.
Aaron Meurer
> Ondřej
The problem is that it's more than a test failure. Importing the quantum module fails, which kills the test runner completely. So actually, it's not really correct that numpy is optionally imported. If it's installed, it's always imported and used.
And it's not too hard to fix. We just need to disable numpy in the quantum code in Python 2.4/2.5. I wrote this helper function to make it easier to do this.
Aaron Meurer
Thanks Aaron
> --
> You received this message because you are subscribed to the Google
> Groups "sympy" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/sympy/-/YjYpu_8OJJkJ