Closed p-luo closed 2 months ago
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
I have defined a quantum circuit
circuit
usingchain
and want to runexpect'(ham, Yao.zero_state(nq) => circuit).
However, if I define my hamiltonian to be aKronBlock
or aScale
object, by e.g.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 doingham = ham + 0*kron(nq, 1 => Z)
, but am wondering if there is a more elegant way to convert between these objects.