# QuantumTape map\_wires equality

**URL:** <https://discuss.pennylane.ai/t/quantumtape-map-wires-equality/3867>\
**Category:** PennyLane Help\
**Created:** [January 6, 2024, 10:35pm UTC](https://discuss.pennylane.ai/t/quantumtape-map-wires-equality/3867 "2024-01-06T22:35:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryanhill1](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/ryanhill1/32/447_2.png) [@ryanhill1](https://discuss.pennylane.ai/u/ryanhill1)\
**Post date:** [January 6, 2024, 10:35pm UTC](https://discuss.pennylane.ai/t/quantumtape-map-wires-equality/3867/1 "2024-01-06T22:35:49Z")

</div>

Hello! If applicable, put your complete code example down below. Make sure that your code:

- is 100% self-contained — someone can copy-paste exactly what is here and run it to  
reproduce the behaviour you are observing
- includes comments

Code to reverse wire ordering using `qml.map_wires`.

Wires seem to be re-ordered as expected. However, fails equality comparison against regularly constructed tape with reverse wire ordering.

```auto
import pennylane as qml

def two_wire_tape(wire1, wire2):
    with qml.tape.QuantumTape() as tape:
        qml.Hadamard(wires=wire1)
        qml.CNOT(wires=[wire1, wire2])
    return tape

wires = [0, 1]
wires_rev = wires[::-1]

tape = two_wire_tape(*wires)
tape_rev_expected = two_wire_tape(*wires_rev)

wire_map = dict(zip(wires, wires_rev))

[tape_rev], _ = qml.map_wires(tape, wire_map)

assert tape_rev.wires == tape_rev_expected.wires # True
assert tape_rev.operations == tape_rev_expected.operations # True
assert str(tape_rev) == str(tape_rev_expected) # True
assert repr(tape_rev) == repr(tape_rev_expected) # True
assert tape_rev == tape_rev_expected # False

```

If you want help with diagnosing an error, please put the full error message below:

```auto
assert <QuantumTape:... 0], params=0> == <QuantumTape:... 0], params=0>
E (pytest_assertion plugin: representation of details failed: /path/to/env/lib/python3.10/site-packages/pennylane/queuing.py:413: KeyError: Wrapped(Hadamard(wires=[1])).
E Probably an object has a faulty __repr__.)

```

And, finally, make sure to include the versions of your packages. Specifically, show us the output of `qml.about()`.

```auto
Name: PennyLane
Version: 0.33.1
Summary: PennyLane is a Python quantum machine learning library by Xanadu Inc.
Home-page: https://github.com/PennyLaneAI/pennylane
Author: 
Author-email: 
License: Apache License 2.0
Location: /Users/ryanhill/anaconda3/envs/sdk310/lib/python3.10/site-packages
Requires: appdirs, autograd, autoray, cachetools, networkx, numpy, pennylane-lightning, requests, rustworkx, scipy, semantic-version, toml, typing-extensions
Required-by: PennyLane-Lightning

Platform info: macOS-14.1.2-arm64-arm-64bit
Python version: 3.10.13
Numpy version: 1.26.3
Scipy version: 1.11.4
Installed devices:
- default.gaussian (PennyLane-0.33.1)
- default.mixed (PennyLane-0.33.1)
- default.qubit (PennyLane-0.33.1)
- default.qubit.autograd (PennyLane-0.33.1)
- default.qubit.jax (PennyLane-0.33.1)
- default.qubit.legacy (PennyLane-0.33.1)
- default.qubit.tf (PennyLane-0.33.1)
- default.qubit.torch (PennyLane-0.33.1)
- default.qutrit (PennyLane-0.33.1)
- null.qubit (PennyLane-0.33.1)
- lightning.qubit (PennyLane-Lightning-0.33.1)

```

---

<div class="post-metadata">

**Author:** ![christina](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/christina/32/583_2.png) [@christina](https://discuss.pennylane.ai/u/christina)\
**Post date:** [January 8, 2024, 2:30pm UTC](https://discuss.pennylane.ai/t/quantumtape-map-wires-equality/3867/2 "2024-01-08T14:30:59Z")

</div>

Thanks for asking @ryanhill1 .

While we have changed the dunder behavior for `Operator` and `MeasurementProcess` to depend on the contents instead of the object identity, we have not made that switch for `QuantumTape`. We could potentially consider doing so in the future.

For now, you can use `qml.equal(tape1, tape2)` to check equality of two tapes.

---

<div class="post-metadata">

**Author:** ![ryanhill1](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/ryanhill1/32/447_2.png) [@ryanhill1](https://discuss.pennylane.ai/u/ryanhill1)\
**Post date:** [January 8, 2024, 5:34pm UTC](https://discuss.pennylane.ai/t/quantumtape-map-wires-equality/3867/3 "2024-01-08T17:34:39Z")

</div>

Thanks @christina. I tried out `qml.equal(tape1, tape2)` but got:

`NotImplementedError: Comparison of <class 'pennylane.tape.tape.QuantumTape'> and <class 'pennylane.tape.tape.QuantumTape'> not implemented`

---

<div class="post-metadata">

**Author:** ![christina](https://yyz2.discourse-cdn.com/flex012/user_avatar/discuss.pennylane.ai/christina/32/583_2.png) [@christina](https://discuss.pennylane.ai/u/christina)\
**Post date:** [January 8, 2024, 5:48pm UTC](https://discuss.pennylane.ai/t/quantumtape-map-wires-equality/3867/4 "2024-01-08T17:48:44Z")

</div>

Ah sorry. That got added to master in November. But it will be in the next release coming out later today/ tomorrow!
