I have a two-qubit gate with below unitary:

    def _unitary_(self):
        st = np.sin(self.theta)
        ct = np.cos(self.theta)
        ei = np.exp(1j*self.phi)
        emi = np.exp(-1j*self.phi)

        return np.array([
            [1.,        0,          0,  0],
            [0,         ct,     ei*st,  0],
            [0,         emi*st,   -ct,  0],
            [0,         0,          0,  1.]

I want to build a three-qubit gate in which one qubit serves as the control qubit on the above two-qubit gate while the gate is applied on the other two qubits.

Here is an example of such gate: Say the gate is applied on q0, q1, and q2 where q0 is the control qubit. The above 4*4 unitary should be applied to q1 and q2 if and only if q0 is 0.

How would the unitary of such three-qubit gate look like? (I'm doing this in Cirq)


MyTwoQubitGate().on(q1, q2).controlled_by(c)


MyTwoQubitGate().controlled().on(c, q1, q2)

  • $\begingroup$ Thanks. Two follow up questions: 1) What if I have more than one control qubit for my MyTwoQubitGate? 2) What if some of the control qubits check for 0 and some others check for 1? I'm interested to know if Cirq has features to allow above two cases. $\endgroup$ – Amin Jul 16 '20 at 15:03
  • $\begingroup$ I think I found the answer: cirq.readthedocs.io/en/stable/generated/… $\endgroup$ – Amin Jul 16 '20 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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