todos
This commit is contained in:
parent
4c4f6bd43b
commit
11ed1b44ac
@ -231,6 +231,18 @@ class State(Vector):
|
|||||||
return "{:0" + str(int(np.ceil(np.log2(len(self))))) + "b}"
|
return "{:0" + str(int(np.ceil(np.log2(len(self))))) + "b}"
|
||||||
|
|
||||||
def measure(self):
|
def measure(self):
|
||||||
|
"""
|
||||||
|
Measures in the computational basis
|
||||||
|
TODO: Generalize the method so it takes a basis
|
||||||
|
TODO: Should we memoize the result? Should we memoize per basis?
|
||||||
|
If it's measured twice, should it return the same state?
|
||||||
|
What about if measured twice but in different bases?
|
||||||
|
E.g. measure1 -> computation -> A
|
||||||
|
measure2 -> +/- basis -> B
|
||||||
|
measure3 -> computation -> should it return A again or random weighted?
|
||||||
|
measure4 -> +/- basis -> should it return B again or random weighted?
|
||||||
|
:return: binary representation of the measured qubit (e.g. "011")
|
||||||
|
"""
|
||||||
weights = [self.get_prob(j) for j in range(len(self))]
|
weights = [self.get_prob(j) for j in range(len(self))]
|
||||||
format_str = self.get_fmt_of_element()
|
format_str = self.get_fmt_of_element()
|
||||||
choices = [format_str.format(i) for i in range(len(weights))]
|
choices = [format_str.format(i) for i in range(len(weights))]
|
||||||
@ -239,13 +251,15 @@ class State(Vector):
|
|||||||
def measure_with_op(self, mo):
|
def measure_with_op(self, mo):
|
||||||
"""
|
"""
|
||||||
Measures with a measurement operator mo
|
Measures with a measurement operator mo
|
||||||
TODO: Can't define mo: MeasurementOperator because in python you can't declare classes before defining them
|
TODO: Can't define `mo: MeasurementOperator` because in python you can't declare classes before defining them
|
||||||
"""
|
"""
|
||||||
m = mo.on(self) / np.sqrt(mo.get_prob(self))
|
m = mo.on(self) / np.sqrt(mo.get_prob(self))
|
||||||
return State(m)
|
return State(m)
|
||||||
|
|
||||||
def measure_n(self, n=1):
|
def measure_n(self, n=1):
|
||||||
"""measures n times"""
|
"""measures n times
|
||||||
|
TODO: Does this make sense? When a state is measured once, it should "collapse"
|
||||||
|
"""
|
||||||
measurements = defaultdict(int)
|
measurements = defaultdict(int)
|
||||||
for _ in range(n):
|
for _ in range(n):
|
||||||
k = self.measure()
|
k = self.measure()
|
||||||
|
Loading…
Reference in New Issue
Block a user