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
|
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]
|
probabilites = [q[0] ** 2 for q in qubits]
|
||||||
return bin(random.choices(
|
return [bin(m) for m in random.choices(
|
||||||
population=range(len(qubits)),
|
population=range(len(qubits)),
|
||||||
weights=probabilites
|
weights=probabilites,
|
||||||
)[0])
|
k=times
|
||||||
|
)]
|
||||||
|
|
||||||
|
|
||||||
_0 = Qubit([[1], [0]])
|
_0 = Qubit([[1], [0]])
|
||||||
@ -89,13 +90,23 @@ def main():
|
|||||||
assert CNOT * (_1 * _1) == (_1 * _0)
|
assert CNOT * (_1 * _1) == (_1 * _0)
|
||||||
|
|
||||||
# TEST HADAMARD
|
# TEST HADAMARD
|
||||||
|
# Put two qubits in superposition
|
||||||
superposition = Qubit(H * _0) * Qubit(H * _0)
|
superposition = Qubit(H * _0) * Qubit(H * _0)
|
||||||
print(superposition)
|
print(superposition)
|
||||||
CNOT_superposition = Qubit(CNOT * superposition)
|
# Entangle the qubits
|
||||||
print(CNOT_superposition)
|
entanglement = Qubit(CNOT * superposition)
|
||||||
|
print(entanglement)
|
||||||
|
|
||||||
print(measure(CNOT_superposition))
|
# TODO: What does it mean to apply H gate on the entangled qubits???
|
||||||
# print(INVERTED_CNOT)
|
# 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
|
# TEST MY MEMORY
|
||||||
# rv = _0
|
# rv = _0
|
||||||
|
Loading…
Reference in New Issue
Block a user