OK.  You can follow my fixes at my external branch (it's almost ready
for review).

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

On Wed, Jun 22, 2011 at 11:47 PM, Brian Granger <[email protected]> wrote:
> Hi,
>
> Just returned from being out of town for 4 days.  I will try to get
> caught up on sympy things tomorrow.
>
> Brian
>
> On Sun, Jun 19, 2011 at 10:42 PM, Aaron Meurer <[email protected]> wrote:
>> The way the quantum code is written, it's not very easy to disable
>> numpy globally.  I could do it, but it would require copying the same
>> four lines checking the system version and emitting a warning in the
>> half dozen files that import numpy.
>>
>> 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
>>
>> On Sun, Jun 19, 2011 at 8:38 PM, Aaron Meurer <[email protected]> wrote:
>>> OK, this is definitely a bug in numpy (or Python).  I created a file
>>> numpyfloattest.py with the following contents:
>>>
>>> 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
>>>
>>> On Sun, Jun 19, 2011 at 8:04 PM, Aaron Meurer <[email protected]> wrote:
>>>> I think I have a lead.  In numpy 1.6, this instead gives
>>>>
>>>>>>> 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
>>>>
>>>> On Sun, Jun 19, 2011 at 7:39 PM, Aaron Meurer <[email protected]> wrote:
>>>>> On Sun, Jun 19, 2011 at 7:32 PM, Aaron Meurer <[email protected]> wrote:
>>>>>> I don't know much about numpy, so this one has me stumped.  For some
>>>>>> reason numpy.matrix([[0, I]], dtype='complex') fails in Python 2.5
>>>>>> (with the above error), but not in Python 2.6 or 2.7 (I is sympy.I).
>>>>>>
>>>>>> 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.
>>>>>
>>>>> 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
>>>>>
>>>>>>
>>>>>> 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
>>>>>>
>>>>>>
>>>>>> On Sun, Jun 19, 2011 at 5:36 PM, Aaron Meurer <[email protected]> wrote:
>>>>>>> Thanks for reporting this.  It seems you've uncovered two bugs (the
>>>>>>> second one is that the error killed the test runner).
>>>>>>>
>>>>>>> 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 <[email protected]> 
>>>>>>> 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 [email protected].
>>>>>>>> To unsubscribe from this group, send email to
>>>>>>>> [email protected].
>>>>>>>> For more options, visit this group at
>>>>>>>> http://groups.google.com/group/sympy?hl=en.
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>
>
>
> --
> Brian E. Granger
> Cal Poly State University, San Luis Obispo
> [email protected] and [email protected]
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to