Skip to main contentIBM Quantum Documentation

QasmQobj

qiskit.qobj.QasmQobj(qobj_id=None, config=None, experiments=None, header=None) GitHub(opens in a new tab)

Bases: object(opens in a new tab)

An OpenQASM 2 Qobj.

Instantiate a new OpenQASM 2 Qobj Object.

Each OpenQASM 2 Qobj object is used to represent a single payload that will be passed to a Qiskit provider. It mirrors the Qobj the published Qobj specification(opens in a new tab) for OpenQASM experiments.

Parameters


Methods

from_dict

classmethod from_dict(data)

Create a new QASMQobj object from a dictionary.

Parameters

data (dict(opens in a new tab)) – A dictionary representing the QasmQobj to create. It will be in the same format as output by to_dict().

Returns

The QasmQobj from the input dictionary.

Return type

QasmQobj

to_dict

to_dict()

Return a dictionary format representation of the OpenQASM 2 Qobj.

Note this dict is not in the json wire format expected by IBM and Qobj specification because complex numbers are still of type complex. Also, this may contain native numpy arrays. When serializing this output for use with IBM systems, you can leverage a json encoder that converts these as expected. For example:

import json
import numpy
 
class QobjEncoder(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, numpy.ndarray):
            return obj.tolist()
        if isinstance(obj, complex):
            return (obj.real, obj.imag)
        return json.JSONEncoder.default(self, obj)
 
json.dumps(qobj.to_dict(), cls=QobjEncoder)

Returns

A dictionary representation of the QasmQobj object

Return type

dict(opens in a new tab)

Was this page helpful?