Skip to content

Commit

Permalink
Simplify remaining control flow op tests for ConsolidateBlocks
Browse files Browse the repository at this point in the history
These simplifications are similar to those made for the first test.
  • Loading branch information
jlapeyre committed Jul 19, 2023
1 parent be2a65f commit 8eae8c3
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions test/python/transpiler/test_consolidate_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,8 @@ def test_not_crossing_between_control_flow_block_and_parent(self):
blocks and the parent circuit."""
qc = QuantumCircuit(2, 1)
qc.cx(0, 1)
qc_true = QuantumCircuit(qc.qubits, qc.clbits)
qc_false = QuantumCircuit(qc.qubits, qc.clbits)
qc_true = QuantumCircuit(2, 1)
qc_false = QuantumCircuit(2, 1)
qc_true.cx(0, 1)
qc_false.cz(0, 1)
ifop = IfElseOp((qc.clbits[0], True), qc_true, qc_false)
Expand All @@ -472,17 +472,18 @@ def test_not_crossing_between_control_flow_block_and_parent(self):
qc_out = pass_manager.run(qc)

self.assertIsInstance(qc_out[0].operation, UnitaryGate)
np.testing.assert_allclose(CXGate().to_matrix(), qc_out[0].operation.to_matrix())
np.testing.assert_allclose(CXGate(), qc_out[0].operation)
op_true = qc_out[1].operation.blocks[0][0].operation
op_false = qc_out[1].operation.blocks[1][0].operation
np.testing.assert_allclose(CXGate().to_matrix(), op_true.to_matrix())
np.testing.assert_allclose(CZGate().to_matrix(), op_false.to_matrix())
np.testing.assert_allclose(CXGate(), op_true)
np.testing.assert_allclose(CZGate(), op_false)


def test_not_crossing_between_control_flow_ops(self):
"""Test that consolidation does not occur between control flow ops."""
qc = QuantumCircuit(2, 1)
qc_true = QuantumCircuit(qc.qubits, qc.clbits)
qc_false = QuantumCircuit(qc.qubits, qc.clbits)
qc_true = QuantumCircuit(2, 1)
qc_false = QuantumCircuit(2, 1)
qc_true.cx(0, 1)
qc_false.cz(0, 1)
ifop1 = IfElseOp((qc.clbits[0], True), qc_true, qc_false)
Expand All @@ -499,10 +500,10 @@ def test_not_crossing_between_control_flow_ops(self):
op_false1 = qc_out[0].operation.blocks[1][0].operation
op_true2 = qc_out[1].operation.blocks[0][0].operation
op_false2 = qc_out[1].operation.blocks[1][0].operation
np.testing.assert_allclose(CXGate().to_matrix(), op_true1.to_matrix())
np.testing.assert_allclose(CZGate().to_matrix(), op_false1.to_matrix())
np.testing.assert_allclose(CXGate().to_matrix(), op_true2.to_matrix())
np.testing.assert_allclose(CZGate().to_matrix(), op_false2.to_matrix())
np.testing.assert_allclose(CXGate(), op_true1)
np.testing.assert_allclose(CZGate(), op_false1)
np.testing.assert_allclose(CXGate(), op_true2)
np.testing.assert_allclose(CZGate(), op_false2)


if __name__ == "__main__":
Expand Down

0 comments on commit 8eae8c3

Please sign in to comment.