Skip to content

Commit e3ecca4

Browse files
committed
adjust some unicode and doc fixing.
1 parent 06a3c14 commit e3ecca4

File tree

7 files changed

+31
-26
lines changed

7 files changed

+31
-26
lines changed

examples/time_evolution_comparison.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ def create_heisenberg_hamiltonian(n, sparse=True):
2727

2828

2929
def create_initial_state(n):
30-
"""Create initial Neel state |↑↓↑↓↑↓↑↓> for n sites."""
30+
r"""
31+
Create initial Neel state
32+
:math:`\vert \uparrow\downarrow\uparrow\downarrow\uparrow\downarrow\uparrow\downarrow\rangle`
33+
for n sites.
34+
"""
3135
c = tc.Circuit(n)
3236
# Apply X gates to odd sites to create Neel state
3337
c.x([i for i in range(1, n, 2)])

examples/vqe_qudit_example.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
This example shows how to run a simple VQE on a qudit system using
55
`tensorcircuit.QuditCircuit`. We build a compact ansatz using single-qudit
66
rotations in selected two-level subspaces and RXX-type entanglers, then
7-
optimize the energy of a Hermitian "clockshift" Hamiltonian:
7+
optimize the energy of a Hermitian "clock-shift" Hamiltonian:
88
99
H(d) = - J * (X_c \otimes X_c) - h * (Z_c \otimes I + I \otimes Z_c)
1010
@@ -31,12 +31,12 @@
3131

3232

3333
def vqe_forward(param, *, nqudits: int, d: int, nlayers: int, J: float, h: float):
34-
"""Build a QuditCircuit ansatz and compute ⟨H⟩.
34+
r"""Build a QuditCircuit ansatz and compute :math:`\langle H\rangle`.
3535
3636
Ansatz:
3737
[ for L in 1...nlayers ]
3838
- On each site q:
39-
RX(q; θ_Lq^(01)) RY(q; θ_Lq^(12)) RZ(q; φ_Lq^(0))
39+
:math:`RX(q; \theta_L q^(01)) RY(q; \theta_L q^(12)) RZ(q; \phi_L q^(0))`
4040
(subspace indices shown as superscripts)
4141
- Entangle neighboring pairs with RXX on subspaces (0,1)
4242
"""
@@ -86,7 +86,7 @@ def build_param_shape(nqudits: int, d: int, nlayers: int):
8686

8787
def main():
8888
parser = argparse.ArgumentParser(
89-
description="VQE on QuditCircuit (clockshift model)"
89+
description="VQE on QuditCircuit (clock-shift model)"
9090
)
9191
parser.add_argument(
9292
"--d", type=int, default=3, help="Local dimension per site (>=3)"

tensorcircuit/basecircuit.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
Note:
55
- Supports qubit (d = 2) and qudit (d >= 2) systems.
6-
- For string-encoded samples/counts when d <= 36, digits use base-d characters 0–9A–Z (A = 10, , Z = 35).
6+
- For string-encoded samples/counts when d <= 36, digits use base-d characters 0-9A-Z (A = 10, ..., Z = 35).
77
"""
88

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

363363
def perfect_sampling(self, status: Optional[Tensor] = None) -> Tuple[str, float]:
364364
"""
365-
Sampling base-d strings (0–9A–Z when d <= 36) from the circuit output based on quantum amplitudes.
365+
Sampling base-d strings (0-9A-Z when d <= 36) from the circuit output based on quantum amplitudes.
366366
Reference: arXiv:1201.3974.
367367
368368
:param status: external randomness, with shape [nqubits], defaults to None
@@ -604,7 +604,7 @@ def sample(
604604
"count_tuple": # (np.array([0]), np.array([2]))
605605
606606
"count_dict_bin": # {"00": 2, "01": 0, "10": 0, "11": 0}
607-
for cases d\in [11, 36], use 0–9A–Z digits (e.g., 'A' -> 10, , 'Z' -> 35);
607+
for cases d\in [11, 36], use 0-9A-Z digits (e.g., 'A' -> 10, ..., 'Z' -> 35);
608608
609609
"count_dict_int": # {0: 2, 1: 0, 2: 0, 3: 0}
610610

tensorcircuit/circuit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
Quantum circuit: the state simulator.
33
Supports qubit (dim=2) and qudit (3 <= dim <= 36) systems.
4-
For string-encoded samples/counts, digits use 0–9A–Z where A=10, , Z=35.
4+
For string-encoded samples/counts, digits use 0-9A-Z where A=10, ..., Z=35.
55
"""
66

