Main Content

quantum.backend.QuantumDeviceIBM class

Package: quantum.backend

Quantum device available through IBM

Since R2023b

Installation Required: This functionality requires MATLAB Support Package for Quantum Computing.

Description

A QuantumDeviceIBM object represents a specific quantum device that is available through IBM® Qiskit® Runtime Services. To work with remote devices and data using IBM Qiskit Runtime Services, you must first set up access following the steps in Run Quantum Circuit on Hardware Using IBM Qiskit Runtime Services.

The quantum.backend.QuantumDeviceIBM class is a handle class.

Creation

Description

example

dev = quantum.backend.QuantumDeviceIBM(deviceName) returns a representation of the specified quantum device. The deviceName input must uniquely define the device.

example

dev = quantum.backend.QuantumDeviceIBM(deviceName,Name=Value) specifies additional options using one or more name-value arguments.

  • You can specify the file name of the JSON file that contains your credentials for authentication with the Qiskit Runtime Services using quantum.backend.QuantumDeviceIBM(deviceName,FileName=filename).

  • You can specify the account name in the credentials file to use for authentication when connecting to the device using quantum.backend.QuantumDeviceIBM(deviceName,AccountName=accountname).

  • You can also specify whether to create tasks in a session using quantum.backend.QuantumDeviceIBM(deviceName,UseSession=tf).

Note

Saving and loading QuantumDeviceIBM objects in MATLAB® are not supported.

Input Arguments

expand all

Name of the quantum device, specified as a string scalar.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: s = quantum.backend.QuantumDeviceIBM("ibmq_qasm_simulator",FileName="myIBMconnection.json",AccountName="my_second_acc")

File name of the JSON file for authentication, specified as a string scalar. By default, the file name is "qiskit-ibm.json" that is located in your .qiskit folder in the home directory. Do not manually edit this "qiskit-ibm.json" file. Instead, create a new JSON file with a different file name to specify your account credentials for authentication.

The JSON file must contain strings that represent scalar structures with the following three required fields.

  • "channel" — the channel for your account, which must be "ibm_quantum" or "ibm_cloud"

  • "instance" — the service instance for your account

  • "token" — the unique API token that is assigned to your account

To retrieve the information about these fields from your IBM account, see Set Up Access to IBM. In the JSON file, specify multiple sets of your account credentials by creating a structure with a given account name as the field name. For each of this account name, set its field value as a structure with the three required "channel", "instance", and "token" fields. For an example, see Specify JSON File and Account Name for Authentication.

Account name in the credentials file to use for authentication, specified as a string scalar. By default, the account name used is the first account listed in the JSON file for authentication.

Toggle to create a task as part of a session, specified as a logical 0 (false) or 1 (true). A session is useful for reducing the overall queue time when you run multiple tasks. Otherwise, a session does not provide any queue time benefit for a single task.

Properties

expand all

Name of the quantum device, returned as a string scalar.

Attributes:

GetAccess
public
SetAccess
private

Account name in the credentials file to use for authentication, returned as a string scalar.

Attributes:

GetAccess
public
SetAccess
private

Toggle to create a task in a session, returned as a logical 1 (true) or 0 (false).

Attributes:

GetAccess
public
SetAccess
private

Methods

expand all

Examples

collapse all

Connect to a remote quantum device through IBM Quantum by specifying the device name as "ibmq_qasm_simulator".

dev = quantum.backend.QuantumDeviceIBM("ibmq_qasm_simulator")
dev = 

  QuantumDeviceIBM with properties:

         Name: "ibmq_qasm_simulator"
  AccountName: "<my account name>"
   UseSession: 0

Create a task by running a quantum circuit on this device.

gates = [hGate(1); cxGate(1,2)];
c = quantumCircuit(gates);
task = run(c,dev)
task = 

  QuantumTaskIBM with properties:

         TaskID: "123abcd4efa5bcdef678"
      SessionID: <missing>
    AccountName: "<my account name>"
         Status: "queued"

After the task has finished, retrieve the measurement result of running the circuit.

m = fetchOutput(task)
m = 

  QuantumMeasurement with properties:

    MeasuredStates: [4×1 string]
            Counts: [4×1 double]
     Probabilities: [4×1 double]
         NumQubits: 2

Connect to a remote quantum device through IBM Quantum or IBM Cloud by using your credentials that are saved in a JSON file .

For example, you can create a JSON file with the following content, and save the file as my-IBM-credentials.json.

{
  "my_first_acc": {
    "channel": "ibm_quantum",
    "instance": "<My Service Instance>",
    "token": "<My IBM Quantum Token>"
  },
  "my_second_acc": {
    "channel": "ibm_cloud",
    "instance": "<My IBM Cloud CRN>",
    "token": "<My IBM Cloud API Token>"
  }
}

To create the JSON file programmatically in MATLAB, you can use jsonencode to convert structured MATLAB data to JSON-formatted text and use writelines to writes text to file. For example, the following code write the previous content to a JSON file.

accountname1 = "my_first_acc";
channel1 = "ibm_quantum";
instance1 = "<My Service Instance>";
token1 = "<My IBM Quantum Token>";

accountname2 = "my_second_acc";
channel2 = "ibm_cloud";
instance2 = "<My IBM Cloud CRN>";
token2 = "<My IBM Cloud API Token>";

credentials1 = struct("channel",channel1,"instance",instance1,"token",token1);
credentials2 = struct("channel",channel2,"instance",instance2,"token",token2);
filename = "my-IBM-credentials.json";
text = jsonencode(struct(accountname1,credentials1,accountname2,credentials2), ...
    PrettyPrint=true);
writelines(text,filename);

Next, connect to a remote quantum device through IBM Cloud by specifying the device name as "ibmq_qasm_simulator" using your second account in the my-IBM-credentials.json file.

dev = quantum.backend.QuantumDeviceIBM("ibmq_qasm_simulator", ...
    AccountName="my_second_acc",FileName="my-IBM-credentials.json")
dev = 

  QuantumDeviceIBM with properties:

         Name: "ibmq_qasm_simulator"
  AccountName: "my_second_acc"
   UseSession: 0

Version History

Introduced in R2023b

expand all