New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Correctly compare Controlled operators with differing control wire order #4944
Conversation
Hello. You may have forgotten to update the changelog!
|
[sc-50266] |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #4944 +/- ##
==========================================
- Coverage 99.66% 99.66% -0.01%
==========================================
Files 388 388
Lines 35379 35111 -268
==========================================
- Hits 35262 34993 -269
- Misses 117 118 +1 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice! 🏆 🎉
…ylane into controlled_equal_update
…der (#4944) **Context:** As long as the mapping of control wires to control values is the same, the order of control wires doesn't matter when comparing two Controlled operators, but the current implementation of `qml.equal` doesn't consider this. This currently returns False, because the wires differ in order: ``` base1 = qml.PauliX(wires=0) base2 = qml.PauliX(wires=0) op1 = qml.ops.op_math.Controlled(base1, control_wires=[1, 2]) op2 = qml.ops.op_math.Controlled(base2, control_wires=[2, 1]) print(qml.equal(op1, op2)) ``` **Description of the Change:** Instead of comparing the operator wires and the control values, we compare the `work_wires` of the two operators, and we compare dictionaries of `{wire1: value1, wire2: value2...}`. **Benefits:** The comparison of operators via `qml.equal` is more complete. **Related GitHub Issues:** #4842
…der (#4944) **Context:** As long as the mapping of control wires to control values is the same, the order of control wires doesn't matter when comparing two Controlled operators, but the current implementation of `qml.equal` doesn't consider this. This currently returns False, because the wires differ in order: ``` base1 = qml.PauliX(wires=0) base2 = qml.PauliX(wires=0) op1 = qml.ops.op_math.Controlled(base1, control_wires=[1, 2]) op2 = qml.ops.op_math.Controlled(base2, control_wires=[2, 1]) print(qml.equal(op1, op2)) ``` **Description of the Change:** Instead of comparing the operator wires and the control values, we compare the `work_wires` of the two operators, and we compare dictionaries of `{wire1: value1, wire2: value2...}`. **Benefits:** The comparison of operators via `qml.equal` is more complete. **Related GitHub Issues:** #4842
Context:
As long as the mapping of control wires to control values is the same, the order of control wires doesn't matter when comparing two Controlled operators, but the current implementation of
qml.equal
doesn't consider this. This currently returns False, because the wires differ in order:Description of the Change:
Instead of comparing the operator wires and the control values, we compare the
work_wires
of the two operators, and we compare dictionaries of{wire1: value1, wire2: value2...}
.Benefits:
The comparison of operators via
qml.equal
is more complete.Related GitHub Issues:
#4842