3

My question is about if there is any way to represent a circuit that take 3 inputs and applies a rotation gate on the third qubit if the first two qubits is similar (has the same state)?

Mark Spinelli
  • 15,378
  • 3
  • 26
  • 83

1 Answers1

1
 #This line creates the circuit instance
 circuit = cirq.Circuit() 

 #These lines creates the cubits you want to use from a given length
 length = 3
 qubits = [cirq.LineQubit(i) for i in range(length)]

 #Here you assign the control qubits (the first two) and then the target qubit
 controlled_rotation_on_Z = cirq.Z.controlled_by(*qubits[:-1])
 circuit.append(controlled_rotation_on_Z(qubits[-1]))

Yielding the following circuit:

0: ───@───
      │
1: ───@───
      │
2: ───Z───

It is worth noting that it can be more than just 3 qubits. You can have N available qubits and you can develop a control gate, i.e. a Toffoli gate, that controls N-1 qubits and the very last qubit is the target qubit. So, it doesn't have to just rotation gates. Something to keep in mind.

Take a look at this question: How to create an $n$-qubit normally controlled gate?

And there are more of these questions in the exchange. I personally asked a couple of weeks ago about an N-Toffoli gate and was helped out greatly by that answer!

Hope it helps!

Enrique Segura
  • 1,011
  • 6
  • 9