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

cirq.dirac_notation can't handle qudits when qid_shape is not passed in. #6165

Closed
vtomole opened this issue Jun 24, 2023 · 3 comments · Fixed by #6179
Closed

cirq.dirac_notation can't handle qudits when qid_shape is not passed in. #6165

vtomole opened this issue Jun 24, 2023 · 3 comments · Fixed by #6179
Labels
good first issue This issue can be resolved by someone who is not familiar with the codebase. A good starting issue. good for learning For beginners in QC, this will help picking up some knowledge. Bit harder than "good first issues" kind/bug-report Something doesn't seem to work. no QC knowledge needed Want to contribute to Cirq, but don't know quantum computing? This issue is for you. triage/accepted there is consensus amongst maintainers that this is a real bug or a reasonable feature to add

Comments

@vtomole
Copy link
Collaborator

vtomole commented Jun 24, 2023

How to reproduce the issue

import cirq
import numpy as np

state_vector = np.array([0, 0, 1], dtype=np.complex64)


print(cirq.dirac_notation(state_vector))
# prints
# 0

The correct result should be

|2⟩

Cirq version
main branch version

@vtomole vtomole added good first issue This issue can be resolved by someone who is not familiar with the codebase. A good starting issue. no QC knowledge needed Want to contribute to Cirq, but don't know quantum computing? This issue is for you. kind/bug-report Something doesn't seem to work. good for learning For beginners in QC, this will help picking up some knowledge. Bit harder than "good first issues" labels Jun 24, 2023
@tanujkhattar tanujkhattar added the triage/accepted there is consensus amongst maintainers that this is a real bug or a reasonable feature to add label Jun 26, 2023
@jeeva2812
Copy link
Contributor

Isn't printing 0 the expected behaviour, given that dirac_notation is considered it to be a qubit unless qid_shape is explicitly mentioned - Code Pointer

We could give a warning when the shape is not a power of 2, when qid_shape is not provided. On that note, there could be an error handling in place when the provide qid_shape and state vector is not compatible as well. Thoughts?

@vtomole vtomole changed the title cirq.dirac_notation can't handle qudits cirq.dirac_notation can't handle qudits when qid_shape is not passed in. Jul 4, 2023
@vtomole
Copy link
Collaborator Author

vtomole commented Jul 4, 2023

Isn't printing 0 the expected behaviour, given that dirac_notation is considered it to be a qubit unless qid_shape is explicitly mentioned

Ah, yes i didn't know you could pass in qid_shape. I thought cirq.dirac_notation should be able to figure it out on it's own but now that i think about it, this doesn't seem likely.

We could give a warning when the shape is not a power of 2, when qid_shape is not provided.

Yep

On that note, there could be an error handling in place when the provide qid_shape and state vector is not compatible as well. Thoughts?

👍

@jeeva2812
Copy link
Contributor

Sent out a pull request for handling this #6179

CirqBot pushed a commit that referenced this issue Jul 7, 2023
Throwing a value error when there is a shape mismatch between state_vector and qid_shape. It also throws an error when qid_shape is not mentioned and length of state_vector is not a power of 2.

Fixes #6165
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue This issue can be resolved by someone who is not familiar with the codebase. A good starting issue. good for learning For beginners in QC, this will help picking up some knowledge. Bit harder than "good first issues" kind/bug-report Something doesn't seem to work. no QC knowledge needed Want to contribute to Cirq, but don't know quantum computing? This issue is for you. triage/accepted there is consensus amongst maintainers that this is a real bug or a reasonable feature to add
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants