Skip to content

Commit 0dbbee8

Browse files
fix numpy backend non jittable adjoint gate
1 parent 54b99d6 commit 0dbbee8

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
- Add tests and fixed some missing methods for cupy backend, cupy backend is now ready to use (though still not guaranteed)
1616

17+
- Fix adjoint gate numpy conversion for fixed gate case
18+
1719
## 0.8.0
1820

1921
### Added

tensorcircuit/gates.py

+8-13
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from scipy.stats import unitary_group
1515

1616
from .cons import backend, dtypestr, npdtype
17-
from .backends import get_backend
1817
from .utils import arg_alias
1918

2019
thismodule = sys.modules[__name__]
@@ -257,22 +256,18 @@ def __init__(
257256
self.ctrl = ctrl
258257

259258
def __call__(self, *args: Any, **kws: Any) -> Gate:
260-
# m = array_to_tensor(self.m)
259+
m1 = array_to_tensor(self.m)
261260
# 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)
264263

265264
def adjoint(self) -> "GateF":
266265
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)
276271
return GateF(ma, name, self.ctrl)
277272

278273
# TODO(@refraction-ray): adjoint gate convention finally determined

0 commit comments

Comments
 (0)