Skip to content

Commit 048e82e

Browse files
fix some warnings in tests
1 parent 5772515 commit 048e82e

File tree

11 files changed

+25
-21
lines changed

11 files changed

+25
-21
lines changed

pytest.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[pytest]
2+
filterwarnings =
3+
ignore::DeprecationWarning
4+
ignore:Explicitly requested dtype*:UserWarning

tensorcircuit/abstractcircuit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ def vis_tex(self, **kws: Any) -> str:
745745
"""
746746
if (not self.is_mps) and (self.inputs is not None):
747747
init = ["" for _ in range(self._nqubits)]
748-
init[self._nqubits // 2] = "\psi"
748+
init[self._nqubits // 2] = r"\psi"
749749
okws = {"init": init}
750750
else:
751751
okws = {"init": None} # type: ignore

tensorcircuit/applications/graphdata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ def regular_graph_generator(d: int, n: int, weights: bool = False) -> Iterator[G
290290

291291

292292
def _maxcut(g: Graph, values: Sequence[int]) -> float:
293-
"""
293+
r"""
294294
To get the max-cut for the graph g by given values $$\pm 1$$ on each vertex as a list.
295295
296296
:param g: The graph

tensorcircuit/applications/layers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def f(
8181

8282

8383
def generate_gate_layer(gate: str) -> None:
84-
"""
84+
r"""
8585
$$e^{-i\theta \sigma}$$
8686
8787
:param gate:
@@ -108,7 +108,7 @@ def f(
108108

109109

110110
def generate_any_gate_layer(gate: str) -> None:
111-
"""
111+
r"""
112112
$$e^{-i\theta_i \sigma}$$
113113
114114
:param gate:
@@ -392,7 +392,7 @@ def cirqcnotgate(
392392
return circuit
393393

394394
def generate_cirq_gate_layer(gate: str) -> None:
395-
"""
395+
r"""
396396
$$e^{-i\theta \sigma}$$
397397
398398
:param gate:
@@ -422,7 +422,7 @@ def f(
422422
setattr(thismodule, "cirq" + gate + "layer", f)
423423

424424
def generate_cirq_any_gate_layer(gate: str) -> None:
425-
"""
425+
r"""
426426
$$e^{-i\theta \sigma}$$
427427
428428
:param gate:

tensorcircuit/asciiart.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def __str__(self) -> str:
3838
(*)`(*)
3939
"""
4040

41-
__bigbike__ = """
41+
__bigbike__ = r"""
4242
$" *.
4343
d$$$$$$$P" $ J
4444
^$. 4r "
@@ -58,7 +58,7 @@ def __str__(self) -> str:
5858
"*==*"" ^"*==*"" Gilo94'
5959
"""
6060

61-
__moon__ = """
61+
__moon__ = r"""
6262
___---___
6363
.-- --.
6464
./ () .-. \.
@@ -77,7 +77,7 @@ def __str__(self) -> str:
7777
"""
7878

7979

