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

random qubit order from the outcome of the simulation #4144

Closed
JiahaoYao opened this issue May 27, 2021 · 7 comments
Closed

random qubit order from the outcome of the simulation #4144

JiahaoYao opened this issue May 27, 2021 · 7 comments
Labels
area/simulation kind/bug-report Something doesn't seem to work. triage/needs-more-evidence [Feature requests] Seems plausible, but maintainers are not convinced about the use cases yet

Comments

@JiahaoYao
Copy link
Contributor

Description of the issue

The output of the cirq simulation gives random order? But in the document, it says that from the tutorial

The qubit_order argument is optional: when it is omitted, qubits are ordered ascending by their name

I have the line qubits

[cirq.LineQubit(0), cirq.LineQubit(1), cirq.LineQubit(2), cirq.LineQubit(3), cirq.LineQubit(4), cirq.LineQubit(5), cirq.LineQubit(6), cirq.LineQubit(7)]

When I do

result = noisy_sim.sample(my_circ, repetitions=n_shots)

I sometimes got this,

Index(['q4', 'q3', 'q2', 'q5', 'q6', 'q1', 'q7', 'q0'], dtype='object')

and another run

Index(['q6', 'q3', 'q2', 'q1', 'q4', 'q5', 'q7', 'q0'], dtype='object')

Is this typical, or I have to state the qubit order, but it seems will use ops.qubitorder.default if I didn't declare? So is this the bug for the qubit order from the outcome of the simulation?

Cirq version: 0.10.0

@JiahaoYao JiahaoYao added the kind/bug-report Something doesn't seem to work. label May 27, 2021
@daxfohl
Copy link
Collaborator

daxfohl commented May 28, 2021

Hi @JiahaoYao can you provide a complete example?

@JiahaoYao
Copy link
Contributor Author

JiahaoYao commented May 28, 2021

Hi @daxfohl , thanks so much. Let me try to figure out how to provide a clear example. Probably will get back to you at a later time.

@viathor viathor added area/simulation triage/needs-more-evidence [Feature requests] Seems plausible, but maintainers are not convinced about the use cases yet labels Jun 14, 2021
@vtomole
Copy link
Collaborator

vtomole commented Jun 18, 2021

Hey @JiahaoYao, a clear example would simply be the whole program that generates the results you are getting. What is your my_circ variable set to? How about noisy_sim? What method are you calling to get Index(['q4', 'q3', 'q2', 'q5', 'q6', 'q1', 'q7', 'q0'], dtype='object')?

@JiahaoYao
Copy link
Contributor Author

Hi @vtomole and @daxfohl , thanks for your patience. Here is the MWE to reproduce the issue:

import cirq
qr = cirq.LineQubit.range(6)
circuit = cirq.Circuit([cirq.H(qr[0]), [cirq.CNOT(qr[0], qr[i]) for i in range(1, 6, 1)], [cirq.measure(qr[i], key="q{}".format(i)) for i in range(len(qr))]])
result = cirq.Simulator().sample(circuit, repetitions=100)

print(result.columns)

Here is also the minimal runnable notebook: Open In Colab

@JiahaoYao
Copy link
Contributor Author

looks like the ordering of qubit can not be controlled, wonder if this is because the data frame does not preserve the ordering.

@daxfohl
Copy link
Collaborator

daxfohl commented Jun 20, 2021

Thanks for the clear example! It took me a while to figure out what was going on vs what was expected.

The behavior is expected. The qubit order comes into play only when looking at the raw state vector (or density matrix, Clifford tableau, or other state representation) and how it's laid out under the hood, but not sample results. Sample results have no guaranteed ordering (defacto they are ordered by which order they are encountered in the simulation). qubit_order has no effect on those because measurements aren't the same thing as qubits; they're string keys that just happen to correspond to the qubit name if no other name is provided. (In future iterations we're expanding the concept of measurement, such that a measurement may correspond to multiple qubits or even no qubits at all).

@JiahaoYao
Copy link
Contributor Author

Hi @daxfohl, thank you for spending time looking into this! I really appreciate it! I very much agree with you and thank you again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/simulation kind/bug-report Something doesn't seem to work. triage/needs-more-evidence [Feature requests] Seems plausible, but maintainers are not convinced about the use cases yet
Projects
None yet
Development

No branches or pull requests

4 participants