TypeError when printing wavefunction
ejdanderson opened this issue · comments
Evan Anderson commented
Printing out the wavefunction using the Reference QVM throws a type error as pyQuil attempts to perform various scalar math operations.
For example:
from referenceqvm import api
import pyquil.quil as pq
from pyquil.gates import *
qvm = api.SyncConnection()
p = pq.Program(H(0), CNOT(0,1))
prog = pq.Program().inst(H(0)).measure(0, [0]).measure(0, [1])
result = qvm.run(prog, [0, 1])
for index, amplitude in enumerate(qvm.wavefunction(p)[0]):
print(amplitude)
print(amplitude.real)
print('--')
print(qvm.wavefunction(p)[0])
produces the following output :
[ 0.70710678+0.j]
[ 0.70710678]
--
[ 0.+0.j]
[ 0.]
--
[ 0.+0.j]
[ 0.]
--
[ 0.70710678+0.j]
[ 0.70710678]
--
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-1-8e1890fb773d> in <module>()
14 print('--')
15
---> 16 print(qvm.wavefunction(p)[0])
/usr/local/lib/python3.6/site-packages/pyquil/wavefunction.py in __str__(self)
29
30 def __str__(self):
---> 31 return self.pretty_print(decimal_digits=10)
32
33 def get_outcome_probs(self):
/usr/local/lib/python3.6/site-packages/pyquil/wavefunction.py in pretty_print(self, decimal_digits)
79 for index, amplitude in enumerate(self):
80 outcome = get_bitstring_from_index(index, qubit_num)
---> 81 amplitude = round(amplitude.real, decimal_digits) + \
82 round(amplitude.imag, decimal_digits) * 1.j
83 if amplitude != 0.:
TypeError: type numpy.ndarray doesn't define __round__ method