Skip to content

Commit b1d492c

Browse files
refactor to commons
1 parent 1403aa4 commit b1d492c

File tree

11 files changed

+472
-335
lines changed

11 files changed

+472
-335
lines changed

docs/source/api/commons.rst

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
tensorcircuit.commons
2+
==================================================
3+
.. automodule:: tensorcircuit.commons
4+
:members:
5+
:undoc-members:
6+
:show-inheritance:
7+
:inherited-members:

docs/source/api/interfaces.rst

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
tensorcircuit.interfaces
22
==================================================
33
.. toctree::
4+
interfaces/numpy.rst
45
interfaces/scipy.rst
56
interfaces/tensorflow.rst
67
interfaces/tensortrans.rst

docs/source/api/interfaces/numpy.rst

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
tensorcircuit.interfaces.numpy
2+
==================================================
3+
.. automodule:: tensorcircuit.interfaces.numpy
4+
:members:
5+
:undoc-members:
6+
:show-inheritance:
7+
:inherited-members:

docs/source/modules.rst

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ tensorcircuit
55
./api/backends.rst
66
./api/channels.rst
77
./api/circuit.rst
8+
./api/commons.rst
89
./api/cons.rst
910
./api/densitymatrix.rst
1011
./api/densitymatrix2.rst

tensorcircuit/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
runtime_contractor,
1818
) # prerun of set hooks
1919
from . import gates
20+
from . import commons
2021
from .circuit import Circuit, expectation
2122
from .mpscircuit import MPSCircuit
2223
from .densitymatrix import DMCircuit as DMCircuit_reference

tensorcircuit/applications/layers.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from ..densitymatrix import DMCircuit
1515
from ..gates import num_to_tensor, array_to_tensor, _swap_matrix
1616
from ..channels import depolarizingchannel
17+
from ..commons import sgates
1718

1819
logger = logging.getLogger(__name__)
1920

@@ -92,7 +93,7 @@ def f(
9293
circuit: Circuit, symbol: Union[Tensor, float] = None, g: Graph = None
9394
) -> Circuit: # compatible with graph mode
9495
symbol0 = _resolve(symbol)
95-
if gate.lower() in Circuit.sgates:
96+
if gate.lower() in sgates:
9697
for n in range(circuit._nqubits):
9798
getattr(circuit, gate)(n)
9899
else:
@@ -102,7 +103,7 @@ def f(
102103

103104
f.__doc__ = """%slayer""" % gate
104105
f.__repr__ = """%slayer""" % gate # type: ignore
105-
f.__trainable__ = False if gate in Circuit.sgates else True # type: ignore
106+
f.__trainable__ = False if gate in sgates else True # type: ignore
106107
setattr(thismodule, gate + "layer", f)
107108

108109

@@ -118,7 +119,7 @@ def generate_any_gate_layer(gate: str) -> None:
118119
def f(
119120
circuit: Circuit, symbol: Union[Tensor, float] = None, g: Graph = None
120121
) -> Circuit: # compatible with graph mode
121-
if gate.lower() in Circuit.sgates:
122+
if gate.lower() in sgates:
122123
for n in range(circuit._nqubits):
123124
getattr(circuit, gate)(n)
124125
else:
@@ -128,7 +129,7 @@ def f(
128129

129130
f.__doc__ = """any%slayer""" % gate
130131
f.__repr__ = """any%slayer""" % gate # type: ignore
131-
f.__trainable__ = False if gate in Circuit.sgates else True # type: ignore
132+
f.__trainable__ = False if gate in sgates else True # type: ignore
132133
setattr(thismodule, "any" + gate + "layer", f)
133134

134135

@@ -259,7 +260,7 @@ def f(circuit: Circuit, symbol: Tensor, g: Graph = None) -> Circuit:
259260

260261
f.__doc__ = """%s_%s_block""" % (d1, d2)
261262
f.__repr__ = """%s_%s_block""" % (d1, d2) # type: ignore
262-
f.__trainable__ = False if (d1 in Circuit.sgates) and (d2 in Circuit.sgates) else True # type: ignore
263+
f.__trainable__ = False if (d1 in sgates) and (d2 in sgates) else True # type: ignore
263264
setattr(thismodule, "%s_%s_block" % (d1, d2), f)
264265

265266

0 commit comments

Comments
 (0)