-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add one function into QuantumWorld #167
Conversation
unitary/alpha/quantum_world.py
Outdated
@@ -484,6 +486,35 @@ def get_histogram( | |||
histogram[idx][cast(int, result[idx])] += 1 | |||
return histogram | |||
|
|||
def get_histogram_with_all_objects_as_key( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we might want to come up with a better name. Maybe get_correlated_histogram? @cognigami @cantwellc any suggestions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Doug. It's updated. @cognigami @cantwellc please let me know if you have other suggestions. Thanks.
unitary/alpha/quantum_world.py
Outdated
if objects is None: | ||
objects = self.public_objects | ||
|
||
simulator = cirq.Simulator() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know that this is a good idea to use cirq.Simulator(). Shouldn't we use self.sampler?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Doug. I updated to use self.sampler, then realized that this does not work for alpha.SparseSimulator. I'm keeping cirq.Simulator() for now. Please see the other comment about whether we want to add this new method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Doug, after some discussion this morning in the meeting, I've removed this util function. Thanks.
unitary/alpha/quantum_world.py
Outdated
@@ -526,6 +557,103 @@ def get_binary_probabilities( | |||
binary_probs.append(1 - one_probs[0]) | |||
return binary_probs | |||
|
|||
# TODO(pengfeichen): make this function work for compile_to_qubits==True. | |||
def get_binary_probabilities_from_state_vector( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty uncomfortable adding this. Nothing else in the alpha library assumes that we are using a simulator that can create a state vector. Why do we need this anyway? Is it because get_histogram_with_all_objects_as_key is too slow and / or needs too many samples?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Doug, I was adding this so that we have a choice to access the accurate/expected probability of quantum objects within a quantum world, while the current method is based on sampling and the the returned probability varies call by call.
I did not compare in terms of how fast this implementation vs sampling.
If you don't think it's useful, I can remove it. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Doug, after some discussion this morning in the meeting, I've removed this util function. Thanks.
unitary/alpha/quantum_world.py
Outdated
|
||
Returns: | ||
A dictionary, with the keys being each possible state of the whole quantum | ||
world (or `objects` if specified) in terms of tuple, and the values being |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's clarify that the key is a tuple of the results of each object in objects
and in the order of that argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Doug. It's updated.
histogram = world.get_correlated_histogram() | ||
assert len(histogram) == 2 | ||
assert histogram[(0,)] > 10 | ||
assert histogram[(1,)] > 10 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have a test where the correlated histogram actually captures some entanglement and is different than the normal histogram?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Doug! A new test is added.
objects
if specified) based on measurements (peeks) carried out;