todo: how to apply hadamard gates after entanglement
This commit is contained in:
parent
e839ac4006
commit
e6ee65c35d
29
computer.py
29
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
|
||||
|
Loading…
Reference in New Issue
Block a user