Skip to content

Commit

Permalink
Keep list of bits storing range predicates up to date when converting (
Browse files Browse the repository at this point in the history
  • Loading branch information
cqc-alec authored Dec 17, 2024
1 parent 6b08af3 commit b3de3d5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
- AerBackend now reject circuits with too many qubits
- Update pytket version requirement to 1.37.0.
- Update qiskit version requirement to 1.3.1.
- Fix conversion of circuits containing multiple operations conditioned on the
same scratch bit.

## 0.61.0 (December 2024)

Expand Down
3 changes: 2 additions & 1 deletion pytket/extensions/qiskit/qiskit_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,8 @@ def append_tk_command_to_qiskit(
bit = args[1]
qb = qregmap[qubit.reg_name][qubit.index[0]]
b = cregmap[bit.reg_name][bit.index[0]]
# If the bit is storing a range predicate it should be invalidated:
range_preds.pop(bit, None)
return qcirc.measure(qb, b)

if optype == OpType.Reset:
Expand Down Expand Up @@ -745,7 +747,6 @@ def append_tk_command_to_qiskit(
if args[0] in range_preds:
assert op.value == 1 # type: ignore
condition_bits, value = range_preds[args[0]] # type: ignore
del range_preds[args[0]] # type: ignore
args = condition_bits + args[1:]
width = len(condition_bits)
else:
Expand Down
14 changes: 14 additions & 0 deletions tests/qiskit_convert_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
RebaseTket,
SequencePass,
)
from pytket.unit_id import _TEMP_BIT_NAME
from pytket.utils.results import (
compare_statevectors,
compare_unitaries,
Expand Down Expand Up @@ -1190,3 +1191,16 @@ def test_nonregister_bits() -> None:
c.rename_units({Bit(0): Bit(1)})
with pytest.raises(NotImplementedError):
tk_to_qiskit(c)


def test_range_preds_with_conditionals():
# https://github.com/CQCL/pytket-qiskit/issues/375
c = Circuit(1, 1)
treg = c.add_c_register(_TEMP_BIT_NAME, 1)
c.add_c_range_predicate(1, 1, [Bit(0)], treg[0])
c.add_gate(OpType.X, [Qubit(0)], condition_bits=[treg[0]], condition_value=1)
c.add_gate(OpType.Y, [Qubit(0)], condition_bits=[treg[0]], condition_value=1)
qkc = tk_to_qiskit(c)
assert len(qkc) == 2
assert len(qkc.qubits) == 1
assert len(qkc.clbits) == 1

0 comments on commit b3de3d5

Please sign in to comment.