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.

Files changed (77) hide show
  1. tensorcircuit/__init__.py +5 -1
  2. tensorcircuit/abstractcircuit.py +4 -0
  3. tensorcircuit/analogcircuit.py +413 -0
  4. tensorcircuit/applications/layers.py +1 -1
  5. tensorcircuit/applications/van.py +1 -1
  6. tensorcircuit/backends/abstract_backend.py +312 -5
  7. tensorcircuit/backends/cupy_backend.py +3 -1
  8. tensorcircuit/backends/jax_backend.py +100 -4
  9. tensorcircuit/backends/jax_ops.py +108 -0
  10. tensorcircuit/backends/numpy_backend.py +49 -3
  11. tensorcircuit/backends/pytorch_backend.py +92 -3
  12. tensorcircuit/backends/tensorflow_backend.py +102 -3
  13. tensorcircuit/basecircuit.py +157 -98
  14. tensorcircuit/circuit.py +115 -57
  15. tensorcircuit/cloud/local.py +1 -1
  16. tensorcircuit/cloud/quafu_provider.py +1 -1
  17. tensorcircuit/cloud/tencent.py +1 -1
  18. tensorcircuit/compiler/simple_compiler.py +2 -2
  19. tensorcircuit/cons.py +105 -23
  20. tensorcircuit/densitymatrix.py +16 -11
  21. tensorcircuit/experimental.py +733 -153
  22. tensorcircuit/fgs.py +254 -73
  23. tensorcircuit/gates.py +66 -22
  24. tensorcircuit/interfaces/jax.py +5 -3
  25. tensorcircuit/interfaces/tensortrans.py +6 -2
  26. tensorcircuit/interfaces/torch.py +14 -4
  27. tensorcircuit/keras.py +3 -3
  28. tensorcircuit/mpscircuit.py +154 -65
  29. tensorcircuit/quantum.py +698 -134
  30. tensorcircuit/quditcircuit.py +733 -0
  31. tensorcircuit/quditgates.py +618 -0
  32. tensorcircuit/results/counts.py +131 -18
  33. tensorcircuit/results/readout_mitigation.py +4 -1
  34. tensorcircuit/shadows.py +1 -1
  35. tensorcircuit/simplify.py +3 -1
  36. tensorcircuit/stabilizercircuit.py +29 -17
  37. tensorcircuit/templates/__init__.py +2 -0
  38. tensorcircuit/templates/blocks.py +2 -2
  39. tensorcircuit/templates/hamiltonians.py +174 -0
  40. tensorcircuit/templates/lattice.py +1789 -0
  41. tensorcircuit/timeevol.py +896 -0
  42. tensorcircuit/translation.py +10 -3
  43. tensorcircuit/utils.py +7 -0
  44. {tensorcircuit_nightly-1.2.0.dev20250326.dist-info → tensorcircuit_nightly-1.4.0.dev20251128.dist-info}/METADATA +66 -29
  45. tensorcircuit_nightly-1.4.0.dev20251128.dist-info/RECORD +96 -0
  46. {tensorcircuit_nightly-1.2.0.dev20250326.dist-info → tensorcircuit_nightly-1.4.0.dev20251128.dist-info}/WHEEL +1 -1
  47. {tensorcircuit_nightly-1.2.0.dev20250326.dist-info → tensorcircuit_nightly-1.4.0.dev20251128.dist-info}/top_level.txt +0 -1
  48. tensorcircuit_nightly-1.2.0.dev20250326.dist-info/RECORD +0 -118
  49. tests/__init__.py +0 -0
  50. tests/conftest.py +0 -67
  51. tests/test_backends.py +0 -1035
  52. tests/test_calibrating.py +0 -149
  53. tests/test_channels.py +0 -409
  54. tests/test_circuit.py +0 -1699
  55. tests/test_cloud.py +0 -219
  56. tests/test_compiler.py +0 -147
  57. tests/test_dmcircuit.py +0 -555
  58. tests/test_ensemble.py +0 -72
  59. tests/test_fgs.py +0 -310
  60. tests/test_gates.py +0 -156
  61. tests/test_interfaces.py +0 -562
  62. tests/test_keras.py +0 -160
  63. tests/test_miscs.py +0 -282
  64. tests/test_mpscircuit.py +0 -341
  65. tests/test_noisemodel.py +0 -156
  66. tests/test_qaoa.py +0 -86
  67. tests/test_qem.py +0 -152
  68. tests/test_quantum.py +0 -549
  69. tests/test_quantum_attr.py +0 -42
  70. tests/test_results.py +0 -380
  71. tests/test_shadows.py +0 -160
  72. tests/test_simplify.py +0 -46
  73. tests/test_stabilizer.py +0 -217
  74. tests/test_templates.py +0 -218
  75. tests/test_torchnn.py +0 -99
  76. tests/test_van.py +0 -102
  77. {tensorcircuit_nightly-1.2.0.dev20250326.dist-info → tensorcircuit_nightly-1.4.0.dev20251128.dist-info}/licenses/LICENSE +0 -0
@@ -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 = int(np.log(N) / np.log(2))
79
+ n = _infer_num_sites(N, self._d)
77
80
  assert n == nqubits
78
- inputs = backend.reshape(inputs, [2 for _ in range(n)])
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(dminputs, [2 for _ in range(2 * nqubits)])
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^† K_i = 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.reshape(tensor, [2 for _ in range(2 * self._nqubits)])
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.reshape(t.tensor, shape=[2**self._nqubits, 2**self._nqubits])
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([2**self._nqubits - 1]), atol=1e-5
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, [2 for _ in range(nlegs)])
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)