Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converting between KronBlock, Scale, and Add Objects #522

Closed
p-luo opened this issue Aug 7, 2024 · 4 comments
Closed

Converting between KronBlock, Scale, and Add Objects #522

p-luo opened this issue Aug 7, 2024 · 4 comments

Comments

@p-luo
Copy link

p-luo commented Aug 7, 2024

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.

@exAClior
Copy link
Collaborator

exAClior commented Aug 8, 2024

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)

@exAClior
Copy link
Collaborator

Closing due to inactivity

@p-luo
Copy link
Author

p-luo commented Aug 17, 2024

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 

@exAClior
Copy link
Collaborator

exAClior commented Aug 17, 2024

Sorry for misunderstanding your question. To convert between Add blocks and other AbstractBlocks, you could simply do Add(blk) with blk = kron(nq,1=>X) for example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants