stern-gerlach-measurements-with-qiskit: "Step 3: Run the job" uses a sampler whose session is already closed
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 88/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- jupyter-notebook, python
- Domain
- documentation, quantum-computing
Research direction
Open the linked Stern-Gerlach measurements with Qiskit notebook and find the “Step 3: Run the job” cell that reuses the closed sampler. Start by comparing it with the earlier cells that create a sampler in a session. Update the cell to use a fresh sampler in job mode or a new session, then confirm the job runs on real hardware.
Written by the indexing model from the issue text.
Description
In Quantum mechanics → Stern-Gerlach measurements with Qiskit (notebook), earlier cells create the sampler inside a session and then close it:
with Session(backend=backend) as session:
sampler = Sampler(mode=session)
dist = sampler.run([qc_ibm], shots=num_shots).result()
session.close()
The later "Step 3: Run the job" cell reuses that sampler:
num_shots = 1000
dist = sampler.run([qc_ibm], shots=num_shots).result()
The session is closed by then, so this fails on real hardware:
IBMRuntimeError: 'The session is closed.'
Suggested fix: create a new sampler in that cell. Either use a new session, as in the earlier cells:
with Session(backend=backend) as session:
sampler = Sampler(mode=session)
dist = sampler.run([qc_ibm], shots=num_shots).result()
or use job mode, which also works on the Open Plan:
sampler = Sampler(mode=backend)
dist = sampler.run([qc_ibm], shots=num_shots).result()
(The extra session.close() after a with Session(...) block is redundant: the context manager already closes the session.)
Found with qiskit 2.5 / qiskit-ibm-runtime 0.50.
- Dominant language
- Jupyter Notebook
- Stars
- 110
- Forks
- 238
- Avg merge
- 3d 10h
- Merged PRs (30d)
- 82
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Qiskit/documentation
-
content 📄 needs triage 🤔
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Qiskit/documentation#5842 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Qiskit/documentation#5838 ·
Maintainers usually reply within 1 day
-
Fix execution spanOpencontent 📄 needs triage 🤔
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Qiskit/documentation#5837 ·
Maintainers usually reply within 1 day
-
Document that shot order is execution order in the samplerPossibly taken @Ashiq1w claimed this 2 days ago. Opencontent 📄
Difficulty 1/5 1-3 hours Newbie friendliness 68/100
Qiskit/documentation#5808 · 1 comment ·
Maintainers usually reply within 1 day
-
Document resource unit fields in service instance API guidePossibly taken @beckykd claimed this 2 days ago. Opencontent 📄
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Qiskit/documentation#5790 · 1 comment · 1 assignee ·
Maintainers usually reply within 1 day
All issues in Qiskit/documentation
Similar issues
-
AGENTS.md: library list omits checkpoint-conformance and describes sdk-js as a live JS SDKPossibly taken @Naeemeh146 claimed this today. Openexternal
Difficulty 1/5 1-3 hours Newbie friendliness 82/100
langchain-ai/langgraph#9388 · 1 comment ·
Maintainers usually reply within 1 day
-
documentation help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
piskyRpapalo/preceptoros-web#231 ·
Maintainers usually reply within 1 day
-
area: assistant area: connections documentation
Difficulty 1/5 Under an hour Newbie friendliness 91/100
Maintainers usually reply within 1 day
-
lane:gh-3
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
LLM-4-People/bridlewise-testing#100 ·
Maintainers usually reply within 1 day
-
type/bug type/docs type/enhancement
Difficulty 1/5 Under an hour Newbie friendliness 86/100
Redo-San/RedoSan-Authenticity#574 ·
Maintainers usually reply within 1 day