Created
October 29, 2021 15:33
-
-
Save GDLMadushanka/4c57c7debcd91195463ed231af0077b7 to your computer and use it in GitHub Desktop.
Quantum Squid Game - method1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from matplotlib import pyplot as plt | |
import numpy as np | |
from qiskit import * | |
from qiskit.circuit.library.standard_gates import XGate | |
# Creating the circuit with 4 classical bits and 4 qbits | |
qc = QuantumCircuit(4,4) | |
# Creating the entanglement between players qubits | |
qc.h(1) | |
qc.cx(1,0) | |
# Applying X gate power raised to (-0.25) | |
new_gate = XGate().power(-0.25) | |
qc.append(new_gate, [0]) | |
qc.barrier() | |
# Initialize input qubits randomly | |
qc.h(2) | |
qc.h(3) | |
qc.barrier() | |
# Players applying a controlled sqrt(x) gate to their qubits | |
# taking input qubits as controllers | |
qc.csx(2,0) | |
qc.csx(3,1) | |
qc.barrier() | |
# Players measure their qubits and inform the result to guards | |
qc.measure(0,0) | |
qc.measure(1,1) | |
# measuring the input qubits to calculate xy | |
qc.measure(2,2) | |
qc.measure(3,3) | |
# un-comment the following line to display the circuit. | |
display(qc.draw(output='mpl')) | |
# Executing the circuit in a simulator 1000 times | |
result = execute(qc,Aer.get_backend('qasm_simulator'),shots=1000).result() | |
# Calculate the XOR of measurement results | |
winCount = 0 | |
for key, value in result.get_counts().items(): | |
# calculate xy | |
xy = int(key[0]) * int(key[1]) | |
# calculate xor of player outputs | |
xor = int(key[2], 2) ^ int(key[3], 2) | |
# count as a win of xy = xor of player outputs | |
if xy == xor: | |
winCount += value | |
print("Win probability : ", winCount/10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment