Skip to content

Commit 29089e6

Browse files
committed
revise thermalrelax
1 parent e563c23 commit 29089e6

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

tensorcircuit/channels.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ def thermalrelaxationchannel(
350350
p1 = backend.cast(array_to_tensor(p1), dtype=cons.dtypestr)
351351

352352
if method == "T1dom":
353-
# git avaliable
353+
# jit avaliable
354354
m0 = backend.convert_to_tensor(
355355
np.array([[1, 0], [0, 0]], dtype=cons.npdtype)
356356
) # reset channel
@@ -387,7 +387,7 @@ def thermalrelaxationchannel(
387387
return Gkraus
388388

389389
else: # method == "general" or method == "T2dom":
390-
# git avaliable
390+
# jit avaliable
391391
choi = (1 - p1 * p_reset) * backend.convert_to_tensor(
392392
np.array(
393393
[[1, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]],
@@ -698,11 +698,14 @@ def choi_to_kraus(
698698
699699
>>> kraus = tc.channels.phasedampingchannel(0.2)
700700
>>> superop = tc.channels.kraus_to_choi(kraus)
701-
>>> kraus_new = tc.channels.choi_to_kraus(superop)
701+
>>> kraus_new = tc.channels.choi_to_kraus(superop, truncation_rules={"max_singular_values":3})
702702
703703
704704
:param choi: Choi matrix
705705
:type choi: Matrix
706+
:param truncation_rules: A dictionary to restrict the calculation of kraus matrices. The restriction
707+
can be the number of kraus terms, which is jitable. It can also be the truncattion error, which is not jitable.
708+
:type truncation_rules: Dictionary
706709
:return: A list of Kraus operators
707710
:rtype: Sequence[Matrix]
708711
"""
@@ -731,7 +734,7 @@ def choi_to_kraus(
731734
kraus.append(k)
732735

733736
else:
734-
if truncation_rules.get("max_singular_values", None) is None:
737+
if truncation_rules.get("max_truncattion_err", None) is None:
735738
atol = 1e-5
736739
else:
737740
atol = truncation_rules["max_truncattion_err"]

tests/test_channels.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,29 +86,21 @@ def test_thermal(backend):
8686
time = 100
8787

8888
t1 = 180
89-
print(t1, t2)
9089
kraus = tc.channels.thermalrelaxationchannel(t1, t2, time, "general", 0.1)
9190
supop1 = tc.channels.kraus_to_super(kraus)
92-
# print(kraus)
93-
# print(supop1)
9491

9592
kraus = tc.channels.thermalrelaxationchannel(t1, t2, time, "T1dom", 0.1)
9693
supop2 = tc.channels.kraus_to_super(kraus)
97-
# print(kraus)
98-
# print(supop2)
94+
9995
np.testing.assert_allclose(supop1, supop2, atol=1e-5)
10096

10197
t1 = 80
102-
print(t1, t2)
10398
kraus = tc.channels.thermalrelaxationchannel(t1, t2, time, "general", 0.1)
10499
supop1 = tc.channels.kraus_to_super(kraus)
105-
# print(kraus)
106-
# print(supop1)
107100

108101
kraus = tc.channels.thermalrelaxationchannel(t1, t2, time, "T2dom", 0.1)
109102
supop2 = tc.channels.kraus_to_super(kraus)
110-
# print(kraus)
111-
# print(supop2)
103+
112104
np.testing.assert_allclose(supop1, supop2, atol=1e-5)
113105

114106

@@ -117,17 +109,26 @@ def test_noisecircuit(backend):
117109

118110
# Monte carlo simulation
119111
def noisecircuit(X):
120-
noise = tc.channels.thermalrelaxationchannel(300, 400, 1000, "T2dom", 0)
121112

122113
n = 1
123114
c = tc.Circuit(n)
124115
c.x(0)
125-
c.general_kraus(noise, 0, status=X)
116+
# noise = tc.channels.thermalrelaxationchannel(300, 400, 1000, "T2dom", 0)
117+
# c.general_kraus(noise, 0, status=X)
118+
c.thermalrelaxation(
119+
0,
120+
t1=300,
121+
t2=400,
122+
time=1000,
123+
method="T2dom",
124+
excitedstatepopulation=0,
125+
status=X,
126+
)
127+
126128
val = c.expectation_ps(z=[0])
127129
return val
128130

129-
noisec = noisecircuit
130-
noisec_vmap = tc.backend.vmap(noisec, vectorized_argnums=0)
131+
noisec_vmap = tc.backend.vmap(noisecircuit, vectorized_argnums=0)
131132
noisec_jit = tc.backend.jit(noisec_vmap)
132133

133134
nmc = 1000
@@ -145,9 +146,7 @@ def noisecircuitdm():
145146
val = dmc.expectation_ps(z=[0])
146147
return val
147148

148-
noisec = noisecircuitdm
149-
noisec_jit = tc.backend.jit(noisec)
150-
149+
noisec_jit = tc.backend.jit(noisecircuitdm)
151150
valuedm = noisec_jit()
152151

153152
np.testing.assert_allclose(valuemc, valuedm, atol=1e-1)

0 commit comments

Comments
 (0)