Intro to Qiskit: GHZ State Lab 0
Intro to Qiskit: GHZ State Lab 0
Table of Contents
Welcome to the Qiskit Global Summer School 2025!
Lab 0 overview
Install Qiskit
Troubleshooting
Setting API token
Imports
Sanity check
Generate a three-qubit GHZ state using Qiskit patterns
Step 1. Map
Step 2. Optimize
Step 3. Execute
Step 4. Post-process
Congratulations!
Bonus challenge: Run GHZ on hardware
Each lab complements the corresponding theoretical lectures and includes helpful
links to documentation, tutorials, and references to the lectures. Furthermore, you
can also find many useful resources in IBM Quantum Learning.
Lab 0 overview
[Link] 1/28
09/07/2025, 13:01 lab0
The main goal of this introductory lab is to show you how to use the challenge
notebooks, grade your solutions, and verify that your computer is correctly set up
for executing the quantum codes that you will be asked to complete.
To complete the different labs of the QGSS, you need to know that every notebook
will contain some predefined cells that you should not modify, and some challenge
code blocks that you will need to fill with your own code. In particular, you will need
to write the required code below each line that has the ### WRITE YOUR CODE
BELOW HERE ### comment. Make sure that every time you restart the kernel, you
execute every cell in order, so that the challenge notebooks execute and are graded
properly. This will guarantee that all the code is updated and everything runs
smoothly. There may be a few exceptions, such as installation cells or cells where
you save your account credentials. These will likely only need to be run once.
The content of this lab focuses on using Qiskit patterns to produce a GHZ state,
emphasizing the importance of designing optimized quantum circuits. At the end is
a bonus exercise where you can execute your code on a real quantum computer.
Install Qiskit
Quantum computers stand as a technology that promises to disrupt how some
calculations are done - from breaking encryption with Shor's algorithm, to enabling
faster searches with Grover's algorithm, to designing better batteries with quantum
phase estimation. A first step is choosing a software tool for designing and
executing such algorithms. In these challenges you will use Qiskit for the design
and implementation of quantum circuits in simulators and real hardware. The
following will help you install Qiskit v2.0.
First, check that the version of Python you are using in your environment is
python>=3.10, to make sure that it is compatible with the latest Qiskit version we
will use:
print(python_version())
3.11.9
If that is not the case, you can upgrade it using your preferred tool. If you are
unsure how to do it, some recommended options are:
MacOS: Homebrew
Linux: sudo apt-get update
⚠️ Note: You cannot run Lab 3 of the QGSS using Windows. Hence, if you are
[Link] 2/28
09/07/2025, 13:01 lab0
Now let's install the grader that will install Qiskit 2.x and the necessary libraries we
will need for the summer school.
[Link] 3/28
09/07/2025, 13:01 lab0
[Link] 4/28
09/07/2025, 13:01 lab0
[Link] 5/28
09/07/2025, 13:01 lab0
[Link]/qiskit-community/[Link]->qc-grader[jupyter,qi
skit]@ git+[Link]
t) (0.16.0)
Requirement already satisfied: numpy<3,>=1.17 in /opt/.qbraid/environment
s/qgss_000000/pyenv/lib/python3.11/site-packages (from qiskit~=2.1.0->qisk
it[visualization]~=2.1.0; extra == "qiskit"->qc-grader@ git+[Link]
[Link]/qiskit-community/[Link]->qc-grader[jupyter,qis
kit]@ git+[Link]
t) (2.3.1)
Requirement already satisfied: scipy>=1.5 in /opt/.qbraid/environments/qgs
s_000000/pyenv/lib/python3.11/site-packages (from qiskit~=2.1.0->qiskit[vi
sualization]~=2.1.0; extra == "qiskit"->qc-grader@ git+[Link]
qiskit-community/[Link]->qc-grader[jupyter,qiskit]@
git+[Link] (1.1
6.0)
Requirement already satisfied: dill>=0.3 in /opt/.qbraid/environments/qgss
_000000/pyenv/lib/python3.11/site-packages (from qiskit~=2.1.0->qiskit[vis
ualization]~=2.1.0; extra == "qiskit"->qc-grader@ git+[Link]
iskit-community/[Link]->qc-grader[jupyter,qiskit]@ g
it+[Link] (0.4.
0)
Requirement already satisfied: stevedore>=3.0.0 in /opt/.qbraid/environmen
ts/qgss_000000/pyenv/lib/python3.11/site-packages (from qiskit~=2.1.0->qis
kit[visualization]~=2.1.0; extra == "qiskit"->qc-grader@ git+[Link]
[Link]/qiskit-community/[Link]->qc-grader[jupyter,qis
kit]@ git+[Link]
t) (5.4.1)
Requirement already satisfied: typing-extensions in /opt/.qbraid/environme
nts/qgss_000000/pyenv/lib/python3.11/site-packages (from qiskit~=2.1.0->qi
skit[visualization]~=2.1.0; extra == "qiskit"->qc-grader@ git+[Link]
[Link]/qiskit-community/[Link]->qc-grader[jupyter,qi
skit]@ git+[Link]
t) (4.14.1)
Requirement already satisfied: matplotlib>=3.3 in /opt/.qbraid/environment
s/qgss_000000/pyenv/lib/python3.11/site-packages (from qiskit[visualizatio
n]~=2.1.0; extra == "qiskit"->qc-grader@ git+[Link]
munity/[Link]->qc-grader[jupyter,qiskit]@ git+http
s://[Link]/qiskit-community/[Link]) (3.10.3)
Requirement already satisfied: pydot in /opt/.qbraid/environments/qgss_000
000/pyenv/lib/python3.11/site-packages (from qiskit[visualization]~=2.1.0;
extra == "qiskit"->qc-grader@ git+[Link]
[Link]->qc-grader[jupyter,qiskit]@ git+[Link]
m/qiskit-community/[Link]) (4.0.1)
Requirement already satisfied: Pillow>=4.2.1 in /opt/.qbraid/environments/
qgss_000000/pyenv/lib/python3.11/site-packages (from qiskit[visualization]
~=2.1.0; extra == "qiskit"->qc-grader@ git+[Link]
nity/[Link]->qc-grader[jupyter,qiskit]@ git+https://
[Link]/qiskit-community/[Link]) (11.3.0)
Requirement already satisfied: pylatexenc>=1.4 in /opt/.qbraid/environment
s/qgss_000000/pyenv/lib/python3.11/site-packages (from qiskit[visualizatio
n]~=2.1.0; extra == "qiskit"->qc-grader@ git+[Link]
munity/[Link]->qc-grader[jupyter,qiskit]@ git+http
s://[Link]/qiskit-community/[Link]) (2.10)
Requirement already satisfied: seaborn>=0.9.0 in /opt/.qbraid/environment
s/qgss_000000/pyenv/lib/python3.11/site-packages (from qiskit[visualizatio
n]~=2.1.0; extra == "qiskit"->qc-grader@ git+[Link]
munity/[Link]->qc-grader[jupyter,qiskit]@ git+http
s://[Link]/qiskit-community/[Link]) (0.13.2)
Requirement already satisfied: sympy>=1.3 in /opt/.qbraid/environments/qgs
s_000000/pyenv/lib/python3.11/site-packages (from qiskit[visualization]~=
[Link] 6/28
09/07/2025, 13:01 lab0
[Link] 7/28
09/07/2025, 13:01 lab0
ttps://[Link]/qiskit-community/[Link]->qc-grader
[jupyter,qiskit]@ git+[Link]
[Link]) (6.1.1)
Requirement already satisfied: setuptools in /opt/.qbraid/environments/qgs
s_000000/pyenv/lib/python3.11/site-packages (from pbr>=2.0.0->stevedore>=
3.0.0->qiskit~=2.1.0->qiskit[visualization]~=2.1.0; extra == "qiskit"->qc-
grader@ git+[Link]
it->qc-grader[jupyter,qiskit]@ git+[Link]
[Link]) (65.5.0)
Requirement already satisfied: mpmath<1.4,>=1.1.0 in /opt/.qbraid/environm
ents/qgss_000000/pyenv/lib/python3.11/site-packages (from sympy>=1.3->qisk
it[visualization]~=2.1.0; extra == "qiskit"->qc-grader@ git+[Link]
[Link]/qiskit-community/[Link]->qc-grader[jupyter,qis
kit]@ git+[Link]
t) (1.3.0)
Requirement already satisfied: ipywidgets>=7.6.0 in /opt/.qbraid/environme
nts/qgss_000000/pyenv/lib/python3.11/site-packages (from ipycytoscape->qc-
grader@ git+[Link]
it->qc-grader[jupyter,qiskit]@ git+[Link]
[Link]) (8.1.7)
Requirement already satisfied: spectate>=1.0.0 in /opt/.qbraid/environment
s/qgss_000000/pyenv/lib/python3.11/site-packages (from ipycytoscape->qc-gr
ader@ git+[Link]
->qc-grader[jupyter,qiskit]@ git+[Link]
[Link]) (1.0.1)
Requirement already satisfied: comm>=0.1.3 in /opt/.qbraid/environments/qg
ss_000000/pyenv/lib/python3.11/site-packages (from ipywidgets>=7.6.0->ipyc
ytoscape->qc-grader@ git+[Link]
[Link]->qc-grader[jupyter,qiskit]@ git+[Link]
community/[Link]) (0.2.2)
Requirement already satisfied: ipython>=6.1.0 in /opt/.qbraid/environment
s/qgss_000000/pyenv/lib/python3.11/site-packages (from ipywidgets>=7.6.0->
ipycytoscape->qc-grader@ git+[Link]
[Link]->qc-grader[jupyter,qiskit]@ git+[Link]
kit-community/[Link]) (9.4.0)
Requirement already satisfied: traitlets>=4.3.1 in /opt/.qbraid/environmen
ts/qgss_000000/pyenv/lib/python3.11/site-packages (from ipywidgets>=7.6.0-
>ipycytoscape->qc-grader@ git+[Link]
[Link]->qc-grader[jupyter,qiskit]@ git+[Link]
skit-community/[Link]) (5.14.3)
Requirement already satisfied: widgetsnbextension~=4.0.14 in /opt/.qbraid/
environments/qgss_000000/pyenv/lib/python3.11/site-packages (from ipywidge
ts>=7.6.0->ipycytoscape->qc-grader@ git+[Link]
y/[Link]->qc-grader[jupyter,qiskit]@ git+[Link]
[Link]/qiskit-community/[Link]) (4.0.14)
Requirement already satisfied: jupyterlab_widgets~=3.0.15 in /opt/.qbraid/
environments/qgss_000000/pyenv/lib/python3.11/site-packages (from ipywidge
ts>=7.6.0->ipycytoscape->qc-grader@ git+[Link]
y/[Link]->qc-grader[jupyter,qiskit]@ git+[Link]
[Link]/qiskit-community/[Link]) (3.0.15)
Requirement already satisfied: decorator in /opt/.qbraid/environments/qgss
_000000/pyenv/lib/python3.11/site-packages (from ipython>=6.1.0->ipywidget
s>=7.6.0->ipycytoscape->qc-grader@ git+[Link]
y/[Link]->qc-grader[jupyter,qiskit]@ git+[Link]
[Link]/qiskit-community/[Link]) (5.2.1)
Requirement already satisfied: ipython-pygments-lexers in /opt/.qbraid/env
ironments/qgss_000000/pyenv/lib/python3.11/site-packages (from ipython>=6.
1.0->ipywidgets>=7.6.0->ipycytoscape->qc-grader@ git+[Link]
skit-community/[Link]->qc-grader[jupyter,qiskit]@ gi
t+[Link] (1.1.
[Link] 8/28
09/07/2025, 13:01 lab0
1)
Requirement already satisfied: jedi>=0.16 in /opt/.qbraid/environments/qgs
s_000000/pyenv/lib/python3.11/site-packages (from ipython>=6.1.0->ipywidge
ts>=7.6.0->ipycytoscape->qc-grader@ git+[Link]
y/[Link]->qc-grader[jupyter,qiskit]@ git+[Link]
[Link]/qiskit-community/[Link]) (0.19.2)
Requirement already satisfied: matplotlib-inline in /opt/.qbraid/environme
nts/qgss_000000/pyenv/lib/python3.11/site-packages (from ipython>=6.1.0->i
pywidgets>=7.6.0->ipycytoscape->qc-grader@ git+[Link]
ommunity/[Link]->qc-grader[jupyter,qiskit]@ git+http
s://[Link]/qiskit-community/[Link]) (0.1.7)
Requirement already satisfied: pexpect>4.3 in /opt/.qbraid/environments/qg
ss_000000/pyenv/lib/python3.11/site-packages (from ipython>=6.1.0->ipywidg
ets>=7.6.0->ipycytoscape->qc-grader@ git+[Link]
ty/[Link]->qc-grader[jupyter,qiskit]@ git+[Link]
[Link]/qiskit-community/[Link]) (4.9.0)
Requirement already satisfied: prompt_toolkit<3.1.0,>=3.0.41 in /opt/.qbra
id/environments/qgss_000000/pyenv/lib/python3.11/site-packages (from ipyth
on>=6.1.0->ipywidgets>=7.6.0->ipycytoscape->qc-grader@ git+[Link]
com/qiskit-community/[Link]->qc-grader[jupyter,qiski
t]@ git+[Link]
(3.0.51)
Requirement already satisfied: pygments>=2.4.0 in /opt/.qbraid/environment
s/qgss_000000/pyenv/lib/python3.11/site-packages (from ipython>=6.1.0->ipy
widgets>=7.6.0->ipycytoscape->qc-grader@ git+[Link]
munity/[Link]->qc-grader[jupyter,qiskit]@ git+http
s://[Link]/qiskit-community/[Link]) (2.19.2)
Requirement already satisfied: stack_data in /opt/.qbraid/environments/qgs
s_000000/pyenv/lib/python3.11/site-packages (from ipython>=6.1.0->ipywidge
ts>=7.6.0->ipycytoscape->qc-grader@ git+[Link]
y/[Link]->qc-grader[jupyter,qiskit]@ git+[Link]
[Link]/qiskit-community/[Link]) (0.6.3)
Requirement already satisfied: wcwidth in /opt/.qbraid/environments/qgss_0
00000/pyenv/lib/python3.11/site-packages (from prompt_toolkit<3.1.0,>=3.0.
41->ipython>=6.1.0->ipywidgets>=7.6.0->ipycytoscape->qc-grader@ git+http
s://[Link]/qiskit-community/[Link]->qc-grader[ju
pyter,qiskit]@ git+[Link]
[Link]) (0.2.13)
Requirement already satisfied: parso<0.9.0,>=0.8.4 in /opt/.qbraid/environ
ments/qgss_000000/pyenv/lib/python3.11/site-packages (from jedi>=0.16->ipy
thon>=6.1.0->ipywidgets>=7.6.0->ipycytoscape->qc-grader@ git+[Link]
[Link]/qiskit-community/[Link]->qc-grader[jupyter,qis
kit]@ git+[Link]
t) (0.8.4)
Requirement already satisfied: ptyprocess>=0.5 in /opt/.qbraid/environment
s/qgss_000000/pyenv/lib/python3.11/site-packages (from pexpect>4.3->ipytho
n>=6.1.0->ipywidgets>=7.6.0->ipycytoscape->qc-grader@ git+[Link]
om/qiskit-community/[Link]->qc-grader[jupyter,qiski
t]@ git+[Link]
(0.7.0)
Requirement already satisfied: debugpy>=1.6.5 in /opt/conda/lib/python3.1
1/site-packages (from ipykernel->qc-grader@ git+[Link]
community/[Link]->qc-grader[jupyter,qiskit]@ git+htt
ps://[Link]/qiskit-community/[Link]) (1.8.1)
Requirement already satisfied: jupyter-client>=6.1.12 in /opt/conda/lib/py
thon3.11/site-packages (from ipykernel->qc-grader@ git+[Link]
qiskit-community/[Link]->qc-grader[jupyter,qiskit]@
git+[Link] (8.
6.1)
Requirement already satisfied: jupyter-core!=5.0.*,>=4.12 in /opt/conda/li
[Link] 9/28
09/07/2025, 13:01 lab0
[Link] 10/28
09/07/2025, 13:01 lab0
[jupyter,qiskit]@ git+[Link]
[Link]) (4.3.0)
Requirement already satisfied: argon2-cffi>=21.1 in /opt/conda/lib/python
3.11/site-packages (from jupyter-server<3,>=2.4.0->jupyterlab->qc-grader@
git+[Link]
rader[jupyter,qiskit]@ git+[Link]
[Link]) (23.1.0)
Requirement already satisfied: jupyter-events>=0.9.0 in /opt/conda/lib/pyt
hon3.11/site-packages (from jupyter-server<3,>=2.4.0->jupyterlab->qc-grade
r@ git+[Link]
c-grader[jupyter,qiskit]@ git+[Link]
[Link]) (0.10.0)
Requirement already satisfied: jupyter-server-terminals>=0.4.4 in /opt/con
da/lib/python3.11/site-packages (from jupyter-server<3,>=2.4.0->jupyterlab
->qc-grader@ git+[Link]
[Link]->qc-grader[jupyter,qiskit]@ git+[Link]
y/[Link]) (0.5.3)
Requirement already satisfied: nbconvert>=6.4.4 in /opt/conda/lib/python3.
11/site-packages (from jupyter-server<3,>=2.4.0->jupyterlab->qc-grader@ gi
t+[Link]
der[jupyter,qiskit]@ git+[Link]
[Link]) (7.16.4)
Requirement already satisfied: nbformat>=5.3.0 in /opt/conda/lib/python3.1
1/site-packages (from jupyter-server<3,>=2.4.0->jupyterlab->qc-grader@ git
+[Link]
er[jupyter,qiskit]@ git+[Link]
[Link]) (5.10.4)
Requirement already satisfied: overrides>=5.0 in /opt/conda/lib/python3.1
1/site-packages (from jupyter-server<3,>=2.4.0->jupyterlab->qc-grader@ git
+[Link]
er[jupyter,qiskit]@ git+[Link]
[Link]) (7.7.0)
Requirement already satisfied: prometheus-client>=0.9 in /opt/conda/lib/py
thon3.11/site-packages (from jupyter-server<3,>=2.4.0->jupyterlab->qc-grad
er@ git+[Link]
qc-grader[jupyter,qiskit]@ git+[Link]
-[Link]) (0.20.0)
Requirement already satisfied: send2trash>=1.8.2 in /opt/conda/lib/python
3.11/site-packages (from jupyter-server<3,>=2.4.0->jupyterlab->qc-grader@
git+[Link]
rader[jupyter,qiskit]@ git+[Link]
[Link]) (1.8.3)
Requirement already satisfied: terminado>=0.8.3 in /opt/conda/lib/python3.
11/site-packages (from jupyter-server<3,>=2.4.0->jupyterlab->qc-grader@ gi
t+[Link]
der[jupyter,qiskit]@ git+[Link]
[Link]) (0.18.1)
Requirement already satisfied: websocket-client>=1.7 in /opt/conda/lib/pyt
hon3.11/site-packages (from jupyter-server<3,>=2.4.0->jupyterlab->qc-grade
r@ git+[Link]
c-grader[jupyter,qiskit]@ git+[Link]
[Link]) (1.8.0)
Requirement already satisfied: babel>=2.10 in /opt/conda/lib/python3.11/si
te-packages (from jupyterlab-server<3,>=2.27.1->jupyterlab->qc-grader@ git
+[Link]
er[jupyter,qiskit]@ git+[Link]
[Link]) (2.14.0)
Requirement already satisfied: json5>=0.9.0 in /opt/conda/lib/python3.11/s
ite-packages (from jupyterlab-server<3,>=2.27.1->jupyterlab->qc-grader@ gi
t+[Link]
[Link] 11/28
09/07/2025, 13:01 lab0
der[jupyter,qiskit]@ git+[Link]
[Link]) (0.9.25)
Requirement already satisfied: jsonschema>=4.18.0 in /opt/conda/lib/python
3.11/site-packages (from jupyterlab-server<3,>=2.27.1->jupyterlab->qc-grad
er@ git+[Link]
qc-grader[jupyter,qiskit]@ git+[Link]
-[Link]) (4.22.0)
Requirement already satisfied: sniffio>=1.1 in /opt/conda/lib/python3.11/s
ite-packages (from anyio>=3.1.0->jupyter-server<3,>=2.4.0->jupyterlab->qc-
grader@ git+[Link]
it->qc-grader[jupyter,qiskit]@ git+[Link]
[Link]) (1.3.1)
Requirement already satisfied: argon2-cffi-bindings in /opt/conda/lib/pyth
on3.11/site-packages (from argon2-cffi>=21.1->jupyter-server<3,>=2.4.0->ju
pyterlab->qc-grader@ git+[Link]
[Link]->qc-grader[jupyter,qiskit]@ git+[Link]
community/[Link]) (21.2.0)
Requirement already satisfied: httpcore==1.* in /opt/conda/lib/python3.11/
site-packages (from httpx>=0.25.0->jupyterlab->qc-grader@ git+[Link]
[Link]/qiskit-community/[Link]->qc-grader[jupyter,qi
skit]@ git+[Link]
t) (1.0.5)
Requirement already satisfied: h11<0.15,>=0.13 in /opt/conda/lib/python3.1
1/site-packages (from httpcore==1.*->httpx>=0.25.0->jupyterlab->qc-grader@
git+[Link]
rader[jupyter,qiskit]@ git+[Link]
[Link]) (0.14.0)
Requirement already satisfied: MarkupSafe>=2.0 in /opt/.qbraid/environment
s/qgss_000000/pyenv/lib/python3.11/site-packages (from jinja2>=3.0.3->jupy
terlab->qc-grader@ git+[Link]
[Link]->qc-grader[jupyter,qiskit]@ git+[Link]
mmunity/[Link]) (3.0.2)
Requirement already satisfied: attrs>=22.2.0 in /opt/conda/lib/python3.11/
site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->jupy
terlab->qc-grader@ git+[Link]
[Link]->qc-grader[jupyter,qiskit]@ git+[Link]
mmunity/[Link]) (23.2.0)
Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /op
t/conda/lib/python3.11/site-packages (from jsonschema>=4.18.0->jupyterlab-
server<3,>=2.27.1->jupyterlab->qc-grader@ git+[Link]
mmunity/[Link]->qc-grader[jupyter,qiskit]@ git+http
s://[Link]/qiskit-community/[Link]) (2023.12.1)
Requirement already satisfied: referencing>=0.28.4 in /opt/conda/lib/pytho
n3.11/site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1
->jupyterlab->qc-grader@ git+[Link]
[Link]->qc-grader[jupyter,qiskit]@ git+[Link]
kit-community/[Link]) (0.35.1)
Requirement already satisfied: rpds-py>=0.7.1 in /opt/conda/lib/python3.1
1/site-packages (from jsonschema>=4.18.0->jupyterlab-server<3,>=2.27.1->ju
pyterlab->qc-grader@ git+[Link]
[Link]->qc-grader[jupyter,qiskit]@ git+[Link]
community/[Link]) (0.18.1)
Requirement already satisfied: python-json-logger>=2.0.4 in /opt/conda/li
b/python3.11/site-packages (from jupyter-events>=0.9.0->jupyter-server<3,>
=2.4.0->jupyterlab->qc-grader@ git+[Link]
[Link]->qc-grader[jupyter,qiskit]@ git+[Link]
om/qiskit-community/[Link]) (2.0.7)
Requirement already satisfied: pyyaml>=5.3 in /opt/conda/lib/python3.11/si
te-packages (from jupyter-events>=0.9.0->jupyter-server<3,>=2.4.0->jupyter
lab->qc-grader@ git+[Link]
[Link] 12/28
09/07/2025, 13:01 lab0
[Link]->qc-grader[jupyter,qiskit]@ git+[Link]
nity/[Link]) (6.0.1)
Requirement already satisfied: rfc3339-validator in /opt/conda/lib/python
3.11/site-packages (from jupyter-events>=0.9.0->jupyter-server<3,>=2.4.0->
jupyterlab->qc-grader@ git+[Link]
[Link]->qc-grader[jupyter,qiskit]@ git+[Link]
t-community/[Link]) (0.1.4)
Requirement already satisfied: rfc3986-validator>=0.1.1 in /opt/conda/lib/
python3.11/site-packages (from jupyter-events>=0.9.0->jupyter-server<3,>=
2.4.0->jupyterlab->qc-grader@ git+[Link]
[Link]->qc-grader[jupyter,qiskit]@ git+[Link]
m/qiskit-community/[Link]) (0.1.1)
Requirement already satisfied: fqdn in /opt/conda/lib/python3.11/site-pack
ages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.9.0->jupyt
er-server<3,>=2.4.0->jupyterlab->qc-grader@ git+[Link]
community/[Link]->qc-grader[jupyter,qiskit]@ git+htt
ps://[Link]/qiskit-community/[Link]) (1.5.1)
Requirement already satisfied: isoduration in /opt/conda/lib/python3.11/si
te-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.9.0
->jupyter-server<3,>=2.4.0->jupyterlab->qc-grader@ git+[Link]
qiskit-community/[Link]->qc-grader[jupyter,qiskit]@
git+[Link] (20.
11.0)
Requirement already satisfied: jsonpointer>1.13 in /opt/conda/lib/python3.
11/site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=
0.9.0->jupyter-server<3,>=2.4.0->jupyterlab->qc-grader@ git+[Link]
[Link]/qiskit-community/[Link]->qc-grader[jupyter,qis
kit]@ git+[Link]
t) (2.4)
Requirement already satisfied: uri-template in /opt/conda/lib/python3.11/s
ite-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=0.9.
0->jupyter-server<3,>=2.4.0->jupyterlab->qc-grader@ git+[Link]
m/qiskit-community/[Link]->qc-grader[jupyter,qiskit]
@ git+[Link]
(1.3.0)
Requirement already satisfied: webcolors>=1.11 in /opt/conda/lib/python3.1
1/site-packages (from jsonschema[format-nongpl]>=4.18.0->jupyter-events>=
0.9.0->jupyter-server<3,>=2.4.0->jupyterlab->qc-grader@ git+[Link]
[Link]/qiskit-community/[Link]->qc-grader[jupyter,qis
kit]@ git+[Link]
t) (1.13)
Requirement already satisfied: beautifulsoup4 in /opt/conda/lib/python3.1
1/site-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->jupyterl
ab->qc-grader@ git+[Link]
[Link]->qc-grader[jupyter,qiskit]@ git+[Link]
ity/[Link]) (4.12.3)
Requirement already satisfied: bleach!=5.0.0 in /opt/conda/lib/python3.11/
site-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->jupyterlab
->qc-grader@ git+[Link]
[Link]->qc-grader[jupyter,qiskit]@ git+[Link]
y/[Link]) (6.1.0)
Requirement already satisfied: defusedxml in /opt/conda/lib/python3.11/sit
e-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->jupyterlab->q
c-grader@ git+[Link]
[Link]->qc-grader[jupyter,qiskit]@ git+[Link]
[Link]) (0.7.1)
Requirement already satisfied: jupyterlab-pygments in /opt/conda/lib/pytho
n3.11/site-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->jupy
terlab->qc-grader@ git+[Link]
[Link]->qc-grader[jupyter,qiskit]@ git+[Link]
[Link] 13/28
09/07/2025, 13:01 lab0
mmunity/[Link]) (0.3.0)
Requirement already satisfied: mistune<4,>=2.0.3 in /opt/conda/lib/python
3.11/site-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->jupyt
erlab->qc-grader@ git+[Link]
[Link]->qc-grader[jupyter,qiskit]@ git+[Link]
munity/[Link]) (3.0.2)
Requirement already satisfied: nbclient>=0.5.0 in /opt/conda/lib/python3.1
1/site-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->jupyterl
ab->qc-grader@ git+[Link]
[Link]->qc-grader[jupyter,qiskit]@ git+[Link]
ity/[Link]) (0.10.0)
Requirement already satisfied: pandocfilters>=1.4.1 in /opt/conda/lib/pyth
on3.11/site-packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->jup
yterlab->qc-grader@ git+[Link]
[Link]->qc-grader[jupyter,qiskit]@ git+[Link]
ommunity/[Link]) (1.5.0)
Requirement already satisfied: tinycss2 in /opt/conda/lib/python3.11/site-
packages (from nbconvert>=6.4.4->jupyter-server<3,>=2.4.0->jupyterlab->qc-
grader@ git+[Link]
it->qc-grader[jupyter,qiskit]@ git+[Link]
[Link]) (1.3.0)
Requirement already satisfied: webencodings in /opt/conda/lib/python3.11/s
ite-packages (from bleach!=5.0.0->nbconvert>=6.4.4->jupyter-server<3,>=2.
4.0->jupyterlab->qc-grader@ git+[Link]
[Link]->qc-grader[jupyter,qiskit]@ git+[Link]
qiskit-community/[Link]) (0.5.1)
Requirement already satisfied: fastjsonschema>=2.15 in /opt/conda/lib/pyth
on3.11/site-packages (from nbformat>=5.3.0->jupyter-server<3,>=2.4.0->jupy
terlab->qc-grader@ git+[Link]
[Link]->qc-grader[jupyter,qiskit]@ git+[Link]
mmunity/[Link]) (2.19.1)
Requirement already satisfied: cffi>=1.0.1 in /opt/.qbraid/environments/qg
ss_000000/pyenv/lib/python3.11/site-packages (from argon2-cffi-bindings->a
rgon2-cffi>=21.1->jupyter-server<3,>=2.4.0->jupyterlab->qc-grader@ git+htt
ps://[Link]/qiskit-community/[Link]->qc-grader[j
upyter,qiskit]@ git+[Link]
[Link]) (1.17.1)
Requirement already satisfied: pycparser in /opt/.qbraid/environments/qgss
_000000/pyenv/lib/python3.11/site-packages (from cffi>=1.0.1->argon2-cffi-
bindings->argon2-cffi>=21.1->jupyter-server<3,>=2.4.0->jupyterlab->qc-grad
er@ git+[Link]
qc-grader[jupyter,qiskit]@ git+[Link]
-[Link]) (2.22)
Requirement already satisfied: soupsieve>1.2 in /opt/conda/lib/python3.11/
site-packages (from beautifulsoup4->nbconvert>=6.4.4->jupyter-server<3,>=
2.4.0->jupyterlab->qc-grader@ git+[Link]
[Link]->qc-grader[jupyter,qiskit]@ git+[Link]
m/qiskit-community/[Link]) (2.5)
Requirement already satisfied: arrow>=0.15.0 in /opt/conda/lib/python3.11/
site-packages (from isoduration->jsonschema[format-nongpl]>=4.18.0->jupyte
r-events>=0.9.0->jupyter-server<3,>=2.4.0->jupyterlab->qc-grader@ git+http
s://[Link]/qiskit-community/[Link]->qc-grader[ju
pyter,qiskit]@ git+[Link]
[Link]) (1.3.0)
Requirement already satisfied: types-python-dateutil>=2.8.10 in /opt/cond
a/lib/python3.11/site-packages (from arrow>=0.15.0->isoduration->jsonschem
a[format-nongpl]>=4.18.0->jupyter-events>=0.9.0->jupyter-server<3,>=2.4.0-
>jupyterlab->qc-grader@ git+[Link]
[Link]->qc-grader[jupyter,qiskit]@ git+[Link]
it-community/[Link]) (2.9.0.20240316)
[Link] 14/28
09/07/2025, 13:01 lab0
[Link] 15/28
09/07/2025, 13:01 lab0
You should have Qiskit version >=2.0.0 and Grader >=0.22.9 . If you see a
lower version, you need to restart your kernel and reinstall the grader.
Troubleshooting
If the previous cell raised an error, you can opt to install Qiskit in a virtual
environment (two suggested methods follow). If you have no errors, you can ignore
this cell and proceed to the next one.
[Link] 16/28
09/07/2025, 13:01 lab0
See this guide for more details on how to set up your IBM Cloud® account.
⚠️ Note: Treat your API key as you would a secure password. See the Cloud
setup guide for more information about using your API key in both secure and
untrusted environments.
In [7]: # Save your API key to track your progress and have access to the quantum
your_api_key = "E17dzCRPbOcoyp1F7XI5VuCunMSPSWxfbZRQ1614LgDB"
your_crn = "crn:v1:bluemix:public:quantum-computing:us-east:a/b644753467c
QiskitRuntimeService.save_account(
channel="ibm_quantum_platform",
token=your_api_key,
instance=your_crn,
name="qgss-2025",
overwrite=True
)
Imports
In [9]: import [Link] as plt
Sanity check
[Link] 17/28
09/07/2025, 13:01 lab0
Let's now create a very simple quantum circuit to check that everything is working
as expected.
Out[10]:
The output you see represents a quantum circuit that produces a Bell state:
$$|Bell\rangle=\frac{|00\rangle+|11\rangle}{\sqrt{2}}$$
Step 1. Map
The Greenberger–Horne–Zeilinger (GHZ) state is the extension to three (or more)
qubits to the maximally entangled state characteristic of the Bell state depicted
[Link] 18/28
09/07/2025, 13:01 lab0
$$ |GHZ\rangle = \frac{|000\rangle+|111\rangle}{\sqrt{2}}. $$
One of the interesting features of the GHZ state is that there are different and
equivalent ways to build it using a quantum circuit. In Exercise 1 you will do it in one
of the most common ways.
In this exercise, you will design a GHZ state following the steps below:
Out[11]:
🎉
Submitting your answer. Please wait...
Congratulations ! Your answer is correct and has been submitted.
[Link] 19/28
09/07/2025, 13:01 lab0
Step 2. Optimize
Well done designing the circuit!
In this case, the circuit is very shallow, and it is not possible to further simplify it or
reduce the required number of gates that are needed to build the GHZ state.
However, there are other scenarios in which optimizing the circuit is key.
There may be situations where you face restrictions in how your quantum circuit
can be designed. For example, when running circuits on quantum hardware, you
might find connectivity constraints between qubits. This means that some qubits
may not be physically connected, so you will need to think of a smart way to
implement gates that produce the desired quantum state. Luckily for us, this is
where the Qiskit pass manager comes to the rescue! You can provide the desired
circuit along with the device's constraints to the pass manager and it will transpile
the circuit and handle the optimization for you.
Let us consider, for the GHZ state, a situation in which we are limited to interactions
only between qubits 0 and 1 and qubits 0 and 2, but not between qubits 1 and 2.
We can introduce these constraints to the paass manager using the
generate_preset_pass_manager function.
In this second exercise you are asked to transpile the previous GHZ state with
the mentioned connectivity constraints:
qc_transpiled.draw("mpl")
[Link] 20/28
09/07/2025, 13:01 lab0
Out[13]:
🎉
Submitting your answer. Please wait...
Congratulations ! Your answer is correct and has been submitted.
Step 3. Execute
The next step is exciting - we are going to run the quantum circuit using Qiskit
Runtime!
1. Sampler samples the output register from the execution of one or more
quantum circuits. Its output is counts on per-shot measurements.
2. Estimator computes the expectation value of one or more observables with
respect to the states generated by the quantum circuit. Its output consist of the
expectation values along with their standard errors.
First, we execute our circuit using the Sampler, then save the results as the variable
results_sampler .
Now, we run our circuit using the Estimator primitive, then save the results as the
variable results_estimator .
[Link] 21/28
09/07/2025, 13:01 lab0
Next is the final step of Qiskit patterns, where we will visualize our results.
Step 4. Post-process
Finally, the last step of Qiskit patterns is to post-process the information we have
gathered from the execution of the quantum circuit.
First we visualize the results from the Sampler. We can visualize the counts with a
histogram plot and quickly see how the two possible quantum states are measured
with a probability of 50%.
[Link] 22/28
09/07/2025, 13:01 lab0
[Link] 23/28
09/07/2025, 13:01 lab0
We see that the observables $ZZI$ and $III$ have an expectation value of 1, since
$ZZI$ introduces two minus signs that cancel out, and $III$ acts as the identity,
leaving the GHZ state unchanged. The rest of the observables have an expectation
value of 0, since their $Z$ operators introduce an odd number of minus signs, or
the $X$ operators flip a number of qubits that make the overlapping states
orthogonal.
Congratulations!
You have successfully completed Lab 0 and are now set to start the Quantum
Global Summer School 2025!
In this lab you have successfully set up your machine to execute Qiskit v2.x, and
saved your IBM Cloud token to track your progress during the Summer School and
execute quantum circuits in real hardware. You have also learned about Qiskit
patterns by implementing a specific example of the GHZ circuit and designing an
optimized quantum circuit. Finally, you have executed a GHZ circuit on a quantum
simulator, and observed how the measurements of the Sampler are in good
agreement with the theoretical probabilities of measuring the states $|000\rangle$
and $|111\rangle$ with 50% probability.
You can check your progress with the labs using the cell below:
[Link] 24/28
09/07/2025, 13:01 lab0
✅
Lab 0: 2/2 exercises completed (100%)
1428 participants have completed this lab
✅
Lab 1: 9/9 exercises completed (100%)
536 participants have completed this lab
✅
Lab 2: 0/7 exercises completed (0%)
1 participants have completed this lab
✅
Lab 3: 0/5 exercises completed (0%)
0 participants have completed this lab
✅
Lab 4: 0/6 exercises completed (0%)
0 participants have completed this lab
In [26]: # Define the service. This allows you to access IBM QPUs.
service = QiskitRuntimeService(name="qgss-2025")
# Get a backend
backend = service.least_busy(operational=True, simulator=False)
print(f"We are using the {[Link]} quantum computer")
The next call illustrates how easy it is to execute quantum circuits on hardware with
QiskitRuntimeService . Once we have selected the backend in the cell above,
we can simply copy and paste the same lines of code that we wrote for the Sampler
simulator, including post-processing and visualization.
# Step 2. Optimize
pm =
qc_transpiled =
qc = QuantumCircuit(3, 3)
qc.h(0)
[Link](0, 1)
[Link] 25/28
09/07/2025, 13:01 lab0
[Link](0, 2)
[Link]([0, 1, 2], [0, 1, 2])
# Step 4 & 5: Submit Job and Wait for Completion (New Method)
# Define options, including the optimization level you had before
options = Options(optimization_level=3)
# [Link]() will block until the job is complete and get the resul
result = [Link]()
print("Job finished!")
[Link] 26/28
09/07/2025, 13:01 lab0
File /opt/.qbraid/environments/qgss_000000/pyenv/lib/python3.11/site-packa
ges/pydantic/_internal/_dataclasses.py:123, in complete_dataclass.<locals
>.__init__(__dataclass_self__, *args, **kwargs)
121 __tracebackhide__ = True
122 s = __dataclass_self__
--> 123 s.__pydantic_validator__.validate_python(ArgsKwargs(args, kwargs),
self_instance=s)
Please note that the open plan only includes 10 minutes time on the real
hardware, and since we will need these minutes in the later labs, please make
sure to save most of your time for these labs.
In [ ]: # Step 3. Execute
sampler =
job =
[Link] 27/28
09/07/2025, 13:01 lab0
In [ ]: # Step 4. Post-process
results =
counts_list =
### YOUR CODE FINISHES HERE ###
print(f"Outcomes : {counts_list}")
plot_histogram(counts_list,title='GHZ state')
Awesome!
You have managed to run a circuit on a real quantum computer, and the results are
very good! The most repeated states are $|000\rangle$ and $|111\rangle$, and
they accumulate a probability just below 50%. However, in this case we observe
that, due to noise from the quantum computer, some quantum states are
measured, even if the theoretical probability of measuring is 0. This is indeed
expected, and we will see in the next labs how we can try to correct or mitigate the
errors that are introduced by the noisy nature of quantum computers.
Additional information
Created by: Jorge Martínez de Lejarza
Version: 1.0.0
[Link] 28/28
Generating a three-qubit GHZ state using Qiskit involves the following steps: 1. Map the circuit by initializing the qubits into a superposition using a Hadamard gate on the first qubit . 2. Optimize the circuit, although in the case of the GHZ circuit, it is already shallow and cannot be further simplified . 3. Execute the circuit using Qiskit Runtime, where the Sampler samples the output register from the execution, producing counts on per-shot measurements . 4. Post-process the results to analyze the measurements from the Sampler . A bonus step is to execute the circuit on real hardware to observe how noise affects the outputs .
A major challenge in optimizing quantum circuits for the GHZ state lies in the connectivity constraints of qubits on physical hardware. For instance, if certain qubits are not directly connected, implementing gates to produce the desired quantum state becomes challenging. The Qiskit pass manager assists in overcoming these challenges by allowing for the description of connectivity constraints, such as interactions only between specific qubit pairs. It then transpiles the circuit to adhere to these constraints, optimizing its execution on the given hardware .
The least_busy method is used to select the quantum computer with the least current load from IBM's available devices, ensuring faster execution of quantum circuits. This is important during the Qiskit Global Summer School as it helps participants quickly run their experiments on actual hardware, mitigating wait times and optimizing resource utilization .
Executing a GHZ circuit on actual quantum hardware differs from running it on a simulator primarily due to the presence of noise in real hardware, which affects measurement outcomes. While simulators can follow theoretical models with precise outcomes, such as 50% probability of measuring states |000⟩ and |111⟩, real hardware introduces inaccuracies and discrepancies due to environmental and hardware-specific noise, leading to deviations from the expected probabilities .
The Qiskit Global Summer School 2025 integrates theoretical knowledge with practical exercises by combining lectures with hands-on labs. These labs are designed as Jupyter notebooks that complement the lectures, providing direct applications of theoretical concepts through guided exercises and challenges. This approach ensures that participants not only understand quantum computing theories but also gain practical coding experience with Qiskit, thereby enhancing their implementation skills in quantum programming .
Qiskit Runtime simplifies the execution of quantum circuits by providing primitives like the Sampler and Estimator, which facilitate sampling and computing expectation values efficiently. These tools reduce the complexity of handling outputs and enhance execution speed through streamlined processes that take advantage of cloud-based quantum computing resources .
Installing the correct Python version, specifically python>=3.10, is crucial because it ensures compatibility with the latest Qiskit version used in the labs. An incompatible Python version could lead to errors and inconsistencies during execution. Participants are advised to upgrade their Python environment if necessary to meet this prerequisite .
Setting up the IBM Quantum account involves saving the IBM Cloud token which is critical for tracking progress and executing quantum circuits on real hardware. This setup is necessary as it allows participants to access IBM's quantum devices, perform calculations, and validate their results with real-world quantum computers, thereby enhancing the learning experience .
Participants are recommended to use an online environment if they are on Windows because Lab 3 of the Qiskit Global Summer School cannot be run using Windows. This limitation necessitates the use of alternative environments to ensure all labs can be completed without technical interruptions .
The guided lab exercises significantly benefit participants by offering a structured learning environment that complements theoretical lectures. This method encourages active learning and problem-solving, providing practical experience through coding challenges. As learners engage with Jupyter notebooks and real quantum programming tasks in Qiskit, they are better positioned to understand complex concepts and develop skills applicable to both simulated and hardware-based quantum computing scenarios .