From c010d3c996eac8f19bf5a66cd6d3311d8e94a844 Mon Sep 17 00:00:00 2001 From: Lauren Capelluto Date: Thu, 26 Aug 2021 10:53:17 -0400 Subject: [PATCH] Fix lint errors --- .../optimization/inverse_cancellation.py | 2 +- .../transpiler/test_inverse_cancellation.py | 22 ++++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/qiskit/transpiler/passes/optimization/inverse_cancellation.py b/qiskit/transpiler/passes/optimization/inverse_cancellation.py index d132482c6f84..65b752ae8afc 100644 --- a/qiskit/transpiler/passes/optimization/inverse_cancellation.py +++ b/qiskit/transpiler/passes/optimization/inverse_cancellation.py @@ -46,7 +46,7 @@ def __init__(self, gates_to_cancel: List[Union[Gate, Tuple[Gate, Gate]]]): raise TranspilerError( "Too many or too few inputs: {}. Only two are allowed.".format(gates) ) - elif gates[0] != gates[1].inverse(): + if gates[0] != gates[1].inverse(): raise TranspilerError( "Gate {} and {} are not inverse.".format(gates[0].name, gates[1].name) ) diff --git a/test/python/transpiler/test_inverse_cancellation.py b/test/python/transpiler/test_inverse_cancellation.py index 939f7fdebe10..c5cb5639b089 100644 --- a/test/python/transpiler/test_inverse_cancellation.py +++ b/test/python/transpiler/test_inverse_cancellation.py @@ -25,6 +25,8 @@ class TestInverseCancellation(QiskitTestCase): + """Test the InverseCancellation transpiler pass.""" + def test_basic_self_inverse(self): """Test that a single self-inverse gate as input can be cancelled.""" qc = QuantumCircuit(2, 2) @@ -83,14 +85,6 @@ def test_non_inverse_do_not_cancel(self): self.assertIn("rx", gates_after) self.assertEqual(gates_after["rx"], 2) - def test_non_inverse_raise_error(self): - """Test that non-inverse gate inputs raise an error.""" - qc = QuantumCircuit(2, 2) - qc.rx(np.pi / 2, 0) - qc.rx(np.pi / 4, 0) - with self.assertRaises(TranspilerError): - pass_ = InverseCancellation([RXGate(0.5)]) - def test_non_consecutive_gates(self): """Test that only consecutive gates cancel.""" qc = QuantumCircuit(2, 2) @@ -131,13 +125,21 @@ def test_self_inverse_on_different_qubits(self): gates_after = new_circ.count_ops() self.assertNotIn("h", gates_after) + def test_non_inverse_raise_error(self): + """Test that non-inverse gate inputs raise an error.""" + qc = QuantumCircuit(2, 2) + qc.rx(np.pi / 2, 0) + qc.rx(np.pi / 4, 0) + with self.assertRaises(TranspilerError): + InverseCancellation([RXGate(0.5)]) + def test_non_gate_inverse_raise_error(self): """Test that non-inverse gate inputs raise an error.""" qc = QuantumCircuit(2, 2) qc.rx(np.pi / 4, 0) qc.rx(np.pi / 4, 0) with self.assertRaises(TranspilerError): - pass_ = InverseCancellation([(RXGate(np.pi / 4))]) + InverseCancellation([(RXGate(np.pi / 4))]) def test_string_gate_error(self): """Test that when gate is passed as a string an error is raised.""" @@ -145,7 +147,7 @@ def test_string_gate_error(self): qc.h(0) qc.h(0) with self.assertRaises(TranspilerError): - pass_ = InverseCancellation(["h"]) + InverseCancellation(["h"]) def test_consecutive_self_inverse_h_x_gate(self): """Test that only consecutive self-inverse gates cancel."""