[{"data":1,"prerenderedAt":6217},["ShallowReactive",2],{"blog-post-building-your-first-qollab-project\u002Fcode-playground":3,"sibling-dives-building-your-first-qollab-project\u002Fcode-playground":287,"learn-track-building-your-first-qollab-project\u002Fcode-playground":288},{"id":4,"title":5,"authors":6,"body":8,"breadcrumb":256,"builders":259,"byline":260,"challenge":262,"courseAuthor":262,"courseLead":262,"dek":263,"description":263,"draft":264,"extension":265,"eyebrow":262,"finish":266,"fork":262,"hero":267,"heroAlt":262,"heroCta":262,"heroImage":262,"kind":269,"lessonCount":270,"meta":271,"navigation":272,"newsItems":262,"next":273,"ogImage":262,"order":270,"outcomes":262,"path":277,"publishDate":278,"readingTime":279,"related":280,"relatedProjects":262,"seo":281,"stem":283,"tags":284,"track":285,"trackName":258,"__hash__":286},"blog\u002Fblog\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Fcode-playground.md","Use the Code Playground",[7],"qollab",{"type":9,"value":10,"toc":243},"minimark",[11,26,29,34,42,50,53,57,65,87,91,98,102,109,128,134,143,147,157,161,164,189,193,196,210,218,220,224,228],[12,13,14,15,20,21,25],"p",{},"Every project on ",[16,17,19],"a",{"href":18},"\u002F","Qollab"," comes with a built-in code playground. It is a full Python and Qiskit editor that runs your circuits right in your browser, whether you are testing on a simulator or executing on real quantum hardware from ",[16,22,24],{"href":23},"https:\u002F\u002Fwww.ionq.com","IonQ",". No complex installations or local environments are required!",[12,27,28],{},"This guide will walk you through everything you need to know to start running your code.",[30,31,33],"h2",{"id":32},"prerequisites","Prerequisites",[12,35,36,37,41],{},"This guide assumes you have a free Qollab account (you can ",[16,38,40],{"href":39},"\u002Flogin","sign up here"," in seconds) and are signed in.",[12,43,44,45,49],{},"To use the Playground, you need to be viewing a project page that contains Qiskit or Python code. You can experiment with the code on any public project you find on the platform. If you want to run your own custom code, check out our guide to ",[16,46,48],{"href":47},"\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Fcreate-project","Create a Project on Qollab"," first.",[51,52],"hr",{},[30,54,56],{"id":55},"step-1-open-the-playground","Step 1: Open the Playground",[12,58,59,60,64],{},"To get started, navigate to any project page. Right below the project description, you will see a ",[61,62,63],"strong",{},"Code Playground"," section. Review your code or tweak your project's Python script. We've built the editor to be as helpful and user-friendly as possible:",[66,67,68,75,81],"ul",{},[69,70,71,74],"li",{},[61,72,73],{},"Syntax Highlighting:"," Keywords, method calls, and strings are color-coded to make reading your code a breeze.",[69,76,77,80],{},[61,78,79],{},"Smart Errors:"," If a line of code fails, the problematic line will light up red so you know exactly where to look.",[69,82,83,86],{},[61,84,85],{},"Focus Mode:"," Click the fullscreen icon in the toolbar when you need a distraction-free coding environment.",[30,88,90],{"id":89},"step-2-edit-your-code","Step 2: Edit Your Code",[12,92,93,94,97],{},"Click on ",[61,95,96],{},"Run"," to switch to the coderunner. You will see a dropdown menu, a Run button, and a dark console panel waiting for your commands. Think of this as your quantum command center!",[30,99,101],{"id":100},"step-3-select-a-qpu","Step 3: Select a QPU",[12,103,104,105,108],{},"Use the ",[61,106,107],{},"Select QPU"," dropdown to choose where your circuit will execute:",[66,110,111,117],{},[69,112,113,116],{},[61,114,115],{},"Simulators:"," These are free, run instantly, and are always available. They are the perfect sandbox for testing your logic and catching errors without using any resources.",[69,118,119,122,123,127],{},[61,120,121],{},"Hardware:"," Ready for the real thing? You can select physical ",[16,124,126],{"href":125},"https:\u002F\u002Fwww.ionq.com\u002Fquantum-systems\u002Fcompare","IonQ quantum computers"," (like Harmony, Aria, or Forte).",[12,129,130,133],{},[61,131,132],{},"Managing Credits:"," Running on actual hardware consumes credits. You can view your remaining balance or set a spending limit directly in your Qollab Profile Settings to ensure you always stay within your budget.",[135,136,137],"aside-note",{},[12,138,139,142],{},[61,140,141],{},"Pro tip:"," Use simulators for your initial runs to catch syntax errors or logic bugs. This ensures that when you do use your hardware credits, you're running a polished, verified circuit.",[30,144,146],{"id":145},"step-4-run-your-circuit","Step 4: Run Your Circuit",[12,148,149,150,152,153,156],{},"Click the ",[61,151,96],{}," button to execute your code. The console background will turn blue, and a timer will start tracking the elapsed time. If you ever need to stop the execution, an ",[61,154,155],{},"Interrupt"," button will appear while it's processing.",[30,158,160],{"id":159},"step-5-read-the-output","Step 5: Read the Output",[12,162,163],{},"Once your run is complete, the results will populate directly in the console panel below. Here is what you can expect to see:",[66,165,166,177,183],{},[69,167,168,171,172,176],{},[61,169,170],{},"Standard Output:"," Any ",[173,174,175],"code",{},"print()"," statements you included in your code.",[69,178,179,182],{},[61,180,181],{},"Errors:"," If something went wrong, you'll see a clear, red traceback pointing to the exact issue.",[69,184,185,188],{},[61,186,187],{},"Circuit & Probabilities:"," After a successful run, you will often see a visual diagram of the circuit that was sent to the QPU, along with a bar chart showing the measurement probabilities of your outcomes.",[30,190,192],{"id":191},"step-6-copy-or-download","Step 6: Copy or Download",[12,194,195],{},"Need to save your results or share them in your project documentation? The toolbar just above the console has you covered:",[66,197,198,204],{},[69,199,200,203],{},[61,201,202],{},"Copy:"," Quickly copy all the console text to your clipboard.",[69,205,206,209],{},[61,207,208],{},"Download:"," Save the full output as an HTML file, complete with your project name and a timestamp.",[135,211,212],{},[12,213,214,217],{},[61,215,216],{},"Community impact:"," Sharing your actual hardware run results in your project's Markdown documentation is incredibly helpful! It allows other learners to see real-world quantum noise and performance data without having to spend their own credits.",[51,219],{},[30,221,223],{"id":222},"technical-requirements","Technical Requirements",[30,225,227],{"id":226},"browser-compatibility","Browser Compatibility",[12,229,230,231,234,235,238,239,242],{},"To ensure the Code Playground runs smoothly, we recommend using a modern browser (like Chrome, Edge, or Opera) that supports WebAssembly JSPI. If you see a compatibility warning, simply switch to Chrome, Edge, or Opera. (If you are a Firefox user, you can enable this manually by going to ",[173,232,233],{},"about:config"," and setting ",[173,236,237],{},"javascript.options.wasm_js_promise_integration"," to ",[173,240,241],{},"true",").",{"title":244,"searchDepth":245,"depth":245,"links":246},"",2,[247,248,249,250,251,252,253,254,255],{"id":32,"depth":245,"text":33},{"id":55,"depth":245,"text":56},{"id":89,"depth":245,"text":90},{"id":100,"depth":245,"text":101},{"id":145,"depth":245,"text":146},{"id":159,"depth":245,"text":160},{"id":191,"depth":245,"text":192},{"id":222,"depth":245,"text":223},{"id":226,"depth":245,"text":227},[19,257,258,5],"Learn","Building your first Qollab project",[],{"username":7,"name":19,"role":261,"avatar":244},"Product docs",null,"Run Qiskit circuits live in your browser, from editing Python to choosing a QPU and reading your results.",false,"md","That’s the course. Your first project runs on real quantum hardware.",{"image":268,"alt":5},"\u002F_content\u002Fimages\u002Fcode-playground\u002Fhero.webp","lesson",7,{},true,{"slug":274,"title":275,"desc":276},"\u002Fprojects","Share what you built","Publish your project page so others can fork it, and browse what the community is building.","\u002Fblog\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Fcode-playground","2026-03-06","3 min read",[],{"title":282,"description":263},"Use the Code Playground · Building your first Qollab project","blog\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Fcode-playground",[],"building-your-first-qollab-project","AP5bvOyLnFqXa42pAO5TPnI0xsntFECJ9XUKSDd-1SU",[],[289,1296,3050,3676,4963,5713,6057],{"id":290,"title":291,"authors":292,"body":294,"breadcrumb":1274,"builders":1275,"byline":1276,"challenge":262,"courseAuthor":262,"courseLead":262,"dek":1279,"description":1279,"draft":264,"extension":265,"eyebrow":262,"finish":262,"fork":262,"hero":1280,"heroAlt":262,"heroCta":262,"heroImage":262,"kind":269,"lessonCount":270,"meta":1282,"navigation":272,"newsItems":262,"next":1283,"ogImage":262,"order":597,"outcomes":262,"path":1287,"publishDate":1288,"readingTime":1289,"related":1290,"relatedProjects":262,"seo":1291,"stem":1293,"tags":1294,"track":285,"trackName":258,"__hash__":1295},"blog\u002Fblog\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Fpython-setup.md","Setup Python on your machine",[293],"stewart-smith",{"type":9,"value":295,"toc":1248},[296,336,340,362,366,384,389,416,449,453,490,494,511,517,521,543,559,563,570,585,616,620,627,631,646,652,664,670,679,682,686,689,704,708,711,715,719,722,736,745,749,752,772,785,789,792,810,816,820,823,828,831,838,851,855,858,863,875,879,886,889,900,912,916,922,934,937,976,979,1009,1013,1016,1032,1035,1051,1057,1061,1100,1113,1217,1221,1224,1244],[12,297,298,299,303,304,308,309,311,312,315,316,319,320,323,324,327,328,331,332,335],{},"Like any language, ",[16,300,302],{"href":301},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FPython_(programming_language)","Python"," is a collection of ",[305,306,307],"em",{},"ideas"," for how to communicate. We can’t download and install ",[305,310,307],{},". But we can download and install a ",[305,313,314],{},"program"," that follows these ideas to the letter; using them as a strict guide for translating our commands into action. This sort of program is called an ",[305,317,318],{},"interpreter."," For brevity we’re going to use “Python” interchangeably to refer to both the ",[305,321,322],{},"language (ideas)"," and the actual ",[305,325,326],{},"interpreter software"," that puts those ideas into action. When you encounter phrases like “running Python” you’ll know this actually means running a Python ",[305,329,330],{},"interpreter"," to make use of the Python ",[305,333,334],{},"language."," Let’s get to it.",[30,337,339],{"id":338},"juggling-pythons","Juggling pythons",[12,341,342,343,346,347,351,352,356,357,361],{},"There are many versions of Python. Perhaps your computer shipped with a particular version of Python pre-installed by the manufacturer. This is referred to as your “System Python” because it’s a specific version of Python used by your machine’s ",[305,344,345],{},"operating system",", like ",[16,348,350],{"href":349},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FMacOS","Apple’s macOS",", or a brand of ",[16,353,355],{"href":354},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FLinux","Linux",", or ",[16,358,360],{"href":359},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FMicrosoft_Windows","Microsoft’s Windows",". Because your OS relies on its System Python remaining exactly in its current state (with its specific version, settings, plugins, and so on), we’d like to leave it untouched. Thankfully, it’s easy to install multiple versions of Python alongside each other, keeping them completely separate from one another. (Installing multiple versions of Python is a common practice, and it doesn’t take up much hard drive space.)",[30,363,365],{"id":364},"_1-open-a-shell","1. Open a “shell”",[12,367,368,369,373,374,378,379,383],{},"A “shell” is a program that allows you to enter text-based commands through a ",[16,370,372],{"href":371},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FCommand-line_interface","command-line interface"," (or “CLI” for short). This is in contrast to a ",[16,375,377],{"href":376},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FGraphical_user_interface","graphic user interface"," (or “GUI”) that you might be accustomed to; using a pointing device like a mouse or your finger to interact with graphic representations of data and actions to perform. (The term “shell” is a linguistic expansion on labeling an operating system’s core as its “kernel.” The shell “wraps” the kernel and is the user-facing surface that handles interactions with it.) For our purposes it’s unnecessary to become a shell expert, but if you’re curious to know more, this video is an excellent resource: ",[16,380,382],{"href":381},"https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=IYZDIhfAUM0","Become a shell wizard in ~12 mins",".",[385,386,388],"h3",{"id":387},"open-a-shell-in-macos","Open a shell in MacOS",[390,391,392,403,409],"ol",{},[69,393,394,395,398,399,402],{},"Press your keyboard’s ",[61,396,397],{},"⌘"," key and ",[61,400,401],{},"spacebar"," simultaneously to open the Spotlight prompt.",[69,404,405,406,383],{},"Type ",[173,407,408],{},"Terminal",[69,410,411,412,415],{},"Press the ",[61,413,414],{},"Enter"," key.",[12,417,418,419,423,424,428,429,433,434,438,439,442,443,445,446,383],{},"This will open the ",[16,420,422],{"href":421},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FTerminal_(macOS)","macOS Terminal application",". On ",[16,425,427],{"href":426},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FMacOS_Ventura","macOS Ventura"," or later, Terminal defaults to ",[16,430,432],{"href":431},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FZ_shell","Z Shell (zsh)",". On older versions of macOS, Terminal defaults to ",[16,435,437],{"href":436},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FBash%3C\u002Fem%3E(Unix_shell)","Bash Shell",". (Either shell is perfectly usable.) You can check which shell you are using by typing (or pasting in) ",[173,440,441],{},"echo $SHELL"," and pressing your ",[61,444,414],{}," key. This command reveals the file location of the shell program you are using, and the names within that location’s path will imply which shell is active. For example, if using Z Shell you might see the path ",[173,447,448],{},"\u002Fbin\u002Fzsh",[385,450,452],{"id":451},"open-a-shell-in-linux","Open a shell in Linux",[390,454,455],{},[69,456,394,457,460,461,464,465,468,469,460,473,460,477,481,482,486,487,383],{},[61,458,459],{},"Ctrl",", ",[61,462,463],{},"Alt",", and ",[61,466,467],{},"T"," keys simultaneously to open the Terminal application. (This should work on ",[16,470,472],{"href":471},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FUbuntu","Ubuntu",[16,474,476],{"href":475},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FLinux_Mint","Linux Mint",[16,478,480],{"href":479},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FPop!_OS","Pop!_OS",", and many ",[16,483,485],{"href":484},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FGNOME","GNOME","-based Linux flavors.) The default shell is usually ",[16,488,489],{"href":436},"Bash",[385,491,493],{"id":492},"open-a-shell-in-windows","Open a shell in Windows",[390,495,496,501,507],{},[69,497,394,498,415],{},[61,499,500],{},"Windows",[69,502,405,503,506],{},[173,504,505],{},"PowerShell"," into the prompt area.",[69,508,411,509,415],{},[61,510,414],{},[12,512,418,513,383],{},[16,514,516],{"href":515},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FPowerShell","Windows PowerShell application",[30,518,520],{"id":519},"_2-install-uv","2. Install UV",[12,522,523,524,528,529,533,534,538,539,383],{},"We need a clean way to install a new version of Python on our system, and to keep it separate from any existing (or future) installations of Python. In the past we may have recommended solutions like ",[16,525,527],{"href":526},"https:\u002F\u002Fwiki.python.org\u002Fmoin\u002FVirtualenv","virtualenv"," or ",[16,530,532],{"href":531},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FConda%3C\u002Fem%3E(package_manager)","Conda",". But these days the winning solution is ",[16,535,537],{"href":536},"https:\u002F\u002Fdocs.astral.sh\u002Fuv\u002F","UV",", a single application that is blazingly fast and replaces (or wraps) several common Python-related tools and package managers such as ",[16,540,542],{"href":541},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FPip%3C\u002Fem%3E(package_manager)","pip",[12,544,545,546,550,551,554,555,383],{},"The following installation instructions come from ",[16,547,549],{"href":548},"https:\u002F\u002Fdocs.astral.sh\u002Fuv\u002Fgetting-started\u002Finstallation\u002F","UV’s installation guide",". For troubleshooting or additional details, refer to their documentation: ",[16,552,553],{"href":548},"https:\u002F\u002Fdocs.astral.sh\u002Fuv\u002Fgetting-started\u002Finstallation",". See also, the ",[16,556,558],{"href":557},"https:\u002F\u002Fgithub.com\u002Fastral-sh\u002Fuv","UV GitHub repository",[385,560,562],{"id":561},"install-uv-on-macos-or-linux","Install UV on macOS or Linux",[12,564,565,566,569],{},"Enter the following command into your shell application: curl -LsSf ",[16,567,568],{"href":568},"https:\u002F\u002Fastral.sh\u002Fuv\u002Finstall.sh"," | sh",[12,571,572,573,576,577,580,581,584],{},"If you receive an error similar to “",[173,574,575],{},"command not found: curl","”, it could mean the your system does not have ",[173,578,579],{},"curl"," installed. Don’t worry. Give this ",[173,582,583],{},"wget"," command a try instead:",[586,587,591],"pre",{"className":588,"code":589,"language":590,"meta":244,"style":244},"language-bash shiki shiki-themes one-dark-pro","wget -qO- https:\u002F\u002Fastral.sh\u002Fuv\u002Finstall.sh | sh\n","bash",[173,592,593],{"__ignoreMap":244},[594,595,598,601,605,609,613],"span",{"class":596,"line":597},"line",1,[594,599,583],{"class":600},"sVbv2",[594,602,604],{"class":603},"sVC51"," -qO-",[594,606,608],{"class":607},"subq3"," https:\u002F\u002Fastral.sh\u002Fuv\u002Finstall.sh",[594,610,612],{"class":611},"sn6KH"," | ",[594,614,615],{"class":600},"sh\n",[385,617,619],{"id":618},"install-uv-on-windows","Install UV on Windows",[12,621,622,623,626],{},"Enter the following command into your shell application: powershell -ExecutionPolicy ByPass -c \"irm ",[16,624,625],{"href":625},"https:\u002F\u002Fastral.sh\u002Fuv\u002Finstall.ps1"," | iex\"",[385,628,630],{"id":629},"make-uv-available","Make UV available",[12,632,633,634,637,638,641,642,645],{},"Congratulations. You now have UV installed on your system. But the ",[173,635,636],{},"uv"," command is ",[305,639,640],{},"not"," available in our current shell window. The easiest way to start using UV immediately is to ",[61,643,644],{},"close your current shell window and open a fresh new one",". Give that a try now.",[12,647,648,649,651],{},"In a fresh shell window, enter the following to ask for the UV version number. This will confirm that the ",[173,650,636],{}," command is available to you.",[586,653,655],{"className":588,"code":654,"language":590,"meta":244,"style":244},"uv --version\n",[173,656,657],{"__ignoreMap":244},[594,658,659,661],{"class":596,"line":597},[594,660,636],{"class":600},[594,662,663],{"class":603}," --version\n",[12,665,666,667,669],{},"Your shell should respond with one line indicating the freshly installed version number. (Did something not go as planned? That’s ok. Refer to ",[16,668,549],{"href":548}," as a first step for troubleshooting.) For a full list of UV’s available commands, enter the following into your shell:",[586,671,673],{"className":588,"code":672,"language":590,"meta":244,"style":244},"uv\n",[173,674,675],{"__ignoreMap":244},[594,676,677],{"class":596,"line":597},[594,678,672],{"class":600},[12,680,681],{},"That’s right, just asking for UV will provide you with a whole menu of commands and useful information.",[30,683,685],{"id":684},"_3-install-python","3. Install Python",[12,687,688],{},"Using UV, we can now safely install a sandboxed Python, separate from any past or future installations of Python. To install the latest Python, enter the following into your shell:",[586,690,692],{"className":588,"code":691,"language":590,"meta":244,"style":244},"uv python install\n",[173,693,694],{"__ignoreMap":244},[594,695,696,698,701],{"class":596,"line":597},[594,697,636],{"class":600},[594,699,700],{"class":607}," python",[594,702,703],{"class":607}," install\n",[385,705,707],{"id":706},"macos-command-line-developer-tools","macOS command-line developer tools",[12,709,710],{},"If you’re on macOS and have not previously installed the command-line developer tools, you will be prompted to do so now. It’s a hefty download, but will enable you to compile and run all of the tools you may wish to use in the future, including installing Python right now.",[712,713],"blog-figure",{"alt":244,"caption":244,"no":244,"src":714},"\u002F_content\u002Fimages\u002Fpython-setup\u002Fdeveloper-tools-2.webp",[385,716,718],{"id":717},"confirm-python-installed","Confirm Python installed",[12,720,721],{},"Once UV has finished installing the latest version of Python, you can verify this (as well as detect previously installed versions of Python) by entering the following into your shell:",[586,723,725],{"className":588,"code":724,"language":590,"meta":244,"style":244},"uv python list\n",[173,726,727],{"__ignoreMap":244},[594,728,729,731,733],{"class":596,"line":597},[594,730,636],{"class":600},[594,732,700],{"class":607},[594,734,735],{"class":607}," list\n",[737,738,739],"blockquote",{},[12,740,741,742],{},"UV can do a whole lot more than list some versions of Python. Here’s a handy cheat sheet for UV’s management commands: ",[16,743,744],{"href":744},"https:\u002F\u002Fdocs.astral.sh\u002Fuv\u002Fgetting-started\u002Ffeatures\u002F",[385,746,748],{"id":747},"hello-world","Hello, World!",[12,750,751],{},"Now that we definitely have Python installed, let’s run a tiny “Hello, World!” program right from the command line. Enter this into your shell:",[586,753,755],{"className":588,"code":754,"language":590,"meta":244,"style":244},"uv run python -c 'print( \"Hello, World!\" )'\n",[173,756,757],{"__ignoreMap":244},[594,758,759,761,764,766,769],{"class":596,"line":597},[594,760,636],{"class":600},[594,762,763],{"class":607}," run",[594,765,700],{"class":607},[594,767,768],{"class":603}," -c",[594,770,771],{"class":607}," 'print( \"Hello, World!\" )'\n",[12,773,774,775,777,778,781,782,784],{},"Our shell responds with “",[173,776,748],{},"” (And we can deduce that the ",[173,779,780],{},"-c"," flag tells ",[173,783,636],{}," to execute any command that follows.) This is progress. But running one command at a time isn’t going to get us very far. Let’s start thinking a little larger.",[30,786,788],{"id":787},"_4-create-your-first-project","4. Create your first project",[12,790,791],{},"We’d like to create a sandboxed environment that both “pins” a specific version of Python for use, and houses any additional code packages we require. This ensures that anything we add to Python remains tidily within our sandbox, and anything done outside of our sandbox is kept at a safe distance and won’t damage our project. Our UV project will be composed of:",[66,793,794,797,804,807],{},[69,795,796],{},"A folder.",[69,798,799,800,803],{},"A ",[173,801,802],{},"pyproject.toml"," file.",[69,805,806],{},"A local virtual environment (created automatically).",[69,808,809],{},"Our Python files.",[12,811,812,813,815],{},"Create a project folder on your Desktop called ",[173,814,7],{},". (The exact name and location of this folder doesn’t matter so much, as long as it’s easy for you to get to and work with.)",[385,817,819],{"id":818},"to-shell-and-back","To shell and back",[12,821,822],{},"As we build up our project, you will likely want to jump back and forth between your graphic user interface (like macOS Finder, Windows Explorer, etc.) and your shell program (like macOS Terminal, Windows PowerShell, etc). Here’s an easy guide for jumping between the two and always landing in the exact folder you need:",[824,825,827],"h4",{"id":826},"macos-finder-and-terminal","macOS: Finder and Terminal",[12,829,830],{},"To jump from Finder to Terminal while remaining in the same folder: 1. Within Finder, navigate to your intended folder. 2. Right-click inside the folder (or on the folder itself) to open a context menu. 3. Choose the “New Terminal at Folder” option.",[12,832,833,834,837],{},"(If you don’t see this option, go to your System Settings → Privacy & Security → Extensions → Finder → enable Terminal.) To jump from Terminal to Finder while remaining in the same folder: 1. Within Terminal, navigate to your intended folder. 2. Enter the following and press Enter. (Yes, include the ",[305,835,836],{},"empty space"," followed by a period. In this context the period is an alias for “here”, as in “open here.”)",[586,839,841],{"className":588,"code":840,"language":590,"meta":244,"style":244},"open .\n",[173,842,843],{"__ignoreMap":244},[594,844,845,848],{"class":596,"line":597},[594,846,847],{"class":600},"open",[594,849,850],{"class":607}," .\n",[824,852,854],{"id":853},"linux-file-manager-and-terminal","Linux: File Manager and Terminal",[12,856,857],{},"To jump from File Manager to Terminal while remaining in the same folder (Ubuntu, Fedora, Debian, Arch, Mint, etc.): 1. Within File Manager, navigate to your intended folder. 2. Right-click inside the folder to open a context menu. 3. Choose the “Open in Terminal” option.",[12,859,860,861,837],{},"To jump from Terminal to File Manager while remaining in the same folder: 1. Within Terminal, navigate to your intended folder. 2. Enter the following and press Enter. (Yes, include the ",[305,862,836],{},[586,864,866],{"className":588,"code":865,"language":590,"meta":244,"style":244},"xdg-open .\n",[173,867,868],{"__ignoreMap":244},[594,869,870,873],{"class":596,"line":597},[594,871,872],{"class":600},"xdg-open",[594,874,850],{"class":607},[824,876,878],{"id":877},"windows-explorer-and-powershell","Windows: Explorer and PowerShell",[12,880,881,882,885],{},"To jump from File Explorer to PowerShell while remaining in the same folder: 1. Within File Explorer, navigate to your intended folder. 2. Click the address bar. 3. Type ",[173,883,884],{},"powershell"," and press Enter.",[12,887,888],{},"To jump from PowerShell to Explorer while remaining in the same folder:",[390,890,891,894],{},[69,892,893],{},"Within PowerShell, navigate to your intended folder.",[69,895,896,897,899],{},"Enter the following and press Enter. (Yes, include the ",[305,898,836],{}," followed by a period. In this context the period is an alias for “here”, as in “explore here.”)",[586,901,903],{"className":588,"code":902,"language":590,"meta":244,"style":244},"explorer .\n",[173,904,905],{"__ignoreMap":244},[594,906,907,910],{"class":596,"line":597},[594,908,909],{"class":600},"explorer",[594,911,850],{"class":607},[385,913,915],{"id":914},"initialize-the-project-with-uv","Initialize the project with UV",[12,917,918,919,921],{},"Now that we have a ",[173,920,7],{}," project folder on our Desktop (and know how to jump between our graphic interface and a shell), open a shell to your project’s folder and enter the following command:",[586,923,925],{"className":588,"code":924,"language":590,"meta":244,"style":244},"uv init\n",[173,926,927],{"__ignoreMap":244},[594,928,929,931],{"class":596,"line":597},[594,930,636],{"class":600},[594,932,933],{"class":607}," init\n",[12,935,936],{},"This little command packs quite a punch. It creates several files for us, some of which are hidden from view (in order to reduce clutter). Let’s have a look at the visible files first:",[66,938,939,944,950,961],{},[69,940,941,943],{},[61,942,802],{},". This file specifies what version of Python our project ought to use, as well as any depencies we decide to include later. This a human-editable file, it’s yours to update.",[69,945,946,949],{},[61,947,948],{},"main.py",". A minimal (yet executable) Python file that we can begin editing and build from. (We’ll run this file in just a moment!)",[69,951,952,955,956,960],{},[61,953,954],{},"README.md",". An empty “Read me” ",[16,957,959],{"href":958},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FMarkdown","Markdown"," file for documenting our project.",[69,962,963,966,967,969,970,972,973,975],{},[61,964,965],{},"uv.lock",". In contrast to ",[173,968,802],{},", this file is machine-generated and should not be manually edited. While ",[173,971,802],{}," decribes our intent, ",[173,974,965],{}," is a detailed documentation of what packages and versions are actually in use.",[12,977,978],{},"The hidden files are also informative:",[66,980,981,992,1003],{},[69,982,983,986,987,991],{},[61,984,985],{},".python-version",". ",[16,988,990],{"href":989},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FDoes_exactly_what_it_says_on_the_tin","Just what it says on the tin",": A file specifying the version of Python required.",[69,993,994,997,998,1002],{},[61,995,996],{},".gitignore",". As part of our project’s initialization, UV automatically created a local ",[16,999,1001],{"href":1000},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FGit","git code repository"," for us, and included this handy list of files and file types to ignore in our commits.",[69,1004,1005,1008],{},[61,1006,1007],{},".venv",". An entire folder dedicated to specifying and maintaining our project’s virtual environment. Leave this folder and its content alone.",[385,1010,1012],{"id":1011},"run-our-uv-project","Run our UV project",[12,1014,1015],{},"As UV was kind enough to generate a skeletal Python file for us, let’s take it for a test drive. Be sure that your shell is still within our project’s folder and enter the following:",[586,1017,1019],{"className":588,"code":1018,"language":590,"meta":244,"style":244},"uv run python main.py\n",[173,1020,1021],{"__ignoreMap":244},[594,1022,1023,1025,1027,1029],{"class":596,"line":597},[594,1024,636],{"class":600},[594,1026,763],{"class":607},[594,1028,700],{"class":607},[594,1030,1031],{"class":607}," main.py\n",[12,1033,1034],{},"Depending on what you named your project folder, your shell should respond with something similar to:",[586,1036,1038],{"className":588,"code":1037,"language":590,"meta":244,"style":244},"Hello from qollab!\n",[173,1039,1040],{"__ignoreMap":244},[594,1041,1042,1045,1048],{"class":596,"line":597},[594,1043,1044],{"class":600},"Hello",[594,1046,1047],{"class":607}," from",[594,1049,1050],{"class":607}," qollab!\n",[12,1052,1053],{},[16,1054,1056],{"href":1055},"https:\u002F\u002Fen.wiktionary.org\u002Fwiki\u002Fcooking_with_gas","Now we’re cooking with gas!",[30,1058,1060],{"id":1059},"_5-pick-a-text-editor","5. Pick a text editor",[12,1062,1063,1064,1067,1068,528,1072,1076,1077,1081,1082,1085,1086,1089,1090,1094,1095,1099],{},"It’s time to start writing your own Python code, and that means editing text files. Python code is just ",[305,1065,1066],{},"plain text",", after all. That means your operating system’s built-in apps (like ",[16,1069,1071],{"href":1070},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FTextEdit","Text Edit",[16,1073,1075],{"href":1074},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FWindows_Notepad","Notepad",") are already enough to write and edit Python (provided you have ",[16,1078,1080],{"href":1079},"https:\u002F\u002Fsites.radford.edu\u002F~rstepno\u002F326\u002Ftextedit\u002Findex.html","rich text turned off",", of course). But a ",[305,1083,1084],{},"robust"," code editing environment can actually make coding ",[305,1087,1088],{},"enjoyable"," through modern conveniences like ",[16,1091,1093],{"href":1092},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FSyntax_highlighting","syntax highlighting",", auto-",[16,1096,1098],{"href":1097},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FIndentation_style","indentation",", and more.",[12,1101,1102,1103,1107,1108,1112],{},"If you don’t already have a favorite text editor or ",[16,1104,1106],{"href":1105},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FIntegrated_development_environment","Integrated Development Environment (IDE)",", now’s the time to discover one that’s right for you. While Wikipedia provides a ",[16,1109,1111],{"href":1110},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FComparison_of_text_editors#Programming_features","comprehensive comparison of text editors",", this more curated list of free, cross-platform coding apps will help you get started.",[1114,1115,1116,1133],"table",{},[1117,1118,1119],"thead",{},[1120,1121,1122,1126,1130],"tr",{},[1123,1124,1125],"th",{},"Name",[1123,1127,1129],{"align":1128},"center","Friendliness",[1123,1131,1132],{},"Description",[1134,1135,1136,1151,1164,1177,1190,1204],"tbody",{},[1120,1137,1138,1145,1148],{},[1139,1140,1141],"td",{},[16,1142,1144],{"href":1143},"https:\u002F\u002Fcode.visualstudio.com","VS Code",[1139,1146,1147],{"align":1128},"✅",[1139,1149,1150],{},"Extension-driven code editor that balances approachability with serious IDE-level power.",[1120,1152,1153,1159,1161],{},[1139,1154,1155],{},[16,1156,1158],{"href":1157},"https:\u002F\u002Fwww.sublimetext.com","Sublime",[1139,1160,1147],{"align":1128},[1139,1162,1163],{},"Blazing-fast, minimalist editor famous for multi-cursor editing and near-instant responsiveness.",[1120,1165,1166,1172,1174],{},[1139,1167,1168],{},[16,1169,1171],{"href":1170},"https:\u002F\u002Fkate-editor.org","Kate",[1139,1173,1147],{"align":1128},[1139,1175,1176],{},"Capable, lightweight KDE editor with strong syntax highlighting and project features without IDE heaviness.",[1120,1178,1179,1185,1187],{},[1139,1180,1181],{},[16,1182,1184],{"href":1183},"https:\u002F\u002Fwww.geany.org","Geany",[1139,1186,1147],{"align":1128},[1139,1188,1189],{},"Small, simple IDE-style editor that offers compilation and tooling with minimal resource usage.",[1120,1191,1192,1198,1201],{},[1139,1193,1194],{},[16,1195,1197],{"href":1196},"https:\u002F\u002Fwww.gnu.org\u002Fsoftware\u002Femacs","Emacs",[1139,1199,1200],{"align":1128},"😅",[1139,1202,1203],{},"Deeply extensible, keyboard-centric editor that doubles as a programmable computing environment.",[1120,1205,1206,1212,1214],{},[1139,1207,1208],{},[16,1209,1211],{"href":1210},"https:\u002F\u002Fwww.vim.org","Vim",[1139,1213,1200],{"align":1128},[1139,1215,1216],{},"Modal, terminal-native editor optimized for extreme speed and precision once its commands are mastered.",[30,1218,1220],{"id":1219},"next-steps","Next steps",[12,1222,1223],{},"You can open a shell. You can bounce between your shell and GUI while staying within your project’s code folder. You’ve installed UV and Python. You’ve created a UV Python project and run some Python code. With a good text editor in hand, you’re ready to start making some really productive mistakes, an exciting start to your journey. You’re ready to venture on to more Qollab tutorials:",[66,1225,1226,1232,1238],{},[69,1227,1228,383],{},[16,1229,1231],{"href":1230},"\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Fpython-basics","Learn Python language basics",[69,1233,1234,383],{},[16,1235,1237],{"href":1236},"\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Fqiskit-setup","Setup the Qiskit SDK",[69,1239,1240,383],{},[16,1241,1243],{"href":1242},"\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Fionq-setup","Setup and simulate with IonQ",[1245,1246,1247],"style",{},"html pre.shiki code .sVbv2, html code.shiki .sVbv2{--shiki-default:#61AFEF}html pre.shiki code .sVC51, html code.shiki .sVC51{--shiki-default:#D19A66}html pre.shiki code .subq3, html code.shiki .subq3{--shiki-default:#98C379}html pre.shiki code .sn6KH, html code.shiki .sn6KH{--shiki-default:#ABB2BF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}",{"title":244,"searchDepth":245,"depth":245,"links":1249},[1250,1251,1257,1262,1267,1272,1273],{"id":338,"depth":245,"text":339},{"id":364,"depth":245,"text":365,"children":1252},[1253,1255,1256],{"id":387,"depth":1254,"text":388},3,{"id":451,"depth":1254,"text":452},{"id":492,"depth":1254,"text":493},{"id":519,"depth":245,"text":520,"children":1258},[1259,1260,1261],{"id":561,"depth":1254,"text":562},{"id":618,"depth":1254,"text":619},{"id":629,"depth":1254,"text":630},{"id":684,"depth":245,"text":685,"children":1263},[1264,1265,1266],{"id":706,"depth":1254,"text":707},{"id":717,"depth":1254,"text":718},{"id":747,"depth":1254,"text":748},{"id":787,"depth":245,"text":788,"children":1268},[1269,1270,1271],{"id":818,"depth":1254,"text":819},{"id":914,"depth":1254,"text":915},{"id":1011,"depth":1254,"text":1012},{"id":1059,"depth":245,"text":1060},{"id":1219,"depth":245,"text":1220},[19,257,258,291],[],{"username":293,"name":1277,"role":1278,"avatar":244},"Stewart Smith","Creative technologist","This guide will walk you through downloading, installing, and enjoying Python via the UV package installer and project manager.",{"image":1281,"alt":291},"\u002F_content\u002Fimages\u002Fpython-setup\u002Fhero.webp",{},{"slug":1284,"title":1285,"desc":1286},"\u002Fblog\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Fpython-basics","2 · Learn Python language basics","Python has become the de facto programming language of quantum computing. This guide highlights some basic Python commands and logic; foundational…","\u002Fblog\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Fpython-setup","2026-01-01","12 min read",[],{"title":1292,"description":1279},"Setup Python on your machine · Building your first Qollab project","blog\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Fpython-setup",[],"HKSfY9GAjazusWgHYpNKQ9dMAa0VjOLFsMA_Ngfv_FU",{"id":1297,"title":1231,"authors":1298,"body":1299,"breadcrumb":3031,"builders":3032,"byline":3033,"challenge":262,"courseAuthor":262,"courseLead":262,"dek":3034,"description":3035,"draft":264,"extension":265,"eyebrow":262,"finish":262,"fork":262,"hero":3036,"heroAlt":262,"heroCta":262,"heroImage":262,"kind":269,"lessonCount":270,"meta":3038,"navigation":272,"newsItems":262,"next":3039,"ogImage":262,"order":245,"outcomes":262,"path":1284,"publishDate":1288,"readingTime":3043,"related":3044,"relatedProjects":262,"seo":3045,"stem":3047,"tags":3048,"track":285,"trackName":258,"__hash__":3049},"blog\u002Fblog\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Fpython-basics.md",[293],{"type":9,"value":1300,"toc":3001},[1301,1321,1325,1347,1365,1371,1385,1395,1404,1418,1422,1438,1493,1496,1502,1540,1564,1568,1609,1612,1720,1724,1875,1879,1883,1909,1913,1940,1944,1981,1985,2011,2014,2054,2057,2093,2097,2135,2141,2145,2223,2227,2268,2274,2278,2281,2285,2288,2335,2350,2398,2402,2449,2452,2510,2513,2573,2577,2580,2584,2605,2609,2633,2637,2663,2667,2693,2697,2732,2736,2767,2771,2774,2850,2854,2882,2885,2889,2998],[12,1302,1303,1304,1307,1308,1311,1312,1316,1317,1320],{},"This guide assumes that you have already installed the ",[16,1305,1306],{"href":536},"UV package manager"," and latest version of ",[16,1309,302],{"href":1310},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FPython%3C\u002Fem%3E(programming_language)"," on your machine. It also assumes that you are able to open a ",[16,1313,1315],{"href":1314},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FShell%3C\u002Fem%3E(computing)","shell application",", and are comfortable editing code. If any of that sounds unfamiliar or outside your expertise, don’t fret! We have a simple guide for that: ",[16,1318,291],{"href":1319},"\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Fpython-setup",". Give that guide a thorough look over first, then come back here to start flexing your code muscles.",[30,1322,1324],{"id":1323},"running-python","Running Python",[12,1326,1327,1328,1332,1333,1336,1337,1339,1340,1343,1344,1346],{},"Python runs line-by-line, like a ",[16,1329,1331],{"href":1330},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FRead%E2%80%93eval%E2%80%93print_loop","Read-Evaluate-Print Loop (REPL)",". Python scripts are just plain text files, often with file names ending in a ",[173,1334,1335],{},".py"," suffix. Our code examples rely on the ",[16,1338,1306],{"href":536},". (See our guide for ",[16,1341,1342],{"href":1319},"Setting up Python and UV on your machine",".) A simple one-line Python script can be run from the command-line shell via ",[173,1345,636],{}," like so:",[586,1348,1350],{"className":588,"code":1349,"language":590,"meta":244,"style":244},"uv run python -c \"print('Hello, World!')\"\n",[173,1351,1352],{"__ignoreMap":244},[594,1353,1354,1356,1358,1360,1362],{"class":596,"line":597},[594,1355,636],{"class":600},[594,1357,763],{"class":607},[594,1359,700],{"class":607},[594,1361,768],{"class":603},[594,1363,1364],{"class":607}," \"print('Hello, World!')\"\n",[12,1366,1367,1368,1370],{},"To enter a full Python REPL via ",[173,1369,636],{},", enter the following into your shell:",[586,1372,1374],{"className":588,"code":1373,"language":590,"meta":244,"style":244},"uv run python\n",[173,1375,1376],{"__ignoreMap":244},[594,1377,1378,1380,1382],{"class":596,"line":597},[594,1379,636],{"class":600},[594,1381,763],{"class":607},[594,1383,1384],{"class":607}," python\n",[12,1386,1387,1388,528,1391,1394],{},"To exit the Python REPL, type ",[173,1389,1390],{},"exit()",[173,1392,1393],{},"quit()"," and press Enter. For Python 3.13 and later, those parenthesis may be omitted.",[12,1396,1397,1398,1400,1401,1403],{},"To run a Python script file via ",[173,1399,636],{},", enter the following, replacing ",[173,1402,948],{}," with the name of the script you wish to execute.",[586,1405,1406],{"className":588,"code":1018,"language":590,"meta":244,"style":244},[173,1407,1408],{"__ignoreMap":244},[594,1409,1410,1412,1414,1416],{"class":596,"line":597},[594,1411,636],{"class":600},[594,1413,763],{"class":607},[594,1415,700],{"class":607},[594,1417,1031],{"class":607},[30,1419,1421],{"id":1420},"basic-syntax","Basic Syntax",[12,1423,1424,1427,1428,460,1431,356,1434,1437],{},[61,1425,1426],{},"Variable creation is implicit",". Unlike other scripting languages, there’s no ",[173,1429,1430],{},"var",[173,1432,1433],{},"let",[173,1435,1436],{},"const"," keywords required in order to create a variable handle. Assignment binds a name to a value:",[586,1439,1443],{"className":1440,"code":1441,"language":1442,"meta":244,"style":244},"language-python shiki shiki-themes one-dark-pro","x = 10\ny = \"hello\"\nz = [1, 2, 3]\n","python",[173,1444,1445,1457,1467],{"__ignoreMap":244},[594,1446,1447,1450,1454],{"class":596,"line":597},[594,1448,1449],{"class":611},"x ",[594,1451,1453],{"class":1452},"sjrmR","=",[594,1455,1456],{"class":603}," 10\n",[594,1458,1459,1462,1464],{"class":596,"line":245},[594,1460,1461],{"class":611},"y ",[594,1463,1453],{"class":1452},[594,1465,1466],{"class":607}," \"hello\"\n",[594,1468,1469,1472,1474,1477,1480,1482,1485,1487,1490],{"class":596,"line":1254},[594,1470,1471],{"class":611},"z ",[594,1473,1453],{"class":1452},[594,1475,1476],{"class":611}," [",[594,1478,1479],{"class":603},"1",[594,1481,460],{"class":611},[594,1483,1484],{"class":603},"2",[594,1486,460],{"class":611},[594,1488,1489],{"class":603},"3",[594,1491,1492],{"class":611},"]\n",[12,1494,1495],{},"Everything is an object. Variables are labels, not boxes.",[12,1497,1498,1501],{},[61,1499,1500],{},"Indentation"," (not curly braces or other visible characters) defines scope blocks:",[586,1503,1505],{"className":1440,"code":1504,"language":1442,"meta":244,"style":244},"if cond:\n    do_something()\nelse:\n    do_other()\n",[173,1506,1507,1516,1524,1532],{"__ignoreMap":244},[594,1508,1509,1513],{"class":596,"line":597},[594,1510,1512],{"class":1511},"seHd6","if",[594,1514,1515],{"class":611}," cond:\n",[594,1517,1518,1521],{"class":596,"line":245},[594,1519,1520],{"class":600},"    do_something",[594,1522,1523],{"class":611},"()\n",[594,1525,1526,1529],{"class":596,"line":1254},[594,1527,1528],{"class":1511},"else",[594,1530,1531],{"class":611},":\n",[594,1533,1535,1538],{"class":596,"line":1534},4,[594,1536,1537],{"class":600},"    do_other",[594,1539,1523],{"class":611},[12,1541,1542,1545,1546,1550,1551,1554,1555,1559,1560,1563],{},[61,1543,1544],{},"Indentation is semantic",", that is, your ",[16,1547,1549],{"href":1548},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FNegative_space","negative space"," carries logical meaning. Therefore, your code must consistenly use ",[305,1552,1553],{},"either"," tabs or spaces for indentation without deviation. The ",[16,1556,1558],{"href":1557},"https:\u002F\u002Fpeps.python.org\u002Fpep-0008\u002F","offical style guide for Python (“PEP 8”)"," specifies an indentation level as ",[61,1561,1562],{},"4"," spaces wide.",[30,1565,1567],{"id":1566},"functions","Functions",[586,1569,1571],{"className":1440,"code":1570,"language":1442,"meta":244,"style":244},"def add(a, b):\n    return a + b\n",[173,1572,1573,1595],{"__ignoreMap":244},[594,1574,1575,1578,1581,1584,1587,1589,1592],{"class":596,"line":597},[594,1576,1577],{"class":1511},"def",[594,1579,1580],{"class":600}," add",[594,1582,1583],{"class":611},"(",[594,1585,16],{"class":1586},"sb9H8",[594,1588,460],{"class":611},[594,1590,1591],{"class":1586},"b",[594,1593,1594],{"class":611},"):\n",[594,1596,1597,1600,1603,1606],{"class":596,"line":245},[594,1598,1599],{"class":1511},"    return",[594,1601,1602],{"class":611}," a ",[594,1604,1605],{"class":1452},"+",[594,1607,1608],{"class":611}," b\n",[12,1610,1611],{},"Python functions capture variables lexically (like JS closures), but the write rules differ, explained in scoping below. Default arguments are evaluated once (careful!):",[586,1613,1615],{"className":1440,"code":1614,"language":1442,"meta":244,"style":244},"def append_to_list(value, lst=[]):  # BAD\n    lst.append(value)\n    return lst\nUse:\ndef append_to_list(value, lst=None):\n    if lst is None:\n        lst = []\n    return lst\n",[173,1616,1617,1641,1652,1659,1664,1686,1703,1713],{"__ignoreMap":244},[594,1618,1619,1621,1624,1626,1629,1631,1634,1637],{"class":596,"line":597},[594,1620,1577],{"class":1511},[594,1622,1623],{"class":600}," append_to_list",[594,1625,1583],{"class":611},[594,1627,1628],{"class":1586},"value",[594,1630,460],{"class":611},[594,1632,1633],{"class":1586},"lst",[594,1635,1636],{"class":611},"=[]):  ",[594,1638,1640],{"class":1639},"sV9Aq","# BAD\n",[594,1642,1643,1646,1649],{"class":596,"line":245},[594,1644,1645],{"class":611},"    lst.",[594,1647,1648],{"class":600},"append",[594,1650,1651],{"class":611},"(value)\n",[594,1653,1654,1656],{"class":596,"line":1254},[594,1655,1599],{"class":1511},[594,1657,1658],{"class":611}," lst\n",[594,1660,1661],{"class":596,"line":1534},[594,1662,1663],{"class":611},"Use:\n",[594,1665,1667,1669,1671,1673,1675,1677,1679,1681,1684],{"class":596,"line":1666},5,[594,1668,1577],{"class":1511},[594,1670,1623],{"class":600},[594,1672,1583],{"class":611},[594,1674,1628],{"class":1586},[594,1676,460],{"class":611},[594,1678,1633],{"class":1586},[594,1680,1453],{"class":611},[594,1682,1683],{"class":603},"None",[594,1685,1594],{"class":611},[594,1687,1689,1692,1695,1698,1701],{"class":596,"line":1688},6,[594,1690,1691],{"class":1511},"    if",[594,1693,1694],{"class":611}," lst ",[594,1696,1697],{"class":1511},"is",[594,1699,1700],{"class":603}," None",[594,1702,1531],{"class":611},[594,1704,1705,1708,1710],{"class":596,"line":270},[594,1706,1707],{"class":611},"        lst ",[594,1709,1453],{"class":1452},[594,1711,1712],{"class":611}," []\n",[594,1714,1716,1718],{"class":596,"line":1715},8,[594,1717,1599],{"class":1511},[594,1719,1658],{"class":611},[30,1721,1723],{"id":1722},"classes-python-style-oop","Classes (Python-style OOP)",[586,1725,1727],{"className":1440,"code":1726,"language":1442,"meta":244,"style":244},"class Car:\n    def __init__(self, make):\n        self.make = make\n\n    def honk(self):\n        print(\"beep\")\n\nc = Car(\"Tesla\")\nc.honk()\nMethods need self explicitly. Inheritance uses the class name:\nclass SportsCar(Car):\n    pass\n",[173,1728,1729,1740,1761,1774,1779,1792,1805,1809,1825,1836,1854,1869],{"__ignoreMap":244},[594,1730,1731,1734,1738],{"class":596,"line":597},[594,1732,1733],{"class":1511},"class",[594,1735,1737],{"class":1736},"sU0A5"," Car",[594,1739,1531],{"class":611},[594,1741,1742,1745,1748,1750,1754,1756,1759],{"class":596,"line":245},[594,1743,1744],{"class":1511},"    def",[594,1746,1747],{"class":1452}," __init__",[594,1749,1583],{"class":611},[594,1751,1753],{"class":1752},"sKU4T","self",[594,1755,460],{"class":611},[594,1757,1758],{"class":1586},"make",[594,1760,1594],{"class":611},[594,1762,1763,1766,1769,1771],{"class":596,"line":1254},[594,1764,1765],{"class":1736},"        self",[594,1767,1768],{"class":611},".make ",[594,1770,1453],{"class":1452},[594,1772,1773],{"class":611}," make\n",[594,1775,1776],{"class":596,"line":1534},[594,1777,1778],{"emptyLinePlaceholder":272},"\n",[594,1780,1781,1783,1786,1788,1790],{"class":596,"line":1666},[594,1782,1744],{"class":1511},[594,1784,1785],{"class":600}," honk",[594,1787,1583],{"class":611},[594,1789,1753],{"class":1752},[594,1791,1594],{"class":611},[594,1793,1794,1797,1799,1802],{"class":596,"line":1688},[594,1795,1796],{"class":1452},"        print",[594,1798,1583],{"class":611},[594,1800,1801],{"class":607},"\"beep\"",[594,1803,1804],{"class":611},")\n",[594,1806,1807],{"class":596,"line":270},[594,1808,1778],{"emptyLinePlaceholder":272},[594,1810,1811,1814,1816,1818,1820,1823],{"class":596,"line":1715},[594,1812,1813],{"class":611},"c ",[594,1815,1453],{"class":1452},[594,1817,1737],{"class":600},[594,1819,1583],{"class":611},[594,1821,1822],{"class":607},"\"Tesla\"",[594,1824,1804],{"class":611},[594,1826,1828,1831,1834],{"class":596,"line":1827},9,[594,1829,1830],{"class":611},"c.",[594,1832,1833],{"class":600},"honk",[594,1835,1523],{"class":611},[594,1837,1839,1842,1844,1847,1849,1852],{"class":596,"line":1838},10,[594,1840,1841],{"class":611},"Methods need ",[594,1843,1753],{"class":1736},[594,1845,1846],{"class":611}," explicitly. Inheritance uses the ",[594,1848,1733],{"class":1511},[594,1850,1851],{"class":1736}," name",[594,1853,1531],{"class":611},[594,1855,1857,1859,1862,1864,1867],{"class":596,"line":1856},11,[594,1858,1733],{"class":1511},[594,1860,1861],{"class":1736}," SportsCar",[594,1863,1583],{"class":611},[594,1865,1866],{"class":1736},"Car",[594,1868,1594],{"class":611},[594,1870,1872],{"class":596,"line":1871},12,[594,1873,1874],{"class":1511},"    pass\n",[30,1876,1878],{"id":1877},"collections","Collections",[385,1880,1882],{"id":1881},"list-array","List (array)",[586,1884,1886],{"className":1440,"code":1885,"language":1442,"meta":244,"style":244},"a = [1, 2, 3]\n",[173,1887,1888],{"__ignoreMap":244},[594,1889,1890,1893,1895,1897,1899,1901,1903,1905,1907],{"class":596,"line":597},[594,1891,1892],{"class":611},"a ",[594,1894,1453],{"class":1452},[594,1896,1476],{"class":611},[594,1898,1479],{"class":603},[594,1900,460],{"class":611},[594,1902,1484],{"class":603},[594,1904,460],{"class":611},[594,1906,1489],{"class":603},[594,1908,1492],{"class":611},[385,1910,1912],{"id":1911},"tuple-immutable","Tuple (immutable)",[586,1914,1916],{"className":1440,"code":1915,"language":1442,"meta":244,"style":244},"t = (1, 2, 3)\n",[173,1917,1918],{"__ignoreMap":244},[594,1919,1920,1923,1925,1928,1930,1932,1934,1936,1938],{"class":596,"line":597},[594,1921,1922],{"class":611},"t ",[594,1924,1453],{"class":1452},[594,1926,1927],{"class":611}," (",[594,1929,1479],{"class":603},[594,1931,460],{"class":611},[594,1933,1484],{"class":603},[594,1935,460],{"class":611},[594,1937,1489],{"class":603},[594,1939,1804],{"class":611},[385,1941,1943],{"id":1942},"dict","Dict",[586,1945,1947],{"className":1440,"code":1946,"language":1442,"meta":244,"style":244},"d = {\"name\": \"Stewart\", \"role\": \"CTO\"}\n",[173,1948,1949],{"__ignoreMap":244},[594,1950,1951,1954,1956,1959,1962,1965,1968,1970,1973,1975,1978],{"class":596,"line":597},[594,1952,1953],{"class":611},"d ",[594,1955,1453],{"class":1452},[594,1957,1958],{"class":611}," {",[594,1960,1961],{"class":607},"\"name\"",[594,1963,1964],{"class":611},": ",[594,1966,1967],{"class":607},"\"Stewart\"",[594,1969,460],{"class":611},[594,1971,1972],{"class":607},"\"role\"",[594,1974,1964],{"class":611},[594,1976,1977],{"class":607},"\"CTO\"",[594,1979,1980],{"class":611},"}\n",[385,1982,1984],{"id":1983},"set","Set",[586,1986,1988],{"className":1440,"code":1987,"language":1442,"meta":244,"style":244},"s = {1, 2, 3}\n",[173,1989,1990],{"__ignoreMap":244},[594,1991,1992,1995,1997,1999,2001,2003,2005,2007,2009],{"class":596,"line":597},[594,1993,1994],{"class":611},"s ",[594,1996,1453],{"class":1452},[594,1998,1958],{"class":611},[594,2000,1479],{"class":603},[594,2002,460],{"class":611},[594,2004,1484],{"class":603},[594,2006,460],{"class":611},[594,2008,1489],{"class":603},[594,2010,1980],{"class":611},[12,2012,2013],{},"List comprehensions:",[586,2015,2017],{"className":1440,"code":2016,"language":1442,"meta":244,"style":244},"squares = [x*x for x in range(10)]\n",[173,2018,2019],{"__ignoreMap":244},[594,2020,2021,2024,2026,2029,2032,2034,2037,2040,2043,2046,2048,2051],{"class":596,"line":597},[594,2022,2023],{"class":611},"squares ",[594,2025,1453],{"class":1452},[594,2027,2028],{"class":611}," [x",[594,2030,2031],{"class":1452},"*",[594,2033,1449],{"class":611},[594,2035,2036],{"class":1511},"for",[594,2038,2039],{"class":611}," x ",[594,2041,2042],{"class":1511},"in",[594,2044,2045],{"class":1452}," range",[594,2047,1583],{"class":611},[594,2049,2050],{"class":603},"10",[594,2052,2053],{"class":611},")]\n",[12,2055,2056],{},"Dictionary comprehensions:",[586,2058,2060],{"className":1440,"code":2059,"language":1442,"meta":244,"style":244},"doubles = {x: x*2 for x in range(5)}\n",[173,2061,2062],{"__ignoreMap":244},[594,2063,2064,2067,2069,2072,2074,2076,2079,2081,2083,2085,2087,2090],{"class":596,"line":597},[594,2065,2066],{"class":611},"doubles ",[594,2068,1453],{"class":1452},[594,2070,2071],{"class":611}," {x: x",[594,2073,2031],{"class":1452},[594,2075,1484],{"class":603},[594,2077,2078],{"class":1511}," for",[594,2080,2039],{"class":611},[594,2082,2042],{"class":1511},[594,2084,2045],{"class":1452},[594,2086,1583],{"class":611},[594,2088,2089],{"class":603},"5",[594,2091,2092],{"class":611},")}\n",[30,2094,2096],{"id":2095},"modules-imports","Modules \u002F Imports",[586,2098,2100],{"className":1440,"code":2099,"language":1442,"meta":244,"style":244},"import math\nfrom pathlib import Path\nfrom mymodule import helper\n",[173,2101,2102,2110,2123],{"__ignoreMap":244},[594,2103,2104,2107],{"class":596,"line":597},[594,2105,2106],{"class":1511},"import",[594,2108,2109],{"class":611}," math\n",[594,2111,2112,2115,2118,2120],{"class":596,"line":245},[594,2113,2114],{"class":1511},"from",[594,2116,2117],{"class":611}," pathlib ",[594,2119,2106],{"class":1511},[594,2121,2122],{"class":611}," Path\n",[594,2124,2125,2127,2130,2132],{"class":596,"line":1254},[594,2126,2114],{"class":1511},[594,2128,2129],{"class":611}," mymodule ",[594,2131,2106],{"class":1511},[594,2133,2134],{"class":611}," helper\n",[12,2136,2137,2138,383],{},"Scripts are modules. Packages are directories with ",[173,2139,2140],{},"__init__.py",[30,2142,2144],{"id":2143},"exceptions","Exceptions",[586,2146,2148],{"className":1440,"code":2147,"language":1442,"meta":244,"style":244},"try:\n    risky()\nexcept ValueError:\n    print(\"Nope\")\nexcept Exception as e:\n    print(\"Other error:\", e)\nfinally:\n    cleanup()\n",[173,2149,2150,2157,2164,2172,2184,2197,2209,2216],{"__ignoreMap":244},[594,2151,2152,2155],{"class":596,"line":597},[594,2153,2154],{"class":1511},"try",[594,2156,1531],{"class":611},[594,2158,2159,2162],{"class":596,"line":245},[594,2160,2161],{"class":600},"    risky",[594,2163,1523],{"class":611},[594,2165,2166,2169],{"class":596,"line":1254},[594,2167,2168],{"class":1511},"except",[594,2170,2171],{"class":611}," ValueError:\n",[594,2173,2174,2177,2179,2182],{"class":596,"line":1534},[594,2175,2176],{"class":1452},"    print",[594,2178,1583],{"class":611},[594,2180,2181],{"class":607},"\"Nope\"",[594,2183,1804],{"class":611},[594,2185,2186,2188,2191,2194],{"class":596,"line":1666},[594,2187,2168],{"class":1511},[594,2189,2190],{"class":611}," Exception ",[594,2192,2193],{"class":1511},"as",[594,2195,2196],{"class":611}," e:\n",[594,2198,2199,2201,2203,2206],{"class":596,"line":1688},[594,2200,2176],{"class":1452},[594,2202,1583],{"class":611},[594,2204,2205],{"class":607},"\"Other error:\"",[594,2207,2208],{"class":611},", e)\n",[594,2210,2211,2214],{"class":596,"line":270},[594,2212,2213],{"class":1511},"finally",[594,2215,1531],{"class":611},[594,2217,2218,2221],{"class":596,"line":1715},[594,2219,2220],{"class":600},"    cleanup",[594,2222,1523],{"class":611},[30,2224,2226],{"id":2225},"file-io","File I\u002FO",[586,2228,2230],{"className":1440,"code":2229,"language":1442,"meta":244,"style":244},"with open(\"data.txt\") as f:\n    text = f.read()\n",[173,2231,2232,2253],{"__ignoreMap":244},[594,2233,2234,2237,2240,2242,2245,2248,2250],{"class":596,"line":597},[594,2235,2236],{"class":1511},"with",[594,2238,2239],{"class":1452}," open",[594,2241,1583],{"class":611},[594,2243,2244],{"class":607},"\"data.txt\"",[594,2246,2247],{"class":611},") ",[594,2249,2193],{"class":1511},[594,2251,2252],{"class":611}," f:\n",[594,2254,2255,2258,2260,2263,2266],{"class":596,"line":245},[594,2256,2257],{"class":611},"    text ",[594,2259,1453],{"class":1452},[594,2261,2262],{"class":611}," f.",[594,2264,2265],{"class":600},"read",[594,2267,1523],{"class":611},[12,2269,2270,2271,2273],{},"The ",[173,2272,2236],{}," block ensures cleanup (context manager).",[30,2275,2277],{"id":2276},"python-variable-scoping-legb-rule","Python Variable Scoping (LEGB Rule)",[12,2279,2280],{},"Python scoping follows L-E-G-B: - Local, inside current function - Enclosing, outer function scopes (closures) - Global, module-level - Built-in, len, print, etc This is very similar to JavaScript lexical scoping except Python treats assignment differently.",[385,2282,2284],{"id":2283},"important-rule","Important Rule",[12,2286,2287],{},"Any variable you assign to inside a function is considered local unless you explicitly declare otherwise. This catches people:",[586,2289,2291],{"className":1440,"code":2290,"language":1442,"meta":244,"style":244},"x = 10\n\ndef f():\n    print(x)     # ERROR? Actually, UnboundLocalError!\n    x = 20\n",[173,2292,2293,2301,2305,2315,2325],{"__ignoreMap":244},[594,2294,2295,2297,2299],{"class":596,"line":597},[594,2296,1449],{"class":611},[594,2298,1453],{"class":1452},[594,2300,1456],{"class":603},[594,2302,2303],{"class":596,"line":245},[594,2304,1778],{"emptyLinePlaceholder":272},[594,2306,2307,2309,2312],{"class":596,"line":1254},[594,2308,1577],{"class":1511},[594,2310,2311],{"class":600}," f",[594,2313,2314],{"class":611},"():\n",[594,2316,2317,2319,2322],{"class":596,"line":1534},[594,2318,2176],{"class":1452},[594,2320,2321],{"class":611},"(x)     ",[594,2323,2324],{"class":1639},"# ERROR? Actually, UnboundLocalError!\n",[594,2326,2327,2330,2332],{"class":596,"line":1666},[594,2328,2329],{"class":611},"    x ",[594,2331,1453],{"class":1452},[594,2333,2334],{"class":603}," 20\n",[12,2336,2337,2338,2341,2342,2345,2346,2349],{},"Why? Because the presence of ",[173,2339,2340],{},"x = 20"," makes ",[173,2343,2344],{},"x"," local to ",[173,2347,2348],{},"f",". Python sees “you assign to x somewhere in the function” → therefore x is local everywhere in that function. To mutate the module-level x:",[586,2351,2353],{"className":1440,"code":2352,"language":1442,"meta":244,"style":244},"x = 10\n\ndef f():\n    global x\n    print(x)\n    x = 20\n",[173,2354,2355,2363,2367,2375,2383,2390],{"__ignoreMap":244},[594,2356,2357,2359,2361],{"class":596,"line":597},[594,2358,1449],{"class":611},[594,2360,1453],{"class":1452},[594,2362,1456],{"class":603},[594,2364,2365],{"class":596,"line":245},[594,2366,1778],{"emptyLinePlaceholder":272},[594,2368,2369,2371,2373],{"class":596,"line":1254},[594,2370,1577],{"class":1511},[594,2372,2311],{"class":600},[594,2374,2314],{"class":611},[594,2376,2377,2380],{"class":596,"line":1534},[594,2378,2379],{"class":1511},"    global",[594,2381,2382],{"class":611}," x\n",[594,2384,2385,2387],{"class":596,"line":1666},[594,2386,2176],{"class":1452},[594,2388,2389],{"class":611},"(x)\n",[594,2391,2392,2394,2396],{"class":596,"line":1688},[594,2393,2329],{"class":611},[594,2395,1453],{"class":1452},[594,2397,2334],{"class":603},[385,2399,2401],{"id":2400},"closures-enclosing-scope","Closures (Enclosing scope)",[586,2403,2405],{"className":1440,"code":2404,"language":1442,"meta":244,"style":244},"def outer():\n    x = 10\n    def inner():\n        print(x)     # OK\n    inner()\n",[173,2406,2407,2416,2424,2433,2442],{"__ignoreMap":244},[594,2408,2409,2411,2414],{"class":596,"line":597},[594,2410,1577],{"class":1511},[594,2412,2413],{"class":600}," outer",[594,2415,2314],{"class":611},[594,2417,2418,2420,2422],{"class":596,"line":245},[594,2419,2329],{"class":611},[594,2421,1453],{"class":1452},[594,2423,1456],{"class":603},[594,2425,2426,2428,2431],{"class":596,"line":1254},[594,2427,1744],{"class":1511},[594,2429,2430],{"class":600}," inner",[594,2432,2314],{"class":611},[594,2434,2435,2437,2439],{"class":596,"line":1534},[594,2436,1796],{"class":1452},[594,2438,2321],{"class":611},[594,2440,2441],{"class":1639},"# OK\n",[594,2443,2444,2447],{"class":596,"line":1666},[594,2445,2446],{"class":600},"    inner",[594,2448,1523],{"class":611},[12,2450,2451],{},"But trying to assign inside the closure fails:",[586,2453,2455],{"className":1440,"code":2454,"language":1442,"meta":244,"style":244},"def outer():\n    x = 10\n    def inner():\n        x = 20      # This creates NEW local x\n    inner()\n    print(x)        # still 10\n",[173,2456,2457,2465,2473,2481,2494,2500],{"__ignoreMap":244},[594,2458,2459,2461,2463],{"class":596,"line":597},[594,2460,1577],{"class":1511},[594,2462,2413],{"class":600},[594,2464,2314],{"class":611},[594,2466,2467,2469,2471],{"class":596,"line":245},[594,2468,2329],{"class":611},[594,2470,1453],{"class":1452},[594,2472,1456],{"class":603},[594,2474,2475,2477,2479],{"class":596,"line":1254},[594,2476,1744],{"class":1511},[594,2478,2430],{"class":600},[594,2480,2314],{"class":611},[594,2482,2483,2486,2488,2491],{"class":596,"line":1534},[594,2484,2485],{"class":611},"        x ",[594,2487,1453],{"class":1452},[594,2489,2490],{"class":603}," 20",[594,2492,2493],{"class":1639},"      # This creates NEW local x\n",[594,2495,2496,2498],{"class":596,"line":1666},[594,2497,2446],{"class":600},[594,2499,1523],{"class":611},[594,2501,2502,2504,2507],{"class":596,"line":1688},[594,2503,2176],{"class":1452},[594,2505,2506],{"class":611},"(x)        ",[594,2508,2509],{"class":1639},"# still 10\n",[12,2511,2512],{},"To mutate the enclosing scope’s variable use nonlocal:",[586,2514,2516],{"className":1440,"code":2515,"language":1442,"meta":244,"style":244},"def outer():\n    x = 10\n    def inner():\n        nonlocal x\n        x = 20\n    inner()\n    print(x)   # 20\n",[173,2517,2518,2526,2534,2542,2549,2557,2563],{"__ignoreMap":244},[594,2519,2520,2522,2524],{"class":596,"line":597},[594,2521,1577],{"class":1511},[594,2523,2413],{"class":600},[594,2525,2314],{"class":611},[594,2527,2528,2530,2532],{"class":596,"line":245},[594,2529,2329],{"class":611},[594,2531,1453],{"class":1452},[594,2533,1456],{"class":603},[594,2535,2536,2538,2540],{"class":596,"line":1254},[594,2537,1744],{"class":1511},[594,2539,2430],{"class":600},[594,2541,2314],{"class":611},[594,2543,2544,2547],{"class":596,"line":1534},[594,2545,2546],{"class":1511},"        nonlocal",[594,2548,2382],{"class":611},[594,2550,2551,2553,2555],{"class":596,"line":1666},[594,2552,2485],{"class":611},[594,2554,1453],{"class":1452},[594,2556,2334],{"class":603},[594,2558,2559,2561],{"class":596,"line":1688},[594,2560,2446],{"class":600},[594,2562,1523],{"class":611},[594,2564,2565,2567,2570],{"class":596,"line":270},[594,2566,2176],{"class":1452},[594,2568,2569],{"class":611},"(x)   ",[594,2571,2572],{"class":1639},"# 20\n",[30,2574,2576],{"id":2575},"pythonic-style-cheat-sheet","Pythonic Style Cheat Sheet",[12,2578,2579],{},"Idiomatic ways to write things:",[385,2581,2583],{"id":2582},"iteration","Iteration",[586,2585,2587],{"className":1440,"code":2586,"language":1442,"meta":244,"style":244},"for x in items:\n    ...\n",[173,2588,2589,2600],{"__ignoreMap":244},[594,2590,2591,2593,2595,2597],{"class":596,"line":597},[594,2592,2036],{"class":1511},[594,2594,2039],{"class":611},[594,2596,2042],{"class":1511},[594,2598,2599],{"class":611}," items:\n",[594,2601,2602],{"class":596,"line":245},[594,2603,2604],{"class":603},"    ...\n",[385,2606,2608],{"id":2607},"enumerate-with-index","Enumerate with index",[586,2610,2612],{"className":1440,"code":2611,"language":1442,"meta":244,"style":244},"for i, x in enumerate(items):\n    ...\n",[173,2613,2614,2629],{"__ignoreMap":244},[594,2615,2616,2618,2621,2623,2626],{"class":596,"line":597},[594,2617,2036],{"class":1511},[594,2619,2620],{"class":611}," i, x ",[594,2622,2042],{"class":1511},[594,2624,2625],{"class":1452}," enumerate",[594,2627,2628],{"class":611},"(items):\n",[594,2630,2631],{"class":596,"line":245},[594,2632,2604],{"class":603},[385,2634,2636],{"id":2635},"iterate-dict","Iterate dict",[586,2638,2640],{"className":1440,"code":2639,"language":1442,"meta":244,"style":244},"for k, v in d.items():\n    ...\n",[173,2641,2642,2659],{"__ignoreMap":244},[594,2643,2644,2646,2649,2651,2654,2657],{"class":596,"line":597},[594,2645,2036],{"class":1511},[594,2647,2648],{"class":611}," k, v ",[594,2650,2042],{"class":1511},[594,2652,2653],{"class":611}," d.",[594,2655,2656],{"class":600},"items",[594,2658,2314],{"class":611},[594,2660,2661],{"class":596,"line":245},[594,2662,2604],{"class":603},[385,2664,2666],{"id":2665},"ternary","Ternary",[586,2668,2670],{"className":1440,"code":2669,"language":1442,"meta":244,"style":244},"msg = \"ok\" if status else \"bad\"\n",[173,2671,2672],{"__ignoreMap":244},[594,2673,2674,2677,2679,2682,2685,2688,2690],{"class":596,"line":597},[594,2675,2676],{"class":611},"msg ",[594,2678,1453],{"class":1452},[594,2680,2681],{"class":607}," \"ok\"",[594,2683,2684],{"class":1511}," if",[594,2686,2687],{"class":611}," status ",[594,2689,1528],{"class":1511},[594,2691,2692],{"class":607}," \"bad\"\n",[385,2694,2696],{"id":2695},"with-open-file-handling","With-open file handling",[586,2698,2700],{"className":1440,"code":2699,"language":1442,"meta":244,"style":244},"with open(\"file.txt\") as f:\n    data = f.read()\n",[173,2701,2702,2719],{"__ignoreMap":244},[594,2703,2704,2706,2708,2710,2713,2715,2717],{"class":596,"line":597},[594,2705,2236],{"class":1511},[594,2707,2239],{"class":1452},[594,2709,1583],{"class":611},[594,2711,2712],{"class":607},"\"file.txt\"",[594,2714,2247],{"class":611},[594,2716,2193],{"class":1511},[594,2718,2252],{"class":611},[594,2720,2721,2724,2726,2728,2730],{"class":596,"line":245},[594,2722,2723],{"class":611},"    data ",[594,2725,1453],{"class":1452},[594,2727,2262],{"class":611},[594,2729,2265],{"class":600},[594,2731,1523],{"class":611},[385,2733,2735],{"id":2734},"write-generator-expression","Write generator expression",[586,2737,2739],{"className":1440,"code":2738,"language":1442,"meta":244,"style":244},"total = sum(x*x for x in nums)\n",[173,2740,2741],{"__ignoreMap":244},[594,2742,2743,2746,2748,2751,2754,2756,2758,2760,2762,2764],{"class":596,"line":597},[594,2744,2745],{"class":611},"total ",[594,2747,1453],{"class":1452},[594,2749,2750],{"class":1452}," sum",[594,2752,2753],{"class":611},"(x",[594,2755,2031],{"class":1452},[594,2757,1449],{"class":611},[594,2759,2036],{"class":1511},[594,2761,2039],{"class":611},[594,2763,2042],{"class":1511},[594,2765,2766],{"class":611}," nums)\n",[30,2768,2770],{"id":2769},"tiny-gotchas-you-should-know-immediately","Tiny “gotchas” you should know immediately",[12,2772,2773],{},"Mutability matters. Lists, dicts, sets = mutable. Tuples, ints, strings = immutable. Everything is reference by default.",[586,2775,2777],{"className":1440,"code":2776,"language":1442,"meta":244,"style":244},"a = [1,2]\nb = a\nb.append(3)\na == [1,2,3]\u002F\u002F True!\n\n",[173,2778,2779,2796,2806,2819],{"__ignoreMap":244},[594,2780,2781,2783,2785,2787,2789,2792,2794],{"class":596,"line":597},[594,2782,1892],{"class":611},[594,2784,1453],{"class":1452},[594,2786,1476],{"class":611},[594,2788,1479],{"class":603},[594,2790,2791],{"class":611},",",[594,2793,1484],{"class":603},[594,2795,1492],{"class":611},[594,2797,2798,2801,2803],{"class":596,"line":245},[594,2799,2800],{"class":611},"b ",[594,2802,1453],{"class":1452},[594,2804,2805],{"class":611}," a\n",[594,2807,2808,2811,2813,2815,2817],{"class":596,"line":1254},[594,2809,2810],{"class":611},"b.",[594,2812,1648],{"class":600},[594,2814,1583],{"class":611},[594,2816,1489],{"class":603},[594,2818,1804],{"class":611},[594,2820,2821,2823,2826,2828,2830,2832,2834,2836,2838,2841,2844,2847],{"class":596,"line":1534},[594,2822,1892],{"class":611},[594,2824,2825],{"class":1452},"==",[594,2827,1476],{"class":611},[594,2829,1479],{"class":603},[594,2831,2791],{"class":611},[594,2833,1484],{"class":603},[594,2835,2791],{"class":611},[594,2837,1489],{"class":603},[594,2839,2840],{"class":611},"]",[594,2842,2843],{"class":1452},"\u002F\u002F",[594,2845,2846],{"class":603}," True",[594,2848,2849],{"class":611},"!\n",[30,2851,2853],{"id":2852},"truthiness","Truthiness:",[586,2855,2857],{"className":1440,"code":2856,"language":1442,"meta":244,"style":244},"0, \"\", [], {}, None, False → falsey\n",[173,2858,2859],{"__ignoreMap":244},[594,2860,2861,2864,2866,2869,2872,2874,2876,2879],{"class":596,"line":597},[594,2862,2863],{"class":603},"0",[594,2865,460],{"class":611},[594,2867,2868],{"class":607},"\"\"",[594,2870,2871],{"class":611},", [], {}, ",[594,2873,1683],{"class":603},[594,2875,460],{"class":611},[594,2877,2878],{"class":603},"False",[594,2880,2881],{"class":611}," → falsey\n",[12,2883,2884],{},"Everything else is truthy.",[30,2886,2888],{"id":2887},"_10-line-example-that-uses-everything-above","10-line example that uses everything above",[586,2890,2892],{"className":1440,"code":2891,"language":1442,"meta":244,"style":244},"def make_counter():\n    count = 0\n    def inc():\n        nonlocal count\n        count += 1\n        return count\n    return inc\n\ncounter = make_counter()\nprint(counter())  # 1\nprint(counter())  # 2\n",[173,2893,2894,2903,2913,2922,2929,2940,2947,2954,2958,2969,2985],{"__ignoreMap":244},[594,2895,2896,2898,2901],{"class":596,"line":597},[594,2897,1577],{"class":1511},[594,2899,2900],{"class":600}," make_counter",[594,2902,2314],{"class":611},[594,2904,2905,2908,2910],{"class":596,"line":245},[594,2906,2907],{"class":611},"    count ",[594,2909,1453],{"class":1452},[594,2911,2912],{"class":603}," 0\n",[594,2914,2915,2917,2920],{"class":596,"line":1254},[594,2916,1744],{"class":1511},[594,2918,2919],{"class":600}," inc",[594,2921,2314],{"class":611},[594,2923,2924,2926],{"class":596,"line":1534},[594,2925,2546],{"class":1511},[594,2927,2928],{"class":611}," count\n",[594,2930,2931,2934,2937],{"class":596,"line":1666},[594,2932,2933],{"class":611},"        count ",[594,2935,2936],{"class":1452},"+=",[594,2938,2939],{"class":603}," 1\n",[594,2941,2942,2945],{"class":596,"line":1688},[594,2943,2944],{"class":1511},"        return",[594,2946,2928],{"class":611},[594,2948,2949,2951],{"class":596,"line":270},[594,2950,1599],{"class":1511},[594,2952,2953],{"class":611}," inc\n",[594,2955,2956],{"class":596,"line":1715},[594,2957,1778],{"emptyLinePlaceholder":272},[594,2959,2960,2963,2965,2967],{"class":596,"line":1827},[594,2961,2962],{"class":611},"counter ",[594,2964,1453],{"class":1452},[594,2966,2900],{"class":600},[594,2968,1523],{"class":611},[594,2970,2971,2974,2976,2979,2982],{"class":596,"line":1838},[594,2972,2973],{"class":1452},"print",[594,2975,1583],{"class":611},[594,2977,2978],{"class":600},"counter",[594,2980,2981],{"class":611},"())  ",[594,2983,2984],{"class":1639},"# 1\n",[594,2986,2987,2989,2991,2993,2995],{"class":596,"line":1856},[594,2988,2973],{"class":1452},[594,2990,1583],{"class":611},[594,2992,2978],{"class":600},[594,2994,2981],{"class":611},[594,2996,2997],{"class":1639},"# 2\n",[1245,2999,3000],{},"html pre.shiki code .sVbv2, html code.shiki .sVbv2{--shiki-default:#61AFEF}html pre.shiki code .subq3, html code.shiki .subq3{--shiki-default:#98C379}html pre.shiki code .sVC51, html code.shiki .sVC51{--shiki-default:#D19A66}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html pre.shiki code .sn6KH, html code.shiki .sn6KH{--shiki-default:#ABB2BF}html pre.shiki code .sjrmR, html code.shiki .sjrmR{--shiki-default:#56B6C2}html pre.shiki code .seHd6, html code.shiki .seHd6{--shiki-default:#C678DD}html pre.shiki code .sb9H8, html code.shiki .sb9H8{--shiki-default:#D19A66;--shiki-default-font-style:italic}html pre.shiki code .sV9Aq, html code.shiki .sV9Aq{--shiki-default:#7F848E;--shiki-default-font-style:italic}html pre.shiki code .sU0A5, html code.shiki .sU0A5{--shiki-default:#E5C07B}html pre.shiki code .sKU4T, html code.shiki .sKU4T{--shiki-default:#E5C07B;--shiki-default-font-style:italic}",{"title":244,"searchDepth":245,"depth":245,"links":3002},[3003,3004,3005,3006,3007,3013,3014,3015,3016,3020,3028,3029,3030],{"id":1323,"depth":245,"text":1324},{"id":1420,"depth":245,"text":1421},{"id":1566,"depth":245,"text":1567},{"id":1722,"depth":245,"text":1723},{"id":1877,"depth":245,"text":1878,"children":3008},[3009,3010,3011,3012],{"id":1881,"depth":1254,"text":1882},{"id":1911,"depth":1254,"text":1912},{"id":1942,"depth":1254,"text":1943},{"id":1983,"depth":1254,"text":1984},{"id":2095,"depth":245,"text":2096},{"id":2143,"depth":245,"text":2144},{"id":2225,"depth":245,"text":2226},{"id":2276,"depth":245,"text":2277,"children":3017},[3018,3019],{"id":2283,"depth":1254,"text":2284},{"id":2400,"depth":1254,"text":2401},{"id":2575,"depth":245,"text":2576,"children":3021},[3022,3023,3024,3025,3026,3027],{"id":2582,"depth":1254,"text":2583},{"id":2607,"depth":1254,"text":2608},{"id":2635,"depth":1254,"text":2636},{"id":2665,"depth":1254,"text":2666},{"id":2695,"depth":1254,"text":2696},{"id":2734,"depth":1254,"text":2735},{"id":2769,"depth":245,"text":2770},{"id":2852,"depth":245,"text":2853},{"id":2887,"depth":245,"text":2888},[19,257,258,1231],[],{"username":293,"name":1277,"role":1278,"avatar":244},"Python has become the de facto programming language of quantum computing. This guide highlights some basic Python commands and logic; foundational elements to build from.","Python has become the de facto language of quantum computing. This guide covers the basic Python commands and logic to build from.",{"image":3037,"alt":1231},"\u002F_content\u002Fimages\u002Fpython-basics\u002Fhero.webp",{},{"slug":3040,"title":3041,"desc":3042},"\u002Fblog\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Fqiskit-setup","3 · Setup IBM’s Qiskit SDK","This guide details how to install IBM’s Qiskit quantum computing packages for Python, using the UV package manager.","5 min read",[],{"title":3046,"description":3035},"Learn Python language basics · Building your first Qollab project","blog\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Fpython-basics",[],"Zs0gGrUcRe99ICeSFSxgdwYG6Yjp2VxvMrvwkeb6PD8",{"id":3051,"title":3052,"authors":3053,"body":3054,"breadcrumb":3659,"builders":3660,"byline":3661,"challenge":262,"courseAuthor":262,"courseLead":262,"dek":3042,"description":3042,"draft":264,"extension":265,"eyebrow":262,"finish":262,"fork":262,"hero":3662,"heroAlt":262,"heroCta":262,"heroImage":262,"kind":269,"lessonCount":270,"meta":3664,"navigation":272,"newsItems":262,"next":3665,"ogImage":262,"order":1254,"outcomes":262,"path":3040,"publishDate":1288,"readingTime":3669,"related":3670,"relatedProjects":262,"seo":3671,"stem":3673,"tags":3674,"track":285,"trackName":258,"__hash__":3675},"blog\u002Fblog\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Fqiskit-setup.md","Setup IBM’s Qiskit SDK",[293],{"type":9,"value":3055,"toc":3649},[3056,3074,3078,3084,3088,3091,3106,3139,3143,3146,3174,3178,3196,3208,3214,3218,3221,3233,3236,3249,3253,3256,3270,3273,3291,3303,3317,3320,3338,3342,3348,3552,3590,3596,3609,3612,3636,3639,3643,3646],[12,3057,3058,3059,3063,3064,3066,3067,3070,3071,383],{},"IBM’s Qiskit is a leading quantum Software Development Kit (SDK) used as a foundation, not just for use with IBM hardware, but for various other quantum computing hardware architectures as well. IBM already has excellent ",[16,3060,3062],{"href":3061},"https:\u002F\u002Fquantum.cloud.ibm.com\u002Fdocs\u002Fen\u002Ftutorials","Qiskit tutorials"," available online for free. Our Qollab Qiskit guides take a specific, ",[16,3065,537],{"href":536},"-based approach to managing Python projects. If you have not installed UV (or Python), take a look at our previous guide: ",[16,3068,3069],{"href":1319},"Setup Python (and UV) on your machine",". For a crash course in Python fundamentals, see our guide: ",[16,3072,3073],{"href":1230},"Learn Python basics",[30,3075,3077],{"id":3076},"_1-create-a-new-project","1. Create a new project",[12,3079,3080,3081,815],{},"Create a project folder on your Desktop titled ",[173,3082,3083],{},"our-qollab",[385,3085,3087],{"id":3086},"initialize-our-app","Initialize our app",[12,3089,3090],{},"Open a shell to your project’s folder and enter the following command:",[586,3092,3094],{"className":588,"code":3093,"language":590,"meta":244,"style":244},"uv init --app\n",[173,3095,3096],{"__ignoreMap":244},[594,3097,3098,3100,3103],{"class":596,"line":597},[594,3099,636],{"class":600},[594,3101,3102],{"class":607}," init",[594,3104,3105],{"class":603}," --app\n",[12,3107,3108,3109,3112,3113,3116,3117,3120,3121,3124,3125,3128,3129,3131,3132,528,3135,3138],{},"This will initialize your new ",[16,3110,3111],{"href":536},"UV-managed"," project. The ",[173,3114,3115],{},"uv init"," command has two main modes: 1. ",[61,3118,3119],{},"Library mode"," (default): For building a script that is primarily intended to be a reusable package, imported by other applications. 2. ",[61,3122,3123],{},"Application mode"," (using the ",[173,3126,3127],{},"--app"," flag): For building a script that is intended to be executable on its own. The ",[173,3130,3127],{}," flag instructs UV to assume the app will be run via ",[173,3133,3134],{},"uv run ...",[173,3136,3137],{},"uv run python -m ...",". It’s not meant to be installed as a dependency, and entry points matter more than exports.",[385,3140,3142],{"id":3141},"select-a-python-version","Select a Python version",[12,3144,3145],{},"We want to be selective about which Python version our application uses because Qiskit and its various packages have particular compatibility requirements, and sometimes lag behind the most recent Python release. As of this writing, Python 3.12 is a safe choice for use. Enter the following into your shell to install Python 3.12 (if not already available) and explitly pin it as the version required by our application.",[586,3147,3149],{"className":588,"code":3148,"language":590,"meta":244,"style":244},"uv python install 3.12\nuv python pin 3.12\n",[173,3150,3151,3163],{"__ignoreMap":244},[594,3152,3153,3155,3157,3160],{"class":596,"line":597},[594,3154,636],{"class":600},[594,3156,700],{"class":607},[594,3158,3159],{"class":607}," install",[594,3161,3162],{"class":603}," 3.12\n",[594,3164,3165,3167,3169,3172],{"class":596,"line":245},[594,3166,636],{"class":600},[594,3168,700],{"class":607},[594,3170,3171],{"class":607}," pin",[594,3173,3162],{"class":603},[824,3175,3177],{"id":3176},"pitfalls-to-avoid","Pitfalls to avoid",[12,3179,3180,3181,464,3185,3187,3188,3192,3193,3195],{},"Qiskit only supports ",[16,3182,3184],{"href":3183},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FCPython","CPython",[305,3186,640],{}," ",[16,3189,3191],{"href":3190},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FPyPy","PyPy",". You can confirm your Python versions via ",[173,3194,636],{}," by entering the following into your shell:",[586,3197,3198],{"className":588,"code":724,"language":590,"meta":244,"style":244},[173,3199,3200],{"__ignoreMap":244},[594,3201,3202,3204,3206],{"class":596,"line":597},[594,3203,636],{"class":600},[594,3205,700],{"class":607},[594,3207,735],{"class":607},[12,3209,3210,3211,383],{},"If you’re upgrading across major Qiskit eras, don’t “upgrade in place” inside an old virtual environment. Instead, make a new virtual environment for each project using ",[173,3212,3213],{},"uv venv",[385,3215,3217],{"id":3216},"create-a-virtual-environment","Create a virtual environment",[12,3219,3220],{},"Initializing a UV app will “lazily” create a virtual environment. That is, the virtual environment ought to create and activate on-demand when it is first needed. But out of precaution we’d like to manually do that now ourselves. Enter the following into your shell:",[586,3222,3224],{"className":588,"code":3223,"language":590,"meta":244,"style":244},"uv venv\n",[173,3225,3226],{"__ignoreMap":244},[594,3227,3228,3230],{"class":596,"line":597},[594,3229,636],{"class":600},[594,3231,3232],{"class":607}," venv\n",[12,3234,3235],{},"At this point our shell may ask us to enter something similar the following in order to activate our virtual environment:",[586,3237,3239],{"className":588,"code":3238,"language":590,"meta":244,"style":244},"source .venv\u002Fbin\u002Factivate\n",[173,3240,3241],{"__ignoreMap":244},[594,3242,3243,3246],{"class":596,"line":597},[594,3244,3245],{"class":1452},"source",[594,3247,3248],{"class":607}," .venv\u002Fbin\u002Factivate\n",[30,3250,3252],{"id":3251},"_2-add-qiskit-packages","2. Add Qiskit packages",[12,3254,3255],{},"Enter the following into your shell to install Qiskit’s core package:",[586,3257,3259],{"className":588,"code":3258,"language":590,"meta":244,"style":244},"uv add qiskit\n",[173,3260,3261],{"__ignoreMap":244},[594,3262,3263,3265,3267],{"class":596,"line":597},[594,3264,636],{"class":600},[594,3266,1580],{"class":607},[594,3268,3269],{"class":607}," qiskit\n",[12,3271,3272],{},"Let’s confirm that Qiskit has installed correctly. Enter the following into your shell and it should respond with a Qiskit version number:",[586,3274,3276],{"className":588,"code":3275,"language":590,"meta":244,"style":244},"uv run python -c \"import qiskit; print('Qiskit', qiskit.__version__)\"\n",[173,3277,3278],{"__ignoreMap":244},[594,3279,3280,3282,3284,3286,3288],{"class":596,"line":597},[594,3281,636],{"class":600},[594,3283,763],{"class":607},[594,3285,700],{"class":607},[594,3287,768],{"class":603},[594,3289,3290],{"class":607}," \"import qiskit; print('Qiskit', qiskit.__version__)\"\n",[12,3292,3293,3294,3297,3298,3302],{},"Our first Qiskit app is going to use a quantum ",[305,3295,3296],{},"simulator"," that runs on your local machine, as opposed to using a cloud-based simulator or actual quantum hardware. (Don’t worry, we’ll get to real quantum hardware soon enough.) Install Qiskit’s fast local simulator (",[16,3299,3301],{"href":3300},"https:\u002F\u002Fqiskit.github.io\u002Fqiskit-aer\u002F","Qiskit Aer",") by entering the following into your shell:",[586,3304,3306],{"className":588,"code":3305,"language":590,"meta":244,"style":244},"uv add qiskit-aer\n",[173,3307,3308],{"__ignoreMap":244},[594,3309,3310,3312,3314],{"class":596,"line":597},[594,3311,636],{"class":600},[594,3313,1580],{"class":607},[594,3315,3316],{"class":607}," qiskit-aer\n",[12,3318,3319],{},"We can run a similiar sanity check for Aer as well:",[586,3321,3323],{"className":588,"code":3322,"language":590,"meta":244,"style":244},"uv run python -c \"import qiskit_aer; print('Qiskit Aer', qiskit_aer.__version__)\"\n",[173,3324,3325],{"__ignoreMap":244},[594,3326,3327,3329,3331,3333,3335],{"class":596,"line":597},[594,3328,636],{"class":600},[594,3330,763],{"class":607},[594,3332,700],{"class":607},[594,3334,768],{"class":603},[594,3336,3337],{"class":607}," \"import qiskit_aer; print('Qiskit Aer', qiskit_aer.__version__)\"\n",[30,3339,3341],{"id":3340},"_3-run-a-local-simulation","3. Run a local simulation",[12,3343,3344,3345,3347],{},"Now that we’ve installed some Qiskit packages, let’s put them to use. Open up your project’s ",[173,3346,948],{}," Python script with your favorite text editor. Replace its contents with the following, and save it to disk:",[586,3349,3351],{"className":1440,"code":3350,"language":1442,"meta":244,"style":244},"from qiskit import QuantumCircuit\nfrom qiskit_aer import AerSimulator\n\ndef main():\n    qc = QuantumCircuit(2)\n    qc.h(0)\n    qc.cx(0, 1)\n    qc.measure_all()\n\n    sim = AerSimulator()\n    result = sim.run(qc, shots=1000).result()\n    counts = result.get_counts()\n    print(\"Counts:\", counts)\n\nif __name__ == \"__main__\":\n    main()\n",[173,3352,3353,3365,3377,3381,3390,3406,3420,3437,3446,3450,3462,3494,3509,3522,3527,3544],{"__ignoreMap":244},[594,3354,3355,3357,3360,3362],{"class":596,"line":597},[594,3356,2114],{"class":1511},[594,3358,3359],{"class":611}," qiskit ",[594,3361,2106],{"class":1511},[594,3363,3364],{"class":611}," QuantumCircuit\n",[594,3366,3367,3369,3372,3374],{"class":596,"line":245},[594,3368,2114],{"class":1511},[594,3370,3371],{"class":611}," qiskit_aer ",[594,3373,2106],{"class":1511},[594,3375,3376],{"class":611}," AerSimulator\n",[594,3378,3379],{"class":596,"line":1254},[594,3380,1778],{"emptyLinePlaceholder":272},[594,3382,3383,3385,3388],{"class":596,"line":1534},[594,3384,1577],{"class":1511},[594,3386,3387],{"class":600}," main",[594,3389,2314],{"class":611},[594,3391,3392,3395,3397,3400,3402,3404],{"class":596,"line":1666},[594,3393,3394],{"class":611},"    qc ",[594,3396,1453],{"class":1452},[594,3398,3399],{"class":600}," QuantumCircuit",[594,3401,1583],{"class":611},[594,3403,1484],{"class":603},[594,3405,1804],{"class":611},[594,3407,3408,3411,3414,3416,3418],{"class":596,"line":1688},[594,3409,3410],{"class":611},"    qc.",[594,3412,3413],{"class":600},"h",[594,3415,1583],{"class":611},[594,3417,2863],{"class":603},[594,3419,1804],{"class":611},[594,3421,3422,3424,3427,3429,3431,3433,3435],{"class":596,"line":270},[594,3423,3410],{"class":611},[594,3425,3426],{"class":600},"cx",[594,3428,1583],{"class":611},[594,3430,2863],{"class":603},[594,3432,460],{"class":611},[594,3434,1479],{"class":603},[594,3436,1804],{"class":611},[594,3438,3439,3441,3444],{"class":596,"line":1715},[594,3440,3410],{"class":611},[594,3442,3443],{"class":600},"measure_all",[594,3445,1523],{"class":611},[594,3447,3448],{"class":596,"line":1827},[594,3449,1778],{"emptyLinePlaceholder":272},[594,3451,3452,3455,3457,3460],{"class":596,"line":1838},[594,3453,3454],{"class":611},"    sim ",[594,3456,1453],{"class":1452},[594,3458,3459],{"class":600}," AerSimulator",[594,3461,1523],{"class":611},[594,3463,3464,3467,3469,3472,3475,3478,3482,3484,3487,3489,3492],{"class":596,"line":1856},[594,3465,3466],{"class":611},"    result ",[594,3468,1453],{"class":1452},[594,3470,3471],{"class":611}," sim.",[594,3473,3474],{"class":600},"run",[594,3476,3477],{"class":611},"(qc, ",[594,3479,3481],{"class":3480},"s_ZVi","shots",[594,3483,1453],{"class":1452},[594,3485,3486],{"class":603},"1000",[594,3488,242],{"class":611},[594,3490,3491],{"class":600},"result",[594,3493,1523],{"class":611},[594,3495,3496,3499,3501,3504,3507],{"class":596,"line":1871},[594,3497,3498],{"class":611},"    counts ",[594,3500,1453],{"class":1452},[594,3502,3503],{"class":611}," result.",[594,3505,3506],{"class":600},"get_counts",[594,3508,1523],{"class":611},[594,3510,3512,3514,3516,3519],{"class":596,"line":3511},13,[594,3513,2176],{"class":1452},[594,3515,1583],{"class":611},[594,3517,3518],{"class":607},"\"Counts:\"",[594,3520,3521],{"class":611},", counts)\n",[594,3523,3525],{"class":596,"line":3524},14,[594,3526,1778],{"emptyLinePlaceholder":272},[594,3528,3530,3532,3536,3539,3542],{"class":596,"line":3529},15,[594,3531,1512],{"class":1511},[594,3533,3535],{"class":3534},"sVyAn"," __name__",[594,3537,3538],{"class":1452}," ==",[594,3540,3541],{"class":607}," \"__main__\"",[594,3543,1531],{"class":611},[594,3545,3547,3550],{"class":596,"line":3546},16,[594,3548,3549],{"class":600},"    main",[594,3551,1523],{"class":611},[12,3553,3554,3555,3558,3559,3563,3564,3566,3567,3571,3572,3574,3575,3577,3578,3582,3583,3585,3586,3589],{},"This Python script imports Qiskit and Qiskit’s “Aer” local simulator. The command ",[173,3556,3557],{},"QuantumCircuit(2)"," creates a quantum circuit composed of two qubit registers, both initialized to a | 0 ⟩ (“ket zero”) state. It then places a ",[16,3560,3562],{"href":3561},"\u002Flearn\u002Fquantum-foundations\u002Fgates#hadamard-gate","Hadamard gate"," onto register ",[173,3565,2863],{},", flipping that qubit into superposition. Next, it places a ",[16,3568,3570],{"href":3569},"\u002Flearn\u002Fquantum-foundations\u002Fgates#controlled-not-gate","CNOT gate"," across the two registers, using register ",[173,3573,2863],{}," as the control qubit and register ",[173,3576,1479],{}," as the target qubit. This creates a ",[16,3579,3581],{"href":3580},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FBell_state","Bell state",", distributing register ",[173,3584,2863],{},"’s superposition across the two qubits, entangling them. Finally, we measure both qubit registers, collapsing the distributed superposition into a definitive value. The two possible measured values are | 00 ⟩ and | 11 ⟩ , each with a 50% probabilty of occurrence. This simulation is run 1,000 times (",[173,3587,3588],{},"shots=1000",") and the results of these “shots” and printed to the command line.",[12,3591,3592,3593,3595],{},"Execute this new ",[173,3594,948],{}," quantum script by entering the following into your shell:",[586,3597,3599],{"className":588,"code":3598,"language":590,"meta":244,"style":244},"uv run main.py\n",[173,3600,3601],{"__ignoreMap":244},[594,3602,3603,3605,3607],{"class":596,"line":597},[594,3604,636],{"class":600},[594,3606,763],{"class":607},[594,3608,1031],{"class":607},[12,3610,3611],{},"It will respond with output similar to the following:",[586,3613,3615],{"className":588,"code":3614,"language":590,"meta":244,"style":244},"Counts: {'00': 517, '11': 483}\n",[173,3616,3617],{"__ignoreMap":244},[594,3618,3619,3622,3625,3628,3631,3634],{"class":596,"line":597},[594,3620,3621],{"class":600},"Counts:",[594,3623,3624],{"class":607}," {'00':",[594,3626,3627],{"class":607}," 517,",[594,3629,3630],{"class":607}," '11':",[594,3632,3633],{"class":603}," 483",[594,3635,1980],{"class":607},[12,3637,3638],{},"Congratulations. You’ve just executed an incredibly convoluted coin-flip routine!",[30,3640,3642],{"id":3641},"coming-soon","Coming soon",[12,3644,3645],{},"Stay tuned for our guide to running quantum simulations in the cloud, performing operations on actual quantum hardware, and making use of IonQ hardware architectures.",[1245,3647,3648],{},"html pre.shiki code .sVbv2, html code.shiki .sVbv2{--shiki-default:#61AFEF}html pre.shiki code .subq3, html code.shiki .subq3{--shiki-default:#98C379}html pre.shiki code .sVC51, html code.shiki .sVC51{--shiki-default:#D19A66}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html pre.shiki code .sjrmR, html code.shiki .sjrmR{--shiki-default:#56B6C2}html pre.shiki code .seHd6, html code.shiki .seHd6{--shiki-default:#C678DD}html pre.shiki code .sn6KH, html code.shiki .sn6KH{--shiki-default:#ABB2BF}html pre.shiki code .s_ZVi, html code.shiki .s_ZVi{--shiki-default:#E06C75;--shiki-default-font-style:italic}html pre.shiki code .sVyAn, html code.shiki .sVyAn{--shiki-default:#E06C75}",{"title":244,"searchDepth":245,"depth":245,"links":3650},[3651,3656,3657,3658],{"id":3076,"depth":245,"text":3077,"children":3652},[3653,3654,3655],{"id":3086,"depth":1254,"text":3087},{"id":3141,"depth":1254,"text":3142},{"id":3216,"depth":1254,"text":3217},{"id":3251,"depth":245,"text":3252},{"id":3340,"depth":245,"text":3341},{"id":3641,"depth":245,"text":3642},[19,257,258,3052],[],{"username":293,"name":1277,"role":1278,"avatar":244},{"image":3663,"alt":3052},"\u002F_content\u002Fimages\u002Fqiskit-setup\u002Fhero.webp",{},{"slug":3666,"title":3667,"desc":3668},"\u002Fblog\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Fionq-setup","4 · Setup and simulate with IonQ","Create and leverage a free IonQ account to run an example quantum circuit on IonQ’s cloud simulator. Builds upon our previous tutorials for…","6 min read",[],{"title":3672,"description":3042},"Setup IBM’s Qiskit SDK · Building your first Qollab project","blog\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Fqiskit-setup",[],"jUMXsmGEDsv9ZSFtclHqtYskcpHnf-c1E6vnLprtyE4",{"id":3677,"title":1243,"authors":3678,"body":3679,"breadcrumb":4943,"builders":4944,"byline":4945,"challenge":262,"courseAuthor":262,"courseLead":262,"dek":4946,"description":4947,"draft":264,"extension":265,"eyebrow":262,"finish":262,"fork":262,"hero":4948,"heroAlt":262,"heroCta":262,"heroImage":262,"kind":269,"lessonCount":270,"meta":4950,"navigation":272,"newsItems":262,"next":4951,"ogImage":262,"order":1534,"outcomes":262,"path":3666,"publishDate":4955,"readingTime":4956,"related":4957,"relatedProjects":262,"seo":4958,"stem":4960,"tags":4961,"track":285,"trackName":258,"__hash__":4962},"blog\u002Fblog\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Fionq-setup.md",[293],{"type":9,"value":3680,"toc":4922},[3681,3731,3735,3746,3750,3754,3758,3769,3773,3776,3784,3788,3792,3809,3820,3855,3867,3871,3874,3891,3894,3912,3916,3940,3944,3947,3965,3968,3988,3992,3998,4011,4013,4028,4031,4035,4041,4059,4065,4069,4076,4090,4093,4130,4133,4204,4208,4231,4243,4251,4255,4265,4272,4276,4281,4337,4348,4357,4360,4382,4388,4405,4413,4417,4434,4600,4604,4607,4661,4671,4674,4708,4711,4766,4769,4794,4798,4808,4893,4895,4919],[12,3682,3683,3686,3687,3691,3692,3696,3697,460,3701,460,3705,460,3709,3713,3714,3717,3718,3722,3723,3726,3727,383],{},[16,3684,24],{"href":3685},"https:\u002F\u002Fwww.ionq.com\u002F"," is a leading quantum hardware startup, developing general-purpose ",[16,3688,3690],{"href":3689},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FTrapped-ion_quantum_computer","trapped ion quantum computers"," and accompanying software to generate, optimize, and execute ",[16,3693,3695],{"href":3694},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FQuantum_circuit","quantum circuits",". In this guide we will ",[16,3698,3700],{"href":3699},"#_1-create-an-ionq-account","create an IonQ account",[16,3702,3704],{"href":3703},"#_2-generate-an-ionq-api-key","generate an IonQ API key",[16,3706,3708],{"href":3707},"#_3-create-a-new-project","create a new Python project",[16,3710,3712],{"href":3711},"#install-ionqs-sdk","install IonQ’s SDK"," (which is built upon ",[16,3715,3716],{"href":1236},"IBM’s Qiskit","), and run an example quantum circuit on ",[16,3719,3721],{"href":3720},"#_6-run-your-circuit-on-ionqs-cloud-simulator","IonQ’s cloud simulator",". In order to follow along, it is essential that you have completed our previous guide for ",[16,3724,3725],{"href":1319},"installing Python via UV",", which also covers operating a shell command-line interface. For additional information on IonQ’s SDK, see ",[16,3728,3730],{"href":3729},"https:\u002F\u002Fdocs.ionq.com\u002Fsdks\u002Fqiskit","IonQ’s Qiskit tutorial",[30,3732,3734],{"id":3733},"_1-create-an-ionq-account","1. Create an IonQ account",[12,3736,3737,3738,3741,3742,3745],{},"Together, we are going to code a simple quantum circuit and execute it on IonQ’s cloud-based simulator. In order to connect to IonQ’s servers we must have authorization, and that comes in the form of an IonQ API key. To generate an API key, we must have an IonQ user account. Sign up for a new IonQ account by visiting ",[16,3739,3740],{"href":3740},"https:\u002F\u002Fcloud.ionq.com",". Click on the ",[61,3743,3744],{},"“Get started for free”"," link. From there you can create your account using an email address and password combination.",[3747,3748],"cta-link",{"href":3740,"label":3749},"Sign up for IonQ →",[712,3751],{"alt":244,"caption":3752,"no":244,"src":3753},"Screen grab of the IonQ signup page with the “Get started for free” link circled in orange by hand.","\u002F_content\u002Fimages\u002Fionq-setup\u002Fionq-signin.webp",[30,3755,3757],{"id":3756},"_2-generate-an-ionq-api-key","2. Generate an IonQ API key",[12,3759,3760,3761,3764,3765,3768],{},"Now that you have created an IonQ account, visit the “API Keys” tab of your account settings page: ",[16,3762,3763],{"href":3763},"https:\u002F\u002Fcloud.ionq.com\u002Fsettings\u002Fkeys",". Log in if you are not presently signed in, then click on the “",[61,3766,3767],{},"Generate key","” button.",[712,3770],{"alt":244,"caption":3771,"no":244,"src":3772},"Screen grab of IonQ’s “API Keys”tab of the account settings page with the “Generate key” button in the upper-right corner of the interface, circled in orange by hand and a hand-drawn orange arrow pointing to it.","\u002F_content\u002Fimages\u002Fionq-setup\u002Fionq-generate-button.webp",[12,3774,3775],{},"You will be prompted to provide a descriptive name for your key, and to choose an associated project. Note that using special characters in the description field may prevent the “Generate key” button from enabling itself. If you have not created any projects within your IonQ workspace, or have not been added to another account’s IonQ workspace project, you can always choose “Personal Workspace” as your key’s associated project.",[737,3777,3778],{},[12,3779,3780,3783],{},[61,3781,3782],{},"Caution",": Your API key will only be revealed to you this once. Store it somewhere private and treat it as you would a regular password.",[712,3785],{"alt":244,"caption":3786,"no":244,"src":3787},"Screen grab of the generated key modal dialogue box (with the actual API key text obscured here).","\u002F_content\u002Fimages\u002Fionq-setup\u002Fionq-key-generated.webp",[30,3789,3791],{"id":3790},"_3-create-a-new-project","3. Create a new project",[12,3793,3794,3795,3797,3798,3801,3802,3805,3806,3808],{},"We’re going to create a new Python project that resides locally on our own machine and communicates with IonQ’s servers. If you have not already followed our guide to ",[16,3796,3725],{"href":1319},", do that now, and then return to this step. That guide explains the easy installation process, and also provides some familiarity with entering basic commands into a shell command-line interface. (If you are currently a ",[173,3799,3800],{},"venv"," user, ",[16,3803,532],{"href":3804},"https:\u002F\u002Fconda.org\u002F"," user, or are accustomed to using unmanaged Python, we still strongly encourage you to switch to ",[16,3807,537],{"href":536},". Your future self will thank you.)",[12,3810,3811,3812,3815,3816,3819],{},"Create a new folder on your Desktop titled ",[173,3813,3814],{},"qollab-ionq",". (The exact name and location of this folder doesn’t matter so much, as long as it’s easy for you to access and work with.) Open a new shell prompt. ",[61,3817,3818],{},"Be sure to navigate to inside your project’s folder",", then enter the following command:",[586,3821,3823],{"className":588,"code":3822,"language":590,"meta":244,"style":244},"uv python install 3.12; uv python pin 3.12; uv init --app\n",[173,3824,3825],{"__ignoreMap":244},[594,3826,3827,3829,3831,3833,3836,3839,3841,3843,3845,3847,3849,3851,3853],{"class":596,"line":597},[594,3828,636],{"class":600},[594,3830,700],{"class":607},[594,3832,3159],{"class":607},[594,3834,3835],{"class":603}," 3.12",[594,3837,3838],{"class":611},"; ",[594,3840,636],{"class":600},[594,3842,700],{"class":607},[594,3844,3171],{"class":607},[594,3846,3835],{"class":603},[594,3848,3838],{"class":611},[594,3850,636],{"class":600},[594,3852,3102],{"class":607},[594,3854,3105],{"class":603},[12,3856,3857,3858,3860,3861,3864,3865,383],{},"This will ensure that a Qiskit-compatible version of Python is installed and that our project is “pinned” to this version. (As of this writing, January 2026, Python 3.12 is the latest release that is fully compatible with the Qiskit SDK core, its various add-on packages that we will use in upcoming tutorials, and IonQ’s SDK. If you are one of those folks that becomes itchy at the prospect of not using the absolute lastest version of Python, be our guest. ",[16,3859,537],{"href":536}," makes it quick and easy to switch Python versions.) Finally, the ",[173,3862,3863],{},"init"," command initializes our app, creating several useful default files. If you experience trouble with this step, refer to our more detailed guide to ",[16,3866,3725],{"href":1319},[385,3868,3870],{"id":3869},"install-ionqs-sdk","Install IonQ’s SDK",[12,3872,3873],{},"IonQ’s SDK is built upon IBM’s Qiskit, allowing us to take advantage of Qiskit’s flourishing ecosystem and IonQ’s unqiue quantum hardware. Enter the following command into our shell to install the latest versions of both IBM’s Qiskit SDK and IonQ’s SDK:",[586,3875,3877],{"className":588,"code":3876,"language":590,"meta":244,"style":244},"uv add qiskit qiskit-ionq\n",[173,3878,3879],{"__ignoreMap":244},[594,3880,3881,3883,3885,3888],{"class":596,"line":597},[594,3882,636],{"class":600},[594,3884,1580],{"class":607},[594,3886,3887],{"class":607}," qiskit",[594,3889,3890],{"class":607}," qiskit-ionq\n",[12,3892,3893],{},"Once this process is complete you can enter the following command into our shell to perform an optional sanity check. If all’s gone well, our shell will respond with an IonQ SDK version number.",[586,3895,3897],{"className":588,"code":3896,"language":590,"meta":244,"style":244},"uv run python -c \"import qiskit_ionq; print('IonQ SDK', qiskit_ionq.__version__)\"\n",[173,3898,3899],{"__ignoreMap":244},[594,3900,3901,3903,3905,3907,3909],{"class":596,"line":597},[594,3902,636],{"class":600},[594,3904,763],{"class":607},[594,3906,700],{"class":607},[594,3908,768],{"class":603},[594,3910,3911],{"class":607}," \"import qiskit_ionq; print('IonQ SDK', qiskit_ionq.__version__)\"\n",[30,3913,3915],{"id":3914},"_4-handle-your-ionq-api-key","4. Handle your IonQ API key",[12,3917,3918,3919,3922,3923,3926,3927,3930,3931,3934,3935,3939],{},"In order to communicate with IonQ’s servers, our new Python project requires your ",[16,3920,3921],{"href":3703},"IonQ API key",". (Recall that your API key is akin to a password, and should be treated as such.) IonQ’s ",[173,3924,3925],{},"IonQProvider"," package will ",[305,3928,3929],{},"automatically"," look for an environment variable named ",[173,3932,3933],{},"IONQ_API_KEY",", and we have a few options for safely providing this. (See also ",[16,3936,3938],{"href":3937},"https:\u002F\u002Fdocs.ionq.com\u002Fguides\u002Fmanaging-api-keys","IonQ’s own guide to managing API keys",".)",[385,3941,3943],{"id":3942},"set-a-key-for-this-shell-session","Set a key for this shell session",[12,3945,3946],{},"This is a quick, temporary solution that will make your API key available to our current shell session. (That means if we close our current shell and open a new one, or execute our Python script from within a different shell session than the one we’ve set your key in, your key value won’t be available to the Python script.) On macOS or Linux, enter the following into our shell:",[586,3948,3950],{"className":588,"code":3949,"language":590,"meta":244,"style":244},"export IONQ_API_KEY=\"your_real_key_here\"\n",[173,3951,3952],{"__ignoreMap":244},[594,3953,3954,3957,3960,3962],{"class":596,"line":597},[594,3955,3956],{"class":1511},"export",[594,3958,3959],{"class":3534}," IONQ_API_KEY",[594,3961,1453],{"class":1452},[594,3963,3964],{"class":607},"\"your_real_key_here\"\n",[12,3966,3967],{},"Or on Windows, enter the following into PowerShell:",[586,3969,3971],{"className":588,"code":3970,"language":590,"meta":244,"style":244},"$Env:IONQ_API_KEY==\"your_real_key_here\"\n",[173,3972,3973],{"__ignoreMap":244},[594,3974,3975,3978,3981,3983,3985],{"class":596,"line":597},[594,3976,3977],{"class":3534},"$Env",[594,3979,3980],{"class":611},":",[594,3982,3933],{"class":3534},[594,3984,1453],{"class":1452},[594,3986,3987],{"class":607},"=\"your_real_key_here\"\n",[385,3989,3991],{"id":3990},"confirm-your-key-is-present","Confirm your key is present",[12,3993,3994,3995,3997],{},"Regardless of whether we set your key only for this current shell session, or for every shell session that your user profile initiates, your key must be present in order to be read by IonQ’s ",[173,3996,3925],{}," package. We can confirm its presence on macOS or Linux by entering the following into our shell:",[586,3999,4001],{"className":588,"code":4000,"language":590,"meta":244,"style":244},"echo $IONQ_API_KEY\n",[173,4002,4003],{"__ignoreMap":244},[594,4004,4005,4008],{"class":596,"line":597},[594,4006,4007],{"class":1452},"echo",[594,4009,4010],{"class":3534}," $IONQ_API_KEY\n",[12,4012,3967],{},[586,4014,4016],{"className":588,"code":4015,"language":590,"meta":244,"style":244},"echo $Env:IONQ_API_KEY\n",[173,4017,4018],{"__ignoreMap":244},[594,4019,4020,4022,4025],{"class":596,"line":597},[594,4021,4007],{"class":1452},[594,4023,4024],{"class":3534}," $Env",[594,4026,4027],{"class":607},":IONQ_API_KEY\n",[12,4029,4030],{},"Our shell should respond with your IonQ API key.",[385,4032,4034],{"id":4033},"confirm-that-your-key-is-functional","Confirm that your key is functional",[12,4036,4037,4038,4040],{},"Just because ",[173,4039,3933],{}," is available in our environment and contains a value doesn’t necessarily mean we’re authorized to access IonQ’s servers. Enter the following into our shell to confirm that we have access to various IonQ backends:",[586,4042,4044],{"className":588,"code":4043,"language":590,"meta":244,"style":244},"uv run python -c \"from qiskit_ionq import IonQProvider; p=IonQProvider(); print([b.name for b in p.backends()])\"\n",[173,4045,4046],{"__ignoreMap":244},[594,4047,4048,4050,4052,4054,4056],{"class":596,"line":597},[594,4049,636],{"class":600},[594,4051,763],{"class":607},[594,4053,700],{"class":607},[594,4055,768],{"class":603},[594,4057,4058],{"class":607}," \"from qiskit_ionq import IonQProvider; p=IonQProvider(); print([b.name for b in p.backends()])\"\n",[12,4060,4061,4062,4064],{},"Our shell should respond with a list of backends available to your account. Regardless of whether your account is on a free tier or paid tier, you should see a ",[305,4063,3296],{}," profile in this list. If your account in on a paid tier you might also see available hardware profiles. (A free tier account may see a single generic hardware profile that serves as a placeholder, but you will be unable to send jobs to any actual quantum hardware.) If your key is missing or invalid then you will receive an authorization error rather than a list of backend profiles.",[385,4066,4068],{"id":4067},"include-your-key-in-our-project","Include your key in our project",[12,4070,4071,4072,4075],{},"We’ve entered your key into our shell’s environment and confirmed that it functions. But what about the next time we open a new shell window? Wouldn’t it be easier if going forward our project always had access to your API key? We can accomplish this by creating a hidden “environment file” for our project that will seed our shell environment with your API key (and whatever other variables we may wish to set). Create a ",[173,4073,4074],{},".env"," file inside of our project’s folder, add the following line, and save the file:",[586,4077,4078],{"className":588,"code":3949,"language":590,"meta":244,"style":244},[173,4079,4080],{"__ignoreMap":244},[594,4081,4082,4084,4086,4088],{"class":596,"line":597},[594,4083,3956],{"class":1511},[594,4085,3959],{"class":3534},[594,4087,1453],{"class":1452},[594,4089,3964],{"class":607},[12,4091,4092],{},"On macOS or Linux, when we’re ready to use this key we would enter the following into our shell to load our environment file and run a Python script.",[586,4094,4096],{"className":588,"code":4095,"language":590,"meta":244,"style":244},"set -a; source .\u002F.env; set +a; uv run python our-future-script.py\n",[173,4097,4098],{"__ignoreMap":244},[594,4099,4100,4102,4105,4107,4109,4112,4114,4116,4119,4121,4123,4125,4127],{"class":596,"line":597},[594,4101,1983],{"class":1452},[594,4103,4104],{"class":603}," -a",[594,4106,3838],{"class":611},[594,4108,3245],{"class":1452},[594,4110,4111],{"class":607}," .\u002F.env",[594,4113,3838],{"class":611},[594,4115,1983],{"class":1452},[594,4117,4118],{"class":607}," +a",[594,4120,3838],{"class":611},[594,4122,636],{"class":600},[594,4124,763],{"class":607},[594,4126,700],{"class":607},[594,4128,4129],{"class":607}," our-future-script.py\n",[12,4131,4132],{},"Or in Windows PowerShell we would do the following:",[586,4134,4136],{"className":588,"code":4135,"language":590,"meta":244,"style":244},"Get-Content .env | ForEach-Object { if ($_ -match '^\\s*([^#=]+?)\\s*=\\s*(.*)\\s*$') { Set-Item -Path \"Env:$($matches[1])\" -Value $matches[2] }}\nuv run python our-future-script.py\n",[173,4137,4138,4194],{"__ignoreMap":244},[594,4139,4140,4143,4146,4148,4151,4153,4155,4158,4161,4164,4167,4170,4173,4176,4179,4182,4185,4188,4191],{"class":596,"line":597},[594,4141,4142],{"class":600},"Get-Content",[594,4144,4145],{"class":607}," .env",[594,4147,612],{"class":611},[594,4149,4150],{"class":600},"ForEach-Object",[594,4152,1958],{"class":607},[594,4154,2684],{"class":607},[594,4156,4157],{"class":611}," ($_ ",[594,4159,4160],{"class":603},"-match",[594,4162,4163],{"class":607}," '^\\s*([^#=]+?)\\s*=\\s*(.*)\\s*$'",[594,4165,4166],{"class":611},") { ",[594,4168,4169],{"class":600},"Set-Item",[594,4171,4172],{"class":603}," -Path",[594,4174,4175],{"class":607}," \"Env:$(",[594,4177,4178],{"class":3534},"$matches",[594,4180,4181],{"class":607},"[1])\"",[594,4183,4184],{"class":603}," -Value",[594,4186,4187],{"class":3534}," $matches",[594,4189,4190],{"class":607},"[2]",[594,4192,4193],{"class":607}," }}\n",[594,4195,4196,4198,4200,4202],{"class":596,"line":245},[594,4197,636],{"class":600},[594,4199,763],{"class":607},[594,4201,700],{"class":607},[594,4203,4129],{"class":607},[824,4205,4207],{"id":4206},"protect-your-api-key","Protect your API key",[12,4209,4210,4211,4213,4214,4216,4217,4219,4220,4222,4223,4226,4227,4230],{},"Perhaps our project is part of a shared code repository. The last thing we want is to accidentally publish your private API key along with the codebase. In that case, add ",[173,4212,4074],{}," to our ",[173,4215,996],{}," list. (If the ",[173,4218,996],{}," does not exist within our project folder, create it, enter the text ",[173,4221,4074],{}," on a single line, and save it.) As a courtesy to our teammates and future selves, also create an ",[305,4224,4225],{},"example"," environment file that serves as a reminder and template for what information must be provided in order for the project to function. Name this file ",[173,4228,4229],{},".env.example"," and include the following line in it:",[586,4232,4234],{"className":588,"code":4233,"language":590,"meta":244,"style":244},"IONQ_API_KEY=\n",[173,4235,4236],{"__ignoreMap":244},[594,4237,4238,4240],{"class":596,"line":597},[594,4239,3933],{"class":3534},[594,4241,4242],{"class":1452},"=\n",[12,4244,4245,4246,238,4248,4250],{},"Now our teammates (or future us) can simply copy this file from ",[173,4247,4229],{},[173,4249,4074],{}," and fill in the appropriate information locally. (This is a standard “don’t leak tokens” pattern.)",[30,4252,4254],{"id":4253},"_5-update-our-transpile-settings","5. Update our transpile settings",[12,4256,4257,4258,4261,4262],{},"There’s always a gap between the theoretical and the actual, between the clear expression of intent and the dirty business of actually making something ",[305,4259,4260],{},"function."," When we code a quantum circuit, more often than not we are creating idealistically. Part of Qiskit’s magic is that it transforms our quantum circuit design in two ways: It reconfigures our gates for IBM’s specific quantum hardware architecture, and also optimizes our algorithms for maximum efficiency, also based on IBM’s available hardware. This optimization process can reduce register depth, merge gates, and change the overall circuit structure while preserving its semantics. The process of compiling code for one model, then translating that compilation to function on a different model, is called ",[305,4263,4264],{},"transpiling.",[12,4266,4267,4268,4271],{},"The twist with our scenario is that we are ",[305,4269,4270],{},"not using IBM’s architecture"," to execute our quantum circuit. We are instead using’s IonQ’s architecture. IonQ’s SDK has its own methods for translating and optimizing our circuit designs, based on its own unique quantum hardware. We want IonQ to have direct access to our original circuit design, not a version that has been “optimized” for some other architecture. (That would be like working from a lossy copy when we have access to the original right in front of us.) In order to hand IonQ’s SDK our original, unaltered circuit design, we must tell Qiskit to only make minimal, necessary changes.",[385,4273,4275],{"id":4274},"qiskits-transpile-levels","Qiskit’s transpile levels",[12,4277,4278,4279,383],{},"The following table describes each of Qiskit’s transpile levels, its general approach to optimization, and what it’s best suited for. We’re most interested in creating “early experiments” and “transpiling at scale”, and will opt for an optimization level of ",[173,4280,1479],{},[1114,4282,4283,4296],{},[1117,4284,4285],{},[1120,4286,4287,4290,4293],{},[1123,4288,4289],{"align":1128},"Level",[1123,4291,4292],{},"Optimization",[1123,4294,4295],{},"Best suited for",[1134,4297,4298,4307,4317,4327],{},[1120,4299,4300,4302,4304],{},[1139,4301,2863],{"align":1128},[1139,4303,1683],{},[1139,4305,4306],{},"Hardware-native backends (IonQ, neutral atoms), learning, debugging, preserving algorithm structure.",[1120,4308,4309,4311,4314],{},[1139,4310,1479],{"align":1128},[1139,4312,4313],{},"Light",[1139,4315,4316],{},"Early experiments, hardware with mild noise, transpiling at scale.",[1120,4318,4319,4321,4324],{},[1139,4320,1484],{"align":1128},[1139,4322,4323],{},"Medium",[1139,4325,4326],{},"General IBM hardware usage, balanced workflows.",[1120,4328,4329,4331,4334],{},[1139,4330,1489],{"align":1128},[1139,4332,4333],{},"Heavy",[1139,4335,4336],{},"Final production runs on noisy IBM devices.",[12,4338,4339,4340,4343,4344,4347],{},"To ensure that all of our future IonQ circuits run as expected, we can edit Qiskit’s user configuration file. The Qiskit installation process creates a hidden ",[173,4341,4342],{},".qiskit"," folder within your home folder. We need to create (or edit) a ",[173,4345,4346],{},"settings.conf"," file within that folder. On macOS or Linux that location should be:",[586,4349,4351],{"className":588,"code":4350,"language":590,"meta":244,"style":244},"~\u002F.qiskit\u002Fsettings.conf\n",[173,4352,4353],{"__ignoreMap":244},[594,4354,4355],{"class":596,"line":597},[594,4356,4350],{"class":611},[12,4358,4359],{},"On Windows that location should be:",[586,4361,4363],{"className":588,"code":4362,"language":590,"meta":244,"style":244},"$HOME\\.qiskit\\settings.conf\n",[173,4364,4365],{"__ignoreMap":244},[594,4366,4367,4370,4373,4376,4379],{"class":596,"line":597},[594,4368,4369],{"class":3534},"$HOME",[594,4371,4372],{"class":1452},"\\.",[594,4374,4375],{"class":611},"qiskit",[594,4377,4378],{"class":1452},"\\s",[594,4380,4381],{"class":611},"ettings.conf\n",[12,4383,4384,4385,4387],{},"Open (or create) that ",[173,4386,4346],{}," file, add the following two lines of code, then save the file:",[586,4389,4393],{"className":4390,"code":4391,"language":4392,"meta":244,"style":244},"language-conf shiki shiki-themes one-dark-pro","[default]\ntranspile_optimization_level = 1\n","conf",[173,4394,4395,4400],{"__ignoreMap":244},[594,4396,4397],{"class":596,"line":597},[594,4398,4399],{},"[default]\n",[594,4401,4402],{"class":596,"line":245},[594,4403,4404],{},"transpile_optimization_level = 1\n",[12,4406,4407,4408,4412],{},"This will prevent Qiskit from making aggressive rewrites to our circuit design, handing it off cleanly to IonQ’s own transpiler. (It will also prevent a warning from IonQ’s SDK when we run our quantum circuit just a bit further down in this tutorial.) For additional information, see IonQ’s article “",[16,4409,4411],{"href":4410},"https:\u002F\u002Fdocs.ionq.com\u002Fsdks\u002Fqiskit\u002Fnative-gates-qiskit","Compilation and native gates with Qiskit",".”",[30,4414,4416],{"id":4415},"_6-run-your-circuit-on-ionqs-cloud-simulator","6. Run your circuit on IonQ’s cloud simulator",[12,4418,4419,4420,464,4423,4425,4426,4429,4430,4433],{},"With our ",[16,4421,4422],{"href":1319},"UV-initiated project folder",[16,4424,3921],{"href":3703}," in place, we’re ready to use IonQ’s quantum ",[305,4427,4428],{},"simulator."," Create a new blank file within your project folder named ",[173,4431,4432],{},"ionq-simulator.py",", open it with your source code editor, paste the following code into it, and save the file:",[586,4435,4437],{"className":1440,"code":4436,"language":1442,"meta":244,"style":244},"from qiskit import QuantumCircuit\nfrom qiskit_ionq import IonQProvider\n\nqc = QuantumCircuit( 2, name=\"Bell state on IonQ simulator\" )\nqc.h( 0 )\nqc.cx( 0, 1 )\nqc.measure_all()\n\nprovider = IonQProvider()\nbackend  = provider.get_backend( \"simulator\" )\njob = backend.run( qc, shots=1000 )\nprint( job.get_counts() )\n",[173,4438,4439,4449,4461,4465,4492,4505,4521,4529,4533,4545,4565,4588],{"__ignoreMap":244},[594,4440,4441,4443,4445,4447],{"class":596,"line":597},[594,4442,2114],{"class":1511},[594,4444,3359],{"class":611},[594,4446,2106],{"class":1511},[594,4448,3364],{"class":611},[594,4450,4451,4453,4456,4458],{"class":596,"line":245},[594,4452,2114],{"class":1511},[594,4454,4455],{"class":611}," qiskit_ionq ",[594,4457,2106],{"class":1511},[594,4459,4460],{"class":611}," IonQProvider\n",[594,4462,4463],{"class":596,"line":1254},[594,4464,1778],{"emptyLinePlaceholder":272},[594,4466,4467,4470,4472,4474,4477,4479,4481,4484,4486,4489],{"class":596,"line":1534},[594,4468,4469],{"class":611},"qc ",[594,4471,1453],{"class":1452},[594,4473,3399],{"class":600},[594,4475,4476],{"class":611},"( ",[594,4478,1484],{"class":603},[594,4480,460],{"class":611},[594,4482,4483],{"class":3480},"name",[594,4485,1453],{"class":1452},[594,4487,4488],{"class":607},"\"Bell state on IonQ simulator\"",[594,4490,4491],{"class":611}," )\n",[594,4493,4494,4497,4499,4501,4503],{"class":596,"line":1666},[594,4495,4496],{"class":611},"qc.",[594,4498,3413],{"class":600},[594,4500,4476],{"class":611},[594,4502,2863],{"class":603},[594,4504,4491],{"class":611},[594,4506,4507,4509,4511,4513,4515,4517,4519],{"class":596,"line":1688},[594,4508,4496],{"class":611},[594,4510,3426],{"class":600},[594,4512,4476],{"class":611},[594,4514,2863],{"class":603},[594,4516,460],{"class":611},[594,4518,1479],{"class":603},[594,4520,4491],{"class":611},[594,4522,4523,4525,4527],{"class":596,"line":270},[594,4524,4496],{"class":611},[594,4526,3443],{"class":600},[594,4528,1523],{"class":611},[594,4530,4531],{"class":596,"line":1715},[594,4532,1778],{"emptyLinePlaceholder":272},[594,4534,4535,4538,4540,4543],{"class":596,"line":1827},[594,4536,4537],{"class":611},"provider ",[594,4539,1453],{"class":1452},[594,4541,4542],{"class":600}," IonQProvider",[594,4544,1523],{"class":611},[594,4546,4547,4550,4552,4555,4558,4560,4563],{"class":596,"line":1838},[594,4548,4549],{"class":611},"backend  ",[594,4551,1453],{"class":1452},[594,4553,4554],{"class":611}," provider.",[594,4556,4557],{"class":600},"get_backend",[594,4559,4476],{"class":611},[594,4561,4562],{"class":607},"\"simulator\"",[594,4564,4491],{"class":611},[594,4566,4567,4570,4572,4575,4577,4580,4582,4584,4586],{"class":596,"line":1856},[594,4568,4569],{"class":611},"job ",[594,4571,1453],{"class":1452},[594,4573,4574],{"class":611}," backend.",[594,4576,3474],{"class":600},[594,4578,4579],{"class":611},"( qc, ",[594,4581,3481],{"class":3480},[594,4583,1453],{"class":1452},[594,4585,3486],{"class":603},[594,4587,4491],{"class":611},[594,4589,4590,4592,4595,4597],{"class":596,"line":1871},[594,4591,2973],{"class":1452},[594,4593,4594],{"class":611},"( job.",[594,4596,3506],{"class":600},[594,4598,4599],{"class":611},"() )\n",[385,4601,4603],{"id":4602},"our-first-ionq-bell-state","Our first IonQ Bell state",[12,4605,4606],{},"Before we run our short Python script above, let’s break down what it intends to accomplish. First, we import Qiskit’s tools for describing quantum circuits. Then we import IonQ’s interface for talking to various resources for executing quantum circuits. These two imports are all we need to begin our circuit building journey.",[12,4608,4609,4610,4613,4614,4618,4619,4623,4624,4627,4628,4631,4632,3563,4634,4636,4637,4641,4642,4631,4645,3571,4647,3574,4649,3577,4651,3582,4653,4655,4656,4660],{},"The command ",[173,4611,4612],{},"QuantumCircuit( 2, … )"," creates a quantum circuit composed of two qubit registers, both initialized to a | 0 ⟩ (“ket zero”) state. (Need a refresher on ",[16,4615,4617],{"href":4616},"\u002Flearn\u002Fquantum-foundations\u002Fqubits","qubits"," and ",[16,4620,4622],{"href":4621},"\u002Flearn\u002Fquantum-foundations\u002Fqubits#ket-notation","ket notation","? See our ",[16,4625,4626],{"href":4616},"guide to qubits",".) We use the command ",[173,4629,4630],{},"qc.h( 0 )"," to place a ",[16,4633,3562],{"href":3561},[173,4635,2863],{},", flipping that qubit into ",[16,4638,4640],{"href":4639},"\u002Flearn\u002Fquantum-foundations\u002Fqubits#superposition","superposition",". Next, we use the command ",[173,4643,4644],{},"qc.cx( 0, 1 )",[16,4646,3570],{"href":3569},[173,4648,2863],{},[173,4650,1479],{},[16,4652,3581],{"href":3580},[173,4654,2863],{},"’s superposition across the two qubits, ",[16,4657,4659],{"href":4658},"https:\u002F\u002Fen.wikipedia.org\u002Fwiki\u002FQuantum_entanglement","entangling"," them.",[12,4662,4663,4664,4667,4668,4670],{},"Finally, we use ",[173,4665,4666],{},"qc.measure_all()"," to measure both qubit registers, collapsing the distributed superposition into a definitive value. The two possible measured values are | 00 ⟩ and | 11 ⟩ , each with a 50% probabilty of occurrence. This simulation is run 1,000 times (",[173,4669,3588],{},") and the results of these “shots” are output to our shell. While it is extremely unlikely that your result will divide into exactly 500 of each value, it should arrive reasonably close.",[12,4672,4673],{},"Now that we have a better idea of what our script does, let’s execute it. On macOS or Linux, enter the following into our shell to load our environment variables and execute our script:",[586,4675,4677],{"className":588,"code":4676,"language":590,"meta":244,"style":244},"set -a; source .\u002F.env; set +a; uv run python ionq-simulator.py\n",[173,4678,4679],{"__ignoreMap":244},[594,4680,4681,4683,4685,4687,4689,4691,4693,4695,4697,4699,4701,4703,4705],{"class":596,"line":597},[594,4682,1983],{"class":1452},[594,4684,4104],{"class":603},[594,4686,3838],{"class":611},[594,4688,3245],{"class":1452},[594,4690,4111],{"class":607},[594,4692,3838],{"class":611},[594,4694,1983],{"class":1452},[594,4696,4118],{"class":607},[594,4698,3838],{"class":611},[594,4700,636],{"class":600},[594,4702,763],{"class":607},[594,4704,700],{"class":607},[594,4706,4707],{"class":607}," ionq-simulator.py\n",[12,4709,4710],{},"Or in Windows PowerShell enter the following:",[586,4712,4714],{"className":588,"code":4713,"language":590,"meta":244,"style":244},"Get-Content .env | ForEach-Object { if ($_ -match '^\\s*([^#=]+?)\\s*=\\s*(.*)\\s*$') { Set-Item -Path \"Env:$($matches[1])\" -Value $matches[2] }}\nuv run python ionq-simulator.py\n",[173,4715,4716,4756],{"__ignoreMap":244},[594,4717,4718,4720,4722,4724,4726,4728,4730,4732,4734,4736,4738,4740,4742,4744,4746,4748,4750,4752,4754],{"class":596,"line":597},[594,4719,4142],{"class":600},[594,4721,4145],{"class":607},[594,4723,612],{"class":611},[594,4725,4150],{"class":600},[594,4727,1958],{"class":607},[594,4729,2684],{"class":607},[594,4731,4157],{"class":611},[594,4733,4160],{"class":603},[594,4735,4163],{"class":607},[594,4737,4166],{"class":611},[594,4739,4169],{"class":600},[594,4741,4172],{"class":603},[594,4743,4175],{"class":607},[594,4745,4178],{"class":3534},[594,4747,4181],{"class":607},[594,4749,4184],{"class":603},[594,4751,4187],{"class":3534},[594,4753,4190],{"class":607},[594,4755,4193],{"class":607},[594,4757,4758,4760,4762,4764],{"class":596,"line":245},[594,4759,636],{"class":600},[594,4761,763],{"class":607},[594,4763,700],{"class":607},[594,4765,4707],{"class":607},[12,4767,4768],{},"Take a patient breath as IonQ’s cloud simulator processes our circuit. In a few moments we should receive results similar to the following:",[586,4770,4772],{"className":588,"code":4771,"language":590,"meta":244,"style":244},"{'00': 492, '11': 508}\n",[173,4773,4774],{"__ignoreMap":244},[594,4775,4776,4779,4782,4784,4787,4789,4792],{"class":596,"line":597},[594,4777,4778],{"class":611},"{",[594,4780,4781],{"class":600},"'00'",[594,4783,3980],{"class":1452},[594,4785,4786],{"class":607}," 492,",[594,4788,3630],{"class":607},[594,4790,4791],{"class":603}," 508",[594,4793,1980],{"class":607},[385,4795,4797],{"id":4796},"optional-use-ionqs-noisy-simulator","Optional: Use IonQ’s “noisy simulator”",[12,4799,4800,4801,4803,4804,4807],{},"In addition to its basic simulator, IonQ provides “noise models” that produce results closer to that of actual quantum hardware. Insert the highlighted line of code below into your existing ",[173,4802,4432],{}," as indicated to use IonQ’s ",[173,4805,4806],{},"aria-1"," noise model in your simulations:",[586,4809,4811],{"className":1440,"code":4810,"language":1442,"meta":244,"style":244},"provider = IonQProvider()\nbackend  = provider.get_backend( \"simulator\" )\nbackend.set_options( noise_model=\"aria-1\" )\njob = backend.run( qc, shots=1000 )\nprint( job.get_counts() )\n",[173,4812,4813,4823,4839,4863,4883],{"__ignoreMap":244},[594,4814,4815,4817,4819,4821],{"class":596,"line":597},[594,4816,4537],{"class":611},[594,4818,1453],{"class":1452},[594,4820,4542],{"class":600},[594,4822,1523],{"class":611},[594,4824,4825,4827,4829,4831,4833,4835,4837],{"class":596,"line":245},[594,4826,4549],{"class":611},[594,4828,1453],{"class":1452},[594,4830,4554],{"class":611},[594,4832,4557],{"class":600},[594,4834,4476],{"class":611},[594,4836,4562],{"class":607},[594,4838,4491],{"class":611},[594,4840,4841],{"class":596,"line":1254},[4842,4843,4844,4847,4850,4852,4855,4857,4860],"mark",{},[594,4845,4846],{"class":611},"backend.",[594,4848,4849],{"class":600},"set_options",[594,4851,4476],{"class":611},[594,4853,4854],{"class":3480},"noise_model",[594,4856,1453],{"class":1452},[594,4858,4859],{"class":607},"\"aria-1\"",[594,4861,4862],{"class":611}," )",[594,4864,4865,4867,4869,4871,4873,4875,4877,4879,4881],{"class":596,"line":1534},[594,4866,4569],{"class":611},[594,4868,1453],{"class":1452},[594,4870,4574],{"class":611},[594,4872,3474],{"class":600},[594,4874,4579],{"class":611},[594,4876,3481],{"class":3480},[594,4878,1453],{"class":1452},[594,4880,3486],{"class":603},[594,4882,4491],{"class":611},[594,4884,4885,4887,4889,4891],{"class":596,"line":1666},[594,4886,2973],{"class":1452},[594,4888,4594],{"class":611},[594,4890,3506],{"class":600},[594,4892,4599],{"class":611},[30,4894,1220],{"id":1219},[12,4896,4897,4898,460,4901,460,4904,460,4907,4910,4911,4913,4914,4918],{},"We’ve ",[16,4899,4900],{"href":3699},"created an IonQ account",[16,4902,4903],{"href":3703},"generated an IonQ API key",[16,4905,4906],{"href":3707},"created a new Python project",[16,4908,4909],{"href":3711},"installed IonQ’s SDK",", and run an example quantum circuit on ",[16,4912,3721],{"href":3720},". (That’s not a bad run for today!) Our next goal is to ",[16,4915,4917],{"href":4916},"\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Fionq-hardware","run quantum circuits on IonQ’s actual quantum hardware",". Keep in mind that this will require a paid tier account and some patience. We must create a support request for accessing IonQ’s QPUs, and wait for that request to be honored. Then once we do have access we must be mindful that QPU jobs are queued for execution and our circuits may need to wait several hours behind previously queued jobs before it’s our turn. When you’re ready to take your quantum journey to the next level join us on the hardware side!",[1245,4920,4921],{},"html pre.shiki code .sVbv2, html code.shiki .sVbv2{--shiki-default:#61AFEF}html pre.shiki code .subq3, html code.shiki .subq3{--shiki-default:#98C379}html pre.shiki code .sVC51, html code.shiki .sVC51{--shiki-default:#D19A66}html pre.shiki code .sn6KH, html code.shiki .sn6KH{--shiki-default:#ABB2BF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html pre.shiki code .seHd6, html code.shiki .seHd6{--shiki-default:#C678DD}html pre.shiki code .sVyAn, html code.shiki .sVyAn{--shiki-default:#E06C75}html pre.shiki code .sjrmR, html code.shiki .sjrmR{--shiki-default:#56B6C2}html pre.shiki code .s_ZVi, html code.shiki .s_ZVi{--shiki-default:#E06C75;--shiki-default-font-style:italic}",{"title":244,"searchDepth":245,"depth":245,"links":4923},[4924,4925,4926,4929,4935,4938,4942],{"id":3733,"depth":245,"text":3734},{"id":3756,"depth":245,"text":3757},{"id":3790,"depth":245,"text":3791,"children":4927},[4928],{"id":3869,"depth":1254,"text":3870},{"id":3914,"depth":245,"text":3915,"children":4930},[4931,4932,4933,4934],{"id":3942,"depth":1254,"text":3943},{"id":3990,"depth":1254,"text":3991},{"id":4033,"depth":1254,"text":4034},{"id":4067,"depth":1254,"text":4068},{"id":4253,"depth":245,"text":4254,"children":4936},[4937],{"id":4274,"depth":1254,"text":4275},{"id":4415,"depth":245,"text":4416,"children":4939},[4940,4941],{"id":4602,"depth":1254,"text":4603},{"id":4796,"depth":1254,"text":4797},{"id":1219,"depth":245,"text":1220},[19,257,258,1243],[],{"username":293,"name":1277,"role":1278,"avatar":244},"Create and leverage a free IonQ account to run an example quantum circuit on IonQ’s cloud simulator. Builds upon our previous tutorials for installing Python via UV, and installing IBM’s Qiskit SDK.","Create a free IonQ account and run an example circuit on IonQ's cloud simulator, building on our earlier Python and Qiskit setup lessons.",{"image":4949,"alt":1243},"\u002F_content\u002Fimages\u002Fionq-setup\u002Fhero.webp",{},{"slug":4952,"title":4953,"desc":4954},"\u002Fblog\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Fionq-hardware","5 · Run circuits on IonQ’s quantum hardware","Run a quantum circuit on IonQ’s quantum hardware and receive the results asynchronously. Builds upon our previous tutorials for executing quantum…","2026-01-02","18 min read",[],{"title":4959,"description":4947},"Setup and simulate with IonQ · Building your first Qollab project","blog\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Fionq-setup",[],"4CoeHtmKoj9tpDycD0ayHhQ5rCyf7l95VA1ixVRVub0",{"id":4964,"title":4965,"authors":4966,"body":4967,"breadcrumb":5693,"builders":5694,"byline":5695,"challenge":262,"courseAuthor":262,"courseLead":262,"dek":5696,"description":5697,"draft":264,"extension":265,"eyebrow":262,"finish":262,"fork":262,"hero":5698,"heroAlt":262,"heroCta":262,"heroImage":262,"kind":269,"lessonCount":270,"meta":5700,"navigation":272,"newsItems":262,"next":5701,"ogImage":262,"order":1666,"outcomes":262,"path":4952,"publishDate":5705,"readingTime":5706,"related":5707,"relatedProjects":262,"seo":5708,"stem":5710,"tags":5711,"track":285,"trackName":258,"__hash__":5712},"blog\u002Fblog\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Fionq-hardware.md","Run circuits on IonQ’s quantum hardware",[293],{"type":9,"value":4968,"toc":5679},[4969,5012,5016,5027,5046,5069,5072,5075,5079,5111,5115,5120,5122,5126,5140,5370,5387,5391,5399,5402,5406,5424,5428,5435,5477,5483,5487,5497,5501,5508,5511,5524,5622,5625,5665,5669,5676],[12,4970,4971,3686,4973,3691,4975,3696,4977,460,4981,460,4985,460,4989,460,4993,4997,4998,5002,5003,5005,5006,5009,5010,383],{},[16,4972,24],{"href":3685},[16,4974,3690],{"href":3689},[16,4976,3695],{"href":3694},[16,4978,4980],{"href":4979},"#_1-upgrade-your-ionq-account","upgrade your IonQ account to a paid tier",[16,4982,4984],{"href":4983},"#_2-prepare-our-ionq-project","prepare our IonQ project",[16,4986,4988],{"href":4987},"#_3-confirm-your-ionq-qpu-access","confirm our QPU access",[16,4990,4992],{"href":4991},"#_5-estimate-your-ionq-spend","estimate our IonQ spend",[16,4994,4996],{"href":4995},"#_6-submit-your-circuit-to-ionqs-quantum-hardware-queue","send our quantum circuit to IonQ’s quantum hardware",", and ultimately ",[16,4999,5001],{"href":5000},"#_7-retrieve-ionq-circuit-results-asynchronously","retrieve our quantum circuit’s results asynchronously",". In order to follow along, it is essential that you have completed our previous guides for ",[16,5004,3725],{"href":1319}," (which also covers operating a shell command-line interface), and ",[16,5007,5008],{"href":1242},"setting up an IonQ project",". For additional information on IonQ’s SDK, see ",[16,5011,3730],{"href":3729},[30,5013,5015],{"id":5014},"_1-upgrade-your-ionq-account","1. Upgrade your IonQ account",[12,5017,5018,5019,5022,5023,5026],{},"It’s important to understand that the use of ",[305,5020,5021],{},"real"," quantum hardware (versus ",[305,5024,5025],{},"simulated"," quantum hardware) is inherently expensive. Completing this tutorial will require you to purchase compute power from IonQ.",[12,5028,5029,5030,5033,5034,460,5037,5040,5041,5045],{},"In our ",[16,5031,5032],{"href":1242},"previous IonQ guide"," we have ",[16,5035,4900],{"href":5036},"\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Fionq-setup#_1-create-an-ionq-account",[16,5038,4903],{"href":5039},"\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Fionq-setup#_2-generate-an-ionq-api-key",", and put it to use running a quantum circuit on ",[16,5042,5044],{"href":5043},"\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Fionq-setup#_6-run-your-circuit-on-ionqs-cloud-simulator","IonQ’s quantum simulator",". Fantastic. But this is as far as we can go using IonQ’s free account tier. In order to run our quantum circuit on actual IonQ hardware, you must upgrade to a paid IonQ account.",[12,5047,5048,5049,5053,5054,5058,5059,5063,5064,5068],{},"If you’ve submitted a ",[16,5050,5052],{"href":5051},"\u002Frfp","Qollab RFP"," and have been approved for a grant, your IonQ account will include a generous number of credits that can be used towards a compute spend. If you do not have available IonQ credits, visit the ",[16,5055,5057],{"href":5056},"https:\u002F\u002Fcloud.ionq.com\u002Fbackends","“Backends” page of your IonQ account",", select a QPU that you would like to use, and click its “Out of Plan, Request Access” badge. Follow the prompts to request access and join a paid account tier. Additionally, you have the option to email ",[16,5060,5062],{"href":5061},"mailto:support@ionq.com","support@ionq.com"," or fill out ",[16,5065,5067],{"href":5066},"https:\u002F\u002Fsupport.ionq.com\u002Fhc\u002Fen-us\u002Frequests\u002Fnew?","this support form"," to discuss account options.",[3747,5070],{"href":5056,"label":5071},"IonQ Backends →",[12,5073,5074],{},"This first step in our guide to running circuits on IonQ’s quantum hardware will take some time because it requires dialogue with real human beings. Be patient. Good things will come.",[30,5076,5078],{"id":5077},"_2-prepare-our-ionq-project","2. Prepare our IonQ project",[12,5080,5029,5081,5083,5084,460,5088,460,5091,464,5095,5099,5100,5102,5103,5106,5107,5110],{},[16,5082,5032],{"href":1242}," we ",[16,5085,5087],{"href":5086},"\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Fionq-setup#_3-create-a-new-project","created a new project",[16,5089,4909],{"href":5090},"\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Fionq-setup#install-ionqs-sdk",[16,5092,5094],{"href":5093},"\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Fionq-setup#_5-update-our-transpile-settings","updated our transpile settings",[16,5096,5098],{"href":5097},"\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Fionq-setup#include-your-key-in-our-project","safely included our IonQ API key inside our project",". If you skipped these steps, now is the perfect time to tend to them as we will build off of their output here. You will also need to ",[16,5101,3704],{"href":5039}," if you have not done so already. Once you have ",[16,5104,5105],{"href":4979},"upgraded your IonQ account to a paid tier"," (see above) and prepared your IonQ Python project (as described in our ",[16,5108,5109],{"href":1242},"previous guide","), you will be ready to proceed to the next step.",[30,5112,5114],{"id":5113},"_3-confirm-your-ionq-qpu-access","3. Confirm your IonQ QPU access",[12,5116,5117,5118,383],{},"Your IonQ account has been upgraded, and your local Python project is setup for action. Let’s confirm what IonQ hardware your API key can access. Point your Web browser to the ",[16,5119,5057],{"href":5056},[3747,5121],{"href":5056,"label":5071},[30,5123,5125],{"id":5124},"_4-prepare-our-quantum-circuit","4. Prepare our quantum circuit",[12,5127,5128,5129,5132,5133,5135,5136,5139],{},"Create a new blank file within your project folder, name it ",[173,5130,5131],{},"ionq-hardware-submit.py",", open it with your source code editor, and paste the following code into it. It should look very similar to our ",[173,5134,4432],{}," code from our ",[16,5137,5138],{"href":1242},"previous tutorial",". Some differences have been highlighted here:",[586,5141,5143],{"className":1440,"code":5142,"language":1442,"meta":244,"style":244},"from qiskit import QuantumCircuit\nfrom qiskit_ionq import IonQProvider, ErrorMitigation\n\nqc = QuantumCircuit( 2, name=\"Bell state on IonQ QPU\" )\nqc.h( 0 )\nqc.cx( 0, 1 )\nqc.measure_all()\n\nprovider = IonQProvider()\nbackend = provider.get_backend( \"qpu.aria-1\" )\njob = backend.run( \n    qc, \n    shots=1000,\n    error_mitigation=ErrorMitigation.NO_DEBIASING\n)\nprint( \"Submitted job:\", job.job_id() )\nprint( \"Status:\", job.status() )\n",[173,5144,5145,5155,5170,5174,5205,5217,5233,5241,5245,5255,5281,5294,5299,5311,5329,5333,5353],{"__ignoreMap":244},[594,5146,5147,5149,5151,5153],{"class":596,"line":597},[594,5148,2114],{"class":1511},[594,5150,3359],{"class":611},[594,5152,2106],{"class":1511},[594,5154,3364],{"class":611},[594,5156,5157,5159,5161,5163,5165],{"class":596,"line":245},[594,5158,2114],{"class":1511},[594,5160,4455],{"class":611},[594,5162,2106],{"class":1511},[594,5164,4542],{"class":611},[4842,5166,5167],{},[594,5168,5169],{"class":611},", ErrorMitigation",[594,5171,5172],{"class":596,"line":1254},[594,5173,1778],{"emptyLinePlaceholder":272},[594,5175,5176,5178,5180,5182,5184,5186,5188,5190,5192,5195,5200,5203],{"class":596,"line":1534},[594,5177,4469],{"class":611},[594,5179,1453],{"class":1452},[594,5181,3399],{"class":600},[594,5183,4476],{"class":611},[594,5185,1484],{"class":603},[594,5187,460],{"class":611},[594,5189,4483],{"class":3480},[594,5191,1453],{"class":1452},[594,5193,5194],{"class":607},"\"Bell state on ",[4842,5196,5197],{},[594,5198,5199],{"class":607},"IonQ QPU",[594,5201,5202],{"class":607},"\"",[594,5204,4491],{"class":611},[594,5206,5207,5209,5211,5213,5215],{"class":596,"line":1666},[594,5208,4496],{"class":611},[594,5210,3413],{"class":600},[594,5212,4476],{"class":611},[594,5214,2863],{"class":603},[594,5216,4491],{"class":611},[594,5218,5219,5221,5223,5225,5227,5229,5231],{"class":596,"line":1688},[594,5220,4496],{"class":611},[594,5222,3426],{"class":600},[594,5224,4476],{"class":611},[594,5226,2863],{"class":603},[594,5228,460],{"class":611},[594,5230,1479],{"class":603},[594,5232,4491],{"class":611},[594,5234,5235,5237,5239],{"class":596,"line":270},[594,5236,4496],{"class":611},[594,5238,3443],{"class":600},[594,5240,1523],{"class":611},[594,5242,5243],{"class":596,"line":1715},[594,5244,1778],{"emptyLinePlaceholder":272},[594,5246,5247,5249,5251,5253],{"class":596,"line":1827},[594,5248,4537],{"class":611},[594,5250,1453],{"class":1452},[594,5252,4542],{"class":600},[594,5254,1523],{"class":611},[594,5256,5257,5260,5262,5264,5266,5268,5270,5277,5279],{"class":596,"line":1838},[594,5258,5259],{"class":611},"backend ",[594,5261,1453],{"class":1452},[594,5263,4554],{"class":611},[594,5265,4557],{"class":600},[594,5267,4476],{"class":611},[594,5269,5202],{"class":607},[4842,5271,5272],{},[1430,5273,5274],{},[594,5275,5276],{"class":607},"qpu.aria-1",[594,5278,5202],{"class":607},[594,5280,4491],{"class":611},[594,5282,5283,5285,5287,5289,5291],{"class":596,"line":1856},[594,5284,4569],{"class":611},[594,5286,1453],{"class":1452},[594,5288,4574],{"class":611},[594,5290,3474],{"class":600},[594,5292,5293],{"class":611},"( \n",[594,5295,5296],{"class":596,"line":1871},[594,5297,5298],{"class":611},"    qc, \n",[594,5300,5301,5304,5306,5308],{"class":596,"line":3511},[594,5302,5303],{"class":3480},"    shots",[594,5305,1453],{"class":1452},[594,5307,3486],{"class":603},[594,5309,5310],{"class":611},",\n",[594,5312,5313,5316],{"class":596,"line":3524},[594,5314,5315],{"class":3480},"    ",[4842,5317,5318,5321,5323,5326],{},[594,5319,5320],{"class":3480},"error_mitigation",[594,5322,1453],{"class":1452},[594,5324,5325],{"class":611},"ErrorMitigation.",[594,5327,5328],{"class":603},"NO_DEBIASING",[594,5330,5331],{"class":596,"line":3529},[594,5332,1804],{"class":611},[594,5334,5335],{"class":596,"line":3546},[4842,5336,5337,5339,5341,5344,5347,5350],{},[594,5338,2973],{"class":1452},[594,5340,4476],{"class":611},[594,5342,5343],{"class":607},"\"Submitted job:\"",[594,5345,5346],{"class":611},", job.",[594,5348,5349],{"class":600},"job_id",[594,5351,5352],{"class":611},"() )",[594,5354,5356,5358,5360,5363,5365,5368],{"class":596,"line":5355},17,[594,5357,2973],{"class":1452},[594,5359,4476],{"class":611},[594,5361,5362],{"class":607},"\"Status:\"",[594,5364,5346],{"class":611},[594,5366,5367],{"class":600},"status",[594,5369,4599],{"class":611},[12,5371,5372,5373,5376,5377,5379,5380,5382,5383,5386],{},"Be certain to swap out the QPU ",[173,5374,5375],{},"id"," in the example above for the ",[173,5378,5375],{}," of a QPU that you have access to. For example, our code above calls upon the ",[173,5381,5276],{}," QPU, but perhaps you are using ",[173,5384,5385],{},"qpu.forte-1",", etc.",[30,5388,5390],{"id":5389},"_5-estimate-your-ionq-spend","5. Estimate your IonQ spend",[12,5392,5393,5394,5398],{},"How much credit might you need for experimenting? ",[16,5395,5397],{"href":5396},"https:\u002F\u002Fwww.ionq.com\u002Fprograms\u002Fresearch-credits\u002Fresource-estimator","IonQ’s Resource Estimator"," enables you to predict your potential spend ahead of time according to your circuit’s number of qubit registers, gates, and so on. Our simple Bell state circuit above, run for one thousand shots, one single time, on IonQ’s “Aria” device without error mitigation, would cost just a bit above USD 12 at current early 2026 rates. But the same setup run on IonQ’s “Forte” architecture with error mitigation enabled would cost nearly USD 170. (You’ll find that the cost of error mitigation is relatively higher for small to medium circuits, and relatively lower for large circuits.) Always use the IonQ’s Resource Estimator beforehand to reduce unwanted surprises.",[3747,5400],{"href":5396,"label":5401},"IonQ Resource Estimator →",[385,5403,5405],{"id":5404},"a-note-on-error-mitigation","A note on error mitigation",[12,5407,5408,5409,5411,5412,5415,5416,5420,5421,5423],{},"IonQ enables error mitigation be default. In our ",[173,5410,5131],{}," script above, we purposely disable error mitigation. Why would we do this? Because error mitigation is rather expensive and we don’t need it in order to demonstrate how to send jobs to IonQ’s QPUs. However, it’s likely that ",[305,5413,5414],{},"you will want to enable error mitigation on future jobs"," in order to obtain the most useful results from real quantum hardware. (What is IonQ’s quantum error mitigation, and how does it work? Read ",[16,5417,5419],{"href":5418},"https:\u002F\u002Fdocs.ionq.com\u002Fguides\u002Ferror-mitigation-debiasing","IonQ’s guide to debiasing"," for more information.) Experiment with ",[16,5422,5397],{"href":5396}," and use your own judgement regarding when to employ error mitigation for your own circuits.",[30,5425,5427],{"id":5426},"_6-submit-your-circuit-to-ionqs-quantum-hardware-queue","6. Submit your circuit to IonQ’s quantum hardware queue",[12,5429,5430,5431,5434],{},"It’s time. Everything has led up to this moment of executing your quantum circuit on ",[305,5432,5433],{},"real quantum hardware."," Enter the following into our shell:",[586,5436,5438],{"className":588,"code":5437,"language":590,"meta":244,"style":244},"set -a;\nsource .\u002F.env; \nset +a; \nuv run python ionq-hardware-submit.py\n",[173,5439,5440,5449,5458,5466],{"__ignoreMap":244},[594,5441,5442,5444,5446],{"class":596,"line":597},[594,5443,1983],{"class":1452},[594,5445,4104],{"class":603},[594,5447,5448],{"class":611},";\n",[594,5450,5451,5453,5455],{"class":596,"line":245},[594,5452,3245],{"class":1452},[594,5454,4111],{"class":607},[594,5456,5457],{"class":611},"; \n",[594,5459,5460,5462,5464],{"class":596,"line":1254},[594,5461,1983],{"class":1452},[594,5463,4118],{"class":607},[594,5465,5457],{"class":611},[594,5467,5468,5470,5472,5474],{"class":596,"line":1534},[594,5469,636],{"class":600},[594,5471,763],{"class":607},[594,5473,700],{"class":607},[594,5475,5476],{"class":607}," ionq-hardware-submit.py\n",[12,5478,5479,5480,5482],{},"Our shell will respond with a job ",[173,5481,5375],{},". This is your ticket to read the results of your real quantum operation once those results are ready.",[385,5484,5486],{"id":5485},"patience-please","Patience, please",[12,5488,5489,5490,5493,5494,383],{},"While simulator results arrive near-instantly (at least for simple circuits), ",[61,5491,5492],{},"hardware jobs are queued, processed in order of their queue index, and take some time to resolve",". To get an overview of current IonQ QPU job queue times, visit your account’s ",[16,5495,5496],{"href":5056},"Backend page",[30,5498,5500],{"id":5499},"_7-retrieve-ionq-circuit-results-asynchronously","7. Retrieve IonQ circuit results asynchronously",[12,5502,5503,5504,383],{},"Once we’ve submitted a job to one of IonQ’s QPUs, we can check on that job’s status using the ",[16,5505,5507],{"href":5506},"https:\u002F\u002Fcloud.ionq.com\u002Fjobs","“My Jobs” tab of your account page",[3747,5509],{"href":5506,"label":5510},"IonQ “My jobs” →",[12,5512,5513,5514,5517,5518,5521,5522,383],{},"You can also programmatically poll the status of a job using a script similar to the following. Create a new file within your project’s folder and name it ",[173,5515,5516],{},"ionq-hardware-results.py",". Copy the following code into your file, replacing “",[173,5519,5520],{},"PASTE_JOB_ID_HERE","” with your real job’s ",[173,5523,5375],{},[586,5525,5527],{"className":1440,"code":5526,"language":1442,"meta":244,"style":244},"from qiskit_ionq import IonQProvider\n\nprovider = IonQProvider()\nbackend  = provider.get_backend( \"qpu.aria-1\" )\njob = backend.retrieve_job( \"PASTE_JOB_ID_HERE\" )\nprint( job.status() )\nprint( job.get_counts() )\n",[173,5528,5529,5539,5543,5553,5577,5602,5612],{"__ignoreMap":244},[594,5530,5531,5533,5535,5537],{"class":596,"line":597},[594,5532,2114],{"class":1511},[594,5534,4455],{"class":611},[594,5536,2106],{"class":1511},[594,5538,4460],{"class":611},[594,5540,5541],{"class":596,"line":245},[594,5542,1778],{"emptyLinePlaceholder":272},[594,5544,5545,5547,5549,5551],{"class":596,"line":1254},[594,5546,4537],{"class":611},[594,5548,1453],{"class":1452},[594,5550,4542],{"class":600},[594,5552,1523],{"class":611},[594,5554,5555,5557,5559,5561,5563,5565,5567,5573,5575],{"class":596,"line":1534},[594,5556,4549],{"class":611},[594,5558,1453],{"class":1452},[594,5560,4554],{"class":611},[594,5562,4557],{"class":600},[594,5564,4476],{"class":611},[594,5566,5202],{"class":607},[4842,5568,5569],{},[1430,5570,5571],{},[594,5572,5276],{"class":607},[594,5574,5202],{"class":607},[594,5576,4491],{"class":611},[594,5578,5579,5581,5583,5585,5588,5590,5592,5598,5600],{"class":596,"line":1666},[594,5580,4569],{"class":611},[594,5582,1453],{"class":1452},[594,5584,4574],{"class":611},[594,5586,5587],{"class":600},"retrieve_job",[594,5589,4476],{"class":611},[594,5591,5202],{"class":607},[4842,5593,5594],{},[1430,5595,5596],{},[594,5597,5520],{"class":607},[594,5599,5202],{"class":607},[594,5601,4491],{"class":611},[594,5603,5604,5606,5608,5610],{"class":596,"line":1688},[594,5605,2973],{"class":1452},[594,5607,4594],{"class":611},[594,5609,5367],{"class":600},[594,5611,4599],{"class":611},[594,5613,5614,5616,5618,5620],{"class":596,"line":270},[594,5615,2973],{"class":1452},[594,5617,4594],{"class":611},[594,5619,3506],{"class":600},[594,5621,4599],{"class":611},[12,5623,5624],{},"Enter the following into your shell, from within your project’s folder:",[586,5626,5628],{"className":588,"code":5627,"language":590,"meta":244,"style":244},"set -a; \nsource .\u002F.env; \nset +a; \nuv run python ionq-hardware-results.py\n",[173,5629,5630,5638,5646,5654],{"__ignoreMap":244},[594,5631,5632,5634,5636],{"class":596,"line":597},[594,5633,1983],{"class":1452},[594,5635,4104],{"class":603},[594,5637,5457],{"class":611},[594,5639,5640,5642,5644],{"class":596,"line":245},[594,5641,3245],{"class":1452},[594,5643,4111],{"class":607},[594,5645,5457],{"class":611},[594,5647,5648,5650,5652],{"class":596,"line":1254},[594,5649,1983],{"class":1452},[594,5651,4118],{"class":607},[594,5653,5457],{"class":611},[594,5655,5656,5658,5660,5662],{"class":596,"line":1534},[594,5657,636],{"class":600},[594,5659,763],{"class":607},[594,5661,700],{"class":607},[594,5663,5664],{"class":607}," ionq-hardware-results.py\n",[30,5666,5668],{"id":5667},"celebrate","Celebrate",[12,5670,5671,5672,383],{},"Have you received your hardware results yet? Yes? Well then you’ve accomplished a lot here: You’ve just harnessed the power of our quantum universe to compute a thousand entangled coin flips. Take a beat, savor the moment. More Qollab tutorials are on on the way. In the meantime check out IBM’s incredibly informative ",[16,5673,5675],{"href":5674},"https:\u002F\u002Fwww.youtube.com\u002F@qiskit","Qiskit YouTube channel",[1245,5677,5678],{},"html pre.shiki code .seHd6, html code.shiki .seHd6{--shiki-default:#C678DD}html pre.shiki code .sn6KH, html code.shiki .sn6KH{--shiki-default:#ABB2BF}html pre.shiki code .sjrmR, html code.shiki .sjrmR{--shiki-default:#56B6C2}html pre.shiki code .sVbv2, html code.shiki .sVbv2{--shiki-default:#61AFEF}html pre.shiki code .sVC51, html code.shiki .sVC51{--shiki-default:#D19A66}html pre.shiki code .s_ZVi, html code.shiki .s_ZVi{--shiki-default:#E06C75;--shiki-default-font-style:italic}html pre.shiki code .subq3, html code.shiki .subq3{--shiki-default:#98C379}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}",{"title":244,"searchDepth":245,"depth":245,"links":5680},[5681,5682,5683,5684,5685,5688,5691,5692],{"id":5014,"depth":245,"text":5015},{"id":5077,"depth":245,"text":5078},{"id":5113,"depth":245,"text":5114},{"id":5124,"depth":245,"text":5125},{"id":5389,"depth":245,"text":5390,"children":5686},[5687],{"id":5404,"depth":1254,"text":5405},{"id":5426,"depth":245,"text":5427,"children":5689},[5690],{"id":5485,"depth":1254,"text":5486},{"id":5499,"depth":245,"text":5500},{"id":5667,"depth":245,"text":5668},[19,257,258,4965],[],{"username":293,"name":1277,"role":1278,"avatar":244},"Run a quantum circuit on IonQ’s quantum hardware and receive the results asynchronously. Builds upon our previous tutorials for executing quantum circuits on IonQ’s cloud simulator, and installing Python via UV.","Run a quantum circuit on IonQ's real hardware and get the results asynchronously, building on our earlier lessons on the IonQ cloud simulator.",{"image":5699,"alt":4965},"\u002F_content\u002Fimages\u002Fionq-hardware\u002Fhero.webp",{},{"slug":5702,"title":5703,"desc":5704},"\u002Fblog\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Fcreate-project","6 · Create a Project on Qollab","This guide highlights the steps to build and publish your project; a step-by-step walkthrough of Qollab's project creation process, from naming…","2026-01-09","8 min read",[],{"title":5709,"description":5697},"Run circuits on IonQ hardware · Building your first Qollab project","blog\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Fionq-hardware",[],"GvDMPLz_bZ84G9vBG12vZ-23EjSejtbi3kt3tYwzdoQ",{"id":5714,"title":48,"authors":5715,"body":5716,"breadcrumb":6040,"builders":6041,"byline":6042,"challenge":262,"courseAuthor":262,"courseLead":262,"dek":6043,"description":6044,"draft":264,"extension":265,"eyebrow":262,"finish":262,"fork":262,"hero":6045,"heroAlt":262,"heroCta":262,"heroImage":262,"kind":269,"lessonCount":270,"meta":6047,"navigation":272,"newsItems":262,"next":6048,"ogImage":262,"order":1688,"outcomes":262,"path":5702,"publishDate":278,"readingTime":6050,"related":6051,"relatedProjects":262,"seo":6052,"stem":6054,"tags":6055,"track":285,"trackName":258,"__hash__":6056},"blog\u002Fblog\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Fcreate-project.md",[7],{"type":9,"value":5717,"toc":6032},[5718,5725,5729,5744,5748,5751,5753,5757,5763,5767,5809,5813,5823,5827,5831,5834,5838,5841,5951,5958,5962,5965,5969,5983,5990,5994,5997,6001,6019,6026,6029],[12,5719,5720,5721,5724],{},"This guide assumes that you have already created a free Qollab account, chosen a username, and are currently signed into the platform. If any of that sounds unfamiliar, don't fret, ",[16,5722,5723],{"href":39},"sign in or sign up here"," first, then come back to start flexing your quantum muscles.",[30,5726,5728],{"id":5727},"navigating-to-the-creation-page","Navigating to the Creation Page",[12,5730,5731,5732,5735,5736,5739,5740,383],{},"To start a new project, simply click the ",[305,5733,5734],{},"Add Project"," button on the ",[16,5737,5738],{"href":274},"Projects"," page or directly create a new ",[16,5741,5743],{"href":5742},"\u002Fnew","project",[712,5745],{"alt":5746,"caption":244,"no":244,"src":5747},"The Projects page showing the Add Project button in the top right corner","\u002F_content\u002Fimages\u002Fcreate-project\u002Fqollab-projects-add-button-1773201441250.webp",[12,5749,5750],{},"You will enter a five-step creation process. Each step is saved automatically as you progress, so you won't lose your work if you happen to navigate away.",[51,5752],{},[30,5754,5756],{"id":5755},"step-1-project-details","Step 1: Project Details",[12,5758,5759,5760],{},"The first step collects the essential information about your project. ",[305,5761,5762],{},"(Note: Project Title and Description are required fields.)",[712,5764],{"alt":5765,"caption":244,"no":244,"src":5766},"Step 1, Project Details form","\u002F_content\u002Fimages\u002Fcreate-project\u002Fstep1-project-details-png-1773201592099.webp",[66,5768,5769,5778,5788,5794],{},[69,5770,5771,5774,5775,242],{},[61,5772,5773],{},"Project Title:"," Enter a concise but descriptive name (e.g., ",[305,5776,5777],{},"Quantum Teleportation Visualizer",[69,5779,5780,5783,5784,5787],{},[61,5781,5782],{},"Project URL Name:"," As you type your title, Qollab automatically generates a web address for your project (e.g., ",[173,5785,5786],{},"quantum-teleportation-visualizer","). You can manually edit this if you want to make it shorter.",[69,5789,5790,5793],{},[61,5791,5792],{},"Description:"," Write a brief summary of what your project does (up to 1,024 characters). This acts as a preview card when people are browsing.",[69,5795,5796,5799,5800,460,5802,356,5805,5808],{},[61,5797,5798],{},"Labels (optional):"," Add tags like ",[173,5801,4375],{},[173,5803,5804],{},"ionq",[173,5806,5807],{},"entanglement",". Clear details and accurate labels make it easy for the community to discover your work when searching for specific quantum topics.",[30,5810,5812],{"id":5811},"step-2-project-content","Step 2: Project Content",[12,5814,5815,5816,4618,5819,5822],{},"This required field is where you explain the ",[305,5817,5818],{},"why",[305,5820,5821],{},"how"," behind your project, documenting your thought process, your goals, and your results, helping others learn from your experience. The editor on this field supports standard Markdown syntax for formatting text.",[712,5824],{"alt":5825,"caption":244,"no":244,"src":5826},"Step 2, Project Content markdown editor","\u002F_content\u002Fimages\u002Fcreate-project\u002Fstep2-content-png-1773201624099.webp",[30,5828,5830],{"id":5829},"step-3-project-code","Step 3: Project Code",[12,5832,5833],{},"This required step is where you add your quantum computing scripts. Qollab pre-loads the editor with a simple Python starter script using Qiskit (a popular quantum SDK), a two-qubit Bell state circuit, just to give you a foundation to build from:",[712,5835],{"alt":5836,"caption":244,"no":244,"src":5837},"Step 3, Project Code editor with Python\u002FQiskit starter template","\u002F_content\u002Fimages\u002Fcreate-project\u002Fstep3-code-png-1773201641617.webp",[12,5839,5840],{},"You can replace this entirely with your own code or build directly upon it.",[586,5842,5844],{"className":1440,"code":5843,"language":1442,"meta":244,"style":244},"from qiskit import QuantumCircuit\nfrom qiskit.quantum_info import Statevector\n\n# Create a 2-qubit circuit\nqc = QuantumCircuit(2)\n\n# Apply gates\nqc.h(0)  # Hadamard gate on qubit 0\nqc.cx(0, 1)  # CNOT gate (creates entanglement)\n\n# Display the circuit\nprint(qc)\n",[173,5845,5846,5856,5868,5872,5877,5891,5895,5900,5916,5935,5939,5944],{"__ignoreMap":244},[594,5847,5848,5850,5852,5854],{"class":596,"line":597},[594,5849,2114],{"class":1511},[594,5851,3359],{"class":611},[594,5853,2106],{"class":1511},[594,5855,3364],{"class":611},[594,5857,5858,5860,5863,5865],{"class":596,"line":245},[594,5859,2114],{"class":1511},[594,5861,5862],{"class":611}," qiskit.quantum_info ",[594,5864,2106],{"class":1511},[594,5866,5867],{"class":611}," Statevector\n",[594,5869,5870],{"class":596,"line":1254},[594,5871,1778],{"emptyLinePlaceholder":272},[594,5873,5874],{"class":596,"line":1534},[594,5875,5876],{"class":1639},"# Create a 2-qubit circuit\n",[594,5878,5879,5881,5883,5885,5887,5889],{"class":596,"line":1666},[594,5880,4469],{"class":611},[594,5882,1453],{"class":1452},[594,5884,3399],{"class":600},[594,5886,1583],{"class":611},[594,5888,1484],{"class":603},[594,5890,1804],{"class":611},[594,5892,5893],{"class":596,"line":1688},[594,5894,1778],{"emptyLinePlaceholder":272},[594,5896,5897],{"class":596,"line":270},[594,5898,5899],{"class":1639},"# Apply gates\n",[594,5901,5902,5904,5906,5908,5910,5913],{"class":596,"line":1715},[594,5903,4496],{"class":611},[594,5905,3413],{"class":600},[594,5907,1583],{"class":611},[594,5909,2863],{"class":603},[594,5911,5912],{"class":611},")  ",[594,5914,5915],{"class":1639},"# Hadamard gate on qubit 0\n",[594,5917,5918,5920,5922,5924,5926,5928,5930,5932],{"class":596,"line":1827},[594,5919,4496],{"class":611},[594,5921,3426],{"class":600},[594,5923,1583],{"class":611},[594,5925,2863],{"class":603},[594,5927,460],{"class":611},[594,5929,1479],{"class":603},[594,5931,5912],{"class":611},[594,5933,5934],{"class":1639},"# CNOT gate (creates entanglement)\n",[594,5936,5937],{"class":596,"line":1838},[594,5938,1778],{"emptyLinePlaceholder":272},[594,5940,5941],{"class":596,"line":1856},[594,5942,5943],{"class":1639},"# Display the circuit\n",[594,5945,5946,5948],{"class":596,"line":1871},[594,5947,2973],{"class":1452},[594,5949,5950],{"class":611},"(qc)\n",[135,5952,5953],{},[12,5954,5955,5957],{},[61,5956,216],{}," Sharing your actual code gives the community a tangible, runnable example to learn from. Others can test your logic, discover new implementation techniques, or even build upon your foundation to create something entirely new.",[30,5959,5961],{"id":5960},"step-4-project-links","Step 4: Project Links",[12,5963,5964],{},"If you have files or websites related to your project hosted somewhere else, you can link them here:",[712,5966],{"alt":5967,"caption":244,"no":244,"src":5968},"Step 4, Project Links with Git Repository and Project Website fields","\u002F_content\u002Fimages\u002Fcreate-project\u002Fstep4-links-png-1773201658327.webp",[66,5970,5971,5977],{},[69,5972,5973,5976],{},[61,5974,5975],{},"Git Repository:"," Provide a link to your source code on GitHub, GitLab, or Bitbucket.",[69,5978,5979,5982],{},[61,5980,5981],{},"Project Website:"," Provide a link to a live demo, a Jupyter notebook, or an arXiv paper.",[135,5984,5985],{},[12,5986,5987,5989],{},[61,5988,216],{}," Linking to external repositories or live demos gives the community a much deeper look into your project. It opens the door for others to actively contribute to your codebase, review your full research, or see your work functioning in the real world.",[30,5991,5993],{"id":5992},"step-5-publish","Step 5: Publish",[12,5995,5996],{},"Congratulations, your project is saved! You now have two choices:",[712,5998],{"alt":5999,"caption":244,"no":244,"src":6000},"Step 5, Publish options with Publish Now and Keep as Draft","\u002F_content\u002Fimages\u002Fcreate-project\u002Fstep5-publish-png-1773201675400.webp",[66,6002,6003,6013],{},[69,6004,6005,6008,6009,6012],{},[61,6006,6007],{},"Publish Now:"," This makes your project publicly visible to the community and tags it as your official ",[305,6010,6011],{},"v1.0"," release. Publishing requires you to agree to the Community Guidelines.",[69,6014,6015,6018],{},[61,6016,6017],{},"Keep as Draft:"," This saves your project privately. You can continue updating your draft and publish it whenever you are completely ready.",[135,6020,6021],{},[12,6022,6023,6025],{},[61,6024,216],{}," Publishing is what makes open collaboration possible! By sharing your work publicly, you invite constructive feedback, spark interesting discussions, and actively contribute to the growing, shared knowledge base of the quantum computing community.",[12,6027,6028],{},"We look forward to seeing what you will build and share with the community!",[1245,6030,6031],{},"html pre.shiki code .seHd6, html code.shiki .seHd6{--shiki-default:#C678DD}html pre.shiki code .sn6KH, html code.shiki .sn6KH{--shiki-default:#ABB2BF}html pre.shiki code .sV9Aq, html code.shiki .sV9Aq{--shiki-default:#7F848E;--shiki-default-font-style:italic}html pre.shiki code .sjrmR, html code.shiki .sjrmR{--shiki-default:#56B6C2}html pre.shiki code .sVbv2, html code.shiki .sVbv2{--shiki-default:#61AFEF}html pre.shiki code .sVC51, html code.shiki .sVC51{--shiki-default:#D19A66}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}",{"title":244,"searchDepth":245,"depth":245,"links":6033},[6034,6035,6036,6037,6038,6039],{"id":5727,"depth":245,"text":5728},{"id":5755,"depth":245,"text":5756},{"id":5811,"depth":245,"text":5812},{"id":5829,"depth":245,"text":5830},{"id":5960,"depth":245,"text":5961},{"id":5992,"depth":245,"text":5993},[19,257,258,48],[],{"username":7,"name":19,"role":261,"avatar":244},"This guide highlights the steps to build and publish your project; a step-by-step walkthrough of Qollab's project creation process, from naming your work to releasing it for the community to discover.","A step-by-step walkthrough of Qollab's project creation, from naming your work to releasing it for the community to discover.",{"image":6046,"alt":48},"\u002F_content\u002Fimages\u002Fcreate-project\u002Fhero.webp",{},{"slug":277,"title":6049,"desc":263},"7 · Use the Code Playground","4 min read",[],{"title":6053,"description":6044},"Create a Project on Qollab · Building your first Qollab project","blog\u002Flearn\u002Fbuilding-your-first-qollab-project\u002Fcreate-project",[],"MIg53Bk8sB6OIQcy9_ioz1Omvlry8U5LTuh49hSsjFk",{"id":4,"title":5,"authors":6058,"body":6059,"breadcrumb":6208,"builders":6209,"byline":6210,"challenge":262,"courseAuthor":262,"courseLead":262,"dek":263,"description":263,"draft":264,"extension":265,"eyebrow":262,"finish":266,"fork":262,"hero":6211,"heroAlt":262,"heroCta":262,"heroImage":262,"kind":269,"lessonCount":270,"meta":6212,"navigation":272,"newsItems":262,"next":6213,"ogImage":262,"order":270,"outcomes":262,"path":277,"publishDate":278,"readingTime":279,"related":6214,"relatedProjects":262,"seo":6215,"stem":283,"tags":6216,"track":285,"trackName":258,"__hash__":286},[7],{"type":9,"value":6060,"toc":6197},[6061,6067,6069,6071,6075,6079,6081,6083,6087,6101,6103,6107,6109,6113,6125,6129,6135,6137,6143,6145,6147,6163,6165,6167,6177,6183,6185,6187,6189],[12,6062,14,6063,20,6065,25],{},[16,6064,19],{"href":18},[16,6066,24],{"href":23},[12,6068,28],{},[30,6070,33],{"id":32},[12,6072,36,6073,41],{},[16,6074,40],{"href":39},[12,6076,44,6077,49],{},[16,6078,48],{"href":47},[51,6080],{},[30,6082,56],{"id":55},[12,6084,59,6085,64],{},[61,6086,63],{},[66,6088,6089,6093,6097],{},[69,6090,6091,74],{},[61,6092,73],{},[69,6094,6095,80],{},[61,6096,79],{},[69,6098,6099,86],{},[61,6100,85],{},[30,6102,90],{"id":89},[12,6104,93,6105,97],{},[61,6106,96],{},[30,6108,101],{"id":100},[12,6110,104,6111,108],{},[61,6112,107],{},[66,6114,6115,6119],{},[69,6116,6117,116],{},[61,6118,115],{},[69,6120,6121,122,6123,127],{},[61,6122,121],{},[16,6124,126],{"href":125},[12,6126,6127,133],{},[61,6128,132],{},[135,6130,6131],{},[12,6132,6133,142],{},[61,6134,141],{},[30,6136,146],{"id":145},[12,6138,149,6139,152,6141,156],{},[61,6140,96],{},[61,6142,155],{},[30,6144,160],{"id":159},[12,6146,163],{},[66,6148,6149,6155,6159],{},[69,6150,6151,171,6153,176],{},[61,6152,170],{},[173,6154,175],{},[69,6156,6157,182],{},[61,6158,181],{},[69,6160,6161,188],{},[61,6162,187],{},[30,6164,192],{"id":191},[12,6166,195],{},[66,6168,6169,6173],{},[69,6170,6171,203],{},[61,6172,202],{},[69,6174,6175,209],{},[61,6176,208],{},[135,6178,6179],{},[12,6180,6181,217],{},[61,6182,216],{},[51,6184],{},[30,6186,223],{"id":222},[30,6188,227],{"id":226},[12,6190,230,6191,234,6193,238,6195,242],{},[173,6192,233],{},[173,6194,237],{},[173,6196,241],{},{"title":244,"searchDepth":245,"depth":245,"links":6198},[6199,6200,6201,6202,6203,6204,6205,6206,6207],{"id":32,"depth":245,"text":33},{"id":55,"depth":245,"text":56},{"id":89,"depth":245,"text":90},{"id":100,"depth":245,"text":101},{"id":145,"depth":245,"text":146},{"id":159,"depth":245,"text":160},{"id":191,"depth":245,"text":192},{"id":222,"depth":245,"text":223},{"id":226,"depth":245,"text":227},[19,257,258,5],[],{"username":7,"name":19,"role":261,"avatar":244},{"image":268,"alt":5},{},{"slug":274,"title":275,"desc":276},[],{"title":282,"description":263},[],1785631563356]