1

I could manage to produce 3 qubit ghz state in Cirq. But I don't know how I can produce $|GHZ\rangle\langle GHZ|$ in Cirq Here is my code for 3 qubit ghz state Can you help me please for improving my code from $|GHZ\rangle$ to $|GHZ\rangle\langle GHZ|$:

n = 3
qubits = cirq.LineQubit.range ( n )

def circuit (): circuit = cirq.Circuit () circuit.append (cirq.H(qubits[0])) for i in range (n-1): circuit.append ( cirq.CNOT ( qubits [i] , qubits [i+1]) ) circuit.append (cirq.measure (* qubits , key ='x') ) print (circuit) return circuit

def simulation (circuit): simulator = cirq.Simulator() results = simulator.run ( circuit , repetitions = 200) counts = cirq.plot_state_histogram (results)

def main(): simulation (circuit()) if name == "main ": main ()

Mark Spinelli
  • 15,378
  • 3
  • 26
  • 83
quest
  • 704
  • 4
  • 11

1 Answers1

0

Since you can produce the GHZ state, I will skip the corresponding code and just use that QuantumCircuit object to build a density matrix $|GHZ><GHZ|$.

from qiskit.quantum_info import DensityMatrix
DM=DensityMatrix.from_instruction(circuit)
# here circuit denotes the circuit that contains your GHZ state.

Or there is another way to do so(not recommended, just for reference).

from qiskit.aqua.operators import StateFn
psi=StateFn(circuit)# produce the state vector
DM=(psi@~psi).eval()# state ket tensor state bra =density matrix
# When calling StateFn function, the quantum circuit must not contain classical register

But note that the density matrix produced by the latter method is not admitted by qiskit, because the DensityMatrix object in qiskit has two attributes(the matrix itself and its dimension).

Yitian Wang
  • 1,008
  • 6
  • 16