Skip to content

Commit

Permalink
Update the qobj schema to support pulse gate calibrations. (#4761)
Browse files Browse the repository at this point in the history
* Update the qobj schema to support pulse gate calibrations.

* Fixup qobj classes: add docstrings, call out to super

* Move pulse library to top level. Fill in more details in qasm_qobj.py

* Fix mistake in schema: the pulse_library definition already contains the 'array' requirement

* Move pulse library to top level in qasm_qobj.py as well

* Add GateCalibration to qobj/__init__.py

* Fixup some implementation errors: gates contains a list of dict items, which needed to be fixed in both the schema and the py files

* Put gate calibrations into calibrations.gates to leave room for adding other metadata in the future. Make a qobj.common file to allow qobj.qasm to use features of qobj.pulse

* Add an example json

* Schema version should be referenced not hardcoded a second time

* Pretty print example file

* Check if calibrations is present when doing to from dict

* Fixup qobj test

* Update the qobj schema to support pulse gate calibrations.

* Fixup qobj classes: add docstrings, call out to super

* Move pulse library to top level. Fill in more details in qasm_qobj.py

* Fix mistake in schema: the pulse_library definition already contains the 'array' requirement

* Move pulse library to top level in qasm_qobj.py as well

* Add GateCalibration to qobj/__init__.py

* Fixup some implementation errors: gates contains a list of dict items, which needed to be fixed in both the schema and the py files

* Put gate calibrations into calibrations.gates to leave room for adding other metadata in the future. Make a qobj.common file to allow qobj.qasm to use features of qobj.pulse

* Add an example json

* Schema version should be referenced not hardcoded a second time

* Pretty print example file

* Update backend snapshots with new conf or defs (#4897)

In #4728 how we handle the difference between the object units and the
serialization format. However the snapshot update didn't actually save
the correct values in the json and this is causing issues for tutorials
that rely on this. This commit updates the backend snapshots for
backends by rerunning the update script to correct this issue.

* One reference to get_sample_pulse is raising deprecation warnings from the assembler (#4903)

* Check if calibrations is present when doing to from dict

* Fixup qobj test

* Add qobj.config.calibrations for common cals

* style

* Move recent qasm qobj changes to the new qobj.common file

* Update schema with qobj level and experiment level calibrations

* Add schema test

* Apply suggestions from code review

Co-authored-by: SooluThomas <[email protected]>

* Fix encoding for validation of new pulse library field in qasm qobj. Add qobj test

Co-authored-by: Matthew Treinish <[email protected]>
Co-authored-by: SooluThomas <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Aug 21, 2020
1 parent 8980e73 commit 68f65d2
Show file tree
Hide file tree
Showing 8 changed files with 1,143 additions and 62 deletions.
9 changes: 7 additions & 2 deletions qiskit/qobj/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
QasmQobjExperimentConfig
QasmQobjExperiment
QasmQobjConfig
QasmExperimentCalibrations
GateCalibration
Pulse
=====
Expand All @@ -64,6 +66,9 @@

import warnings

from qiskit.qobj.common import QobjExperimentHeader
from qiskit.qobj.common import QobjHeader

from qiskit.qobj.pulse_qobj import PulseQobj
from qiskit.qobj.pulse_qobj import PulseQobjInstruction
from qiskit.qobj.pulse_qobj import PulseQobjExperimentConfig
Expand All @@ -72,13 +77,13 @@
from qiskit.qobj.pulse_qobj import QobjMeasurementOption
from qiskit.qobj.pulse_qobj import PulseLibraryItem

from qiskit.qobj.qasm_qobj import GateCalibration
from qiskit.qobj.qasm_qobj import QasmExperimentCalibrations
from qiskit.qobj.qasm_qobj import QasmQobj
from qiskit.qobj.qasm_qobj import QasmQobjInstruction
from qiskit.qobj.qasm_qobj import QasmQobjExperiment
from qiskit.qobj.qasm_qobj import QasmQobjConfig
from qiskit.qobj.qasm_qobj import QobjExperimentHeader
from qiskit.qobj.qasm_qobj import QasmQobjExperimentConfig
from qiskit.qobj.qasm_qobj import QobjHeader

from .utils import validate_qobj_against_schema

Expand Down
83 changes: 83 additions & 0 deletions qiskit/qobj/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2020.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.
# pylint: disable=invalid-name

"""Module providing definitions of common Qobj classes."""
import json
import os
from types import SimpleNamespace

import fastjsonschema


path_part = 'schemas/qobj_schema.json'
path = os.path.join(
os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
path_part)
with open(path) as fd:
json_schema = json.loads(fd.read())
validator = fastjsonschema.compile(json_schema)


class QobjDictField(SimpleNamespace):
"""A class used to represent a dictionary field in Qobj
Exists as a backwards compatibility shim around a dictionary for Qobjs
previously constructed using marshmallow.
"""

def __init__(self, **kwargs):
"""Instantiate a new Qobj dict field object.
Args:
kwargs: arbitrary keyword arguments that can be accessed as
attributes of the object.
"""
self.__dict__.update(kwargs)

def to_dict(self):
"""Return a dictionary format representation of the QASM Qobj.
Returns:
dict: The dictionary form of the QobjHeader.
"""
return self.__dict__

@classmethod
def from_dict(cls, data):
"""Create a new QobjHeader object from a dictionary.
Args:
data (dict): A dictionary representing the QobjHeader to create. It
will be in the same format as output by :func:`to_dict`.
Returns:
QobjDictFieldr: The QobjDictField from the input dictionary.
"""

return cls(**data)

def __eq__(self, other):
if isinstance(other, self.__class__):
if self.__dict__ == other.__dict__:
return True
return False


class QobjHeader(QobjDictField):
"""A class used to represent a dictionary header in Qobj objects."""
pass


class QobjExperimentHeader(QobjHeader):
"""A class representing a header dictionary for a Qobj Experiment."""
pass
8 changes: 4 additions & 4 deletions qiskit/qobj/pulse_qobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@

import numpy

from qiskit.qobj.qasm_qobj import QobjDictField
from qiskit.qobj.qasm_qobj import QobjHeader
from qiskit.qobj.qasm_qobj import QobjExperimentHeader
from qiskit.qobj.qasm_qobj import validator
from qiskit.qobj.common import QobjDictField
from qiskit.qobj.common import QobjHeader
from qiskit.qobj.common import QobjExperimentHeader
from qiskit.qobj.common import validator


class QobjMeasurementOption:
Expand Down
Loading

0 comments on commit 68f65d2

Please sign in to comment.