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

Extend DecomposeClassicalExp to handle ClExprOp #1678

Merged
merged 7 commits into from
Nov 15, 2024
Merged

Extend DecomposeClassicalExp to handle ClExprOp #1678

merged 7 commits into from
Nov 15, 2024

Conversation

cqc-alec
Copy link
Collaborator

@cqc-alec cqc-alec commented Nov 14, 2024

Also fix #1581 by adding support for constant expressions (in ClExprOp).

@cqc-alec cqc-alec changed the title Ae/decompose Extend DecomposeClassicalExp to handle ClExprOp Nov 14, 2024
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note that this reverts to the file as it was before #1628 .

@@ -464,14 +465,18 @@ def test_extended_qasm() -> None:

assert circuit_to_qasm_str(c2, "hqslib1")

assert not DecomposeClassicalExp().apply(c)
with pytest.raises(DecomposeClassicalError):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This reverts to the test as it was before #1628 .

@cqc-alec cqc-alec marked this pull request as ready for review November 14, 2024 15:50
assert isinstance(output0, Bit)
out_var: Variable = (
BitRegister(output0.reg_name, len(output_posn))
if has_reg_output(expr.op)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it not possible to have an incomplete register here?

Copy link
Contributor

Choose a reason for hiding this comment

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

(for example when using temp bits?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The check at line 380 would catch this case and throw an exception. We do not allow this pass to be run on circuits with non-register-aligned ClExprOp (even though they are valid pytket circuits). I think removing this restriction would be possible, but would make decomposition more complicated, so prefer to keep it unless there is a real need.

Temporary (scratch) bits would not normally form part of a ClExprOp. They are introduced when decomposing it into elementary classical operations.

@cqc-alec cqc-alec requested a review from cqc-melf November 15, 2024 08:31
@cqc-alec cqc-alec merged commit c91e562 into main Nov 15, 2024
30 checks passed
@cqc-alec cqc-alec deleted the ae/decompose branch November 15, 2024 10:23
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.

DecomposeClassicalExp() fails for constant conditions
2 participants