I am experimenting a bit with qutrits on Cirq and came across a problem: my output is 0 when it should be |2>.

I defined my qutrit as follows:

qutrit = cirq.NamedQid('qtr', dimension=3) 

And defined the following 'NOT' gates:

  • This NOT gate takes my |0> and 'flips' it to |1>
    class qutrit_01(cirq.Gate): 
        def _qid_shape_(self):      
            return (3,)
        def _unitary_(self):
            return np.array([[0, 1, 0],
                             [1, 0, 0],
                             [0, 0, 1]])
        def _circuit_diagram_info_(self, args):
            return "X"

This works nicely when added to a circuit. However, the following 2 NOT gates do not work as expected:

  • This NOT gate takes my |1> and (should) 'flip' it to |2>
class qutrit_12(cirq.Gate): 
    def _qid_shape_(self):      
        return (3,)
    def _unitary_(self):
        return np.array([[1, 0, 0],
                         [0, 0, 1],
                         [0, 1, 0]])
    def _circuit_diagram_info_(self, args):
        return "XX"
  • This NOT gate takes my |0> and (should) 'flip' it to |2>:
class qutrit_02(cirq.Gate): 
    def _qid_shape_(self):      
        return (3,)
    def _unitary_(self):
        return np.array([[0, 0, 1],
                         [0, 1, 0],
                         [1, 0, 0]])
    def _circuit_diagram_info_(self, args):
        return "XXX"

I then add the gates to a circuit as follows:

NOT01 = qutrit_01()
NOT12 = qutrit_12()
NOT02 = qutrit_02()

circuit = cirq.Circuit()
s = cirq.Simulator()
results = s.simulate(circuit)

As usual, the qutrit is automatically initialised in the |0> state. When I use the NOT01 gate, I get as expected |1> as output vector. However, when I then also add the NOT12 gate I get 0 as output vector (just the value, not even as a ket). Similarly, if I only add the NOT02 gate I get 0 as output vector. So, it seems like it outputs 0 when it should output |2>. Am I doing something wrong?

  • 1
    $\begingroup$ This has been fixed. You can get it by installing the latest dev version of Cirq with the command pip install cirq==1.2.0.dev20230704233149. $\endgroup$ Commented Jul 5, 2023 at 4:53

1 Answer 1


Cirq should be outputting |2⟩ instead of 0 but it's not. I've filed an issue.

It is indeed simulating qutrits which you can confirm with

# prints
# (3,)

Measuring the circuit and sampling will destroy the statevector but it does print the correct result

result = cirq.sample(circuit)
# prints
# qtr (d=3)=2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.