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.
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:
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()
.
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)