Skip to content

Commit 9a7ebf2

Browse files
committed
minor testing and cnotsim improvements
1 parent 111ac31 commit 9a7ebf2

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

qlasskit/boolopt/bool_optimizer.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,17 @@ def apply(self, exps):
9393
transform_or2and(),
9494
]
9595
)
96+
97+
98+
bestWorkingOptimizerDebug = BoolOptimizerProfile(
99+
[
100+
print_step("before"),
101+
merge_expressions,
102+
apply_cse,
103+
remove_ITE(),
104+
remove_Implies(),
105+
transform_or2xor(),
106+
transform_or2and(),
107+
print_step("after"),
108+
]
109+
)

qlasskit/qcircuit/cnotsim.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@ def simulate( # noqa: C901
5555
elif isinstance(g, CCX):
5656
if qubits[w[0]] and qubits[w[1]]:
5757
qubits[w[2]] = not qubits[w[2]]
58-
elif isinstance(g, MCX):
59-
if all([qubits[x] for x in w[0:-1]]):
60-
qubits[w[-1]] = not qubits[w[-1]]
61-
elif isinstance(g, MCtrl) and isinstance(g.gate, X):
58+
elif isinstance(g, MCX) or (isinstance(g, MCtrl) and isinstance(g.gate, X)):
6259
if all([qubits[x] for x in w[0:-1]]):
6360
qubits[w[-1]] = not qubits[w[-1]]
6461
else:

test/test_qlassf.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from parameterized import parameterized_class
1818

1919
from qlasskit import Qint, Qint2, Qint4, Qint12, QlassF, exceptions, qlassf
20+
from qlasskit.boolopt.bool_optimizer import bestWorkingOptimizerDebug
2021

2122
from . import utils
2223
from .utils import COMPILATION_ENABLED, ENABLED_COMPILERS, compute_and_compare_results
@@ -28,6 +29,16 @@ def test_decorator(self):
2829
self.assertTrue(isinstance(c, QlassF))
2930

3031

32+
class TestQlassfOptimizerSelection(unittest.TestCase):
33+
def test_debug_optimizer(self):
34+
qf = qlassf(
35+
"def t(a: bool) -> bool: return a",
36+
to_compile=COMPILATION_ENABLED,
37+
bool_optimizer=bestWorkingOptimizerDebug,
38+
)
39+
compute_and_compare_results(self, qf)
40+
41+
3142
@parameterized_class(("compiler"), ENABLED_COMPILERS)
3243
class TestQlassfCustomTypes(unittest.TestCase):
3344
def test_custom_qint3(self):

0 commit comments

Comments
 (0)