-
Notifications
You must be signed in to change notification settings - Fork 31
fix: cast node.size to IntegerLiteral for qubit register size #258
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,10 +98,16 @@ | |
| [BooleanLiteral(xv.value ^ yv.value) for xv, yv in zip(x.values, y.values)] | ||
| ), | ||
| getattr(BinaryOperator, "<<"): lambda x, y: ArrayLiteral( | ||
| x.values[y.value :] + [BooleanLiteral(False) for _ in range(y.value)] | ||
| x.values[len(y.values) :] + [BooleanLiteral(False) for _ in range(len(y.values))] | ||
| if isinstance(y, ArrayLiteral) | ||
| else x.values[y.value :] + [BooleanLiteral(False) for _ in range(y.value)] | ||
| ), | ||
| getattr(BinaryOperator, ">>"): lambda x, y: ArrayLiteral( | ||
| [BooleanLiteral(False) for _ in range(y.value)] + x.values[: len(x.values) - y.value] | ||
| [BooleanLiteral(False) for _ in range(len(y.values))] | ||
| + x.values[: len(x.values) - len(y.values)] | ||
| if isinstance(y, ArrayLiteral) | ||
| else [BooleanLiteral(False) for _ in range(y.value)] | ||
| + x.values[: len(x.values) - y.value] | ||
|
Comment on lines
+106
to
+110
Contributor
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. [minor] this inline logic is getting hard to read - could it be factored out into an internal helper function? perhaps 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. Does this mean that these operators can be applied to array literals too now? It might be better to convert 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. Also on this theme, it seems as though this is treating |
||
| ), | ||
| getattr(UnaryOperator, "~"): lambda x: ArrayLiteral( | ||
| [BooleanLiteral(not v.value) for v in x.values] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2207,3 +2207,77 @@ def test_measure_invalid_qubit(): | |
| def test_measure_qubit_out_of_range(qasm, expected): | ||
| with pytest.raises(IndexError, match=expected): | ||
| Interpreter().build_circuit(qasm) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "qasm, expected", | ||
| [ | ||
| ( | ||
| """ | ||
| bit[2] b; | ||
| qubit["10"] r1; | ||
| b = measure r1; | ||
| """, | ||
| [0, 1], | ||
| ), | ||
| ( | ||
| """ | ||
| bit[3] b; | ||
| qubit["11"] r1; | ||
| b = measure r1; | ||
| """, | ||
| [0, 1, 2], | ||
| ), | ||
| ( | ||
| """ | ||
| bit[1] b; | ||
| qubit[!"1"] r1; | ||
| b = measure r1; | ||
| """, | ||
| [], | ||
| ), | ||
| ( | ||
| """ | ||
| qubit["1" ^ "0"] r1; | ||
| """, | ||
| [], | ||
| ), | ||
| ( | ||
| """ | ||
| bit[1] b; | ||
| qubit["1" != "0"] r1; | ||
| b = measure r1; | ||
| """, | ||
| [0], | ||
| ), | ||
| ( | ||
| """ | ||
| bit[1] b; | ||
| qubit["1" == "0"] r1; | ||
| b = measure r1; | ||
| """, | ||
| [], | ||
| ), | ||
| ( | ||
| """ | ||
| bit[1] b; | ||
| qubit[1] r1; | ||
| h r1["0" << "1"]; | ||
| b = measure r1; | ||
| """, | ||
|
Comment on lines
+2262
to
+2267
Contributor
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. [minor] these tests which run gates don't validate that they are run correctly, and they also only test 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. I believe this would be (a bit) better as I don't have a quantum background, but by me eye this should result in the probability state of |
||
| [0], | ||
| ), | ||
| ( | ||
| """ | ||
| bit[2] b; | ||
| qubit[1] r1; | ||
| h r1["0" >> "1"]; | ||
| b = measure r1; | ||
| """, | ||
| [0], | ||
| ), | ||
| ], | ||
| ) | ||
| def test_circuit_from_string_literal(qasm, expected): | ||
| circ = Interpreter().build_circuit(source=qasm) | ||
| assert expected == circ.measured_qubits | ||
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.
[minor] this inline logic is getting hard to read - could it be factored out into an internal helper function? perhaps
casting.pywould be a good place.