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

feat: Improved support for IfElseOp in qiskit_to_tk #463

Merged
merged 17 commits into from
Mar 12, 2025

Conversation

CalMacCQ
Copy link
Contributor

@CalMacCQ CalMacCQ commented Mar 6, 2025

Description

Adding handling of register conditions for IfElseOp.

For now I think we should only handle conditions on single bits or entire registers. Conditons involving multiple bits, partial register conditons, or bits from different classical registers are out of scope for now. Handling these cases could be a bit annoying and I'm not sure its worth the maintenence overhead.

driveby: use the new Circuit.has_implicit_wireswaps property to make a small simplification to tk_to_qiskit. See bc8f2f9.

Related issues

closes #452

Checklist

  • I have performed a self-review of my code.
  • I have commented hard-to-understand parts of my code.
  • I have made corresponding changes to the public API documentation.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have updated the changelog with any user-facing changes.

@CalMacCQ CalMacCQ requested a review from cqc-melf as a code owner March 6, 2025 17:01
@CalMacCQ CalMacCQ marked this pull request as draft March 6, 2025 17:02
@CalMacCQ CalMacCQ marked this pull request as ready for review March 12, 2025 10:02
@CalMacCQ CalMacCQ requested review from cqc-alec and removed request for cqc-melf March 12, 2025 10:05
Copy link
Collaborator

@cqc-alec cqc-alec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, couple of small comments.

@@ -8,6 +8,8 @@
## 0.64.0 (March 2025)

- Update pytket version requirement to 2.0.1.
- Improve {py:func}`qiskit_to_tk` to handle `IfElseOp` (generated by `QuantumCircuit.if_test`)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be under a new "Unreleased" heading above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I mistakenly thought v0.64 was not out yet. Will fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed 493b3a4

expected_circ.Measure(qreg_tk[0], creg_tk[0])
expected_circ.Measure(qreg_tk[1], creg_tk[1])

assert expected_circ == tkc

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add one more test where there is no else condition to make sure that works?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea. A test for a single branch using more qubits/bits and a different circuit.

@CalMacCQ CalMacCQ requested a review from cqc-melf March 12, 2025 13:09
Copy link
Collaborator

@cqc-alec cqc-alec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks


if isinstance(if_else_op.condition[0], Clbit):
if len(bits) != 1:
raise NotImplementedError("Conditions on multiple bits not supported")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an issues / is this something we want to add in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly but it may be more annoying to handle and maintain. I'm not certain on the limits on what you can express with QuantumCircuit.if_test (I should check).

I think for now we should stick with single bit conditions and entire register command conditions. If theres a demand for different cases then we can decide to support that.

@cqc-melf cqc-melf self-requested a review March 12, 2025 16:51
@CalMacCQ CalMacCQ merged commit e807fbf into main Mar 12, 2025
5 checks passed
@CalMacCQ CalMacCQ deleted the cm/support_reg_conditions branch March 12, 2025 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle register conditions/multiple bits for IfElseOp in qiskit_to_tk
3 participants