diff --git a/qlasskit/boolopt/bool_optimizer.py b/qlasskit/boolopt/bool_optimizer.py index 52c86db4..516b4ebf 100644 --- a/qlasskit/boolopt/bool_optimizer.py +++ b/qlasskit/boolopt/bool_optimizer.py @@ -93,3 +93,17 @@ def apply(self, exps): transform_or2and(), ] ) + + +bestWorkingOptimizerDebug = BoolOptimizerProfile( + [ + print_step("before"), + merge_expressions, + apply_cse, + remove_ITE(), + remove_Implies(), + transform_or2xor(), + transform_or2and(), + print_step("after"), + ] +) diff --git a/qlasskit/qcircuit/cnotsim.py b/qlasskit/qcircuit/cnotsim.py index 4d2c08d6..ef94f63e 100644 --- a/qlasskit/qcircuit/cnotsim.py +++ b/qlasskit/qcircuit/cnotsim.py @@ -55,10 +55,7 @@ def simulate( # noqa: C901 elif isinstance(g, CCX): if qubits[w[0]] and qubits[w[1]]: qubits[w[2]] = not qubits[w[2]] - elif isinstance(g, MCX): - if all([qubits[x] for x in w[0:-1]]): - qubits[w[-1]] = not qubits[w[-1]] - elif isinstance(g, MCtrl) and isinstance(g.gate, X): + elif isinstance(g, MCX) or (isinstance(g, MCtrl) and isinstance(g.gate, X)): if all([qubits[x] for x in w[0:-1]]): qubits[w[-1]] = not qubits[w[-1]] else: diff --git a/test/test_qlassf.py b/test/test_qlassf.py index 19c4720a..a5c81068 100644 --- a/test/test_qlassf.py +++ b/test/test_qlassf.py @@ -17,6 +17,7 @@ from parameterized import parameterized_class from qlasskit import Qint, Qint2, Qint4, Qint12, QlassF, exceptions, qlassf +from qlasskit.boolopt.bool_optimizer import bestWorkingOptimizerDebug from . import utils from .utils import COMPILATION_ENABLED, ENABLED_COMPILERS, compute_and_compare_results @@ -28,6 +29,16 @@ def test_decorator(self): self.assertTrue(isinstance(c, QlassF)) +class TestQlassfOptimizerSelection(unittest.TestCase): + def test_debug_optimizer(self): + qf = qlassf( + "def t(a: bool) -> bool: return a", + to_compile=COMPILATION_ENABLED, + bool_optimizer=bestWorkingOptimizerDebug, + ) + compute_and_compare_results(self, qf) + + @parameterized_class(("compiler"), ENABLED_COMPILERS) class TestQlassfCustomTypes(unittest.TestCase): def test_custom_qint3(self):