-
Notifications
You must be signed in to change notification settings - Fork 47
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0265e94
Extend DecomposeClassicalExp to handle ClExprOp.
cqc-alec 0bfc373
Fix test.
cqc-alec 89a2151
Fix test and parametrize over use_clexpr.
cqc-alec 80c33f6
Regenerate stubs.
cqc-alec e0be2a1
Update changelog.
cqc-alec bba9d6d
Add support for more operations.
cqc-alec 243bf8c
Fixes for mypy.
cqc-alec File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ | |
reg_lt, | ||
reg_neq, | ||
) | ||
from pytket.circuit.decompose_classical import DecomposeClassicalError | ||
from pytket.circuit.logic_exp import BitWiseOp, create_bit_logic_exp | ||
from pytket.passes import DecomposeBoxes, DecomposeClassicalExp | ||
from pytket.qasm import ( | ||
|
@@ -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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This reverts to the test as it was before #1628 . |
||
DecomposeClassicalExp().apply(c) | ||
|
||
|
||
def test_decomposable_extended() -> None: | ||
@pytest.mark.parametrize("use_clexpr", [True, False]) | ||
def test_decomposable_extended(use_clexpr: bool) -> None: | ||
fname = str(curr_file_path / "qasm_test_files/test18.qasm") | ||
out_fname = str(curr_file_path / "qasm_test_files/test18_output.qasm") | ||
|
||
c = circuit_from_qasm_wasm(fname, "testfile.wasm", maxwidth=64, use_clexpr=True) | ||
c = circuit_from_qasm_wasm( | ||
fname, "testfile.wasm", maxwidth=64, use_clexpr=use_clexpr | ||
) | ||
DecomposeClassicalExp().apply(c) | ||
|
||
out_qasm = circuit_to_qasm_str(c, "hqslib1", maxwidth=64) | ||
|
@@ -1233,7 +1238,8 @@ def test_multibitop() -> None: | |
test_hqs_conditional_params() | ||
test_barrier() | ||
test_barrier_2() | ||
test_decomposable_extended() | ||
test_decomposable_extended(True) | ||
test_decomposable_extended(False) | ||
test_alternate_encoding() | ||
test_header_stops_gate_definition() | ||
test_tk2_definition() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that this reverts to the file as it was before #1628 . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?)
There was a problem hiding this comment.
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.