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

🐛 pretty printing of Reset and parsing of cx #5

Merged
merged 2 commits into from
Sep 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ RBNF.@parser QASMLang begin
uop = (inst | ugate | csemantic_gate)
inst::Instruction := [name = id, ['(', [cargs = explist].?, ')'].?, qargs = bitlist, ';']
ugate::UGate := [:U, '(', z1 = exp, ',', y = exp, ',', z2 = exp, ')', qarg = bit, ';']
csemantic_gate::CXGate := [:CX, ctrl = bit, ',', qarg = bit, ';']
csemantic_gate::CXGate := [:CX | :cx, ctrl = bit, ',', qarg = bit, ';']

idlist = @direct_recur begin
init = [id]
Expand Down
1 change: 1 addition & 0 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ end
function print_qasm(io::IO, stmt::Reset)
print_kw(io, "reset ")
print_qasm(io, stmt.qarg)
print(io, ";")
end

function print_qasm(io::IO, stmt::Measure)
Expand Down
9 changes: 9 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ end
measure q[0] -> c0[0];
if(c0==1) z q[2];
u3(0.1 + 0.2, 0.2, 0.3) q[0];
reset q[0];
"""

ast = OpenQASM.parse(qasm)
Expand Down Expand Up @@ -266,6 +267,14 @@ end
@test inst.cargs[3].str == "0.3"
end

@testset "reset" begin
reset = ast.prog[15]
@test reset isa Reset
@test reset.qarg.name.str == "q"
@test reset.qarg.address.str == "0"
@test string(reset) == "reset q[0];"
end

end

@testset "cmp_ast" begin
Expand Down
Loading