Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion examples/time_evolution_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ def create_heisenberg_hamiltonian(n, sparse=True):


def create_initial_state(n):
"""Create initial Neel state |↑↓↑↓↑↓↑↓> for n sites."""
r"""
Create initial Neel state
:math:`\vert \uparrow\downarrow\uparrow\downarrow\uparrow\downarrow\uparrow\downarrow\rangle`
for n sites.
"""
c = tc.Circuit(n)
# Apply X gates to odd sites to create Neel state
c.x([i for i in range(1, n, 2)])
Expand Down
16 changes: 8 additions & 8 deletions examples/vqe_qudit_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
This example shows how to run a simple VQE on a qudit system using
`tensorcircuit.QuditCircuit`. We build a compact ansatz using single-qudit
rotations in selected two-level subspaces and RXX-type entanglers, then
optimize the energy of a Hermitian "clockshift" Hamiltonian:
optimize the energy of a Hermitian "clock-shift" Hamiltonian:

H(d) = - J * (X_c \otimes X_c) - h * (Z_c \otimes I + I \otimes Z_c)

Expand All @@ -31,20 +31,20 @@


def vqe_forward(param, *, nqudits: int, d: int, nlayers: int, J: float, h: float):
"""Build a QuditCircuit ansatz and compute ⟨H⟩.
r"""Build a QuditCircuit ansatz and compute :math:`\langle H\rangle`.

Ansatz:
[ for L in 1...nlayers ]
- On each site q:
RX(q; θ_Lq^(01)) ∘ RY(q; θ_Lq^(12)) ∘ RZ(q; φ_Lq^(0))
:math:`RX(q; \theta_L q^{(01)}) RY(q; \theta_L q^{(12)}) RZ(q; \phi_L q^{(0)})`
(subspace indices shown as superscripts)
- Entangle neighboring pairs with RXX on subspaces (0,1)
"""
if d < 3:
raise ValueError("This example assumes d >= 3 (qutrit or higher).")

S = tc.quditgates._x_matrix_func(d)
Z = tc.quditgates._z_matrix_func(d)
S = tc.quditgates.x_matrix_func(d)
Z = tc.quditgates.z_matrix_func(d)
Sdag = tc.backend.adjoint(S)
Zdag = tc.backend.adjoint(Z)

Expand Down Expand Up @@ -76,8 +76,8 @@ def vqe_forward(param, *, nqudits: int, d: int, nlayers: int, J: float, h: float
return tc.backend.real(energy)


def build_param_shape(nqudits: int, d: int, nlayers: int):
# Per layer per qudit: RX^(01), RY^(12) (or dummy), RZ^(0) = 3 params
def build_param_shape(nqudits: int, nlayers: int):
# Per layer per qudit: RX^{(01)}, RY^{(12)} (or dummy), RZ^{(0)} = 3 params
# Per layer entanglers: len(pairs) parameters
pairs = nqudits - 1
per_layer = 3 * nqudits + pairs
Expand All @@ -86,7 +86,7 @@ def build_param_shape(nqudits: int, d: int, nlayers: int):

def main():
parser = argparse.ArgumentParser(
description="VQE on QuditCircuit (clockshift model)"
description="VQE on QuditCircuit (clock-shift model)"
)
parser.add_argument(
"--d", type=int, default=3, help="Local dimension per site (>=3)"
Expand Down
2 changes: 1 addition & 1 deletion tensorcircuit/applications/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

def _resolve(symbol: Union[Symbol, Tensor], i: int = 0) -> Tensor:
"""
Make sure the layer is compatible with both multi-param and single param requirements
Make sure the layer is compatible with both multi-param and single param requirements

What could be the input: list/tuple of sympy.symbol, tf.tensor with 1D or 0D shape
"""
Expand Down
4 changes: 2 additions & 2 deletions tensorcircuit/backends/abstract_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,8 +1039,8 @@ def searchsorted(self: Any, a: Tensor, v: Tensor, side: str = "left") -> Tensor:
:type a: Tensor
:param v: value to inserted
:type v: Tensor
:param side: If left, the index of the first suitable location found is given.
If right, return the last such index.
:param side: If `left`, the index of the first suitable location found is given.
If `right`, return the last such index.
If there is no suitable index, return either 0 or N (where N is the length of a),
defaults to "left"
:type side: str, optional
Expand Down
6 changes: 3 additions & 3 deletions tensorcircuit/basecircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Note:
- Supports qubit (d = 2) and qudit (d >= 2) systems.
- For string-encoded samples/counts when d <= 36, digits use base-d characters 0–9A–Z (A = 10, , Z = 35).
- For string-encoded samples/counts when d <= 36, digits use base-d characters 0-9A-Z (A = 10, ..., Z = 35).
"""

# pylint: disable=invalid-name
Expand Down Expand Up @@ -362,7 +362,7 @@ def to_qir(self) -> List[Dict[str, Any]]:

