Skip to content

Commit f771f26

Browse files
committed
Revert "Fixes Wires objects as wire labels bug (#6933)"
This reverts commit e0b2174.
1 parent 8bb96b2 commit f771f26

File tree

2 files changed

+5
-20
lines changed

2 files changed

+5
-20
lines changed

pennylane/wires.py

+2-11
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ def _process(wires):
9393
if len(set_of_wires) != len(tuple_of_wires):
9494
raise WireError(f"Wires must be unique; got {wires}.")
9595

96-
# required to make `Wires` object idempotent
97-
return tuple(itertools.chain(*(_flatten_wires_object(x) for x in tuple_of_wires)))
96+
return tuple_of_wires
9897

9998

10099
class Wires(Sequence):
@@ -121,7 +120,7 @@ class Wires(Sequence):
121120
"""
122121

123122
def _flatten(self):
124-
"""Serialize Wires into a flattened representation according to the PyTree convention."""
123+
"""Serialize Wires into a flattened representation according to the PyTree convension."""
125124
return self._labels, ()
126125

127126
@classmethod
@@ -732,13 +731,5 @@ def __rxor__(self, other):
732731

733732
WiresLike = Union[Wires, Iterable[Hashable], Hashable]
734733

735-
736-
def _flatten_wires_object(wire_label):
737-
"""Converts the input to a tuple of wire labels."""
738-
if isinstance(wire_label, Wires):
739-
return wire_label.labels
740-
return [wire_label]
741-
742-
743734
# Register Wires as a PyTree-serializable class
744735
register_pytree(Wires, Wires._flatten, Wires._unflatten) # pylint: disable=protected-access

tests/test_wires.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@
3434
class TestWires:
3535
"""Tests for the ``Wires`` class."""
3636

37-
def test_wires_object_as_label(self):
38-
"""Tests that a Wires object can be used as a label for another Wires object."""
39-
assert Wires([0, 1]) == Wires([Wires([0]), Wires([1])])
40-
assert Wires(["a", "b", 1]) == Wires([Wires(["a", "b"]), Wires([1])])
41-
assert Wires([Wires([(0, 0), (0, 1)])]) == Wires([(0, 0), (0, 1)])
42-
4337
def test_error_if_wires_none(self):
4438
"""Tests that a TypeError is raised if None is given as wires."""
4539
with pytest.raises(TypeError, match="Must specify a set of wires."):
@@ -80,7 +74,7 @@ def test_creation_from_wires_lists(self):
8074
"""Tests that a Wires object can be created from a list of Wires."""
8175

8276
wires = Wires([Wires([0]), Wires([1]), Wires([2])])
83-
assert wires.labels == (0, 1, 2)
77+
assert wires.labels == (Wires([0]), Wires([1]), Wires([2]))
8478

8579
@pytest.mark.parametrize(
8680
"iterable", [[1, 0, 4], ["a", "b", "c"], [0, 1, None], ["a", 1, "ancilla"]]
@@ -154,7 +148,7 @@ def test_contains(
154148
wires = Wires([0, 1, 2, 3, Wires([4, 5]), None])
155149

156150
assert 0 in wires
157-
assert Wires([4, 5]) not in wires
151+
assert Wires([4, 5]) in wires
158152
assert None in wires
159153
assert Wires([1]) not in wires
160154
assert Wires([0, 3]) not in wires
@@ -176,7 +170,7 @@ def test_contains_wires(
176170

177171
assert not wires.contains_wires(0) # wrong type
178172
assert not wires.contains_wires([0, 1]) # wrong type
179-
assert wires.contains_wires(
173+
assert not wires.contains_wires(
180174
Wires([4, 5])
181175
) # looks up 4 and 5 in wires, which are not present
182176

0 commit comments

Comments
 (0)