Skip to content

Extracting Qubit Indices #1587

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

Closed

Conversation

AbdullahKazi500
Copy link

the issue brought up by the users on Slack regarding how to retrieve the index of a qubit within a QuantumCircuit object. The original documentation lacked clarity on this point, which led to confusion among users. The updated version explains how to extract the index of a qubit from a Qubit object using both QuantumCircuit.find_bit() and QuantumCircuit.qubits.index(), ensuring that users can easily understand how to manage qubits and registers in their circuits.
fixes #1469

@qiskit-bot
Copy link
Contributor

Thanks for contributing to Qiskit documentation!

Before your PR can be merged, it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient. Thanks! 🙌

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Comment on lines +61 to +64
" # Method 2: Using qubits.index to get the index\n",
" qarg_indices_index = [qc.qubits.index(qarg) for qarg in qargs]\n",
" print(\"qargs indices (index):\", qarg_indices_index)\n",
" print(\"\\n\")"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not recommend this, it will have significant performance overhead which scales quadratically with the number of qubit it's almost never the right thing to do. The find_bit() pattern was added specifically to have a constant time lookup for this and should be the only thing we recommend.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mtreinish what do you suggest should we add only the find_bit() pattern

@AbdullahKazi500
Copy link
Author

@mtreinish for some reason I am not able to make changes directly into the source code of the ipynb file do you want me to make a notebook for this

@frankharkins
Copy link
Member

I'm closing this PR as this issue is already being worked on by another contributor.

@AbdullahKazi500
Copy link
Author

I'm closing this PR as this issue is already being worked on by another contributor.

Hi Frank thanks but I have not heard back from you on the blogpost yet for our project can I get an update

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Better documentation on Registers and Qubits
4 participants