Skip to content

Commit

Permalink
Enable testing for opt 2 and 3.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinhartman committed Jul 5, 2023
1 parent 74fd38a commit b2e303e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
10 changes: 4 additions & 6 deletions test/python/compiler/test_transpiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1525,9 +1525,7 @@ def test_target_ideal_gates(self, opt_level):

self.assertEqual(Operator.from_circuit(result), Operator.from_circuit(qc))

# TODO: Add optimization level 2 and 3 after they support control flow
# compilation
@data(0, 1)
@data(0, 1, 2, 3)
def test_transpile_with_custom_control_flow_target(self, opt_level):
"""Test transpile() with a target and constrol flow ops."""
target = FakeMumbaiV2().target
Expand Down Expand Up @@ -1759,7 +1757,7 @@ def test_qpy_roundtrip_backendv2(self, optimization_level):

self.assertEqual(round_tripped, transpiled)

@data(0, 1)
@data(0, 1, 2, 3)
def test_qpy_roundtrip_control_flow(self, optimization_level):
"""Test that the output of a transpiled circuit with control flow can be round-tripped
through QPY."""
Expand All @@ -1781,7 +1779,7 @@ def test_qpy_roundtrip_control_flow(self, optimization_level):
round_tripped = qpy.load(buffer)[0]
self.assertEqual(round_tripped, transpiled)

@data(0, 1)
@data(0, 1, 2, 3)
def test_qpy_roundtrip_control_flow_backendv2(self, optimization_level):
"""Test that the output of a transpiled circuit with control flow can be round-tripped
through QPY."""
Expand Down Expand Up @@ -1818,7 +1816,7 @@ def test_qasm3_output(self, optimization_level):
# itself doesn't throw an error, though.
self.assertIsInstance(qasm3.dumps(transpiled).strip(), str)

@data(0, 1)
@data(0, 1, 2, 3)
def test_qasm3_output_control_flow(self, optimization_level):
"""Test that the output of a transpiled circuit with control flow can be dumped into
OpenQASM 3."""
Expand Down
20 changes: 5 additions & 15 deletions test/python/transpiler/test_preset_passmanagers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1428,7 +1428,7 @@ def get_translation_stage_plugin(self):
class TestIntegrationControlFlow(QiskitTestCase):
"""Integration tests for control-flow circuits through the preset pass managers."""

@data(0, 1)
@data(0, 1, 2, 3)
def test_default_compilation(self, optimization_level):
"""Test that a simple circuit with each type of control-flow passes a full transpilation
pipeline with the defaults."""
Expand Down Expand Up @@ -1504,7 +1504,7 @@ def _visit_block(circuit, stack=None):
# Assert routing ran.
_visit_block(transpiled)

@data(0, 1)
@data(0, 1, 2, 3)
def test_allow_overriding_defaults(self, optimization_level):
"""Test that the method options can be overridden."""
circuit = QuantumCircuit(3, 1)
Expand Down Expand Up @@ -1542,7 +1542,7 @@ def callback(pass_, **_):
self.assertNotIn("SabreLayout", calls)
self.assertNotIn("BasisTranslator", calls)

@data(0, 1)
@data(0, 1, 2, 3)
def test_invalid_methods_raise_on_control_flow(self, optimization_level):
"""Test that trying to use an invalid method with control flow fails."""
qc = QuantumCircuit(1)
Expand All @@ -1556,17 +1556,7 @@ def test_invalid_methods_raise_on_control_flow(self, optimization_level):
with self.assertRaisesRegex(TranspilerError, "Got scheduling_method="):
transpile(qc, scheduling_method="alap", optimization_level=optimization_level)

@data(2, 3)
def test_unsupported_levels_raise(self, optimization_level):
"""Test that trying to use an invalid method with control flow fails."""
qc = QuantumCircuit(1)
with qc.for_loop((1,)):
qc.x(0)

with self.assertRaisesRegex(TranspilerError, "The optimizations in optimization_level="):
transpile(qc, optimization_level=optimization_level)

@data(0, 1)
@data(0, 1, 2, 3)
def test_unsupported_basis_gates_raise(self, optimization_level):
"""Test that trying to transpile a control-flow circuit for a backend that doesn't support
the necessary operations in its `basis_gates` will raise a sensible error."""
Expand All @@ -1592,7 +1582,7 @@ def test_unsupported_basis_gates_raise(self, optimization_level):
with self.assertRaisesRegex(TranspilerError, "The control-flow construct.*not supported"):
transpile(qc, backend, optimization_level=optimization_level)

@data(0, 1)
@data(0, 1, 2, 3)
def test_unsupported_targets_raise(self, optimization_level):
"""Test that trying to transpile a control-flow circuit for a backend that doesn't support
the necessary operations in its `Target` will raise a more sensible error."""
Expand Down

0 comments on commit b2e303e

Please sign in to comment.