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

Support multi-qubit measurements in cirq.plot_state_histogram #3031

Closed
cduck opened this issue May 21, 2020 · 2 comments · Fixed by #3054
Closed

Support multi-qubit measurements in cirq.plot_state_histogram #3031

cduck opened this issue May 21, 2020 · 2 comments · Fixed by #3054
Labels
no QC knowledge needed Want to contribute to Cirq, but don't know quantum computing? This issue is for you.

Comments

@cduck
Copy link
Collaborator

cduck commented May 21, 2020

Quote from the docstring: "Currently this function assumes each measurement gate applies to only a single qubit."

Currently, I get an incorrect histogram if I didn't read the docstring and used a multi-qubit measurement (I always make circuits like this):

qubits = cirq.LineQubit.range(3)
c = cirq.Circuit(
    (cirq.X**0.4).on_each(*qubits),
    cirq.measure(*qubits),  # One multi-qubit measurement
)
cirq.plot_state_histogram(cirq.sample(c, repetitions=10000))
# Incorrect output, no warning or error

index2

If I use single-qubit measurement gates, I get the expected histogram:

qubits = cirq.LineQubit.range(3)
c = cirq.Circuit(
    (cirq.X**0.4).on_each(*qubits),
    cirq.measure_each(*qubits),  # One measurement per qubit
)
cirq.plot_state_histogram(cirq.sample(c, repetitions=10000))

index

This looks like it could be fixed by adding some logic to plot_state_histogram (https://github.com/quantumlib/Cirq/blob/master/cirq/study/visualize.py#L22) that checks for multi-qubit measurements and either correctly interpret them or raise an error.

@cduck cduck added no QC knowledge needed Want to contribute to Cirq, but don't know quantum computing? This issue is for you. difficulty: low labels May 21, 2020
@AnimeshSinha1309
Copy link
Contributor

AnimeshSinha1309 commented Jun 1, 2020

I have made a quick-fix, I guess. Can you tell me what would be better, to raise an error/warning or to add said logic? Adding said logic does not seem hard, just a little longer.

@AnimeshSinha1309
Copy link
Contributor

Along with the 2 code sample provided above being made equivalent, I have also made a mixture of single and mutli-qubit measurements work the same. Please tell me if some other combinations might have been expected. Just h-stacking the results worked.

    c3 = cirq.Circuit(
        (cirq.X**0.4).on_each(*qubits),
        cirq.measure(*qubits[:2]),  # One multi-qubit measurement
        cirq.measure_each(*qubits[2:]),  # One single-qubit measurement
    )
    r3 = cirq.sample(c3, repetitions=10000)
    cirq.plot_state_histogram(r3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no QC knowledge needed Want to contribute to Cirq, but don't know quantum computing? This issue is for you.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants