Skip to main content
IBM Quantum Platform

Configurazione per l'utilizzo della piattaforma IBM Quantum con API REST

È possibile accedere ai processori quantistici con le API REST, che consentono di lavorare con le QPU utilizzando qualsiasi linguaggio o framework di programmazione.

1. Ottieni l'accesso

  1. Se non disponi ancora di un account utente, creane uno alla pagina di accesso IBM Quantum.
  2. Crea una chiave API (chiamata anche token) sulla dashboard. Si noti che la stessa chiave API può essere utilizzata per entrambe le regioni.
  3. Generare un token bearer IBM Cloud Identity and Access Management (IAM). È un token di breve durata utilizzato per autenticare le richieste all'API REST. Per generarne uno, chiamare l' API IAM Identity Services come mostrato nella seguente richiesta di esempio:
curl -X POST 'https://iam.cloud.ibm.com/identity/token' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d 'grant_type=urn:ibm:params:oauth:grant-type:apikey&apikey=MY_APIKEY'

Risposta attesa

{
   "access_token": "eyJhbGciOiJIUz......sgrKIi8hdFs",
   "refresh_token": "SPrXw5tBE3......KBQ+luWQVY=",
   "token_type": "Bearer",
   "expires_in": 3600,
   "expiration": 1473188353
}

2. Scegli un metodo di autenticazione

Scegliere il metodo di autenticazione appropriato, a seconda dell'ambiente di lavoro:

Creare una variabile di ambiente (ambiente affidabile)

  1. Per impostare la variabile d'ambiente IQP_API_TOKEN nel vostro sistema, potete aggiungere la seguente riga al vostro profilo di shell (ad esempio,.bashrc o.zshrc) o impostarla direttamente nel vostro terminale:

    export IQP_API_TOKEN=<your-API_KEY> 
    # Use the 44-character API_KEY you created and saved 
    # from the IBM Quantum Platform Home dashboard

    Quando si richiama la variabile d'ambiente nel codice, includere import os, come in questo esempio:

    import os
    api_token = os.environ['IQP_API_TOKEN']

    Si noti che quando si crea una variabile d'ambiente, la chiave API è ancora memorizzata localmente in testo normale e deve essere protetta.

  2. Autentica le richieste all'API REST includendo l' CRN e e il token bearer nelle intestazioni della richiesta.

curl -X 'GET' \
   'https://quantum.cloud.ibm.com/api/v1/usage' \
   '-H accept: application/json' \
   '-H authorization: Bearer <BEARER_TOKEN>' \
   '-H Service-CRN: <INSTANCE_CRN>'

3. Facoltativo: configurare il firewall

Se necessario, utilizzare queste informazioni per abilitare l'accesso agli endpoint API di IBM Quantum.


Passi successivi

Suggerimenti
Questa pagina è stata utile?
Segnala un bug, un errore di battitura o richiedi contenuti su GitHub.