Skip to content

method get_job_by_id() missing in Qiskit Function Intro #2629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

abbycross
Copy link
Collaborator

Closes #2627 which was opened by @johannesgreiner. Johannes, can you provide more info on the fix please?

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@qiskit-bot
Copy link
Contributor

One or more of the following people are relevant to this code:

@johannesgreiner
Copy link
Contributor

So basically we'd want a few lines showing how to take an existing job_id and pass it to catalog.get_job_by_id() to load a job

@johannesgreiner
Copy link
Contributor

e.g. we can use the existing old_jobs = catalog.jobs() and take jobid=old_jobs[0].job_id to get job_by_id = catalog.get_job_by_id(jobid)

Co-authored-by: Johannes Greiner <[email protected]>
"metadata": {},
"source": [
"```\n",
"<Job | b1486233-3f59-4c19-b52d-6ad729b891cc>\n",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Eric-Arellano when there is no print statement, would the assert statement still give an output of any kind? (What is here is left over from when there was a print statement, so I need to update it)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the assert does not give output. Rather than hardcoding the output as markdown like this, it's better to update the code block to directly call print() and rely on nb-tester (i.e. run tox) to generate the output.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been running the notebook locally to get outputs. Should I be leaving them blank and leave it to tox to supply the outputs?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running it locally is fine too

This reverts commit 731bc4c.
"output_type": "execute_result"
}
],
"outputs": [],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR makes a bad revert

Suggested change
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"'d76b6abf-3a16-4dd6-a9ac-a7ffa780d2f7'"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],

"id": "af7fa72a-f272-43ff-800d-5ae37dd42b2b",
"metadata": {},
"source": [
"To retrieve a job's job_id by its position in the list, use `catalog.get_job_by_id()`:"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johannesgreiner this seems wrong to me to say "by its position in the list"? I think this should instead read as something like:

If you already have the job ID for a certain job, you can retrieve it with catalog.get_job_by_id():

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the job id the thing you're retrieving, and rather you're trying to find the nth job id in a list?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, get_job_by_id is when you already have a particular job ID (some string) and you are getting a job (I think https://docs.quantum.ibm.com/api/qiskit-ibm-runtime/runtime-job-v2?)

and rather you're trying to find the nth job id in a list?

That's what you're doing with old_jobs[0]: you're getting the nth job where old_jobs is all the jobs that have run, sorted by date.

Comment on lines +437 to +438
"# Print the job_id for the latest job.\n",
"print(latest_job)"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

job_by_id and latest_job should be the same thing. It might be clearer if we use job_by_id since that is what we are demoing

Suggested change
"# Print the job_id for the latest job.\n",
"print(latest_job)"
"# Print the job_id for this job.\n",
"print(job_by_id.job_id)"

Comment on lines +434 to +435
"# Verify that the job ID is the same using both retrieval methods.\n",
"assert job_by_id.job_id == latest_job.job_id\n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will actually be more clear. It demonstrates that the entire Job is the same, not just the ID.

Suggested change
"# Verify that the job ID is the same using both retrieval methods.\n",
"assert job_by_id.job_id == latest_job.job_id\n",
"# Verify that the job is the same using both retrieval methods.\n",
"assert job_by_id == latest_job\n",

Comment on lines +431 to +432
"latest_job = old_jobs[0]\n",
"job_by_id = catalog.get_job_by_id(latest_job.job_id)\n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"latest_job = old_jobs[0]\n",
"job_by_id = catalog.get_job_by_id(latest_job.job_id)\n",
"latest_job = old_jobs[0]\n",
"\n",
"# We can also get that same job with get_job_by_id\n",
"job_by_id = catalog.get_job_by_id(latest_job.job_id)\n",

"metadata": {},
"outputs": [],
"source": [
"# Get the most recent job that has been executed.\n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"# Get the most recent job that has been executed.\n",
"# First, get the most recent job that has been executed.\n",

@@ -132,6 +132,7 @@ ipywidgets
iqft
iswap
ISYM
jobid
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this should be in the dictionary, I think we should either say " job ID" in a sentence, or use code stying (jobid) if referring to the method / variable.

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

Successfully merging this pull request may close these issues.

method get_job_by_id() missing in Qiskit Function Intro
5 participants