def perfect_sampling(self, status: Optional[Tensor] = None) -> Tuple[str, float]:
"""
Sampling base-d strings (0–9A–Z when d <= 36) from the circuit output based on quantum amplitudes.
Sampling base-d strings (0-9A-Z when d <= 36) from the circuit output based on quantum amplitudes.
Reference: arXiv:1201.3974.

:param status: external randomness, with shape [nqubits], defaults to None
Expand Down Expand Up @@ -604,7 +604,7 @@ def sample(
"count_tuple": # (np.array([0]), np.array([2]))

"count_dict_bin": # {"00": 2, "01": 0, "10": 0, "11": 0}
for cases d\in [11, 36], use 0–9A–Z digits (e.g., 'A' -> 10, , 'Z' -> 35);
for cases d\in [11, 36], use 0-9A-Z digits (e.g., 'A' -> 10, ..., 'Z' -> 35);

"count_dict_int": # {0: 2, 1: 0, 2: 0, 3: 0}

Expand Down
6 changes: 3 additions & 3 deletions tensorcircuit/circuit.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Quantum circuit: the state simulator.
Supports qubit (dim=2) and qudit (3 <= dim <= 36) systems.
For string-encoded samples/counts, digits use 0–9A–Z where A=10, , Z=35.
For string-encoded samples/counts, digits use 0-9A-Z where A=10, ..., Z=35.
"""

# pylint: disable=invalid-name
Expand Down Expand Up @@ -768,7 +768,7 @@ def measure_reference(
Take measurement on the given quantum lines by ``index``.

Return format:
- For d <= 36, the sample is a base-d string using 0–9A–Z (A=10,).
- For d <= 36, the sample is a base-d string using 0-9A-Z (A=10,...).

:Example:

Expand Down Expand Up @@ -874,7 +874,7 @@ def expectation(
:param nmc: repetition time for Monte Carlo sampling for noisfy calculation, defaults to 1000
:type nmc: int, optional
:param status: external randomness given by tensor uniformly from [0, 1], defaults to None,
used for noisfy circuit sampling
used for noisy circuit sampling
:type status: Optional[Tensor], optional
:raises ValueError: "Cannot measure two operators in one index"
:return: Tensor with one element
Expand Down
4 changes: 2 additions & 2 deletions tensorcircuit/densitymatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ def _contract(self) -> None:

@staticmethod
def check_kraus(kraus: Sequence[Gate]) -> bool:
"""
r"""
Check if Kraus operators satisfy the completeness relation:
sum_i K_i^ K_i = I
:math:`\sum_i K_i^\dagger K_i = I`

:param kraus: Sequence of Kraus operators
:type kraus: Sequence[Gate]
Expand Down
20 changes: 10 additions & 10 deletions tensorcircuit/quantum.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def _decode_basis_label(label: str, n: int, dim: int) -> List[int]:
"""
Decode a string basis label into a list of integer digits.

The label is interpreted in base-``dim`` using characters ``0–9A–Z``.
The label is interpreted in base-``dim`` using characters ``0-9A-Z``.
Only dimensions up to 36 are supported.

:param label: basis label string, e.g. "010" or "A9F"
Expand All @@ -97,7 +97,7 @@ def _decode_basis_label(label: str, n: int, dim: int) -> List[int]:
"""
if dim > 36:
raise NotImplementedError(
f"String basis label supports d<=36 (0–9A–Z). Got dim={dim}. "
f"String basis label supports d<=36 (0-9A-Z). Got dim={dim}. "
"Use an integer array/tensor of length n instead."
)
s = label.upper()
Expand All @@ -107,7 +107,7 @@ def _decode_basis_label(label: str, n: int, dim: int) -> List[int]:
for ch in s:
if ch not in _ALPHABET:
raise ValueError(
f"Invalid character '{ch}' in basis label (allowed 0–9A–Z)."
f"Invalid character '{ch}' in basis label (allowed 0-9A-Z)."
)
v = _ALPHABET.index(ch)
if v >= dim:
Expand Down Expand Up @@ -751,7 +751,7 @@ def tensor_product(self, other: "QuOperator") -> "QuOperator":
"""
Tensor product with another operator.
Given two operators `A` and `B`, produces a new operator `AB` representing
:math:`A B`. The `out_edges` (`in_edges`) of `AB` is simply the
:math:`A \otimes B`. The `out_edges` (`in_edges`) of `AB` is simply the
concatenation of the `out_edges` (`in_edges`) of `A.copy()` with that of
`B.copy()`:
`new_out_edges = [*out_edges_A_copy, *out_edges_B_copy]`
Expand Down Expand Up @@ -2403,13 +2403,13 @@ def free_energy(

def renyi_entropy(rho: Union[Tensor, QuOperator], k: int = 2) -> Tensor:
"""
Compute the Rényi entropy of order :math:`k` by given density matrix.
Compute the Renyi entropy of order :math:`k` by given density matrix.

:param rho: The density matrix in form of Tensor or QuOperator.
:type rho: Union[Tensor, QuOperator]
:param k: The order of Rényi entropy, default is 2.
:param k: The order of Renyi entropy, default is 2.
:type k: int, optional
:return: The :math:`k` th order of Rényi entropy.
:return: The :math:`k` th order of Renyi entropy.
:rtype: Tensor
"""
s = 1 / (1 - k) * backend.real(backend.log(trace_product(*[rho for _ in range(k)])))
Expand All @@ -2423,7 +2423,7 @@ def renyi_free_energy(
k: int = 2,
) -> Tensor:
"""
Compute the Rényi free energy of the corresponding density matrix and Hamiltonian.
Compute the Renyi free energy of the corresponding density matrix and Hamiltonian.

:Example:

Expand All @@ -2440,9 +2440,9 @@ def renyi_free_energy(
:type h: Union[Tensor, QuOperator]
:param beta: Constant for the optimization, default is 1.
:type beta: float, optional
:param k: The order of Rényi entropy, default is 2.
:param k: The order of Renyi entropy, default is 2.
:type k: int, optional
:return: The :math:`k` th order of Rényi entropy.
:return: The :math:`k` th order of Renyi entropy.
:rtype: Tensor
"""
energy = backend.real(trace_product(rho, h))
Expand Down
Loading