Skip to content

Commit

Permalink
Default init plugin was not properly raising when called with an in…
Browse files Browse the repository at this point in the history
…valid optimization level (#12170) (#12175)

* Raise instead of return.

---

Co-authored-by: Evgenii Zheltonozhskii <zheltonozhskiy@gmail.com>

* link

* reno

---------

Co-authored-by: Evgenii Zheltonozhskii <zheltonozhskiy@gmail.com>
(cherry picked from commit e0be97c)

Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
  • Loading branch information
mergify[bot] and 1ucian0 committed Apr 13, 2024
1 parent 79c5192 commit 7591490
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion qiskit/transpiler/preset_passmanagers/builtin_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def pass_manager(self, pass_manager_config, optimization_level=None) -> PassMana
init.append(OptimizeSwapBeforeMeasure())
init.append(RemoveDiagonalGatesBeforeMeasure())
else:
return TranspilerError(f"Invalid optimization level {optimization_level}")
raise TranspilerError(f"Invalid optimization level {optimization_level}")
return init


Expand Down
4 changes: 4 additions & 0 deletions releasenotes/notes/followup_11468-61c6181e62531796.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
The default ``init`` plugin was not properly raising a :class:`.TranspilerError` when called with an invalid optimization level.
9 changes: 9 additions & 0 deletions test/python/transpiler/test_stage_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ def test_build_pm(self):
)
self.assertIsInstance(pm, PassManager)

def test_init_invalid_optlevel(self):
"""Test default init stage with invalid optimization level.
See: https://github.com/Qiskit/qiskit/pull/12170"""
plugin_manager = PassManagerStagePluginManager()
with self.assertRaises(TranspilerError):
plugin_manager.get_passmanager_stage(
"init", "default", PassManagerConfig(), optimization_level=4
)


@ddt.ddt
class TestBuiltinPlugins(QiskitTestCase):
Expand Down

0 comments on commit 7591490

Please sign in to comment.