Skip to content
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

Add tests for code in serverless-manage-resources.ipynb #1960

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

frankharkins
Copy link
Member

@frankharkins frankharkins commented Sep 16, 2024

This PR fixes the code in serverless-manage-resources.ipynb and adds tests to check it runs correctly.

Link to preview: https://qiskit.github.io/documentation/pr-1960/guides/serverless-manage-resources

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:

Unlikely, but we could have a problem if CI runs two versions of this notebook at the same time. Setting a random ID solves that
Copy link
Collaborator

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

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

Thanks for working on this!

@@ -22,22 +22,53 @@
},
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 line 20 should be transpile_remote.py. /guides/serverless-first-program#get-program-arguments also uses the wrong file name

docs/guides/serverless-manage-resources.ipynb Outdated Show resolved Hide resolved
" title=TITLE,\n",
" entrypoint=\"transpile_remote.py\",\n",
" working_dir=\"./source_files/\",\n",
"\tdependencies=[\"qiskit-aer==0.14.1\"],\n",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this hardcoded? I'm not very familiar with serverless

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's just to demonstrate that you can set dependencies for your serverless code

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm, I wonder if we can remove it. I'm worried about the dep falling out of sync. Think about how many people copy and paste code, or even Qiskit Code Assistant learning from our docs. We don't want them installing an old version.

Copy link
Member Author

@frankharkins frankharkins Sep 18, 2024

Choose a reason for hiding this comment

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

lol I'm sorry; I didn't realise this was part of the testing code I added. I copied it from https://docs.quantum.ibm.com/guides/serverless-first-program. I'll remove the dep.

Think about how many people copy and paste code

👀

"source": [
"```python\n",
"# source_files/transpile_parallel.py\n",
"%%writefile ./source_files/transpile_parallel.py\n",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you know why we change file names here?

Copy link
Member Author

@frankharkins frankharkins Sep 18, 2024

Choose a reason for hiding this comment

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

Not really, I guess they could both be transpile_remote

EDIT: Actually I think it's helpful to make it clear they're different programs

Comment on lines 545 to 547
"from qiskit.circuit.random import random_circuit\n",
"from qiskit_serverless import IBMServerlessClient, QiskitFunction\n",
"import time\n",
Copy link
Collaborator

Choose a reason for hiding this comment

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

It'd probably be good to DRY this code. Can you define a hidden helper function at the top that gets called by both?

@frankharkins
Copy link
Member Author

Converting to draft as I'm struggling to work around a limitation. The problem is that IBMServerlessClient() (without API token) fails on the server. I thought it'd work since QiskitRuntimeService() works ok, but it turns out that's because it can get user details from an environment variable (which is set on the server), whereas serverless can only use a config file (set locally but not on the server). To get this to work, we'd need to inject our API token into the code at somepoint, and I don't think we can do that without adding more logic to nb-tester. I think the best course of action is to wait until this is possible before picking this PR back up.

github-merge-queue bot pushed a commit that referenced this pull request Sep 24, 2024
…rces" (#2015)

This makes the code examples runnable. Unfortunately we can't add tests
just yet (will happen in #1960), but this does mean users will be able
to run all the code on the page.

I've removed the section on automatic QPU selection after discussion
with the serverless team. This feature is being developed but isn't
ready just yet. We'll add the section back in when it's ready.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants