Skip to content

Commit

Permalink
🚸 Rename arg
Browse files Browse the repository at this point in the history
  • Loading branch information
EarlMilktea committed Nov 1, 2024
1 parent d7d6780 commit c320ea9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions graphix/pauli.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@ def __neg__(self) -> Pauli:
return dataclasses.replace(self, unit=-self.unit)

@staticmethod
def iterate(include_unit: bool = True) -> Iterator[Pauli]:
def iterate(symbol_only: bool = False) -> Iterator[Pauli]:
"""Iterate over all Pauli gates.
Parameters
----------
include_unit (bool, optional): Include the unit in the iteration. Defaults to True.
symbol_only (bool, optional): Exclude the unit in the iteration. Defaults to False.
"""
us = tuple(ComplexUnit) if include_unit else (ComplexUnit.ONE,)
us = (ComplexUnit.ONE,) if symbol_only else tuple(ComplexUnit)
for symbol in IXYZ:
for unit in us:
yield Pauli(symbol, unit)
Expand Down
16 changes: 8 additions & 8 deletions tests/test_pauli.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_unit_mul(self, u: ComplexUnit, p: Pauli) -> None:
def test_matmul(self, a: Pauli, b: Pauli) -> None:
assert np.allclose((a @ b).matrix, a.matrix @ b.matrix)

@pytest.mark.parametrize("p", Pauli.iterate(include_unit=False))
@pytest.mark.parametrize("p", Pauli.iterate(symbol_only=True))
def test_repr(self, p: Pauli) -> None:
pstr = f"Pauli.{p.symbol.name}"
assert repr(p) == pstr
Expand All @@ -45,7 +45,7 @@ def test_repr(self, p: Pauli) -> None:
assert repr(-1 * p) == f"-{pstr}"
assert repr(-1j * p) == f"-1j * {pstr}"

@pytest.mark.parametrize("p", Pauli.iterate(include_unit=False))
@pytest.mark.parametrize("p", Pauli.iterate(symbol_only=True))
def test_str(self, p: Pauli) -> None:
pstr = p.symbol.name
assert str(p) == pstr
Expand All @@ -59,16 +59,16 @@ def test_neg(self, p: Pauli) -> None:
pneg = -p
assert pneg == -p

def test_iterate_false(self) -> None:
cmp = list(Pauli.iterate(include_unit=False))
def test_iterate_true(self) -> None:
cmp = list(Pauli.iterate(symbol_only=True))
assert len(cmp) == 4
assert cmp[0] == Pauli.I
assert cmp[1] == Pauli.X
assert cmp[2] == Pauli.Y
assert cmp[3] == Pauli.Z

def test_iterate_true(self) -> None:
cmp = list(Pauli.iterate(include_unit=True))
def test_iterate_false(self) -> None:
cmp = list(Pauli.iterate(symbol_only=False))
assert len(cmp) == 16
assert cmp[0] == Pauli.I
assert cmp[1] == 1j * Pauli.I
Expand All @@ -88,14 +88,14 @@ def test_iterate_true(self) -> None:
assert cmp[15] == -1j * Pauli.Z

def test_iter_meta(self) -> None:
it = Pauli.iterate(include_unit=True)
it = Pauli.iterate(symbol_only=False)
it_ = iter(Pauli)
for p, p_ in zip(it, it_):
assert p == p_
assert all(False for _ in it)
assert all(False for _ in it_)

@pytest.mark.parametrize(("p", "b"), itertools.product(Pauli.iterate(include_unit=False), [0, 1]))
@pytest.mark.parametrize(("p", "b"), itertools.product(Pauli.iterate(symbol_only=True), [0, 1]))
def test_eigenstate(self, p: Pauli, b: int) -> None:
ev = float(Sign.plus_if(b == 0)) if p != Pauli.I else 1
evec = p.eigenstate(b).get_statevector()
Expand Down

0 comments on commit c320ea9

Please sign in to comment.