주 콘텐츠로 건너뛰기

로그인 자격 증명 저장하기

신뢰할 수 있는 Python 환경(예: 개인 노트북이나 워크스테이션)에서 작업하는 경우, save_account() 메서드를 사용하여 자격 증명을 로컬에 저장한 다음, 이를 사용하여 서비스를 초기화할 수 있습니다.

참고 사항
  • 공용 컴퓨터나 신뢰할 수 없는 환경을 사용하고 있다면, 대신 신뢰할 수 없는 환경에서 서비스 초기화하기의 안내를 따르세요.
  • Qiskit 대신 REST API를 사용하여 연결하려면 이 안내를 따르세요.
  • 필요한 경우, IBM Quantum API 엔드포인트에 대한 접근을 허용하도록 방화벽을 구성하려면 이 정보를 사용하세요.

시작하기 전에​

  1. 활성 Python 환경에서 qiskit 및 qiskit-ibm-runtime 패키지가 설치된 상태로 작업 중인지 확인하세요.

  2. Python 가상 환경을 활성화하고 가상 환경에서 Python을 실행하세요.

  3. IBM Quantum Platform에 로그인하세요.

액세스 자격 증명 찾기​

  1. 헤더의 계정 전환기에서 올바른 계정과 리전이 선택되어 있는지 확인하세요.

  2. API 키를 찾으세요. 대시보드에서 API 키를 생성한 다음, 인증에 사용할 수 있도록 안전한 위치에 복사해 두세요. 동일한 API 키를 사용하여 모든 리전에 연결할 수 있습니다.

  3. 선택 사항: 인스턴스 페이지에서 사용하려는 인스턴스를 찾으세요. CRN 위에 마우스를 올린 후 아이콘을 클릭하여 복사한 다음, 인스턴스를 식별하는 데 사용할 수 있도록 안전한 위치에 저장하세요.

액세스 자격 증명 저장하기​

저장하려는 각 계정에 대해 적절한 코드를 한 번씩 실행하여 자격 증명을 저장하세요. 자격 증명을 저장한 후에는 IBM Quantum Compute Service 초기화하기의 단계를 따라 자격 증명을 불러오세요.

특정 인스턴스에 접근하는 자격 증명 저장하기:​

여러 인스턴스가 있고 Quantum Compute가 사용할 인스턴스를 쉽게 지정하려면, 인스턴스 CRN이 포함된 자격 증명을 저장하세요.

from qiskit_ibm_runtime import QiskitRuntimeService

QiskitRuntimeService.save_account(
# For `token`, use the 44-character API_KEY you created
# and saved from the IBM Quantum Platform Home dashboard:
token="<your-api-key>",
name="<account-name>", # Optional
instance="<IBM Cloud CRN or instance name>", # Optional
set_as_default=True, # Optional
overwrite=True, # Optional
)

자동 인스턴스 선택을 위한 자격 증명 저장하기:​

인스턴스 CRN을 제공하지 않고 이 자격 증명을 Quantum Compute에 전달하면, 지정된 옵션에 따라 적절한 인스턴스가 자동으로 선택됩니다.

from qiskit_ibm_runtime import QiskitRuntimeService

QiskitRuntimeService.save_account(
# For `token`, use the 44-character API_KEY you created
# and saved from the IBM Quantum Platform Home dashboard:
token="<your=api-key>",
name="<account-name>", # Optional
instance="<instance-to-use>", # Optional
plans_preference="<plan_types>", # Optional
region="<region>", # Optional
tags="<instance-tags>", # Optional
set_as_default=True, # Optional
overwrite=True, # Optional
)

Available options​

  • token: IBM Cloud API key. Your token is confidential. Do not share your token in public code.
  • instance: Optionally specify the instance to use through its IBM Cloud CRN or instance name.
  • plans_preference: Optionally set the types of plans to prioritize. This is ignored if the instance is specified. Available options are open, pay-as-you-go, flex, premium, and on-prem. Instances of a certain plan type are excluded if the plan name is not specified. For example, if [open] is passed in, only Open Plan instances are available. This is ignored if instance is specified.
  • region: Optionally set the region to use. Accepted values are us-east and eu-de. This is ignored if instance is specified.
  • tags: Optionally specify the instance's tags. Accepts a list of tag name strings. This is ignored if instance is specified.
  • name: Optionally name this set of account credentials.
  • set_as_default: Set the value to True to save these as your default credentials. If you save only one account, it is automatically set as the default.
  • overwrite: Set this value to True to update your default credentials.

Examples​

Example 1​

This example saves credentials for specific instances, which allow open and premium access. The open credentials are set as the default.

from qiskit_ibm_runtime import QiskitRuntimeService

QiskitRuntimeService.save_account(token="<API_TOKEN>",
instance="<CRN_for_premium_instance>",
name="premium")
QiskitRuntimeService.save_account(token="<API_TOKEN>",
instance="<CRN_for_open_instance>",
name="open", set_as_default=True)

예시 2​

이 예시는 자동 인스턴스 선택을 위한 자격 증명을 저장합니다. Quantum Compute는 계정에서 사용 가능한 EU 리전의 Premium 인스턴스만 확인합니다. 이 자격 증명이 새로운 기본값이 됩니다.

QiskitRuntimeService.save_account(
token="your-api-key",
set_as_default=True,
overwrite = True,

# Set instance "filters" instead of specifying the instance:
region="eu-de",
plans_preference=["premium"]
)

저장된 자격 증명 보기​

저장한 모든 자격 증명을 보려면 service.saved_accounts()를 실행하세요. 기본 자격 증명을 저장하고 이름을 지정하지 않은 경우 default-ibm-quantum-platform으로 이름이 지정됩니다. 기본 자격 증명에 이름을 지정한 경우 출력에서 "is_default_account": true를 확인할 수 있습니다.

고려 사항​

  • 여러 계정을 저장하는 경우 name 매개변수를 사용하여 구분하세요.

  • 자격 증명은 $HOME/.qiskit/qiskit-ibm.json에 저장됩니다. 이 파일을 수동으로 편집하지 마세요.

  • 자격 증명을 저장하지 않으면 새 세션을 시작할 때마다(IBM Quantum Compute Service를 인스턴스화할 때마다) 자격 증명을 지정해야 합니다.

  • 자격 증명을 수동으로 지정하면 저장된 계정은 사용되지 않습니다.

다음 단계