From e6ee65c35deb6fa07da5b2fb3a884fde2dda7000 Mon Sep 17 00:00:00 2001 From: Daniel Tsvetkov Date: Tue, 24 Sep 2019 22:49:58 +0200 Subject: [PATCH] todo: how to apply hadamard gates after entanglement --- computer.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/computer.py b/computer.py index 00f9c8c..ec1e3ff 100644 --- a/computer.py +++ b/computer.py @@ -29,15 +29,16 @@ class Qubit(list): return rv -def measure(qubits): +def measure(qubits, times=10): """ - Measure result from computation + Measure result from computation based on the qubit population """ probabilites = [q[0] ** 2 for q in qubits] - return bin(random.choices( + return [bin(m) for m in random.choices( population=range(len(qubits)), - weights=probabilites - )[0]) + weights=probabilites, + k=times + )] _0 = Qubit([[1], [0]]) @@ -89,13 +90,23 @@ def main(): assert CNOT * (_1 * _1) == (_1 * _0) # TEST HADAMARD + # Put two qubits in superposition superposition = Qubit(H * _0) * Qubit(H * _0) print(superposition) - CNOT_superposition = Qubit(CNOT * superposition) - print(CNOT_superposition) + # Entangle the qubits + entanglement = Qubit(CNOT * superposition) + print(entanglement) - print(measure(CNOT_superposition)) - # print(INVERTED_CNOT) + # TODO: What does it mean to apply H gate on the entangled qubits??? + # https://en.wikipedia.org/wiki/Controlled_NOT_gate#Behaviour_in_the_Hadamard_transformed_basis + # Should it be: + # q1 = Qubit(H * entanglement[:2]) + # q2 = Qubit(H * entanglement[3:]) + # /TODO + + # this should get us 1/4 chance for each combination of 00 01 10 and 10; + # measure 42 times + print(measure(entanglement, times=42)) # TEST MY MEMORY # rv = _0