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

Error: 'DefaultQubit' object has no attribute 'num_wires' #65

Closed
1 task done
nireekreddy opened this issue Apr 29, 2024 · 11 comments
Closed
1 task done

Error: 'DefaultQubit' object has no attribute 'num_wires' #65

nireekreddy opened this issue Apr 29, 2024 · 11 comments

Comments

@nireekreddy
Copy link

Node number

Codercise I.12.1.

Expected behavior

Compile without error

Actual behavior

Error: 'DefaultQubit' object has no attribute 'num_wires'

Additional information

No response

Source code

bits = [int(x) for x in np.binary_repr(basis_id, width=dev.num_wires)]

Tracebacks

No response

Check other issues

  • I have searched existing GitHub issues to make sure the issue does not already exist.
@isaacdevlugt
Copy link
Collaborator

Hey @nireekreddy! Thanks 👍. The num_wires attribute was removed with the new device API changes (v0.33 I believe). You can do this instead:

num_wires = len(dev.wires)
bits = [int(x) for x in np.binary_repr(basis_id, width=num_wires)]

Let me know if that works!

@nireekreddy
Copy link
Author

@isaacdevlugt , thanks for the prompt reply. It works. Could you also change it in the codebook ? So that someone else trying to learn will not waste time on it the simple error. This was the main reason I opened an issue here. thanks :)

@isaacdevlugt
Copy link
Collaborator

Ah! Yes I will fix that 😄.

@MadhurimaNayak
Copy link

@isaacdevlugt hey! I tried this node yesterday and this issue wasn't fixed.

@isaacdevlugt
Copy link
Collaborator

Hey @MadhurimaNayak, apologies! I merged that PR. You can still use this fix as a temporary workaround:

num_wires = len(dev.wires)
bits = [int(x) for x in np.binary_repr(basis_id, width=num_wires)]

@lionelbrits
Copy link

@isaacdevlugt This is still outstanding :)

@isaacdevlugt
Copy link
Collaborator

Hey @lionelbrits, what's the code you're trying to run?

@lionelbrits
Copy link

@isaacdevlugt Codercise I.12.1

@isaacdevlugt
Copy link
Collaborator

I just want to make sure that we're talking about the same code here. Do you mind copy-pasting what you're trying to run on the codebook website?

@lionelbrits
Copy link

lionelbrits commented Oct 8, 2024

@isaacdevlugt:
This is the same bug that is discussed here. When the exercise loads the code contains

    bits = [int(x) for x in np.binary_repr(basis_id, width=dev.num_wires)]

which needs to be changed to

    bits = [int(x) for x in np.binary_repr(basis_id, width=num_wires)]

in order to run. As I have completed the exercise, pasting my version wouldn't really help here.
tl;rd: Codercise I.12.1 loads referencing dev.num_wires which is deprecated.

@isaacdevlugt
Copy link
Collaborator

Thanks! Indeed, dev.num_wires is still there. It must've been my browser cache misleading me 😅.

We can address issues that crop up on codebook.xanadu.ai in terms of helping you achieve the correct answers that it expects, but changing the source code at this juncture is not something we're doing because we're migrating the codebook to https://pennylane.ai/codebook/ 🚀! Please visit that URL for the most up-to-date and maintained version of the codebook

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

No branches or pull requests

4 participants