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

Define alias function to make it simpler to define gate aliases #243

Open
mtfishman opened this issue Oct 8, 2021 · 2 comments
Open

Define alias function to make it simpler to define gate aliases #243

mtfishman opened this issue Oct 8, 2021 · 2 comments

Comments

@mtfishman
Copy link
Collaborator

See here for example: https://github.com/ITensor/ITensors.jl/blob/fb9b73a08513bd677fa9e0d81c81ea17e4582c24/src/physics/site_types/electron.jl#L79-L88

This should allow us to simplify the code. For example, we could define a single fallback definition:

gate(gn::GateName; kwargs...) = 
  gate(alias(gn); kwargs...)

which would automatically look for an alias of a gate name, so that we don't have to explicitly define overloads of gate for every new alias.

@GTorlai
Copy link
Owner

GTorlai commented Oct 8, 2021

Good idea, though I'm not sure how we would avoid this clashing with the basis rotation function"

function gate(::GateName{gn}; kwargs...) where {gn}
  gn_st = String(gn)
  if startswith(gn_st, "basis")
    GN = GateName(replace(gn_st, "basis" => ""))
    return eigenbasis(GN; kwargs...)
  end
  return error(
    "A gate with the name \"$gn\" has not been implemented yet. You can define it by overloading `gate(::GateName\"$gn\") = [...]`.",
  )
end

Or maybe I am missing some fallback mechanism?

@mtfishman
Copy link
Collaborator Author

mtfishman commented Nov 17, 2021

We could put the call to gate(alias(gn); kwargs...) within that function, but that could lead to infinite loops so we would need to design it carefully.

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