Skip to content

Commit

Permalink
fix: Integer division for IntegerLiterals (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
speller26 authored May 1, 2024
1 parent 474c539 commit 971ce40
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
getattr(BinaryOperator, "+"): lambda x, y: IntegerLiteral(x.value + y.value),
getattr(BinaryOperator, "-"): lambda x, y: IntegerLiteral(x.value - y.value),
getattr(BinaryOperator, "*"): lambda x, y: IntegerLiteral(x.value * y.value),
getattr(BinaryOperator, "/"): lambda x, y: IntegerLiteral(x.value / y.value),
getattr(BinaryOperator, "/"): lambda x, y: IntegerLiteral(x.value // y.value),
getattr(BinaryOperator, "%"): lambda x, y: IntegerLiteral(x.value % y.value),
getattr(BinaryOperator, "**"): lambda x, y: IntegerLiteral(x.value**y.value),
getattr(UnaryOperator, "-"): lambda x: IntegerLiteral(-x.value),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,7 @@ def test_pow():
pow(two) @ cx c, a;
}
gate cxx_2 c, a {
pow(1/2) @ pow(4) @ cx c, a;
pow(1./2.) @ pow(4) @ cx c, a;
}
gate cxxx c, a {
pow(1) @ pow(two) @ cx c, a;
Expand All @@ -1029,18 +1029,19 @@ def test_pow():
qubit q4;
qubit q5;
pow(1/2) @ x q1; // half flip
pow(1/2) @ x q1; // half flip
cx q1, q2; // flip
cxx_1 q1, q3; // don't flip
cxx_2 q1, q4; // don't flip
cnot q1, q5; // flip
x q3; // flip
x q4; // flip
s q1; // sqrt z
s q1; // again
inv @ z q1; // inv z
pow(1./2) @ x q1; // half flip
pow(1/2.) @ x q1; // half flip
cx q1, q2; // flip
cxx_1 q1, q3; // don't flip
cxx_2 q1, q4; // don't flip
cnot q1, q5; // flip
x q3; // flip
x q4; // flip
pow(1/2) @ x q5; // don't flip
s q1; // sqrt z
s q1; // again
inv @ z q1; // inv z
"""
circuit = Interpreter().build_circuit(qasm)
simulation = StateVectorSimulation(5, 1, 1)
Expand Down

0 comments on commit 971ce40

Please sign in to comment.