To initialize a state in Cirq, I created a custom controlled rotation and a custom rotation gate. The effect of applying the custom controlled gates to the qubits doesn't seem to affect the state. Here's the definition of the custom controlled rotation gate:

a00 = 2/np.sqrt(30)
a01 = 4/np.sqrt(30)
a10 = 3/np.sqrt(30)
a11 = 1/np.sqrt(30)

class Con0Gate(cirq.SingleQubitGate):
    def _unitary_(self):
        return np.array([
            [a00/(np.sqrt((np.abs(a00)**2)+(np.abs(a01)**2))), a01/(np.sqrt((np.abs(a00)**2)+(np.abs(a01)**2)))],
            [a01/(np.sqrt((np.abs(a00)**2)+(np.abs(a01)**2))), -a00/(np.sqrt((np.abs(a00)**2)+(np.abs(a01)**2)))]])

    def _circuit_diagram_info_(self, args):
        return 'Con0Gate'

And here it is in the circuit (ignore the first "rotation" gate, which works fine)

circuit = cirq.Circuit(

After running this through a simulator, it looks like the gate isn't controlling on the target, and only applies a rotation to the controlled qubit.

  • $\begingroup$ I can't reproduce your program because I don't have access to the a00 and a1 variables the definition of RotationGate. Please add them to your question. $\endgroup$ Commented Mar 14, 2021 at 16:30
  • $\begingroup$ Could you be more specific about what test you are using to determine whether or not the gate is being applied in a controlled way? Your example code should ideally include an assert expression that is failing. In my quick tests it appears to work. $\endgroup$ Commented Mar 14, 2021 at 17:01
  • $\begingroup$ @CraigGidney im trying to initialize 2 qubits to equal a00,a01,a10 and a11 by using these rotation gates. I didnt get an error, but the states arent initializing like I was hoping they would (I read this particular strategy in a paper, and doing it by hand the initialization should work) $\endgroup$
    – user14860
    Commented Mar 14, 2021 at 21:17
  • 1
    $\begingroup$ @user14860 If you're trying to make the state look like the unitary of the gate, the problem is that the circuit you're making won't do that. You need to prepare the state |00>+|11> via a Hadamard then a CNOT, then apply your gate to one of the qubits in the pair (it does matter which one; if you pick the wrong one the middle entries will be swapped). $\endgroup$ Commented Mar 14, 2021 at 22:26
  • $\begingroup$ @CraigGidney what qubits should I be applying the H and CNOT gates to? $\endgroup$
    – user14860
    Commented Mar 15, 2021 at 19:30


Your Answer

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

Browse other questions tagged or ask your own question.