บันทึกข้อมูลการเข้าสู่ระบบของคุณ
หากคุณทำงานในสภาพแวดล้อม Python ที่เชื่อถือได้ (เช่น บนแล็ปท็อปส่วนตัวหรือเวิร์กสเตชัน) คุณสามารถใช้เมธอด save_account() เพื่อบันทึกข้อมูลการเข้าสู่ระบบของคุณในเครื่อง แล้วใช้เพื่อเริ่มต้นบริการได้
- หากคุณใช้คอมพิวเตอร์สาธารณะหรือสภาพแวดล้อมที่ไม่น่าเชื่อถืออื่น ๆ ให้ทำตามคำแนะนำใน เริ่มต้นบริการในสภาพแวดล้อมที่ไม่น่าเชื่อถือ แทน
- ทำตามคำแนะนำเหล่านี้ หากต้องการเชื่อมต่อโดยใช้ REST API แทนการใช้ Qiskit
- หากจำเป็น ใช้ข้อมูลนี้ เพื่อกำหนดค่า firewall ของคุณให้เปิดใช้งานการเข้าถึง IBM Quantum API endpoints
ก่อนเริ่มต้น
-
ตรวจสอบว่าคุณทำงานในสภาพแวดล้อม Python ที่ใช้งานอยู่พร้อมติดตั้ง
qiskitและqiskit-ibm-runtimepackages -
เปิดใช้งาน Python virtual environment แล้วรัน Python ในสภาพแวดล้อม virtual ของคุณ
-
ล็อกอินเข้าสู่ IBM Quantum Platform
ค้นหาข้อมูลการเข้าสู่ระบบของคุณ
-
ตรวจสอบว่าเลือกบัญชีและภูมิภาคที่ถูกต้องใน account switcher ในส่วนหัว
-
ค้นหา API key ของคุณ จากแดชบอร์ด สร้าง API key ของคุณ แล้วคัดลอกไปไว้ในที่ปลอดภัยเพื่อใช้สำหรับการยืนยันตัวตน โปรดสังเกตว่าคุณสามารถใช้ API key เดียวกันในการเชื่อมต่อกับทุกภูมิภาคได้
-
ตัวเลือก: ค้นหา instance ที่ต้องการใช้จากหน้า Instances วางเมาส์เหนือ CRN คลิกไอคอนเพื่อคัดลอก แล้วบันทึกในที่ปลอดภัยเพื่อใช้ระบุ instance
บันทึกข้อมูลการเข้าสู่ระบบของคุณ
บันทึกข้อมูลการเข้าสู่ระบบโดยรันโค้ดที่เหมาะสมครั้งละหนึ่งครั้งต่อบัญชีที่ต้องการบันทึก หลังจากบันทึกข้อมูลการเข้าสู่ระบบแล้ว โหลดข้อมูลเหล่านั้นโดยทำตามขั้นตอนใน Initialize IBM Quantum Compute Service
บันทึกข้อมูลการเข้าสู่ระบบที่เข้าถึง instance เฉพาะ:
หากคุณมีหลาย instances และต้องการบอก Quantum Compute ว่าจะใช้ instance ไหนได้ง่าย ๆ ให้บันทึกข้อมูลการเข้าสู่ระบบที่มี instance 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
)
บันทึกข้อมูลการเข้าสู่ระบบสำหรับการเลือก instance อัตโนมัติ:
หากคุณไม่ระบุ instance CRN และส่งข้อมูลการเข้าสู่ระบบเหล่านี้ไปยัง Quantum Compute ระบบจะเลือก instance ที่เหมาะสมให้คุณโดยอัตโนมัติตามตัวเลือกที่ระบุ
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 areopen,pay-as-you-go,flex,premium, andon-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 ifinstanceis specified.region: Optionally set the region to use. Accepted values areus-eastandeu-de. This is ignored ifinstanceis specified.tags: Optionally specify the instance's tags. Accepts a list of tag name strings. This is ignored ifinstanceis specified.name: Optionally name this set of account credentials.set_as_default: Set the value toTrueto save these as your default credentials. If you save only one account, it is automatically set as the default.overwrite: Set this value toTrueto 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
ตัวอย่างนี้บันทึกข้อมูลการเข้าสู่ระบบสำหรับการเลือก instance อัตโนมัติ Quantum Compute จะมองหาเฉพาะ premium instances ในภูมิภาค EU ที่บัญชีสามารถเข้าถึงได้เท่านั้น ข้อมูลการเข้าสู่ระบบเหล่านี้จะกลายเป็นค่าเริ่มต้นใหม่
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อย่าแก้ไขไฟล์นี้ด้วยตนเอง -
หากคุณไม่บันทึกข้อมูลการเข้าสู่ระบบ คุณต้องระบุข้อมูลเหล่านั้นทุกครั้งที่เริ่ม session ใหม่ (instantiate IBM Quantum Compute Service)
-
หากคุณระบุข้อมูลการเข้าสู่ระบบด้วยตนเอง ข้อมูลบัญชีที่บันทึกไว้จะไม่ถูกใช้
ขั้นตอนถัดไป
- Initialize IBM Quantum Compute Service ในสภาพแวดล้อม Python ที่เชื่อถือได้
- Initialize IBM Quantum Compute Service ในสภาพแวดล้อมที่ไม่น่าเชื่อถือ
- ดู QPUs ที่ใช้ได้ของคุณ
- กำหนดค่า Qiskit SDK ในเครื่อง
- ทำตามขั้นตอนใน Hello world เพื่อเขียนและรันโปรแกรมควอนตัม
- ตั้งค่าการใช้ IBM Quantum Platform ด้วย REST API
- ลอง tutorial