Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep list of bits storing range predicates up to date when converting #439

Merged
merged 4 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading