1

I have this state: $$p |\text{GHZ}\rangle \langle \text{GHZ}| + (1-p)\rho$$ And after creating this state I have this code lines:

state = p * GHZ+(1-p)* rho
state = p * GHZ + (1 - p) * rho
print(f"final state: \n {state}")
print(cirq.sample_density_matrix(state, indices=[0, 1, 2], repetitions=10))

Now I want to measure this state. I know we have cirq.measure in Cirq But I don't know which kind of measurement is used by this function (and the last line is also doing measurement if I am not wrong??)

cirq.measure(a, b, c)

I have 3 questions

  1. I want to use rotation matrix and measure my state. Do we have rotation matrix in Cirq. Can you please show me how can I measure my state with rotation matrix in Cirq?

  2. I want to choose x and Y randomly and I want to do measurement

  3. Which kind of measurement is used by Cirq.measure() and (cirq.sample_density_matrix(state, indices=[0, 1, 2], repetitions=10))

    cirq.measure(a, b, c) (cirq.sample_density_matrix(state, indices=[0, 1, 2], repetitions=10))

Best and thanks

glS
  • 27,670
  • 7
  • 39
  • 126
quest
  • 704
  • 4
  • 11

1 Answers1

2
  1. cirq.rx ry, rz exist for rotation around X, Y and Z axes on the Bloch sphere

  2. If you have to measure in non-computational bases, you will have to do the rotations yourself. In my answer to previous your question I wrote two versions: one with density matrices the other one with cirq.Circuit.

    • In case of the circuit model you can use circuit.append(cirq.rx(np.pi/3)(a)) for example before the measurement, where a is the first qubit.

    • in case of the density matrix you'll have to calculate the tensored unitaries with cirq.kron and cirq.unitary and then multiply the density as usual: unitary @ density_matrix @ unitary.conj().T. For example:

      # this is rx(pi/3) ⊗ I ⊗ I - the first qubit gets rotated, the other
      # two remains the same
      u = cirq.kron(cirq.unitary(cirq.rx(np.pi/3)), np.eye(2), np.eye(2))
      # this applies the unitary evolution on the state density matrix 
      rotated_state = u @ state @ u.conj().T
    

  3. cirq.measure measures in the computational basis. cirq.sample_density_matrix samples in the computational basis repeatedly see reference docs - it simulates "preparing the state and measuring it" multiple times. If you want the state after the measurement then probably cirq.measure_density_matrix is better suited.

Balint Pato
  • 1,221
  • 7
  • 16