Skip to content

Commit

Permalink
minor testing and cnotsim improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
dakk committed Nov 16, 2023
1 parent 111ac31 commit 9a7ebf2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
14 changes: 14 additions & 0 deletions qlasskit/boolopt/bool_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
]
)
5 changes: 1 addition & 4 deletions qlasskit/qcircuit/cnotsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
11 changes: 11 additions & 0 deletions test/test_qlassf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down

0 comments on commit 9a7ebf2

Please sign in to comment.