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

IBM quantum API key solution needed #26

Open
laserlab opened this issue Sep 20, 2024 · 5 comments
Open

IBM quantum API key solution needed #26

laserlab opened this issue Sep 20, 2024 · 5 comments
Labels
help wanted Extra attention is needed

Comments

@laserlab
Copy link
Contributor

Check ubsuny/compphys/qiskit for examples how to generate github secrets to use the IBM quantum computer

Write documentation what an API key is and why publishing it is an issue. See e.g. here: https://cloud.ibm.com/apidocs/quantum-computing
copy necessary files and write a documentation how to use the IBM quantum API key without publishing it.

@laserlab laserlab added the help wanted Extra attention is needed label Sep 20, 2024
@laserlab laserlab added this to the Homework due date milestone Sep 20, 2024
@iglesias-cardinale
Copy link
Contributor

I wrote some documentation in a markdown cell in my own Jupyter Notebook file. I'm not sure how to connect it to this issue, but I'll copy and paste it here.

Make sure your IBM Quantum API is activated

In order to run code on IBM Quantum, we need to connect our code to the IBM Quantum service. This can be accomplished by activating your IBM Quantum API token. In lay terms, an API, or Application Programming Interface, is a bridge that connects two programs. It allows one program to request functions/data from another. In our present case, we want to connect our code written with qiskit to the IBM Quantum systems so that we can implement Bells Inequality on an actual quantum computer.

This can be done by including the line

"QiskitRuntimeService.save_account(token="YOUR_API_TOKEN", channel="ibm_quantum")

after the

from qiskit_ibm_runtime import QiskitRuntimeService

statement. If the code you're working on is exclusively private and not published anywhere, you can directly copy and paste your token into this line of code. If, however, the code you're using is public, do not do this. Instead, you can use something like Codespace Secrets to initialize your service. You can do that using the following steps (which I took directly from https://github.com/ubsuny/CompPhys/tree/main/qiskit):

  1. In the upper-right corner of any page on GitHub, click your profile photo, then click Settings.

  2. In the "Code, planning, and automation" section of the sidebar, click Codespaces.

  3. To the right of "Codespaces secrets", click New secret.

  4. Under "Name," type a name for your secret, use IBMQUANTUM.

  5. Under "Value", copy the API key from your IBM quantum profile.

  6. Select the "Repository access" drop-down menu, then click a repository you want to have access to the secret. Repeat for every repository you want to have access to the secret.

You can find your API token in the top right of the screen after by going to ibm.com/quantum and signing in. There's a button that allows you to copy the token to your clipboard.

This line only needs to be run once. It will update your local configuration file which holds all of your qiskit and IBM Quantum credentials. On windows the configuration file is usually located at: C:\Users\YourUsername.qiskit\qiskitrc. On Mac it's /home/YourUsername/.qiskit/qiskitrc.

Once the configuration file has been updated (i.e. you've run that line of code), you can simply use the line service = QiskitRuntimeService() to set up the connection between your code (qiskit in this case) and IBM Quantum's cloud services. This will work in any python file or github codespace you use.

@laserlab
Copy link
Contributor Author

laserlab commented Sep 20, 2024

That’s perfect, but to add it to the repository please use a pull request.

@p-pxmpo
Copy link
Contributor

p-pxmpo commented Sep 22, 2024

Once we've made the codespace secret do we just paste the name of the secret where it says "YOUR_API_TOKEN" and run it? @iglesias-cardinale

@laserlab
Copy link
Contributor Author

@p-pxmpo you might want to reference the original author @iglesias-cardinale so he gets a notification about your questions

@iglesias-cardinale
Copy link
Contributor

@p-pxmpo Yes, that's right. If you used the name "IBMQUANTUM" for your codespace secret, your line of code in your codespace should look like this:

QiskitRuntimeService.save_account(token="IBMQUANTUM", channel="ibm_quantum")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants