tensorcircuit-nightly 1.4.0.dev20251001__py3-none-any.whl → 1.4.0.dev20251105__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 CHANGED
@@ -1,4 +1,4 @@
1
- __version__ = "1.4.0.dev20251001"
1
+ __version__ = "1.4.0.dev20251105"
2
2
  __author__ = "TensorCircuit Authors"
3
3
  __creator__ = "refraction-ray"
4
4
 
@@ -132,13 +132,17 @@ def general_args_to_backend(
132
132
  target_backend = backend
133
133
  elif isinstance(target_backend, str):
134
134
  target_backend = get_backend(target_backend)
135
+ try:
136
+ t = backend.tree_map(target_backend.from_dlpack, caps)
137
+ except TypeError:
138
+ t = backend.tree_map(target_backend.from_dlpack, args)
139
+
135
140
  if dtype is None:
136
- return backend.tree_map(target_backend.from_dlpack, caps)
141
+ return t
137
142
  if isinstance(dtype, str):
138
143
  leaves, treedef = backend.tree_flatten(args)
139
144
  dtype = [dtype for _ in range(len(leaves))]
140
145
  dtype = backend.tree_unflatten(treedef, dtype)
141
- t = backend.tree_map(target_backend.from_dlpack, caps)
142
146
  t = backend.tree_map(target_backend.cast, t, dtype)
143
147
  return t
144
148
 
@@ -69,12 +69,14 @@ def torch_interface(
69
69
  @staticmethod
70
70
  def forward(ctx: Any, *x: Any) -> Any: # type: ignore
71
71
  # ctx.xdtype = [xi.dtype for xi in x]
72
- ctx.xdtype = backend.tree_map(lambda s: s.dtype, x)
72
+ ctx.save_for_backward(*x)
73
+ x_detached = backend.tree_map(lambda s: s.detach(), x)
74
+ ctx.xdtype = backend.tree_map(lambda s: s.dtype, x_detached)
73
75
  # (x, )
74
76
  if len(ctx.xdtype) == 1:
75
77
  ctx.xdtype = ctx.xdtype[0]
76
- ctx.device = (backend.tree_flatten(x)[0][0]).device
77
- x = general_args_to_backend(x, enable_dlpack=enable_dlpack)
78
+ ctx.device = (backend.tree_flatten(x_detached)[0][0]).device
79
+ x = general_args_to_backend(x_detached, enable_dlpack=enable_dlpack)
78
80
  y = fun(*x)
79
81
  ctx.ydtype = backend.tree_map(lambda s: s.dtype, y)
80
82
  if len(x) == 1:
@@ -88,6 +90,9 @@ def torch_interface(
88
90
 
89
91
  @staticmethod
90
92
  def backward(ctx: Any, *grad_y: Any) -> Any:
93
+ x = ctx.saved_tensors
94
+ x_detached = backend.tree_map(lambda s: s.detach(), x)
95
+ x_backend = general_args_to_backend(x_detached, enable_dlpack=enable_dlpack)
91
96
  if len(grad_y) == 1:
92
97
  grad_y = grad_y[0]
93
98
  grad_y = backend.tree_map(lambda s: s.contiguous(), grad_y)
@@ -96,7 +101,12 @@ def torch_interface(
96
101
  )
97
102
  # grad_y = general_args_to_numpy(grad_y)
98
103
  # grad_y = numpy_args_to_backend(grad_y, dtype=ctx.ydtype) # backend.dtype
99
- _, g = vjp_fun(ctx.x, grad_y)
104
+ if len(x_backend) == 1:
105
+ x_backend_for_vjp = x_backend[0]
106
+ else:
107
+ x_backend_for_vjp = x_backend
108
+
109
+ _, g = vjp_fun(x_backend_for_vjp, grad_y)
100
110
  # a redundency due to current vjp API
101
111
 
102
112
  r = general_args_to_backend(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tensorcircuit-nightly
3
- Version: 1.4.0.dev20251001
3
+ Version: 1.4.0.dev20251105
4
4
  Summary: High performance unified quantum computing framework for the NISQ era
5
5
  Author-email: TensorCircuit Authors <znfesnpbh@gmail.com>
6
6
  License-Expression: Apache-2.0
@@ -1,4 +1,4 @@
1
- tensorcircuit/__init__.py,sha256=-I3cXGyP18LtbqFas9sTDRFIbgHrqx3dJpXn9X1HQIs,2160
1
+ tensorcircuit/__init__.py,sha256=to6pXWOK45qhkwh82NaRnhlRbwT1HbkwKoU4LBatYXo,2160
2
2
  tensorcircuit/about.py,sha256=DazTswU2nAwOmASTaDII3L04PVtaQ7oiWPty5YMI3Wk,5267
3
3
  tensorcircuit/abstractcircuit.py,sha256=uDRgaDeH_Ym-6_ZEOZwvxHIDycVLHkGZv4zfaIgaEnc,44235
4
4
  tensorcircuit/analogcircuit.py,sha256=4BzIC631MZ2m05CXuk2T6HQ8RTmHBE6NszaOLuxmlEc,15639
@@ -71,8 +71,8 @@ tensorcircuit/interfaces/jax.py,sha256=q_nay20gcrPRyY2itvcOtkCjqtvcC4qotbvrgm2a3
71
71
  tensorcircuit/interfaces/numpy.py,sha256=T7h64dG9e5xDG0KVOy9O8TXyrt5RWRnTWN9iXf3aGyY,1439
72
72
  tensorcircuit/interfaces/scipy.py,sha256=_P2IeqvJiO7cdjTzNCIAFm8Y56Wd3j3jGmWUeeQ1Fw8,3402
73
73
  tensorcircuit/interfaces/tensorflow.py,sha256=U4hZjm-yWxOJ5tqmffk8-tNvOkAltYBJ8Z6jYwOtTaM,3355
74
- tensorcircuit/interfaces/tensortrans.py,sha256=oUxIVpXfANZVRXfPjiGJDzFPiszfBsiY40ydh0BaELE,10364
75
- tensorcircuit/interfaces/torch.py,sha256=13IFGmWUFoWiSzKAzwp2EkOSxgiwN_oUFxjQb36gimo,5149
74
+ tensorcircuit/interfaces/tensortrans.py,sha256=YHTKIINjXE085fqO_AfUJGE-t3OThUH8csk5PFK7Dig,10414
75
+ tensorcircuit/interfaces/torch.py,sha256=J04-bguSvJOiV-uhNVzMH28Pl-pDYPnTOv7wNm-QRZM,5633
76
76
  tensorcircuit/results/__init__.py,sha256=3kkIvmjLYQd5ff-emY8l82rpv9mwMZdM2kTLZ9sNfA4,89
77
77
  tensorcircuit/results/counts.py,sha256=gJ9x2D09wSZ8bwLB5ZR9lyx-bg6AAoz6JDr9cDAb83w,7267
78
78
  tensorcircuit/results/readout_mitigation.py,sha256=dVpNvtFZe7n_fDVczKcqYPEepu3fV2qK3u-SfOpTf68,31746
@@ -89,8 +89,8 @@ tensorcircuit/templates/graphs.py,sha256=cPYrxjoem0xZ-Is9dZKAvEzWZL_FejfIRiCEOTA
89
89
  tensorcircuit/templates/hamiltonians.py,sha256=Guvqqi-V47w8xeZDmca4_mU4mW9V4c3AplsBOrRtxFo,6308
90
90
  tensorcircuit/templates/lattice.py,sha256=IvFyNgsFMfj82g-tpJraI3lMbI-EIZ0Cghq9v7tZ6Wg,72851
91
91
  tensorcircuit/templates/measurements.py,sha256=pzc5Aa9S416Ilg4aOY77Z6ZhUlYcXnAkQNQFTuHjFFs,10943
92
- tensorcircuit_nightly-1.4.0.dev20251001.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
93
- tensorcircuit_nightly-1.4.0.dev20251001.dist-info/METADATA,sha256=5_bax53d-AUXID6Ko2i_lcHNYwyKXJvohqXnq-gNr0U,38283
94
- tensorcircuit_nightly-1.4.0.dev20251001.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
95
- tensorcircuit_nightly-1.4.0.dev20251001.dist-info/top_level.txt,sha256=9dcuK5488dWpVauYz8cdvx743z_La1h7zIQCsEEgu7o,14
96
- tensorcircuit_nightly-1.4.0.dev20251001.dist-info/RECORD,,
92
+ tensorcircuit_nightly-1.4.0.dev20251105.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
93
+ tensorcircuit_nightly-1.4.0.dev20251105.dist-info/METADATA,sha256=ZWM4Jiqp66UW4azejkkE7En8GovxnceTStVtqQHWpbE,38283
94
+ tensorcircuit_nightly-1.4.0.dev20251105.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
95
+ tensorcircuit_nightly-1.4.0.dev20251105.dist-info/top_level.txt,sha256=9dcuK5488dWpVauYz8cdvx743z_La1h7zIQCsEEgu7o,14
96
+ tensorcircuit_nightly-1.4.0.dev20251105.dist-info/RECORD,,