Skip to content

Commit

Permalink
fix a bug in internal compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
dakk committed Dec 13, 2023
1 parent cb06fa0 commit 38b2cb3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
8 changes: 4 additions & 4 deletions qlasskit/compiler/internalcompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ def compile_expr( # noqa: C901

elif isinstance(expr, Xor):
d = qc.get_free_ancilla()
neg = False

for e in expr.args:
if isinstance(e, Symbol):
qc.cx(qc[e], d)
else:
d = self.compile_expr(qc, e, dest=d)
if neg:
qc.x(d)
d2 = self.compile_expr(qc, e)
qc.cx(d2, d)

self.expqmap[expr] = d
return d

Expand Down
2 changes: 1 addition & 1 deletion test/test_algo_simon.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ def hash(k: Qint4) -> Qint4:

for x in [0, 8]:
self.assertEqual(x in counts_readable, True)
self.assertEqual(counts_readable[x] > 480, True)
self.assertEqual(counts_readable[x] > 400, True)
self.assertEqual(algo.output_qubits, [0, 1, 2, 3])
6 changes: 6 additions & 0 deletions test/test_qlassf_hybrid_quantum.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,9 @@ def test_bell(self):
count = qiskit_measure_and_count(qf.circuit().export(), 1024)
[self.assertEqual(x in count, True) for x in ["00", "11"]]
self.assertEqual(len(count.keys()), 2)

def test_h_and_add(self):
f = "def test(a: Qint2) -> Qint2:\n\ta = Q.H(a)\n\treturn a + 1"
qf = qlassf(f, to_compile=COMPILATION_ENABLED, uncompute=False)
count = qiskit_measure_and_count(qf.circuit().export(), 128)
[self.assertEqual(x in count, True) for x in ["1110", "0011", "1001", "0100"]]

0 comments on commit 38b2cb3

Please sign in to comment.