80-
__cat__ = """
80+
__cat__ = r"""
8181
,_ _
8282
|\ _,-~/
8383
/ _ _ | ,--.
@@ -90,7 +90,7 @@ def __str__(self) -> str:
9090
((_/`(____,-'
9191
"""
9292

93-
__moonlanding__ = """
93+
__moonlanding__ = r"""
9494
_ _ ____________.--.
9595
|\|_|//_.-"" .' \ /| |
9696
|.-"-"-.| / \_/ | |
@@ -124,7 +124,7 @@ def __str__(self) -> str:
124124
125125
"""
126126

127-
__moonshot__ = """
127+
__moonshot__ = r"""
128128
.-.
129129
( (
130130
`-'

tensorcircuit/backends/jax_backend.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def is_tensor(self, a: Any) -> bool:
395395
return False
396396

397397
def solve(self, A: Tensor, b: Tensor, assume_a: str = "gen") -> Tensor: # type: ignore
398-
return jsp.linalg.solve(A, b, assume_a)
398+
return jsp.linalg.solve(A, b, assume_a=assume_a)
399399

400400
def searchsorted(self, a: Tensor, v: Tensor, side: str = "left") -> Tensor:
401401
if not self.is_tensor(a):
@@ -408,10 +408,10 @@ def tree_map(self, f: Callable[..., Any], *pytrees: Any) -> Any:
408408
return libjax.tree_map(f, *pytrees)
409409

410410
def tree_flatten(self, pytree: Any) -> Tuple[Any, Any]:
411-
return libjax.tree_flatten(pytree) # type: ignore
411+
return libjax.tree_util.tree_flatten(pytree) # type: ignore
412412

413413
def tree_unflatten(self, treedef: Any, leaves: Any) -> Any:
414-
return libjax.tree_unflatten(treedef, leaves)
414+
return libjax.tree_util.tree_unflatten(treedef, leaves)
415415

416416
def from_dlpack(self, a: Any) -> Tensor:
417417
import jax.dlpack

tensorcircuit/backends/numpy_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def left_shift(self, x: Tensor, y: Tensor) -> Tensor:
229229
def solve(self, A: Tensor, b: Tensor, assume_a: str = "gen") -> Tensor: # type: ignore
230230
# gen, sym, her, pos
231231
# https://stackoverflow.com/questions/44672029/difference-between-numpy-linalg-solve-and-numpy-linalg-lu-solve/44710451
232-
return solve(A, b, assume_a)
232+
return solve(A, b, assume_a=assume_a)
233233

234234
def searchsorted(self, a: Tensor, v: Tensor, side: str = "left") -> Tensor:
235235
return np.searchsorted(a, v, side=side) # type: ignore

tensorcircuit/quantum.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ def eval(
711711
return list(nodes)[0].tensor
712712

713713
def eval_matrix(self, final_edge_order: Optional[Sequence[Edge]] = None) -> Tensor:
714-
"""
714+
r"""
715715
Contracts the tensor network in place and returns the final tensor
716716
in two dimentional matrix.
717717
The default ordering for the axes of the final tensor is:
@@ -2176,7 +2176,7 @@ def spin_by_basis(n: int, m: int, elements: Tuple[int, int] = (1, -1)) -> Tensor
21762176

21772177

21782178
def correlation_from_samples(index: Sequence[int], results: Tensor, n: int) -> Tensor:
2179-
"""
2179+
r"""
21802180
Compute :math:`\prod_{i\in \\text{index}} s_i (s=\pm 1)`,
21812181
Results is in the format of "sample_int" or "sample_bin"
21822182
@@ -2200,7 +2200,7 @@ def correlation_from_samples(index: Sequence[int], results: Tensor, n: int) -> T
22002200

22012201

22022202
def correlation_from_counts(index: Sequence[int], results: Tensor) -> Tensor:
2203-
"""
2203+
r"""
22042204
Compute :math:`\prod_{i\in \\text{index}} s_i`,
22052205
where the probability for each bitstring is given as a vector ``results``.
22062206
Results is in the format of "count_vector"

tensorcircuit/templates/measurements.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def heisenberg_measurements(
218218
hy: float = 0.0,
219219
reuse: bool = True,
220220
) -> Tensor:
221-
"""
221+
r"""
222222
Evaluate Heisenberg energy expectation, whose Hamiltonian is defined on the lattice graph ``g`` as follows:
223223
(e are edges in graph ``g`` where e1 and e2 are two nodes for edge e and v are nodes in graph ``g``)
224224

tensorcircuit/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def wrapper(*args: Any, **kws: Any) -> Any:
136136
if isinstance(vs, str):
137137
vs = []
138138
for v in vs:
139-
if kws.get(v, "qazxswedcvfr198") != "qazxswedcvfr198":
139+
if v in kws:
140140
# in case it is None by design!
141141
kws[k] = kws[v]
142142
del kws[v]

tensorcircuit/vis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def qir2tex(
102102
p = max(flag[min(idx) : max(idx) + 1]) + 1
103103
for i in range(min(idx), max(idx) + 1):
104104
tex_string_table[i] += [r"\qw "] * (p - flag[i] - 1)
105-
tex_string_table[i] += [r"\ghost{" + x["name"][7:] + "}\qw "]
105+
tex_string_table[i] += [r"\ghost{" + x["name"][7:] + r"}\qw "]
106106
flag[i] = p
107107
else:
108108
ctrl_number, gate_name = gate_name_trans(x["name"])

0 commit comments

Comments
 (0)