Skip to content
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

Merged
merged 8 commits into from
Nov 30, 2023
Merged

Add one function into QuantumWorld #167

merged 8 commits into from
Nov 30, 2023

Conversation

madcpf
Copy link
Collaborator

@madcpf madcpf commented Oct 30, 2023

  • get_histogram_with_all_objects_as_key(), which creates histogram of the whole quantum world (or objects if specified) based on measurements (peeks) carried out;

@madcpf madcpf requested a review from dstrain115 October 30, 2023 04:03
@@ -484,6 +486,35 @@ def get_histogram(
histogram[idx][cast(int, result[idx])] += 1
return histogram

def get_histogram_with_all_objects_as_key(
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

if objects is None:
objects = self.public_objects

simulator = cirq.Simulator()
Copy link
Collaborator

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?

Copy link
Collaborator Author

@madcpf madcpf Nov 10, 2023

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.

Copy link
Collaborator Author

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.

@@ -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(
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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.

@madcpf madcpf requested a review from dstrain115 November 10, 2023 04:03
@madcpf madcpf changed the title Add two functions into QuantumWorld Add one function into QuantumWorld Nov 14, 2023

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
Copy link
Collaborator

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.

Copy link
Collaborator Author

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
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Pengfei Chen added 2 commits November 29, 2023 15:31
@madcpf madcpf merged commit abb7a0b into quantumlib:main Nov 30, 2023
6 checks passed
@madcpf madcpf deleted the board branch November 30, 2023 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants