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

Still got an error in @code_qasm #2

Open
ChenZhao44 opened this issue Nov 12, 2020 · 3 comments
Open

Still got an error in @code_qasm #2

ChenZhao44 opened this issue Nov 12, 2020 · 3 comments

Comments

@ChenZhao44
Copy link
Member

I supposed that the CNOT gate should be available without including qelib1.inc. But I still got an error when using @code_qasm, even if I include qelib1.inc.

julia> using YaoCompiler

julia> qasm"""
       OPENQASM 2.0;
       include "test/compiler/qelib1.inc";
       """
cu3 (generic routine with 1 methods)

julia> @device function adder3()
           @ctrl 1 4=>X
           @ctrl 2 4=>X
           @ctrl 3 4=>X
       end
adder3 (generic routine with 1 methods)

julia> @code_qasm adder3()
ERROR: invalid control statement for QASM backend, got: YaoCompiler.Semantic.ctrl(Main.X, %3, %4)
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:33
 [2] codegen_ctrl(#unused#::YaoCompiler.TargetQASMTopLevel, ci::Core.CodeInfo, st::YaoCompiler.QASMCodeGenState)
   @ YaoCompiler ~/.julia/dev/YaoCompiler/src/compiler/codegen/qasm.jl:533
 [3] codegen_stmt(target::YaoCompiler.TargetQASMTopLevel, ci::Core.CodeInfo, st::YaoCompiler.QASMCodeGenState)
   @ YaoCompiler ~/.julia/dev/YaoCompiler/src/compiler/codegen/qasm.jl:333
 [4] codegen(target::YaoCompiler.TargetQASMTopLevel, ci::Core.CodeInfo)
   @ YaoCompiler ~/.julia/dev/YaoCompiler/src/compiler/codegen/qasm.jl:237
 [5] code_qasm(spec::RoutineSpec{GenericRoutine{:adder3}, Tuple{}}; optimize::Bool, gate::Bool, passes::Vector{Symbol})
   @ YaoCompiler ~/.julia/dev/YaoCompiler/src/compiler/reflection.jl:6
 [6] code_qasm(spec::RoutineSpec{GenericRoutine{:adder3}, Tuple{}})
   @ YaoCompiler ~/.julia/dev/YaoCompiler/src/compiler/reflection.jl:4
 [7] top-level scope
   @ ~/.julia/dev/YaoCompiler/src/compiler/reflection.jl:26
@Roger-luo
Copy link
Member

you need to using YaoCompiler.Intrinsics first, or you won't have the definition of X, with the ccx case, e.g

using YaoCompiler
using YaoCompiler.Intrinsics

qasm"""OPENQASM 2.0;
include "qelib1.inc";
"""

@device function adder3()
    @ctrl 1 4=>X
    @ctrl 2 4=>X
    @ctrl 3 4=>X
    (1,2,5) => ccx()
    (1,3,5) => ccx()
    (2,3,5) => ccx()
end

This is a bit cumbersome since there is an extra step, but I don't want to export X from YaoCompiler at least because X is too short and it causes name conflicts quite often.

@Roger-luo
Copy link
Member

for other examples you can check the tests first, the tests should be working at least.

@Roger-luo
Copy link
Member

actually some other code won't work due to wrong constant prop at the moment, I'm fixing it in #3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants