Skip to content

Commit

Permalink
fix typo in soft_compare (#12054) (#12073)
Browse files Browse the repository at this point in the history
* fix logic in soft_compare

* black

* add release note

* Update releasenotes/notes/fix_soft_compare-3f4148aab3a4606b.yaml

---------

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
(cherry picked from commit 5e7a6d0)

Co-authored-by: ewinston <ewinston@us.ibm.com>
  • Loading branch information
mergify[bot] and ewinston committed Mar 25, 2024
1 parent d562ed5 commit 7c1b510
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions qiskit/circuit/instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ def soft_compare(self, other: "Instruction") -> bool:
"""
if (
self.name != other.name
or other.num_qubits != other.num_qubits
or other.num_clbits != other.num_clbits
or self.num_qubits != other.num_qubits
or self.num_clbits != other.num_clbits
or len(self.params) != len(other.params)
):
return False
Expand Down
4 changes: 4 additions & 0 deletions releasenotes/notes/fix_soft_compare-3f4148aab3a4606b.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
The method :meth:`qiskit.instruction.Instruction.soft_compare` is meant to compare whether two gates match in their name, number of qubits, number of clbits, and the number of parameters. However, there was a typo where it would not check the number of qubits and number of clbits for a match. This resolves the apparent typo.
6 changes: 6 additions & 0 deletions test/python/circuit/test_instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ def test_instructions_soft_compare(self):
Instruction("u", 1, 0, [0.4, phi]).soft_compare(Instruction("v", 1, 0, [theta, phi]))
)

# Test that when names are the same but number of qubits differ we get False
self.assertFalse(Instruction("u", 1, 0, []).soft_compare(Instruction("u", 2, 0, [])))

# Test that when names are the same but number of clbits differ we get False
self.assertFalse(Instruction("u", 1, 0, []).soft_compare(Instruction("u", 1, 1, [])))

# Test cutoff precision.
self.assertFalse(
Instruction("v", 1, 0, [0.401, phi]).soft_compare(Instruction("v", 1, 0, [0.4, phi]))
Expand Down

0 comments on commit 7c1b510

Please sign in to comment.