tensorcircuit-nightly 1.3.0.dev20250908__py3-none-any.whl → 1.3.0.dev20250910__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 +3 -1
- tensorcircuit/applications/layers.py +1 -1
- tensorcircuit/backends/abstract_backend.py +2 -2
- tensorcircuit/basecircuit.py +7 -23
- tensorcircuit/circuit.py +3 -3
- tensorcircuit/densitymatrix.py +2 -2
- tensorcircuit/quantum.py +11 -11
- tensorcircuit/quditcircuit.py +670 -0
- tensorcircuit/quditgates.py +618 -0
- tensorcircuit/results/counts.py +1 -1
- tensorcircuit/shadows.py +1 -1
- tensorcircuit/templates/hamiltonians.py +14 -6
- tensorcircuit/templates/lattice.py +1 -1
- tensorcircuit/timeevol.py +2 -2
- {tensorcircuit_nightly-1.3.0.dev20250908.dist-info → tensorcircuit_nightly-1.3.0.dev20250910.dist-info}/METADATA +2 -2
- {tensorcircuit_nightly-1.3.0.dev20250908.dist-info → tensorcircuit_nightly-1.3.0.dev20250910.dist-info}/RECORD +19 -17
- {tensorcircuit_nightly-1.3.0.dev20250908.dist-info → tensorcircuit_nightly-1.3.0.dev20250910.dist-info}/WHEEL +0 -0
- {tensorcircuit_nightly-1.3.0.dev20250908.dist-info → tensorcircuit_nightly-1.3.0.dev20250910.dist-info}/licenses/LICENSE +0 -0
- {tensorcircuit_nightly-1.3.0.dev20250908.dist-info → tensorcircuit_nightly-1.3.0.dev20250910.dist-info}/top_level.txt +0 -0
tensorcircuit/__init__.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
__version__ = "1.3.0.
|
|
1
|
+
__version__ = "1.3.0.dev20250910"
|
|
2
2
|
__author__ = "TensorCircuit Authors"
|
|
3
3
|
__creator__ = "refraction-ray"
|
|
4
4
|
|
|
@@ -23,8 +23,10 @@ from .cons import (
|
|
|
23
23
|
runtime_contractor,
|
|
24
24
|
) # prerun of set hooks
|
|
25
25
|
from . import gates
|
|
26
|
+
from . import quditgates
|
|
26
27
|
from . import basecircuit
|
|
27
28
|
from .gates import Gate
|
|
29
|
+
from .quditcircuit import QuditCircuit
|
|
28
30
|
from .circuit import Circuit, expectation
|
|
29
31
|
from .mpscircuit import MPSCircuit
|
|
30
32
|
from .densitymatrix import DMCircuit as DMCircuit_reference
|
|
@@ -35,7 +35,7 @@ Symbol = Any # sympy.Symbol
|
|
|
35
35
|
|
|
36
36
|
def _resolve(symbol: Union[Symbol, Tensor], i: int = 0) -> Tensor:
|
|
37
37
|
"""
|
|
38
|
-
Make sure the layer is compatible with both multi-param and single param requirements
|
|
38
|
+
Make sure the layer is compatible with both multi-param and single param requirements
|
|
39
39
|
|
|
40
40
|
What could be the input: list/tuple of sympy.symbol, tf.tensor with 1D or 0D shape
|
|
41
41
|
"""
|
|
@@ -1039,8 +1039,8 @@ class ExtendedBackend:
|
|
|
1039
1039
|
:type a: Tensor
|
|
1040
1040
|
:param v: value to inserted
|
|
1041
1041
|
:type v: Tensor
|
|
1042
|
-
:param side: If
|
|
1043
|
-
If
|
|
1042
|
+
:param side: If `left`, the index of the first suitable location found is given.
|
|
1043
|
+
If `right`, return the last such index.
|
|
1044
1044
|
If there is no suitable index, return either 0 or N (where N is the length of a),
|
|
1045
1045
|
defaults to "left"
|
|
1046
1046
|
:type side: str, optional
|
tensorcircuit/basecircuit.py
CHANGED
|
@@ -3,7 +3,7 @@ Quantum circuit: common methods for all circuit classes as MixIn
|
|
|
3
3
|
|
|
4
4
|
Note:
|
|
5
5
|
- Supports qubit (d = 2) and qudit (d >= 2) systems.
|
|
6
|
-
- For string-encoded samples/counts when d <= 36, digits use base-d characters 0
|
|
6
|
+
- For string-encoded samples/counts when d <= 36, digits use base-d characters 0-9A-Z (A = 10, ..., Z = 35).
|
|
7
7
|
"""
|
|
8
8
|
|
|
9
9
|
# pylint: disable=invalid-name
|
|
@@ -362,7 +362,7 @@ class BaseCircuit(AbstractCircuit):
|
|
|
362
362
|
|
|
363
363
|
def perfect_sampling(self, status: Optional[Tensor] = None) -> Tuple[str, float]:
|
|
364
364
|
"""
|
|
365
|
-
Sampling base-d strings (0
|
|
365
|
+
Sampling base-d strings (0-9A-Z when d <= 36) from the circuit output based on quantum amplitudes.
|
|
366
366
|
Reference: arXiv:1201.3974.
|
|
367
367
|
|
|
368
368
|
:param status: external randomness, with shape [nqubits], defaults to None
|
|
@@ -480,28 +480,12 @@ class BaseCircuit(AbstractCircuit):
|
|
|
480
480
|
|
|
481
481
|
def amplitude_before(self, l: Union[str, Tensor]) -> List[Gate]:
|
|
482
482
|
r"""
|
|
483
|
-
Returns the tensornetwor nodes for the amplitude of the circuit given
|
|
484
|
-
For
|
|
485
|
-
for
|
|
483
|
+
Returns the tensornetwor nodes for the amplitude of the circuit given the bitstring l.
|
|
484
|
+
For state simulator, it computes :math:`\langle l\vert \psi\rangle`,
|
|
485
|
+
for density matrix simulator, it computes :math:`Tr(\rho \vert l\rangle \langle 1\vert)`
|
|
486
486
|
Note how these two are different up to a square operation.
|
|
487
487
|
|
|
488
|
-
:
|
|
489
|
-
|
|
490
|
-
>>> c = tc.Circuit(2)
|
|
491
|
-
>>> c.X(0)
|
|
492
|
-
>>> c.amplitude("10") # d=2, per-qubit digits
|
|
493
|
-
array(1.+0.j, dtype=complex64)
|
|
494
|
-
>>> c.CNOT(0, 1)
|
|
495
|
-
>>> c.amplitude("11")
|
|
496
|
-
array(1.+0.j, dtype=complex64)
|
|
497
|
-
|
|
498
|
-
For qudits (d>2, d<=36):
|
|
499
|
-
>>> c = tc.Circuit(3, dim=12)
|
|
500
|
-
>>> c.amplitude("0A2") # base-12 string, A stands for 10
|
|
501
|
-
|
|
502
|
-
:param l: Basis label.
|
|
503
|
-
- If a string: it must be a base-d string of length ``nqubits``, using 0–9A–Z (A=10,…,Z=35) when ``d<=36``.
|
|
504
|
-
- If a tensor/array/list: it should contain per-site integers in ``[0, d-1]`` with length ``nqubits``.
|
|
488
|
+
:param l: The bitstring of 0 and 1s.
|
|
505
489
|
:type l: Union[str, Tensor]
|
|
506
490
|
:return: The tensornetwork nodes for the amplitude of the circuit.
|
|
507
491
|
:rtype: List[Gate]
|
|
@@ -620,7 +604,7 @@ class BaseCircuit(AbstractCircuit):
|
|
|
620
604
|
"count_tuple": # (np.array([0]), np.array([2]))
|
|
621
605
|
|
|
622
606
|
"count_dict_bin": # {"00": 2, "01": 0, "10": 0, "11": 0}
|
|
623
|
-
for cases d\in [11, 36], use 0
|
|
607
|
+
for cases d\in [11, 36], use 0-9A-Z digits (e.g., 'A' -> 10, ..., 'Z' -> 35);
|
|
624
608
|
|
|
625
609
|
"count_dict_int": # {0: 2, 1: 0, 2: 0, 3: 0}
|
|
626
610
|
|
tensorcircuit/circuit.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"""
|
|
2
2
|
Quantum circuit: the state simulator.
|
|
3
3
|
Supports qubit (dim=2) and qudit (3 <= dim <= 36) systems.
|
|
4
|
-
For string-encoded samples/counts, digits use 0
|
|
4
|
+
For string-encoded samples/counts, digits use 0-9A-Z where A=10, ..., Z=35.
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
7
|
# pylint: disable=invalid-name
|
|
@@ -768,7 +768,7 @@ class Circuit(BaseCircuit):
|
|
|
768
768
|
Take measurement on the given quantum lines by ``index``.
|
|
769
769
|
|
|
770
770
|
Return format:
|
|
771
|
-
- For d <= 36, the sample is a base-d string using 0
|
|
771
|
+
- For d <= 36, the sample is a base-d string using 0-9A-Z (A=10,...).
|
|
772
772
|
|
|
773
773
|
:Example:
|
|
774
774
|
|
|
@@ -874,7 +874,7 @@ class Circuit(BaseCircuit):
|
|
|
874
874
|
:param nmc: repetition time for Monte Carlo sampling for noisfy calculation, defaults to 1000
|
|
875
875
|
:type nmc: int, optional
|
|
876
876
|
:param status: external randomness given by tensor uniformly from [0, 1], defaults to None,
|
|
877
|
-
used for
|
|
877
|
+
used for noisy circuit sampling
|
|
878
878
|
:type status: Optional[Tensor], optional
|
|
879
879
|
:raises ValueError: "Cannot measure two operators in one index"
|
|
880
880
|
:return: Tensor with one element
|
tensorcircuit/densitymatrix.py
CHANGED
|
@@ -179,9 +179,9 @@ class DMCircuit(BaseCircuit):
|
|
|
179
179
|
|
|
180
180
|
@staticmethod
|
|
181
181
|
def check_kraus(kraus: Sequence[Gate]) -> bool:
|
|
182
|
-
"""
|
|
182
|
+
r"""
|
|
183
183
|
Check if Kraus operators satisfy the completeness relation:
|
|
184
|
-
sum_i K_i
|
|
184
|
+
:math:`\sum_i K_i^\dagger K_i = I`
|
|
185
185
|
|
|
186
186
|
:param kraus: Sequence of Kraus operators
|
|
187
187
|
:type kraus: Sequence[Gate]
|
tensorcircuit/quantum.py
CHANGED
|
@@ -79,7 +79,7 @@ def _decode_basis_label(label: str, n: int, dim: int) -> List[int]:
|
|
|
79
79
|
"""
|
|
80
80
|
Decode a string basis label into a list of integer digits.
|
|
81
81
|
|
|
82
|
-
The label is interpreted in base-``dim`` using characters ``0
|
|
82
|
+
The label is interpreted in base-``dim`` using characters ``0-9A-Z``.
|
|
83
83
|
Only dimensions up to 36 are supported.
|
|
84
84
|
|
|
85
85
|
:param label: basis label string, e.g. "010" or "A9F"
|
|
@@ -97,7 +97,7 @@ def _decode_basis_label(label: str, n: int, dim: int) -> List[int]:
|
|
|
97
97
|
"""
|
|
98
98
|
if dim > 36:
|
|
99
99
|
raise NotImplementedError(
|
|
100
|
-
f"String basis label supports d<=36 (0
|
|
100
|
+
f"String basis label supports d<=36 (0-9A-Z). Got dim={dim}. "
|
|
101
101
|
"Use an integer array/tensor of length n instead."
|
|
102
102
|
)
|
|
103
103
|
s = label.upper()
|
|
@@ -107,7 +107,7 @@ def _decode_basis_label(label: str, n: int, dim: int) -> List[int]:
|
|
|
107
107
|
for ch in s:
|
|
108
108
|
if ch not in _ALPHABET:
|
|
109
109
|
raise ValueError(
|
|
110
|
-
f"Invalid character '{ch}' in basis label (allowed 0
|
|
110
|
+
f"Invalid character '{ch}' in basis label (allowed 0-9A-Z)."
|
|
111
111
|
)
|
|
112
112
|
v = _ALPHABET.index(ch)
|
|
113
113
|
if v >= dim:
|
|
@@ -748,10 +748,10 @@ class QuOperator:
|
|
|
748
748
|
return self.__mul__(other)
|
|
749
749
|
|
|
750
750
|
def tensor_product(self, other: "QuOperator") -> "QuOperator":
|
|
751
|
-
"""
|
|
751
|
+
r"""
|
|
752
752
|
Tensor product with another operator.
|
|
753
753
|
Given two operators `A` and `B`, produces a new operator `AB` representing
|
|
754
|
-
:math:`A
|
|
754
|
+
:math:`A \otimes B`. The `out_edges` (`in_edges`) of `AB` is simply the
|
|
755
755
|
concatenation of the `out_edges` (`in_edges`) of `A.copy()` with that of
|
|
756
756
|
`B.copy()`:
|
|
757
757
|
`new_out_edges = [*out_edges_A_copy, *out_edges_B_copy]`
|
|
@@ -2403,13 +2403,13 @@ def free_energy(
|
|
|
2403
2403
|
|
|
2404
2404
|
def renyi_entropy(rho: Union[Tensor, QuOperator], k: int = 2) -> Tensor:
|
|
2405
2405
|
"""
|
|
2406
|
-
Compute the
|
|
2406
|
+
Compute the Renyi entropy of order :math:`k` by given density matrix.
|
|
2407
2407
|
|
|
2408
2408
|
:param rho: The density matrix in form of Tensor or QuOperator.
|
|
2409
2409
|
:type rho: Union[Tensor, QuOperator]
|
|
2410
|
-
:param k: The order of
|
|
2410
|
+
:param k: The order of Renyi entropy, default is 2.
|
|
2411
2411
|
:type k: int, optional
|
|
2412
|
-
:return: The :math:`k` th order of
|
|
2412
|
+
:return: The :math:`k` th order of Renyi entropy.
|
|
2413
2413
|
:rtype: Tensor
|
|
2414
2414
|
"""
|
|
2415
2415
|
s = 1 / (1 - k) * backend.real(backend.log(trace_product(*[rho for _ in range(k)])))
|
|
@@ -2423,7 +2423,7 @@ def renyi_free_energy(
|
|
|
2423
2423
|
k: int = 2,
|
|
2424
2424
|
) -> Tensor:
|
|
2425
2425
|
"""
|
|
2426
|
-
Compute the
|
|
2426
|
+
Compute the Renyi free energy of the corresponding density matrix and Hamiltonian.
|
|
2427
2427
|
|
|
2428
2428
|
:Example:
|
|
2429
2429
|
|
|
@@ -2440,9 +2440,9 @@ def renyi_free_energy(
|
|
|
2440
2440
|
:type h: Union[Tensor, QuOperator]
|
|
2441
2441
|
:param beta: Constant for the optimization, default is 1.
|
|
2442
2442
|
:type beta: float, optional
|
|
2443
|
-
:param k: The order of
|
|
2443
|
+
:param k: The order of Renyi entropy, default is 2.
|
|
2444
2444
|
:type k: int, optional
|
|
2445
|
-
:return: The :math:`k` th order of
|
|
2445
|
+
:return: The :math:`k` th order of Renyi entropy.
|
|
2446
2446
|
:rtype: Tensor
|
|
2447
2447
|
"""
|
|
2448
2448
|
energy = backend.real(trace_product(rho, h))
|