# Cirq: n-qubit GHZ state

I am trying to write $$n$$ party GHZ state but at the end of the day, it seems like bi partite state. I am missing a detail. Here is my code

number =6
qubits = cirq.LineQubit.range(number)
def n_party_GHZ_circuit(qubits)
GHZ_circuit = cirq.Circuit(cirq.H(qubits[i]),
cirq.CNOT(qubits[i], qubits[j]))

GHZ = cirq.final_density_matrix(n_party_GHZ_circuit)


I can write it by hand with indexes but suppose that we have 10 qubits and in that case I do not want to write it by hand for all combinations. So I am trying to write a function but I couldn't.

import cirq
number = 6
qubits = cirq.LineQubit.range(number)
GHZ_circuit = cirq.Circuit(cirq.H(qubits[0]))
for i in range(number-1):
C = cirq.Circuit(cirq.CX(qubits[i], qubits[i+1] ) )
GHZ_circuit = GHZ_circuit + C

print(GHZ_circuit)


which outputs:

0: ───H───@───────────────────
│
1: ───────X───@───────────────
│
2: ───────────X───@───────────
│
3: ───────────────X───@───────
│
4: ───────────────────X───@───
│
5: ───────────────────────X───


This will produce the state:

which is what 6 qubit GHZ state you want.

• Thank you very much for your answer! It works for me :) But it could be nice to learn as a function. If someone does not write, I will give you your point. Jan 27 at 21:42
• It should be CNOT instead of CX??? Jan 27 at 22:13
• Both CX and CNOT should work.... did it not work for you? I ran it on mine as CX and it works fine. Jan 27 at 22:25