Skip to content

Commit ec4740c

Browse files
improve fss function and fix token multiprocessing issue
1 parent 4e4f5a2 commit ec4740c

File tree

5 files changed

+18
-12
lines changed

5 files changed

+18
-12
lines changed

examples/mipt_pideal.py

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
K = tc.set_backend("jax")
1313
tc.set_dtype("complex128")
1414
# tf backend is slow (at least on cpu)
15+
tc.set_contractor("cotengra-16-64")
1516

1617

1718
def delete2(pick, plist):

tensorcircuit/applications/physics/fss.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,24 @@ def data_collapse(
1818
xL: List[List[float]] = [] # x=(p-pc)L^(1/\nv)
1919
yL: List[List[float]] = [] # y=S(p,L)-S(pc,L) or S(p,L)
2020
pc_list = []
21+
if not isinstance(p[0], list):
22+
p = [p for _ in n] # type: ignore
2123
for n0 in range(len(n)):
2224
xL.append([])
2325
yL.append([])
24-
for p0 in range(len(p)):
25-
xL[n0].append((p[p0] - pc) * (n[n0] ** (1 / nu)))
26-
pc_L = pc_linear_interpolation(p, obs[n0], pc)
26+
for p0 in range(len(p[n0])): # type: ignore
27+
xL[n0].append((p[n0][p0] - pc) * (n[n0] ** (1 / nu))) # type: ignore
28+
pc_L = pc_linear_interpolation(p[n0], obs[n0], pc) # type: ignore
2729
if obs_type == 0:
28-
yL[n0].append((obs[n0][p0] - pc_L) * n[n0] ** (beta / nu))
30+
yL[n0].append((obs[n0][p0] - pc_L) * n[n0] ** beta)
2931
# entanglement with only collapse and no crossing
3032
else:
31-
yL[n0].append(obs[n0][p0] * n[n0] ** (beta / nu))
33+
yL[n0].append(obs[n0][p0] * n[n0] ** beta)
3234
# tripartite mutual information
3335
pc_list.append(pc_L)
34-
35-
xL_all = np.reshape(xL, -1)
36+
xL_all = []
37+
for i in range(len(xL)):
38+
xL_all.extend(xL[i])
3639
yL_ave = []
3740
loss = []
3841
for x0 in range(len(xL_all)):
@@ -48,7 +51,7 @@ def data_collapse(
4851
yL_ave.append(ybar)
4952
loss = np.sum(loss)
5053

51-
return pc_list, xL, np.array(yL), loss # type: ignore
54+
return pc_list, xL, yL, loss # type: ignore
5255

5356

5457
def pc_linear_interpolation(p: List[float], SA: List[float], pc_input: float) -> float:

tensorcircuit/cloud/apis.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,9 @@ def set_token(
237237
if cached:
238238
# file_token = backend.tree_map(b64encode_s, saved_token)
239239
file_token = {k: b64encode_s(v) for k, v in saved_token.items()}
240-
241-
with open(authpath, "w") as f:
242-
json.dump(file_token, f)
240+
if file_token:
241+
with open(authpath, "w") as f:
242+
json.dump(file_token, f)
243243

244244
return saved_token
245245

tensorcircuit/experimental.py

+1
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ def grad_f(*args: Any, **kws: Any) -> Any:
347347

348348

349349
# TODO(@refraction-ray): add SPSA gradient wrapper similar to parameter shift
350+
# -- using noisyopt package instead
350351

351352

352353
def finite_difference_differentiator(

tensorcircuit/mpscircuit.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ def split_tensor(
5252
return backend.qr(tensor) # type: ignore
5353

5454

55-
# TODO(@refraction-ray): AD + MPS can lead to numerical stability issue
55+
# AD + MPS can lead to numerical stability issue
5656
# E ./tensorflow/core/kernels/linalg/svd_op_impl.h:110] Eigen::BDCSVD failed with error code 3
57+
# this is now solved by setting os.environ["TC_BACKENDS_TENSORFLOW_BACKEND__SVD_TF_EPS"]="10"
5758

5859

5960
class MPSCircuit(AbstractCircuit):

0 commit comments

Comments
 (0)