-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Description
It turns out that computations of grid coordinates are done more conveniently using numpy integer arrays than 2-tuples of python ints. However, when offsets thus computed are used with GridQubit exception is raised. For example:
In [2]: q = cirq.GridQubit(10, 20)
In [3]: d = np.array([2, 3], dtype=int)
In [4]: q + d
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-4-2e9dafea4fc1> in <module>
----> 1 q + d
~/src/Cirq/cirq/devices/grid_qubit.py in __add__(self, other)
81 if not (isinstance(other, tuple) and len(other) == 2 and
82 all(isinstance(x, int) for x in other)):
---> 83 raise TypeError('Can only add integer tuples of length 2 to '
84 f'{type(self).__name__}. Instead was {other}')
85 return self._with_row_col(row=self.row + other[0],
TypeError: Can only add integer tuples of length 2 to GridQubit. Instead was [2 3]
In [5]: q + tuple(int(v) for v in d)
Out[5]: cirq.GridQubit(12, 23)
It'd be nice to be able to say q + d
instead of having to write q + tuple(int(v) for v in d)
or similar.
Metadata
Metadata
Assignees
Labels
No labels