Saving the Quantum Rings account locally

First, obtain the Quantum Rings Provider and then use the QuantumRingsLib.QuantumRingsProvider.save_account() API to save your account locally. You can use the following code example.

import QuantumRingsLib
from QuantumRingsLib import QuantumRingsProvider

# Acquire the Quantum Rings Provider and your preferred backend
provider = QuantumRingsProvider(token =<YOUR_TOKEN_HERE>, name=<YOUR_ACCOUNT_NAME_HERE>)
backend = provider.get_backend("scarlet_quantum_rings")
print("Account Name: ", provider.active_account()["name"], "\nMax Qubits: ", provider.active_account()["max_qubits"])

# Save the account locally.
provider.save_account(token =<YOUR_TOKEN_HERE>, name=<YOUR_ACCOUNT_NAME_HERE>)
print(provider.saved_accounts(False, "default"))

You can also directly create the configuration file and store your credentials, by following these steps:

If you are a Linux or a macOS user

mkdir ~/.config/quantumrings
echo -e '[default]\nemail = <YOUR_ACCOUNT_ID>\nkey = <YOUR_ACCESS_KEY>\nbackend = scarlet_quantum_rings' > ~/.config/quantumrings/quantumrings.conf

If you are a Windows user

  • Create a folder quantumrings under %APPDATA%. In that folder, create a file by name quantumrings.conf and store the following contents using notepad in that file.

[default]
email = <YOUR_ACCOUNT_ID>
key = <YOUR_ACCESS_KEY>
backend = "amber_quantum_rings"

If you are using the Quantum Rings toolkit for Qiskit

If you are using the Quantum Rings toolkit for Qiskit, you can use the save_account method in the QrRuntimeService class. The following code illustrates this step.

from quantumrings.toolkit.qiskit import QrRuntimeService

# Acquire the Quantum Rings runtime service
service = QrRuntimeService( token =<YOUR_TOKEN_HERE>, name=<YOUR_ACCOUNT_NAME_HERE> )

# Save the account to the local configuration file
service.save_account(token =<YOUR_TOKEN_HERE>, name=<YOUR_ACCOUNT_NAME_HERE>, backend = <BACKEND_NAME> )

Alternatively, use the OS Environment Variable

As an alternative method, you can store the account name and API key in the OS as environment variables. If you are a windows user, you can set the environment variables from the command line for your account as follows:

setx QR_TOKEN "<YOUR_TOKEN_HERE>"
setx QR_ACCOUNT "<YOUR_ACCOUNT_NAME_HERE>"

Next time you open the terminal, the changes are applied. You can also use the user interface by searching for Environment Variables from the search option in the task bar.

If you are a Linux user, add the following lines to the bottom of your ~/.bashrc script.

export QR_TOKEN="<YOUR_TOKEN_HERE>"
export QR_ACCOUNT="<YOUR_ACCOUNT_NAME_HERE>"

Once the environment variables are set, you can access them from Python.

import os
my_token = os.environ["QR_TOKEN"]
my_name = os.environ["QR_ACCOUNT"]
my_backend = "scarlet_quantum_rings"

from quantumrings.toolkit.qiskit import QrRuntimeService

qr_services = QrRuntimeService(name = my_name, token = my_token)
qr_backend = qr_services.backend(name = my_backend)