PastaQ.jl
PastaQ.jl copied to clipboard
Define `alias` function to make it simpler to define gate aliases
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.
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?
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.