Extending op function definitions for the Qudit SiteType

Hello everyone,

I am new both to Julia and ITensor, so apologies for the possible trivial question. I want to implement a TEBD algorithm on an MPS for a transmon (qutrit) system. The Hamiltonian is composed of two terms, drift and control, \mathcal{H}=\mathcal{H}_{\text{drift}}+\mathcal{H}_{\text{ctrl}}: for my particular case I need to rotate \mathcal{H} in the control-diagonal basis.

I figured that the best way to do it would be to define a custom operators as in this page via the matrix representation of the rotated operator O (\hat{\mathcal{R}}^\dagger O\hat{\mathcal{R}}, with \hat{\mathcal{R}} the rotating matrix whose columns are the eigenvectors of \mathcal{H}_{\text{ctrl}}) and then proceed as explained here.
The issue is that while the extension of the op function for a SiteType "S=1/2" works as expected, if I try to change the class to "Qudit", ITensor doesn’t recognize the new operator and throws MethodError: no method matching _op(::OpName{:R}, ::SiteType{Qudit}; dim=(3,)).
Below an example using Julia 1.7.3 and ITensors v0.3.18.

ITensors.op(::OpName"R",::SiteType"Qudit") =
 [1 0 0
  0 1 0
  0 0 1]
s = siteind("Qudit"; dim=3)
R = op("R",s)
@show R;

What am I missing here?
As a follow up question, is there a way to apply the same transformation (multiplication by a rotation matrix) to the state (MPS)?

1 Like

Thanks for pointing out this issue. Actually what you’ve come across is a bug in the “Qudit” site type, so I’ll file an issue so that we will fix it. Fortunately the bug only affects this site type and only affect this kind of function overload, so as a workaround for now you can use a different “style” of overload of the op function, like this:

function ITensors.op(::OpName"R",::SiteType"Qudit",s::Index)
  M = [1 0 0
       0 1 0
       0 0 1]
   return ITensor(M,s',s)

That version ought to work for your case & please let me know if it doesn’t.

Here’s the issue that I filed: https://github.com/ITensor/ITensors.jl/issues/957
Matt and I will discuss the best way to fix it, but hopefully the workaround / alternate version I mentioned above will handle the case that you needed. :+1:

1 Like