tensorcircuit-nightly 1.2.0.dev20250326__py3-none-any.whl → 1.4.0.dev20251128__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of tensorcircuit-nightly might be problematic. Click here for more details.
- tensorcircuit/__init__.py +5 -1
- tensorcircuit/abstractcircuit.py +4 -0
- tensorcircuit/analogcircuit.py +413 -0
- tensorcircuit/applications/layers.py +1 -1
- tensorcircuit/applications/van.py +1 -1
- tensorcircuit/backends/abstract_backend.py +312 -5
- tensorcircuit/backends/cupy_backend.py +3 -1
- tensorcircuit/backends/jax_backend.py +100 -4
- tensorcircuit/backends/jax_ops.py +108 -0
- tensorcircuit/backends/numpy_backend.py +49 -3
- tensorcircuit/backends/pytorch_backend.py +92 -3
- tensorcircuit/backends/tensorflow_backend.py +102 -3
- tensorcircuit/basecircuit.py +157 -98
- tensorcircuit/circuit.py +115 -57
- tensorcircuit/cloud/local.py +1 -1
- tensorcircuit/cloud/quafu_provider.py +1 -1
- tensorcircuit/cloud/tencent.py +1 -1
- tensorcircuit/compiler/simple_compiler.py +2 -2
- tensorcircuit/cons.py +105 -23
- tensorcircuit/densitymatrix.py +16 -11
- tensorcircuit/experimental.py +733 -153
- tensorcircuit/fgs.py +254 -73
- tensorcircuit/gates.py +66 -22
- tensorcircuit/interfaces/jax.py +5 -3
- tensorcircuit/interfaces/tensortrans.py +6 -2
- tensorcircuit/interfaces/torch.py +14 -4
- tensorcircuit/keras.py +3 -3
- tensorcircuit/mpscircuit.py +154 -65
- tensorcircuit/quantum.py +698 -134
- tensorcircuit/quditcircuit.py +733 -0
- tensorcircuit/quditgates.py +618 -0
- tensorcircuit/results/counts.py +131 -18
- tensorcircuit/results/readout_mitigation.py +4 -1
- tensorcircuit/shadows.py +1 -1
- tensorcircuit/simplify.py +3 -1
- tensorcircuit/stabilizercircuit.py +29 -17
- tensorcircuit/templates/__init__.py +2 -0
- tensorcircuit/templates/blocks.py +2 -2
- tensorcircuit/templates/hamiltonians.py +174 -0
- tensorcircuit/templates/lattice.py +1789 -0
- tensorcircuit/timeevol.py +896 -0
- tensorcircuit/translation.py +10 -3
- tensorcircuit/utils.py +7 -0
- {tensorcircuit_nightly-1.2.0.dev20250326.dist-info → tensorcircuit_nightly-1.4.0.dev20251128.dist-info}/METADATA +66 -29
- tensorcircuit_nightly-1.4.0.dev20251128.dist-info/RECORD +96 -0
- {tensorcircuit_nightly-1.2.0.dev20250326.dist-info → tensorcircuit_nightly-1.4.0.dev20251128.dist-info}/WHEEL +1 -1
- {tensorcircuit_nightly-1.2.0.dev20250326.dist-info → tensorcircuit_nightly-1.4.0.dev20251128.dist-info}/top_level.txt +0 -1
- tensorcircuit_nightly-1.2.0.dev20250326.dist-info/RECORD +0 -118
- tests/__init__.py +0 -0
- tests/conftest.py +0 -67
- tests/test_backends.py +0 -1035
- tests/test_calibrating.py +0 -149
- tests/test_channels.py +0 -409
- tests/test_circuit.py +0 -1699
- tests/test_cloud.py +0 -219
- tests/test_compiler.py +0 -147
- tests/test_dmcircuit.py +0 -555
- tests/test_ensemble.py +0 -72
- tests/test_fgs.py +0 -310
- tests/test_gates.py +0 -156
- tests/test_interfaces.py +0 -562
- tests/test_keras.py +0 -160
- tests/test_miscs.py +0 -282
- tests/test_mpscircuit.py +0 -341
- tests/test_noisemodel.py +0 -156
- tests/test_qaoa.py +0 -86
- tests/test_qem.py +0 -152
- tests/test_quantum.py +0 -549
- tests/test_quantum_attr.py +0 -42
- tests/test_results.py +0 -380
- tests/test_shadows.py +0 -160
- tests/test_simplify.py +0 -46
- tests/test_stabilizer.py +0 -217
- tests/test_templates.py +0 -218
- tests/test_torchnn.py +0 -99
- tests/test_van.py +0 -102
- {tensorcircuit_nightly-1.2.0.dev20250326.dist-info → tensorcircuit_nightly-1.4.0.dev20251128.dist-info}/licenses/LICENSE +0 -0
tensorcircuit/densitymatrix.py
CHANGED
|
@@ -17,7 +17,7 @@ from .channels import kraus_to_super_gate
|
|
|
17
17
|
from .circuit import Circuit
|
|
18
18
|
from .cons import backend, contractor, dtypestr
|
|
19
19
|
from .basecircuit import BaseCircuit
|
|
20
|
-
from .quantum import QuOperator
|
|
20
|
+
from .quantum import QuOperator, _infer_num_sites
|
|
21
21
|
|
|
22
22
|
Gate = gates.Gate
|
|
23
23
|
Tensor = Any
|
|
@@ -35,9 +35,11 @@ class DMCircuit(BaseCircuit):
|
|
|
35
35
|
dminputs: Optional[Tensor] = None,
|
|
36
36
|
mpo_dminputs: Optional[QuOperator] = None,
|
|
37
37
|
split: Optional[Dict[str, Any]] = None,
|
|
38
|
+
dim: Optional[int] = None,
|
|
38
39
|
) -> None:
|
|
39
40
|
"""
|
|
40
41
|
The density matrix simulator based on tensornetwork engine.
|
|
42
|
+
Do not use this class with d!=2 directly
|
|
41
43
|
|
|
42
44
|
:param nqubits: Number of qubits
|
|
43
45
|
:type nqubits: int
|
|
@@ -55,6 +57,7 @@ class DMCircuit(BaseCircuit):
|
|
|
55
57
|
``max_singular_values`` and ``max_truncation_err``.
|
|
56
58
|
:type split: Optional[Dict[str, Any]]
|
|
57
59
|
"""
|
|
60
|
+
self._d = 2 if dim is None else dim
|
|
58
61
|
if not empty:
|
|
59
62
|
if (
|
|
60
63
|
(inputs is None)
|
|
@@ -73,9 +76,9 @@ class DMCircuit(BaseCircuit):
|
|
|
73
76
|
inputs = backend.cast(inputs, dtype=dtypestr)
|
|
74
77
|
inputs = backend.reshape(inputs, [-1])
|
|
75
78
|
N = inputs.shape[0]
|
|
76
|
-
n =
|
|
79
|
+
n = _infer_num_sites(N, self._d)
|
|
77
80
|
assert n == nqubits
|
|
78
|
-
inputs = backend.reshape(inputs, [
|
|
81
|
+
inputs = backend.reshape(inputs, [self._d for _ in range(n)])
|
|
79
82
|
inputs_gate = Gate(inputs)
|
|
80
83
|
self._nodes = [inputs_gate]
|
|
81
84
|
self.coloring_nodes(self._nodes)
|
|
@@ -94,7 +97,9 @@ class DMCircuit(BaseCircuit):
|
|
|
94
97
|
elif dminputs is not None:
|
|
95
98
|
dminputs = backend.convert_to_tensor(dminputs)
|
|
96
99
|
dminputs = backend.cast(dminputs, dtype=dtypestr)
|
|
97
|
-
dminputs = backend.reshape(
|
|
100
|
+
dminputs = backend.reshape(
|
|
101
|
+
dminputs, [self._d for _ in range(2 * nqubits)]
|
|
102
|
+
)
|
|
98
103
|
dminputs_gate = Gate(dminputs)
|
|
99
104
|
nodes = [dminputs_gate]
|
|
100
105
|
self._front = [dminputs_gate.get_edge(i) for i in range(2 * nqubits)]
|
|
@@ -174,9 +179,9 @@ class DMCircuit(BaseCircuit):
|
|
|
174
179
|
|
|
175
180
|
@staticmethod
|
|
176
181
|
def check_kraus(kraus: Sequence[Gate]) -> bool:
|
|
177
|
-
"""
|
|
182
|
+
r"""
|
|
178
183
|
Check if Kraus operators satisfy the completeness relation:
|
|
179
|
-
sum_i K_i
|
|
184
|
+
:math:`\sum_i K_i^\dagger K_i = I`
|
|
180
185
|
|
|
181
186
|
:param kraus: Sequence of Kraus operators
|
|
182
187
|
:type kraus: Sequence[Gate]
|
|
@@ -217,7 +222,7 @@ class DMCircuit(BaseCircuit):
|
|
|
217
222
|
dd = dmc.densitymatrix()
|
|
218
223
|
circuits.append(dd)
|
|
219
224
|
tensor = reduce(add, circuits)
|
|
220
|
-
tensor = backend.
|
|
225
|
+
tensor = backend.reshaped(tensor, d=self._d)
|
|
221
226
|
self._nodes = [Gate(tensor)]
|
|
222
227
|
dangling = [e for e in self._nodes[0]]
|
|
223
228
|
self._front = dangling
|
|
@@ -255,7 +260,7 @@ class DMCircuit(BaseCircuit):
|
|
|
255
260
|
t = contractor(nodes, output_edge_order=d_edges)
|
|
256
261
|
else:
|
|
257
262
|
t = nodes[0]
|
|
258
|
-
dm = backend.
|
|
263
|
+
dm = backend.reshapem(t.tensor)
|
|
259
264
|
if check:
|
|
260
265
|
self.check_density_matrix(dm)
|
|
261
266
|
return dm
|
|
@@ -274,7 +279,7 @@ class DMCircuit(BaseCircuit):
|
|
|
274
279
|
dm = self.densitymatrix()
|
|
275
280
|
e, v = backend.eigh(dm)
|
|
276
281
|
np.testing.assert_allclose(
|
|
277
|
-
e[:-1], backend.zeros([
|
|
282
|
+
e[:-1], backend.zeros([self._d**self._nqubits - 1]), atol=1e-5
|
|
278
283
|
)
|
|
279
284
|
return v[:, -1]
|
|
280
285
|
|
|
@@ -297,7 +302,7 @@ class DMCircuit(BaseCircuit):
|
|
|
297
302
|
reuse: bool = True,
|
|
298
303
|
noise_conf: Optional[Any] = None,
|
|
299
304
|
status: Optional[Tensor] = None,
|
|
300
|
-
**kws: Any
|
|
305
|
+
**kws: Any,
|
|
301
306
|
) -> tn.Node.tensor:
|
|
302
307
|
"""
|
|
303
308
|
Compute the expectation of corresponding operators.
|
|
@@ -375,7 +380,7 @@ class DMCircuit2(DMCircuit):
|
|
|
375
380
|
# index = [index[0] for _ in range(len(kraus))]
|
|
376
381
|
super_op = kraus_to_super_gate(kraus)
|
|
377
382
|
nlegs = 4 * len(index)
|
|
378
|
-
super_op = backend.reshape(super_op, [
|
|
383
|
+
super_op = backend.reshape(super_op, [self._d for _ in range(nlegs)])
|
|
379
384
|
super_op = Gate(super_op)
|
|
380
385
|
o2i = int(nlegs / 2)
|
|
381
386
|
r2l = int(nlegs / 4)
|