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

Make it clearer guides use notebook environment #2669

Open
1 of 5 tasks
OmegaTwiddle opened this issue Feb 24, 2025 · 3 comments
Open
1 of 5 tasks

Make it clearer guides use notebook environment #2669

OmegaTwiddle opened this issue Feb 24, 2025 · 3 comments
Assignees
Labels
bug 🐛 content 📄 needs triage 🤔 this issue needs to be prioritized by the docs team

Comments

@OmegaTwiddle
Copy link

URL to the relevant documentation

I'm following the tutorial at https://docs.quantum.ibm.com/guides/hello-world

If I follow Step 1 line for line, my script just exits without printing or displaying anything.

Select all that apply

  • typo
  • code bug
  • out-of-date content
  • broken link
  • other

Describe the fix.

I needed to add the below code to get it to show anything (this wasn't obvious to me).

import matplotlib.pyplot as plt 
plt.show()
@frankharkins
Copy link
Member

frankharkins commented Feb 27, 2025

Hi @OmegaTwiddle, how are you running the code examples?

I've seen this confusion before when users run code examples in a Python script: Our documentation is written in Jupyter notebooks. In notebooks, the output of the last line of a cell is displayed right after the cell. In the case of qc.draw(), the output is a matplotlib figure, which has a rich representation (image). That's why you see the image immediately after the cell.

I do wonder if there's a way we can make this clearer to users though.

EDIT: I've since realised we do have a comment about that in the same code cell:

# Return a drawing of the circuit using MatPlotLib ("mpl"). This is the
# last line of the cell, so the drawing appears in the cell output.
# Remove the "mpl" argument to get a text drawing.

Do you remember if you saw this comment? I'm wondering how we could make it clearer to future readers.

@javabster javabster removed the needs triage 🤔 this issue needs to be prioritized by the docs team label Feb 27, 2025
@OmegaTwiddle
Copy link
Author

I see. Yeah I am using a standalone script on my machine, and running via python from the command line.

I did read and try the suggestion in the comment. Even removing the argument didn't draw a text drawing to the screen, so the comment isn't accurate for those running it as a script.

It may depend on your user base (perhaps very few people are running scripts), but I find them easier to setup than Jupyter notebooks. I might recomment updating the language that says "It is recommended that you use the Jupyter development environment to interact with quantum computers." to something more like "This tutorial is designed for Jupyter development experience, etc etc". When I read the first statement, since I was running locally (and not interacting with quantum computers yet), I didn't think it applied to me. Anyways, maybe time to follow suit with the Jupyter setup :)

Thanks for your consideration!

@frankharkins frankharkins changed the title First Example in hello_world tutorial doesn't show the circuit image [Arch Linux] Make it clearer guides use notebook environment Mar 10, 2025
@frankharkins
Copy link
Member

That makes sense, I think we can do a couple of things:

  1. Update the comment to be a bit clearer, here's a quick draft that could definitely be improved upon:
# Return a drawing of the circuit using MatPlotLib ("mpl"). These guides are
# written using Jupyter notebooks, which display the output of the last line
# of each cell. If you're running this in a script, use `print(qc.draw())` to
# print a text drawing.
  1. Find a good place for an admonition explaining Jupyter notebooks and that these guides use them, either at the top of the page or near the first code cell.

@abbycross abbycross added the needs triage 🤔 this issue needs to be prioritized by the docs team label Mar 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 content 📄 needs triage 🤔 this issue needs to be prioritized by the docs team
Projects
Status: No status
Development

No branches or pull requests

5 participants