tencent-quantum-lab / tensorcircuit

Tensor network based quantum software framework for the NISQ era
https://tensorcircuit.readthedocs.io
Apache License 2.0
252 stars 75 forks source link

`copy` operation of DM circuit forgets previous `apply_general_kraus` operations #203

Open SUSYUSTC opened 5 months ago

SUSYUSTC commented 5 months ago

copy operation of DM circuit forgets previous apply_general_kraus operations.

n = 1
c = tc.DMCircuit(n)
c.h(0)
P0 = np.array([[1.0, 0.0], [0.0, 0.0]])
P1 = np.array([[0.0, 0.0], [0.0, 1.0]])
c.apply_general_kraus([P0, P1], 0)
print('without copy')
print(c.densitymatrix())
print('with copy')
print(c.copy().densitymatrix())

Error Output

without copy
[[0.5+0.j 0. +0.j]
 [0. +0.j 0.5+0.j]]
with copy
[[0.5+0.j 0.5+0.j]
 [0.5+0.j 0.5+0.j]]
refraction-ray commented 5 months ago

Indeed, copy only copy the operations recorded on the c._qir, since channel operations is now not recorded on qir, these channels cannot move the the copied circuit