I implemented the following circuit on cirq:
For clarity: the circuit consists of X gates, (controlled) Hadamard gates (H), N-toffoli gates, and reset operations (R).
The (1,4) qubit is the one I have a question about. Simulating this circuit, I get -1$|0\rangle$ as output vector for the (1,4) qubit, but I don't understand why I get a phase factor of -1. Given that all qubits are initialised in the $|0\rangle$ state, the N-Toffoli gates acting on qubit (1,4) are not even activated (since not all control qubits are $|1\rangle$), so I don't see why the (1,4) qubit is not simply left unchanged? And even if the N-Toffoli gates were activated, my (1,4) qubit would just be flipped, so even then I don't see where the -1 comes from.
The other strange thing is that if I remove the first reset operation, I no longer get the -1 factor in my output vector.
Maybe my understanding of the reset operation is lacking, but I thought it simply 'resets' the qubit back to the $|0\rangle$ state, so I don't see how that could introduce a phase either.
I am very confused about what is going on here, any help would be appreciated!
Here is my code for the circuit:
import cirq
number_qubits_y = 3
qubits_y = cirq.GridQubit.rect(1, number_qubits_y, top=1)
coin_qubit_y = cirq.GridQubit(1, number_qubits_y)
anc = cirq.GridQubit(1, number_qubits_y+1)
def initial_state():
yield cirq.X.on(cirq.GridQubit(1, 1))
yield cirq.X.on(coin_qubit_y)
def steps():
yield cirq.H(coin_qubit_y)
control_1 = [*qubits_y, coin_qubit_y]
control_2 = [*qubits_y, anc]
for i in range(0, number_qubits_y-1, 1):
yield cirq.X.on(cirq.GridQubit(1, i))
yield cirq.H.on(coin_qubit_y).controlled_by(*qubits_y)
yield cirq.X.on(anc).controlled_by(*control_1)
yield cirq.X.on(coin_qubit_y).controlled_by(*control_2)
for i in range(0, number_qubits_y-1, 1):
yield cirq.X.on(cirq.GridQubit(1, i))
yield cirq.reset(anc)
l = [cirq.GridQubit(1,1), cirq.GridQubit(1,2)]
for i in l:
yield cirq.X.on(i)
yield cirq.H.on(coin_qubit_y).controlled_by(*qubits_y)
yield cirq.X.on(coin_qubit_y)
yield cirq.X.on(anc).controlled_by(*control_1)
yield cirq.X.on(coin_qubit_y).controlled_by(*control_2)
yield cirq.X.on(coin_qubit_y)
for i in l:
yield cirq.X.on(i)
yield cirq.reset(anc)
def circuit(number_qubits_y):
circuit = cirq.Circuit()
circuit.append(initial_state())
for j in range(0, 1):
circuit.append(steps())
simulator = cirq.Simulator()
print(circuit)
result = simulator.simulate(circuit)
return result
result = circuit(number_qubits_y)
print(result)