Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

stern-gerlach-measurements-with-qiskit: "Step 3: Run the job" uses a sampler whose session is already closed

Open Beginner friendly
#5,839 0 comments 0 reactions 0 assignees View on GitHub

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

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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Qiskit/documentation

All issues in Qiskit/documentation

Similar issues

More Documentation issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.