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

Fix sites in Yao to Tenet conversion #298

Merged
merged 4 commits into from
Jan 20, 2025
Merged

Conversation

Todorbsc
Copy link
Contributor

When converting a Yao circuit to a Tenet tensor network, the gates' sites and its duals had an incorrect order causing a bad interconnection inside the tensor network. This is, the outputs were taken as inputs and viceversa giving the following inconsistent results:

julia> U.mat
4×4 Matrix{ComplexF64}:
 0.512459+0.606575im   0.88142+0.973414im  0.617066+0.694744im    0.765335+0.470115im
 0.196287+0.34693im   0.618943+0.114418im  0.905947+0.0761331im   0.237069+0.318266im
 0.586231+0.158916im  0.189495+0.691832im  0.991734+0.241937im    0.675667+0.365597im
 0.303253+0.705869im  0.575559+0.778916im  0.511385+0.380175im   0.0958053+0.303978im

julia> Tenet.contract(merge(zerost, Quantum(circuit), onest')) # Tenet <11|U|00>
0-dimensional Tensor{ComplexF64, 0, Array{ComplexF64, 0}}:
0.7653346690086762 + 0.4701150758843342im

julia> onesv' * U.mat * zerosv # Yao <11|U|00>
0.3032530724516256 + 0.7058692432387914im

@Todorbsc Todorbsc added the bug Something isn't working label Jan 20, 2025
@Todorbsc Todorbsc self-assigned this Jan 20, 2025

@test only(ampl11) ≈ yaoampl11
yaosv = apply!(zero_state(n_qubits), yaocirc) # circuit|00>
@test only(expected_value) ≈ only(statevec(ArrayReg(bit"11"))' * statevec(yaosv)) # Yao <11|circuit|00>
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mind leaving the tests how they were before? it does the exact same thing but it's cleaner

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@@ -22,7 +22,7 @@ function Base.convert(::Type{Circuit}, yaocirc::AbstractBlock)
# end

gatelanes = Lane.(occupied_locs(gate))
gatesites = [Site.(gatelanes; dual=true)..., Site.(gatelanes)...]
gatesites = [Site.(gatelanes)..., Site.(gatelanes; dual=true)...]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah dammit, yeah. my fault.

@mofeing mofeing merged commit f66d1f9 into master Jan 20, 2025
3 of 7 checks passed
@mofeing mofeing deleted the fix/yao-tenet-sites-conversion branch January 20, 2025 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants