Main Content

quantum.backend.QuantumDeviceIBM Class

Namespace: 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 the 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. This syntax sets the Name property to deviceName.

example

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

  • You can specify the filename of a 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-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: dev = quantum.backend.QuantumDeviceIBM("ibmq_qasm_simulator",FileName="myIBMconnection.json",AccountName="my_second_acc")

Name of the JSON file for authentication, specified as a string scalar. By default, the filename is "qiskit-ibm.json", which 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 filename to specify your account credentials for authentication.

The JSON file must contain strings that represent scalar structures with these 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 for these fields from your IBM account, see Set Up Access to IBM.

In the JSON file, you can specify multiple sets of account credentials by creating a structure for each account. For each account structure, specify the field name as the account name and the 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 credentials file.

This argument sets the AccountName property.

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

This argument sets the UseSession property.

Properties

expand all

Name of the quantum device, returned as a string scalar. Specify the value of this property during creation of the object.

Attributes:

GetAccess
public
SetAccess
private

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

This property is set by the AccountName name-value argument.

Attributes:

GetAccess
public
SetAccess
private

Option to use a session for tasks, returned as a 1 or 0 of data type logical.

This property is set by the UseSession name-value argument.

Attributes:

GetAccess
public
SetAccess
private

Methods

expand all

Examples

collapse all

Connect to a remote quantum device through the IBM Qiskit Runtime Services 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 is 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®. Authenticate by specifying account credentials in a JSON file.

First, create a JSON file named my-IBM-credentials.json that contains your credentials.

{
  "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 write text to the file. For example, this code writes 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" and using the 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