|
14 | 14 | from scipy.stats import unitary_group
|
15 | 15 |
|
16 | 16 | from .cons import backend, dtypestr, npdtype
|
17 |
| -from .backends import get_backend |
18 | 17 | from .utils import arg_alias
|
19 | 18 |
|
20 | 19 | thismodule = sys.modules[__name__]
|
@@ -257,22 +256,18 @@ def __init__(
|
257 | 256 | self.ctrl = ctrl
|
258 | 257 |
|
259 | 258 | def __call__(self, *args: Any, **kws: Any) -> Gate:
|
260 |
| - # m = array_to_tensor(self.m) |
| 259 | + m1 = array_to_tensor(self.m) |
261 | 260 | # m = backend.cast(m, dtypestr)
|
262 |
| - m = self.m.astype(npdtype) |
263 |
| - return Gate(deepcopy(m), name=self.n) |
| 261 | + m1 = backend.cast(m1, dtypestr) |
| 262 | + return Gate(m1, name=self.n) |
264 | 263 |
|
265 | 264 | def adjoint(self) -> "GateF":
|
266 | 265 | m = self.__call__()
|
267 |
| - npb = get_backend("numpy") |
268 |
| - shape0 = npb.shape_tuple(m.tensor) |
269 |
| - m0 = npb.reshapem(m.tensor) |
270 |
| - ma = npb.adjoint(m0) |
271 |
| - if np.allclose(m0, ma, atol=1e-5): |
272 |
| - name = self.n |
273 |
| - else: |
274 |
| - name = self.n + "d" |
275 |
| - ma = npb.reshape(ma, shape0) |
| 266 | + shape0 = backend.shape_tuple(m.tensor) |
| 267 | + m0 = backend.reshapem(m.tensor) |
| 268 | + ma = backend.adjoint(m0) |
| 269 | + name = self.n + "d" |
| 270 | + ma = backend.reshape(ma, shape0) |
276 | 271 | return GateF(ma, name, self.ctrl)
|
277 | 272 |
|
278 | 273 | # TODO(@refraction-ray): adjoint gate convention finally determined
|
|
0 commit comments