generated from CQCL/pytemplate
-
Notifications
You must be signed in to change notification settings - Fork 2
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
fix: Emit nested binary expressions for classical ops #224
Merged
qartik
merged 8 commits into
main
from
215-error-simulating-circuit-with-condition-based-on-more-than-two-bits
Sep 11, 2024
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
05a18ce
test: add test for issue 215
qartik a8f56a5
build: require pecos for CI
qartik 9fc484e
docs: provide maintainer email ID
qartik f0ea2e9
chore: update deps
qartik 0d7815c
fix: generate nested multi-bit conditions for pecos support
qartik a64cec7
test: remove dependency on pecos and more granular test
qartik d511345
refactor: raise TypeError on passing less than min_args
qartik b1105c4
refactor: use `min_args` in the error message
qartik 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,11 @@ name = "pytket-phir" | |
description = "A circuit analyzer and translator from pytket to PHIR" | ||
readme = "README.md" | ||
requires-python = ">=3.10, <3.13" | ||
license = {file = "LICENSE"} | ||
authors = [{name = "Quantinuum"}] | ||
license = { file = "LICENSE" } | ||
authors = [{ name = "Quantinuum" }] | ||
maintainers = [ | ||
{ name = "Kartik Singhal", email = "[email protected]" }, | ||
] | ||
|
||
classifiers = [ | ||
"Environment :: Console", | ||
|
@@ -50,9 +53,7 @@ where = ["."] | |
|
||
[tool.pytest.ini_options] | ||
addopts = "-s -vv" | ||
pythonpath = [ | ||
"." | ||
] | ||
pythonpath = ["."] | ||
log_cli = true | ||
log_cli_level = "INFO" | ||
log_level = "DEBUG" | ||
|
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 |
---|---|---|
|
@@ -94,8 +94,8 @@ def test_pytket_classical_only() -> None: | |
"condition": { | ||
"cop": "&", | ||
"args": [ | ||
{"cop": "==", "args": [["b", 2], 1]}, | ||
{"cop": "==", "args": [["b", 1], 0]}, | ||
{"cop": "==", "args": [["b", 2], 1]}, | ||
], | ||
}, | ||
"true_branch": [ | ||
|
@@ -177,8 +177,8 @@ def test_conditional_barrier() -> None: | |
"condition": { | ||
"cop": "&", | ||
"args": [ | ||
{"cop": "==", "args": [["m", 1], 0]}, | ||
{"cop": "==", "args": [["m", 0], 0]}, | ||
{"cop": "==", "args": [["m", 1], 0]}, | ||
], | ||
}, | ||
"true_branch": [{"meta": "barrier", "args": [["q", 0], ["q", 1]]}], | ||
|
@@ -463,3 +463,26 @@ def test_nullary_ops() -> None: | |
"cop": "==", | ||
"args": [["tk_SCRATCH_BIT", 1], 1], # evals to False | ||
} | ||
|
||
|
||
def test_condition_multiple_bits() -> None: | ||
"""From https://github.com/CQCL/pytket-phir/issues/215 .""" | ||
n_bits = 3 | ||
c = Circuit(1, n_bits) | ||
c.Rz(0.5, 0, condition_bits=list(range(n_bits)), condition_value=6) | ||
phir = json.loads(pytket_to_phir(c)) | ||
|
||
assert phir["ops"][2] == {"//": "IF ([c[0], c[1], c[2]] == 6) THEN Rz(0.5) q[0];"} | ||
assert phir["ops"][3]["condition"] == { | ||
"cop": "&", | ||
"args": [ | ||
{"cop": "==", "args": [["c", 0], 0]}, | ||
{ | ||
"cop": "&", | ||
"args": [ | ||
{"cop": "==", "args": [["c", 1], 1]}, | ||
{"cop": "==", "args": [["c", 2], 1]}, | ||
Comment on lines
+475
to
+484
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 endianness of pytket: #162 (comment)
|
||
], | ||
}, | ||
], | ||
} |
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.
I have a feeling this will error out if
len(args)
is 0 or 1. While these may be rare edge cases it would be good to handle them or at least raise an informative exception.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.
This would make sense, but PECOS does not seem to be able to deal with
"cop": "&"
with fewer than two arguments.Is there a way to add a "True" constant to an expression in PHIR? The AND with a single element
args == [x]
could be implemented as(x == val) & (x == val)
, but in the case ofargs == []
you'd need to be able to output True somehow.Not sure if we'd want to do this, though. Is it OK for pytket-phir to create valid PHIR when the conditions the user inputted would not be accepted by PECOS if done directly? It's true that in this case, the action of AND on 1 and 0 arguments is not ambiguous, but it still makes me uneasy. I'd just throw an exception with informative message.
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 function is only called at one place when
len(args)
is not 1, but for generality (and reusability), it's certainly worth doing an edge case check. Implemented and pushed.