Converting between KronBlock, Scale, and Add Objects
p-luo opened this issue · 4 comments
I have defined a quantum circuit circuit
using chain
and want to run expect'(ham, Yao.zero_state(nq) => circuit).
However, if I define my hamiltonian to be a KronBlock
or a Scale
object, by e.g.
using Yao
nq = 10
ham = kron(nq, 1 => Z)
ham |> typeof
Output: KronBlock{2, 1, Tuple{ZGate}}
I cannot pass it through the desired function, and it seems like it only takes Add
objects as input. I am able to bypass this issue but doing ham = ham + 0*kron(nq, 1 => Z)
, but am wondering if there is a more elegant way to convert between these objects.
Hello, I cannot reproduce your issue with the following code. Did I miss-understood your mininmal working example? If this persists, could you please send the version of your Yao.jl?
nq = 10
qc = chain(nq,control(nq,4,3=>X))
ham = kron(nq, 1 => Z)
grad = expect'(ham, zero_state(nq)=>qc)
res = expect(ham, zero_state(nq)=>qc)
Closing due to inactivity
Hi,
Please see below for a MWE. Also, it's not an error per se but I am just not sure how to convert between different objects from the Yao package in a clean way. Thanks!
using Yao
nq = 10
layers = 2
circuit = chain(nq)
for _ in 1:layers
for i in 1:nq-1
push!(circuit, rot(kron(nq, i => X, i+1 => X), 0.))
end
for i in 1:nq-1
push!(circuit, rot(kron(nq, i => X, i+1 => Y), 0.))
end
for i in 1:nq
push!(circuit, put(nq, i => Rz(0.)))
end
end
ham = kron(nq, 1 => Z)
ham |> typeof