3
$\begingroup$

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.

$\endgroup$

1 Answer 1

3
$\begingroup$

How about:

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:

enter image description here

which is what 6 qubit GHZ state you want.

$\endgroup$
3
  • $\begingroup$ 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. $\endgroup$
    – quest
    Jan 27, 2021 at 21:42
  • $\begingroup$ It should be CNOT instead of CX??? $\endgroup$
    – quest
    Jan 27, 2021 at 22:13
  • 1
    $\begingroup$ Both CX and CNOT should work.... did it not work for you? I ran it on mine as CX and it works fine. $\endgroup$
    – KAJ226
    Jan 27, 2021 at 22:25

Your Answer

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

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