GTorlai / PastaQ.jl

Package for Simulation, Tomography and Analysis of Quantum Computers
Apache License 2.0
142 stars 23 forks source link

Gates with more than 2 qubits break `runcircuit` #218

Closed GTorlai closed 3 years ago

GTorlai commented 3 years ago
circuit = [("Toffoli",(1,2,3))]
runcircuit(circuit)
# ERROR: DimensionMismatch("In ITensor(::Array, inds), length of Array (64) must match total dimension of IndexSet (16)")

The following function in runcircuit.jl needs to be modified

function gate(M::Union{MPS,MPO}, gatename::String, site::Tuple; kwargs...)
  site_ind1 = ( 
    typeof(M) == MPS ? siteind(M, site[1]) : firstind(M[site[1]]; tags="Site", plev=0)
  )
  site_ind2 = ( 
    typeof(M) == MPS ? siteind(M, site[2]) : firstind(M[site[2]]; tags="Site", plev=0)
  )

  return gate(gatename, site_ind1, site_ind2; kwargs...)
end
mtfishman commented 3 years ago
  site_inds = [typeof(M) == MPS ? siteind(M, s) : firstind(M[s]; tags="Site", plev=0) for s in site]
GTorlai commented 3 years ago

yes

mtfishman commented 3 years ago

Also this reminders me that it would be good to have a function, maybe called originalsiteind[s], that returns the siteind in the case of MPS and the unprimed (and daggered) siteind in the case of an MPO, so then this could be written as:

  site_inds = [originalsiteind(M, s) for s in site]

This could be defined as:

originalsiteind(M::MPS, n::Int) = siteind(M, n)
originalsiteind(M::MPO, n::Int) = dag(siteind(M, n; plev=0))
GTorlai commented 3 years ago

I have fixed this on PastaQ due a time-sensitive project. I assume the originalsiteind would be a ITensor function. We can change this here once that is implemented.