Closed thautwarm closed 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.
That's okay. Just treat it as the last or first param.
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.
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. compilingh q[1]
toput(nbits, 1=>H)
is better, although bothU(nbits, pi/2,0,pi, [1])
andput(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
andCX
are just fallback implementations. Then it would be super cool.
Possible indeed if the choices are enumerable.
Nice but not necessary.
I'll check this when parsing.
@GiggleLiu I'll modify yaoapi myself, no need to bother you except for the sementics of QASM.
How should we treat include ""qelib1.inc"
? Also I didn't have this file yet.
(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)
note that
ref* should be of
Vector{Int}`.