2
$\begingroup$

I am creating a 2 qubit entangled state:

    def density_matrix_chsh(i, j, qs):
        circuit = chsh_circuit(i, j, qs)
        return cirq.final_density_matrix(circuit, qubit_order=qs)


    def chsh_circuit(i, j, qs):
        return cirq.Circuit(cirq.H(qs[i]), cirq.CNOT(qs[i], qs[j]))


    qs = [a, b]

    state = density_matrix_chsh(0, 1, qs)

Then I am applying rotation for maximum violation:

th = np.pi/(-2)
th1 = np.pi/(4)
th2 = 0 
random_angles = []
newlist = []
b_big = cirq.kron(cirq.unitary(cirq.ry(th)),cirq.unitary(cirq.ry(th)))
results = []
for choosen in itertools.product([th2, th1], repeat=2): 
        random_angles.append(choosen)
for i in range (1000):
    choosen_combination = random.choice(random_angles)
    a_big = cirq.kron(cirq.unitary(cirq.rz(choosen_combination[0])),cirq.unitary(cirq.rz(choosen_combination[1])))    
    rotated_state = b_big @ a_big @ state @ b_big.conj().T
    measurement_rotated = cirq.measure_density_matrix(rotated_state,indices=[0, 1])
    print("measuring qubits ",measurement_rotated)
    qubit_result = measurement_rotated[0]
    results.append(qubit_result)

For instance here I tried 1000 times and both qubits are either 0 or 1 at the sma time but I could never see one of them 1 and the other one is 0 after measurement. Probably I am doing something wrong and I can't see Thanks for helps

$\endgroup$
4
  • 2
    $\begingroup$ You'll have a much easier time if you pass a circuit into cirq.Simulator().sample(...) rather than trying to do the matrix math yourself by assembling unitaries ad hoc. E.g. it looks like you applied a_big differently than b_big. $\endgroup$ Jan 23, 2021 at 15:17
  • $\begingroup$ well sorry, I did not get your point. I am trying to have chsh measurements so I am rotating my state on bloch sphere with 45° angle and then I am measuring the state and saving the results. But my question is that: I could never see 0 1 or 1 0 for two qubits. I am always seeing 11 or 00. $\endgroup$
    – quest
    Jan 23, 2021 at 18:27
  • $\begingroup$ b_big provides to rotate the state with -90 degree because I have measurement on computational basis $\endgroup$
    – quest
    Jan 23, 2021 at 18:40
  • $\begingroup$ @Balint Pato maybe you have an idea? $\endgroup$
    – quest
    Jan 23, 2021 at 19:40

1 Answer 1

3
$\begingroup$

As Craig said, you applied b_big and a_big differently. The adjoint a_big is missing from your product. Try rotated_state = b_big @ a_big @ state @ a_big.conj().T @ b_big.conj().T. But Craig's right. Using Circuits would be much simpler:

import itertools
import random
import cirq
import numpy as np

def chsh_circuit(i, j, qs):
    return cirq.Circuit(cirq.H(qs[i]), cirq.CNOT(qs[i], qs[j]))

qs = cirq.NamedQubit("a"), cirq.NamedQubit("b")

th = np.pi/(-2)
th1 = np.pi/(4)
th2 = 0
random_angles = []
newlist = []
b_big = cirq.Circuit(cirq.ry(th)(qs[0]), cirq.ry(th)(qs[1]))
results = []
for choosen in itertools.product([th2, th1], repeat=2):
        random_angles.append(choosen)

print(random_angles)
for i in range (1000):
    choosen_combination = random.choice(random_angles)
    a_big = cirq.Circuit(cirq.rz(choosen_combination[0])(qs[0]),
                         cirq.rz(choosen_combination[1])(qs[1]))
    rotated_state = cirq.Circuit(chsh_circuit(0,1, qs), a_big, b_big, cirq.measure(*qs))
    res = cirq.Simulator().run(program=rotated_state, repetitions=1)
    print("measuring qubits ",res.measurements)
$\endgroup$
3
  • $\begingroup$ if th1 would be np.pi/(2) instead of np.pi/(4), would I need to write rotated_state = b_big @ a_big @ state @ a_big.conj().T @ b_big.conj().T instead of rotated_state = b_big @ a_big @ state @ b_big.conj().T? $\endgroup$
    – quest
    Jan 24, 2021 at 12:36
  • 1
    $\begingroup$ No. Because you're working with a density matrix $|\psi\rangle \langle \psi |$ instead of a statevector ($|\psi\rangle$), unitary evolution (gate) $U$ is $U |\psi\rangle \langle \psi | U^\dagger$ instead of $U |\psi\rangle$. So you'll typically need the operator on both "sides". $\endgroup$ Jan 24, 2021 at 17:05
  • $\begingroup$ so the answer is " yes I need to write for both sides"! and it is not related to angle. I thought mathematically they can cancelled, if they are equal but I saw your point. Thanks! $\endgroup$
    – quest
    Jan 24, 2021 at 18:15

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.