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

FLOYao no support for nbatch #9

Open
p-luo opened this issue Sep 25, 2023 · 2 comments
Open

FLOYao no support for nbatch #9

p-luo opened this issue Sep 25, 2023 · 2 comments

Comments

@p-luo
Copy link

p-luo commented Sep 25, 2023

In Yao, the zero_state function supports an optional parameter nbatch, whereas FLOYao.zero_state does not (see example below).

using Yao
using FLOYao

nbatch = 10
yao_reg = zero_state(4; nbatch)
floyao_reg = FLOYao.zero_state(4; nbatch)

Is there a way to implement the nbatch in FLOYao?

@jlbosse
Copy link
Collaborator

jlbosse commented Sep 25, 2023

So far FLOYao doesn't support batch simulation of many states in parallel, but evolves a single state by doing (clever) matrix-matrix multiplication. In principle this could be changed to make the content of a MajoranaReg a Array{3,T} instead of Matrix{T}, but that would be a fair bit of work.

What do you want the feature for? Maybe it is easier to just have a vector of MajoranaRegs and use julia's dot-syntax to pipe them through circuits?

@p-luo
Copy link
Author

p-luo commented May 30, 2024

I honestly just wanted the feature so that my code could be cleaner. Unless batch simulation of many states in parallel is significantly faster than evolving each state through the circuit one-by-one, it's fine for now. For what it's worth, I implemented your suggestion and it worked; see the below MWE:

using FLOYao, Yao

nq = 2
circuit = chain(nq)
push!(circuit, put(nq, 1=>Rz(0.5)))

regs = []
nbatch = 5
for _ in 1:nbatch
    push!(regs, FLOYao.rand_state(nq))
end
new_states = regs .|> circuit

#output
3-element Vector{MajoranaReg{Float64}}:
 MajoranaReg{Float64}(2)
 MajoranaReg{Float64}(2)
 MajoranaReg{Float64}(2)
for i in 1:nbatch
    new_states[i] |> state |> println
end

#output
[-0.7668885487411203 0.312456896719723 0.2159993916117787 0.5172976941040434; -0.6042237042763625 -0.6248313051834304 -0.29995352644237966 -0.3930997802442814; 0.005546676980823645 0.308319100949791 -0.9279220768907074 0.20944972089458433; -0.2162519442103582 0.6456747321558772 0.04829869581011839 -0.7307574651440231]
[0.9775710401337321 -0.07730360405978609 -0.14973051030739953 0.12633205679599258; -0.07786574402059304 -0.9969375126230046 0.00717706654973211 0.0010057578817703541; -0.15023378588627606 0.00461038358366843 -0.988619170362541 -0.006378866135073871; 0.12538579256936722 -0.010885453028505474 -0.012704329596938261 -0.9919669903497839]
[0.3629279470486389 -0.5994061555507496 0.5902654723349837 0.40072713672534027; 0.7927757785381314 -0.20217245318898594 -0.5001642303064363 -0.2836698906418825; -0.4530544103416353 -0.6882784776092233 -0.5389757055116502 0.17469867600569364; -0.18582672435447523 -0.35512152443825207 0.333057958558788 -0.8534808302691927]

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