Skip to content

Commit 86026fa

Browse files
new black
1 parent 11fc3b6 commit 86026fa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+87
-33
lines changed

docs/source/tutorials/barren_plateaus_cn.ipynb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@
158158
" dtype=\"float32\",\n",
159159
")\n",
160160
"\n",
161-
"e, grad = op_expectation_vmap_vvag(params, seed, n, nlayers) # 不同随机电路的 ZZ 可观测量和梯度的期望\n",
161+
"e, grad = op_expectation_vmap_vvag(\n",
162+
" params, seed, n, nlayers\n",
163+
") # 不同随机电路的 ZZ 可观测量和梯度的期望\n",
162164
"\n",
163165
"grad_var = tf.math.reduce_std(tf.math.reduce_std(grad, axis=0), axis=0)[\n",
164166
" 0, 0\n",

docs/source/tutorials/nnvqe_cn.ipynb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@
115115
"metadata": {},
116116
"outputs": [],
117117
"source": [
118-
"def MERA(inp, n, d=1, lamb=1.0, energy_flag=False): # 对于单变量一维XXZ模型,我们固定lamb\n",
118+
"def MERA(\n",
119+
" inp, n, d=1, lamb=1.0, energy_flag=False\n",
120+
"): # 对于单变量一维XXZ模型,我们固定lamb\n",
119121
" params = K.cast(inp[\"params\"], \"complex128\")\n",
120122
" delta = K.cast(inp[\"delta\"], \"complex128\")\n",
121123
" c = tc.Circuit(n)\n",

docs/source/tutorials/optimization_and_expressibility_cn.ipynb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,9 @@
276276
"@tf.function\n",
277277
"def entropy(v):\n",
278278
" ψ = get_state(v)\n",
279-
" ρ_reduced = tc.quantum.reduced_density_matrix(ψ, NA) # 部分描绘出子系统A得到的降密度矩阵\n",
279+
" ρ_reduced = tc.quantum.reduced_density_matrix(\n",
280+
" ψ, NA\n",
281+
" ) # 部分描绘出子系统A得到的降密度矩阵\n",
280282
" S = tc.quantum.renyi_entropy(ρ_reduced) # Renyi 纠缠熵\n",
281283
" return S"
282284
]

docs/source/tutorials/tfim_vqe_diffreph_cn.ipynb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,9 @@
420420
"\n",
421421
"Jx = np.array([1.0 for _ in range(n - 1)]) # xx 相互作用的强度 (OBC)\n",
422422
"Bz = np.array([1.0 for _ in range(n)]) # 横向场强\n",
423-
"hamiltonian_mpo = tn.matrixproductstates.mpo.FiniteTFI(Jx, Bz, dtype=dtype) # 矩阵乘积算子\n",
423+
"hamiltonian_mpo = tn.matrixproductstates.mpo.FiniteTFI(\n",
424+
" Jx, Bz, dtype=dtype\n",
425+
") # 矩阵乘积算子\n",
424426
"hamiltonian_mpo = quoperator_mpo(hamiltonian_mpo) # 从 mpo 生成 QuOperator"
425427
]
426428
},

examples/matprod_vmap.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
matrix product: a new twist
33
rewrite matrix product in a vmap style
44
"""
5+
56
from functools import partial
67

78
import numpy as np

tensorcircuit/abstractcircuit.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Methods for abstract circuits independent of nodes, edges and contractions
33
"""
4+
45
# pylint: disable=invalid-name
56

67
from typing import Any, Callable, Dict, List, Optional, Sequence, Union, Tuple

tensorcircuit/applications/dqas.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Modules for DQAS framework
33
"""
4+
45
# possibly deprecated, multiprocessing is not the recommended way to do DQAS task now, using vmap!
56

67
import sys
@@ -486,9 +487,9 @@ def qaoa_simple_train(
486487
if "prob_model_func" in kws:
487488
pmf = kws["prob_model_func"]
488489
del kws["prob_model_func"]
489-
kws[
490-
"prob_model"
491-
] = pmf() # in case keras model cannot pickled for multiprocessing map
490+
kws["prob_model"] = (
491+
pmf()
492+
) # in case keras model cannot pickled for multiprocessing map
492493
if isinstance(graph, list):
493494

494495
def graph_generator() -> Iterator[Graph]:

tensorcircuit/applications/layers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Module for functions adding layers of circuits
33
"""
4+
45
import itertools
56
import logging
67
import sys

tensorcircuit/applications/physics/fss.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
finite size scaling tools
33
"""
4+
45
from typing import List, Tuple, Optional
56

67
import numpy as np

tensorcircuit/applications/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
A collection of useful function snippets that irrelevant with the main modules
33
or await for further refactor
44
"""
5+
56
import logging
67
from typing import Any, Callable, Iterator, Optional, Sequence, Tuple
78

tensorcircuit/applications/vags.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
DQAS application kernels as vag functions
33
"""
4+
45
from functools import lru_cache, partial, reduce
56
import logging
67
import operator

tensorcircuit/applications/vqes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
VQNHE application
33
"""
4+
45
from functools import lru_cache
56
from itertools import product
67
import time

tensorcircuit/asciiart.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Some ascii art from https://www.asciiart.eu/, have fun!
33
"""
4+
45
# pylint: disable=invalid-name
56

67
import hashlib

tensorcircuit/backends/abstract_backend.py

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Backend magic inherited from tensornetwork: abstract backend
33
"""
4+
45
# pylint: disable=invalid-name
56
# pylint: disable=unused-variable
67

@@ -1539,16 +1540,19 @@ def wrapper(*args: Any, **kws: Any) -> Any:
15391540
args,
15401541
tuple(
15411542
[
1542-
self.reshape(
1543-
self.eye(self.sizen(arg), dtype=arg.dtype),
1544-
[-1] + list(self.shape_tuple(arg)),
1545-
)
1546-
if i == argnum
1547-
else self.reshape(
1548-
self.zeros(
1549-
[self.sizen(arg), self.sizen(arg)], dtype=arg.dtype
1550-
),
1551-
[-1] + list(self.shape_tuple(arg)),
1543+
(
1544+
self.reshape(
1545+
self.eye(self.sizen(arg), dtype=arg.dtype),
1546+
[-1] + list(self.shape_tuple(arg)),
1547+
)
1548+
if i == argnum
1549+
else self.reshape(
1550+
self.zeros(
1551+
[self.sizen(arg), self.sizen(arg)],
1552+
dtype=arg.dtype,
1553+
),
1554+
[-1] + list(self.shape_tuple(arg)),
1555+
)
15521556
)
15531557
for i, arg in enumerate(args)
15541558
]
@@ -1607,16 +1611,18 @@ def _first(x: Sequence[Any]) -> Any:
16071611
args,
16081612
collect(
16091613
[
1610-
self.reshape(
1611-
self.eye(self.sizen(v), dtype=v.dtype),
1612-
[-1] + list(self.shape_tuple(v)),
1613-
)
1614-
if i == k
1615-
else self.reshape(
1616-
self.zeros(
1617-
[self.sizen(v), self.sizen(v)], dtype=v.dtype
1618-
),
1619-
[-1] + list(self.shape_tuple(v)),
1614+
(
1615+
self.reshape(
1616+
self.eye(self.sizen(v), dtype=v.dtype),
1617+
[-1] + list(self.shape_tuple(v)),
1618+
)
1619+
if i == k
1620+
else self.reshape(
1621+
self.zeros(
1622+
[self.sizen(v), self.sizen(v)], dtype=v.dtype
1623+
),
1624+
[-1] + list(self.shape_tuple(v)),
1625+
)
16201626
)
16211627
for i, v in enumerate(values)
16221628
]

tensorcircuit/backends/cupy_backend.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
CuPy backend. Not in the tensornetwork package and highly experimental.
33
"""
4+
45
# pylint: disable=invalid-name
56

67
import logging

tensorcircuit/backends/jax_backend.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Backend magic inherited from tensornetwork: jax backend
33
"""
4+
45
# pylint: disable=invalid-name
56

67
from functools import partial

tensorcircuit/backends/jax_ops.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Customized ops for ML framework
33
"""
4+
45
# pylint: disable=invalid-name
56

67
from typing import Any, Tuple, Sequence

tensorcircuit/backends/numpy_backend.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Backend magic inherited from tensornetwork: numpy backend
33
"""
4+
45
# pylint: disable=invalid-name
56

67
import logging

tensorcircuit/backends/pytorch_backend.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Backend magic inherited from tensornetwork: pytorch backend
33
"""
4+
45
# pylint: disable=invalid-name
56

67
import logging

tensorcircuit/backends/pytorch_ops.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Customized ops for ML framework
33
"""
4+
45
# pylint: disable=invalid-name
56

67
from typing import Any

tensorcircuit/backends/tensorflow_backend.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Backend magic inherited from tensornetwork: tensorflow backend
33
"""
4+
45
# pylint: disable=invalid-name
56

67
import os

tensorcircuit/backends/tf_ops.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Customized ops for ML framework
33
"""
4+
45
# pylint: disable=invalid-name
56

67
from typing import Any

tensorcircuit/basecircuit.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Quantum circuit: common methods for all circuit classes as MixIn
33
"""
4+
45
# pylint: disable=invalid-name
56

67
from typing import Any, Dict, List, Optional, Sequence, Tuple, Union

tensorcircuit/circuit.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Quantum circuit: the state simulator
33
"""
4+
45
# pylint: disable=invalid-name
56

67
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple

tensorcircuit/cloud/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
utility functions for cloud connection
33
"""
4+
45
from typing import Any, Callable, Optional
56
from functools import wraps
67
import inspect

tensorcircuit/cloud/wrapper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
higher level wrapper shortcut for submit_task
33
"""
4+
45
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
56
import logging
67
import time

tensorcircuit/compiler/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Experimental module, no software agnostic unified interface for now,
33
only reserve for internal use
44
"""
5+
56
from .composed_compiler import Compiler, DefaultCompiler, default_compile
67
from . import simple_compiler
78
from . import qiskit_compiler

tensorcircuit/cons.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Constants and setups
33
"""
4+
45
# pylint: disable=invalid-name
56

67
import logging

tensorcircuit/densitymatrix.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Quantum circuit class but with density matrix simulator
33
"""
4+
45
# pylint: disable=invalid-name
56

67
from functools import reduce
@@ -333,9 +334,11 @@ def apply_general_kraus(
333334
) -> None:
334335
# incompatible API for now
335336
kraus = [
336-
k
337-
if isinstance(k, tn.Node)
338-
else Gate(backend.cast(backend.convert_to_tensor(k), dtypestr))
337+
(
338+
k
339+
if isinstance(k, tn.Node)
340+
else Gate(backend.cast(backend.convert_to_tensor(k), dtypestr))
341+
)
339342
for k in kraus
340343
]
341344
self.check_kraus(kraus)

tensorcircuit/fgs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Fermion Gaussian state simulator
33
"""
4+
45
from typing import Any, Dict, List, Optional, Tuple
56

67
import numpy as np

tensorcircuit/mps_base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
FiniteMPS from tensornetwork with bug fixed
33
"""
4+
45
# pylint: disable=invalid-name
56

67
from typing import Any, Optional, List, Sequence

tensorcircuit/mpscircuit.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Quantum circuit: MPS state simulator
33
"""
4+
45
# pylint: disable=invalid-name
56

67
from functools import reduce

tensorcircuit/noisemodel.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
General Noise Model Construction.
33
"""
4+
45
import logging
56
from functools import partial
67
from typing import Any, Sequence, Optional, List, Dict, Tuple, Callable, Union

tensorcircuit/quantum.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
88
import tensorcircuit.quantum as qu
99
"""
10+
1011
# pylint: disable=invalid-name
1112

1213
import os

tensorcircuit/results/counts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
dict related functionalities
33
"""
4+
45
from typing import Any, Dict, Optional, Sequence
56

67
import numpy as np

0 commit comments

Comments
 (0)