77
# pylint: disable=invalid-name
@@ -768,7 +768,7 @@ def measure_reference(
768768
Take measurement on the given quantum lines by ``index``.
769769
770770
Return format:
771-
- For d <= 36, the sample is a base-d string using 0–9A–Z (A=10,).
771+
- For d <= 36, the sample is a base-d string using 0-9A-Z (A=10,...).
772772
773773
:Example:
774774

tensorcircuit/quditcircuit.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
This module provides a high-level `QuditCircuit` API that mirrors `tensorcircuit.circuit.Circuit`
55
but targets qudits with dimension `3 <= d <= 36`.
6-
For string-encoded samples/counts, digits use `0–9A–Z` where `A=10, , Z=35`.
6+
For string-encoded samples/counts, digits use `0-9A-Z` where `A=10, ..., Z=35`.
77
88
.. note::
99
For qubits (`d=2`) please use :class:`tensorcircuit.circuit.Circuit`.
@@ -42,8 +42,8 @@ class QuditCircuit:
4242
>>> c.sample(1024, format="count_dict_bin")
4343
4444
.. note::
45-
For `3 <= d <= 36`, string samples and count keys use base-`d` characters `0–9A–Z`
46-
(`A=10, , Z=35`).
45+
For `3 <= d <= 36`, string samples and count keys use base-`d` characters `0-9A-Z`
46+
(`A=10, ..., Z=35`).
4747
4848
:param nqudits: Number of qudits (wires) in the circuit.
4949
:type nqudits: int
@@ -94,7 +94,7 @@ def _set_dim(self, dim: int) -> None:
9494
f"QuditCircuit is only for qudits (dim>=3). "
9595
f"You passed dim={dim}. For qudits, please use `Circuit` instead."
9696
)
97-
# Require integer d>=2; current string-encoded IO supports d<=36 (0–9A–Z digits).
97+
# Require integer d>=2; current string-encoded IO supports d<=36 (0-9A-Z digits).
9898
if dim > 36:
9999
raise NotImplementedError(
100100
"The Qudit interface is only supported for dimension < 36 now."
@@ -486,7 +486,7 @@ def amplitude(self, l: Union[str, Tensor]) -> Tensor:
486486
>>> c.amplitude("21")
487487
array(1.+0.j, dtype=complex64)
488488
489-
:param l: Bitstring in base-`d` using `0–9A–Z`.
489+
:param l: Bitstring in base-`d` using `0-9A-Z`.
490490
:type l: Union[str, Tensor]
491491
:return: Complex amplitude.
492492
:rtype: Tensor
@@ -528,7 +528,7 @@ def sample(
528528
"count_vector": # np.array([2, 0, 0, 0])
529529
530530
"count_dict_bin": # {"00": 2, "01": 0, "10": 0, "11": 0}
531-
for cases d\in [11, 36], use 0–9A–Z digits (e.g., 'A' -> 10, , 'Z' -> 35);
531+
for cases :math:`d\in [11, 36]`, use 0-9A-Z digits (e.g., 'A' -> 10, ..., 'Z' -> 35);
532532
533533
:type format: Optional[str]
534534
:param random_generator: random generator, defaults to None
@@ -593,7 +593,7 @@ def mid_measurement(self, index: int, keep: int = 0) -> Tensor:
593593
594594
:param index: Qudit index where post-selection is applied.
595595
:type index: int
596-
:param keep: Post-selected digit in `{0, , d-1}`.
596+
:param keep: Post-selected digit in `{0, ..., d-1}`.
597597
:type keep: int
598598
:return: Unnormalized post-selected state.
599599
:rtype: Tensor
@@ -662,7 +662,7 @@ def amplitude_before(self, l: Union[str, Tensor]) -> List[Gate]:
662662
For density-matrix simulators,
663663
it would correspond to :math:`\operatorname{Tr}(\rho \vert l \rangle \langle l \vert)`.
664664
665-
:param l: Base-`d` string using `0–9A–Z` or an equivalent tensor index.
665+
:param l: Base-`d` string using `0-9A-Z` or an equivalent tensor index.
666666
:type l: Union[str, Tensor]
667667
:return: The tensornetwork nodes for the amplitude of the circuit.
668668
:rtype: List[Gate]

tensorcircuit/quditgates.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def _check_rotation_indices(
195195
j1, k1, j2, k2 = indices
196196
if j1 == k1 and j2 == k2:
197197
raise ValueError(
198-
"Selected basis states must be different: (j1, j2) (k1, k2)."
198+
"Selected basis states must be different: (j1, j2) != (k1, k2)."
199199
)
200200

201201

@@ -343,7 +343,7 @@ def rzz_matrix_func(
343343
Two-qudit ``RZZ(\theta)`` on a selected two-state subspace.
344344
345345
Acts like a qubit :math:`RZZ(\theta)=\exp(-i\,\tfrac{\theta}{2}\,\sigma_z)` on the
346-
two-dimensional subspace spanned by ``|j1, j2⟩`` and ``|k1, k2⟩``,
346+
two-dimensional subspace spanned by :math:`\lvert j1, j2\rangle` and :math:`\lvert k1, k2\rangle`,
347347
and as identity elsewhere. The resulting block is diagonal with phases
348348
:math:`\mathrm{diag}(e^{-i\theta/2},\, e^{+i\theta/2})`.
349349
@@ -384,7 +384,8 @@ def rxx_matrix_func(
384384
r"""
385385
Two-qudit ``RXX(\theta)`` on a selected two-state subspace.
386386
387-
Acts like a qubit :math:`RXX` on the subspace spanned by ``|j1, j2⟩`` and ``|k1, k2⟩``.
387+
Acts like a qubit :math:`RXX` on the subspace spanned by
388+
:math:`\lvert j1, j2\rangle` and :math:`\lvert k1, k2\rangle`.
388389
389390
:param d: Dimension of each qudit (assumed equal).
390391
:type d: int
@@ -429,7 +430,7 @@ def u8_matrix_func(
429430
``U8`` diagonal single-qudit gate for prime dimensions.
430431
431432
See ref: Howard, Mark, and Jiri Vala.
432-
"Qudit versions of the qubit π/8 gate." Physical Review A 86, no. 2 (2012): 022316.
433+
"Qudit versions of the qubit \pi/8 gate." Physical Review A 86, no. 2 (2012): 022316.
433434
https://doi.org/10.1103/PhysRevA.86.022316
434435
435436
This gate is the qudit analogue of the qubit :math:`\pi/8` gate, defined in
@@ -448,8 +449,8 @@ def u8_matrix_func(
448449
:param d: Qudit dimension (must be prime).
449450
:type d: int
450451
:param gamma: Shear parameter :math:`\gamma' \in \mathbb{Z}_d`.
451-
If ``gamma = 0``, the gate is a diagonal Clifford.
452-
If ``gamma ≠ 0``, the gate is a genuine non-Clifford (analogue of :math:`\pi/8`).
452+
If :math:`gamma = 0`, the gate is a diagonal Clifford.
453+
If :math:`gamma \neq 0`, the gate is a genuine non-Clifford (analogue of :math:`\pi/8`).
453454
:type gamma: int
454455
:param z: Displacement parameter :math:`z' \in \mathbb{Z}_d`,
455456
which sets the symplectic part of the associated Clifford.

tests/test_quditcircuit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,8 @@ def test_quditcircuit_set_dim_validation():
350350

351351
@pytest.mark.parametrize("backend", [lf("jaxb"), lf("tfb"), lf("torchb")])
352352
def test_qudit_minimal_ad_qudit(backend):
353-
"""Minimal AD test on a single-qudit (d=3) circuit.
354-
We differentiate the expectation ⟨Z⟩ w.r.t. a single RY parameter and
353+
r"""Minimal AD test on a single-qudit (d=3) circuit.
354+
We differentiate the expectation :math:`\langle Z\rangle` w.r.t. a single RY parameter and
355355
compare to a finite-difference estimate.
356356
"""
357357

0 commit comments

Comments
 (0)