Skip to content

Commit

Permalink
fix typo in soft_compare (#12054)
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>
  • Loading branch information
ewinston and 1ucian0 committed Mar 24, 2024
1 parent 17949dc commit 5e7a6d0
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 @@ -240,8 +240,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 5e7a6d0

Please sign in to comment.