Quantum Computing Asked on May 18, 2021
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
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)
Correct answer by Balint Pato on May 18, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP