QuantumBFS / YaoQASM.jl

Bidirectional transformation between Yao IR and QASM.
Apache License 2.0
11 stars 4 forks source link

Need implementations for some QASM `uop` in Julia/Yao.jl #3

Closed thautwarm closed 5 years ago

thautwarm commented 5 years ago
CX(refa, refb) = ...
U(a, b, c, refc) = ...

note that ref* should be ofVector{Int}`.

GiggleLiu commented 5 years ago

Could you please add another input parameter nbits in these functions, which is the total number of allocated qubits in qreg? This is required by QBIR.

thautwarm commented 5 years ago

That's okay. Just treat it as the last or first param.

GiggleLiu commented 5 years ago

https://github.com/QuantumBFS/YaoQASM.jl/blob/master/src/yaoapi.jl

See if this is what you wanted.

In practise, we'd better also map the functions in qelib1.inc (see open qasm file). This helps generating simpler circuit structures. e.g. compiling h q[1] to put(nbits, 1=>H) is better, although both U(nbits, pi/2,0,pi, [1]) and put(nbits, 1=>H) are both correct.

Is it possible to write a macro/function like @map h(args...) => f(nbits, ...) to allow user spefiy the parsing behavior. U and CX are just fallback implementations. Then it would be super cool.

thautwarm commented 5 years ago

That's exactly what I want.

In practise, we'd better also map the functions in qelib1.inc (see open qasm file). This helps generating simpler circuit structures. e.g. compiling h q[1] to put(nbits, 1=>H) is better, although both U(nbits, pi/2,0,pi, [1]) and put(nbits, 1=>H) are both correct.

Don't worry, I'll perform it.

Is it possible to write a macro/function like @map h(args...) => f(nbits, ...) to allow user spefiy the parsing behavior. U and CX are just fallback implementations. Then it would be super cool.

Possible indeed if the choices are enumerable.

thautwarm commented 5 years ago

https://github.com/QuantumBFS/YaoQASM.jl/blob/cb72659ae1966f4b707e9f4e8eb4c946ae69b381/src/yaoapi.jl#L9

Nice but not necessary.

I'll check this when parsing.

thautwarm commented 5 years ago

@GiggleLiu I'll modify yaoapi myself, no need to bother you except for the sementics of QASM.

thautwarm commented 5 years ago

How should we treat include ""qelib1.inc"? Also I didn't have this file yet.

thautwarm commented 5 years ago
(v1.2) pkg> activate .
Activating environment at `~/.julia/dev/YaoQASM/Project.toml`

julia> using YaoQASM

julia> a = (parse_qasm ∘ lex)("""
       OPENQASM 2.0;
           qreg a[2];
           gate cu1(lambda, theta) a,b
           {
               U(0,0,theta/2) a;
               CX a,b;
               U(0,0,-theta/2) b;
           }
       """);

julia> eval(trans(a))
cu1 (generic function with 1 method)

julia> cu1((0.5, 0.2), 1, 2)
nqubits: 2
put on (2)
└─ chain
   ├─ rot(Z gate, -0.1)
   ├─ rot(Y gate, 0.0)
   └─ rot(Z gate, 0.0)