customed (random) unitary operation too hard to define
jzzhuang opened this issue · comments
Jingze Zhuang commented
I want to sample a random unitary circuit. The desired code is like
for _ in 1:10
@const_gate U = rand(4, 4)
circuit = chain(2, put((1, 2)=>U)
psi = zero_state(2)
apply!(psi, circuit)
end
The problems of redefining the gate U are summarized here:
- When I repeat this for multiple times, gives too many warnings when redefining U.
- Such code cannot be put into a function: "World Too New Error"
- Redefining costs too much time on compilation
Jinguo Liu (刘金国) commented
There is a better way to define a generic block from a matrix. @const
is just not designed for it because it creates a new type every time you call it. Please check matblock
for generic gates.
julia> for _ in 1:10
U = matblock(rand(ComplexF64, 4, 4); tag="U")
circuit = chain(2, put((1, 2)=>U))
psi = zero_state(2)
apply!(psi, circuit)
end
Jingze Zhuang commented
It works well! Thank you so much!