Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/apidocs/terra.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Qiskit Terra API Reference
transpiler_passes
transpiler_preset
utils
validation
visualization
opflow
algorithms
6 changes: 0 additions & 6 deletions docs/apidocs/validation.rst

This file was deleted.

11 changes: 5 additions & 6 deletions qiskit/compiler/assembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from qiskit.pulse.channels import PulseChannel
from qiskit.qobj import QobjHeader, Qobj
from qiskit.qobj.utils import MeasLevel, MeasReturnType
from qiskit.validation.jsonschema import SchemaValidationError

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -413,15 +412,15 @@ def _parse_pulse_args(
RunConfig: a run config, which is a standardized object that configures the qobj
and determines the runtime environment.
Raises:
SchemaValidationError: If the given meas_level is not allowed for the given `backend`.
QiskitError: If the given meas_level is not allowed for the given `backend`.
"""
# grab relevant info from backend if it exists
backend_config = None
if backend:
backend_config = backend.configuration()

if meas_level not in getattr(backend_config, "meas_levels", [MeasLevel.CLASSIFIED]):
raise SchemaValidationError(
raise QiskitError(
("meas_level = {} not supported for backend {}, only {} is supported").format(
meas_level, backend_config.backend_name, backend_config.meas_levels
)
Expand Down Expand Up @@ -501,7 +500,7 @@ def _parse_rep_delay(
rep_delay_range: Backend list defining allowable range of rep delays.

Raises:
SchemaValidationError: If rep_delay is not in the backend rep_delay_range.
QiskitError: If rep_delay is not in the backend rep_delay_range.
Returns:
float: Modified rep delay after parsing.
"""
Expand All @@ -512,13 +511,13 @@ def _parse_rep_delay(
# check that rep_delay is in rep_delay_range
if rep_delay_range is not None and isinstance(rep_delay_range, list):
if len(rep_delay_range) != 2:
raise SchemaValidationError(
raise QiskitError(
"Backend rep_delay_range {} must be a list with two entries.".format(
rep_delay_range
)
)
if not rep_delay_range[0] <= rep_delay <= rep_delay_range[1]:
raise SchemaValidationError(
raise QiskitError(
"Supplied rep delay {} not in the supported "
"backend range {}".format(rep_delay, rep_delay_range)
)
Expand Down
2 changes: 0 additions & 2 deletions qiskit/qobj/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@
from qiskit.qobj.qasm_qobj import QasmQobjConfig
from qiskit.qobj.qasm_qobj import QasmQobjExperimentConfig

from .utils import validate_qobj_against_schema


class Qobj(QasmQobj):
"""A backwards compat alias for QasmQobj."""
Expand Down
11 changes: 0 additions & 11 deletions qiskit/qobj/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,8 @@
# 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
Expand Down
35 changes: 1 addition & 34 deletions qiskit/qobj/pulse_qobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,14 @@
"""Module providing definitions of Pulse Qobj classes."""

import copy
import json
import pprint
from typing import Union, List
import warnings

import numpy

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 Expand Up @@ -559,20 +556,6 @@ def __init__(self, qobj_id, config, experiments, header=None):
self.type = "PULSE"
self.schema_version = "1.2.0"

def _validate_json_schema(self, out_dict):
class PulseQobjEncoder(json.JSONEncoder):
"""A json encoder for pulse qobj"""

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_str = json.dumps(out_dict, cls=PulseQobjEncoder)
validator(json.loads(json_str))

def __repr__(self):
experiments_str = [repr(x) for x in self.experiments]
experiments_repr = "[" + ", ".join(experiments_str) + "]"
Expand All @@ -595,7 +578,7 @@ def __str__(self):
out += "%s" % str(experiment)
return out

def to_dict(self, validate=False):
def to_dict(self):
"""Return a dictionary format representation of the Pulse Qobj.

Note this dict is not in the json wire format expected by IBMQ and qobj
Expand All @@ -619,10 +602,6 @@ def default(self, obj):

json.dumps(qobj.to_dict(), cls=QobjEncoder)

Args:
validate (bool): When set to true validate the output dictionary
against the jsonschema for qobj spec.

Returns:
dict: A dictionary representation of the PulseQobj object
"""
Expand All @@ -634,18 +613,6 @@ def default(self, obj):
"type": self.type,
"experiments": [x.to_dict() for x in self.experiments],
}
if validate:
warnings.warn(
"The jsonschema validation included in qiskit-terra "
"is deprecated and will be removed in a future release. "
"If you're relying on this schema validation you should "
"pull the schemas from the Qiskit/ibmq-schemas and directly "
"validate your payloads with that",
DeprecationWarning,
stacklevel=2,
)
self._validate_json_schema(out_dict)

return out_dict

@classmethod
Expand Down
38 changes: 2 additions & 36 deletions qiskit/qobj/qasm_qobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@

import copy
import pprint
import json
from types import SimpleNamespace
import warnings

import numpy

from qiskit.circuit.parameterexpression import ParameterExpression
from qiskit.qobj.pulse_qobj import PulseQobjInstruction, PulseLibraryItem
from qiskit.qobj.common import QobjDictField, QobjHeader, validator
from qiskit.qobj.common import QobjDictField, QobjHeader


class QasmQobjInstruction:
Expand Down Expand Up @@ -577,20 +573,6 @@ def __init__(self, qobj_id=None, config=None, experiments=None, header=None):
self.type = "QASM"
self.schema_version = "1.3.0"

def _validate_json_schema(self, out_dict):
class QobjEncoder(json.JSONEncoder):
"""A json encoder for qobj"""

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_str = json.dumps(out_dict, cls=QobjEncoder)
validator(json.loads(json_str))

def __repr__(self):
experiments_str = [repr(x) for x in self.experiments]
experiments_repr = "[" + ", ".join(experiments_str) + "]"
Expand All @@ -613,7 +595,7 @@ def __str__(self):
out += "%s" % str(experiment)
return out

def to_dict(self, validate=False):
def to_dict(self):
"""Return a dictionary format representation of the QASM Qobj.

Note this dict is not in the json wire format expected by IBMQ and qobj
Expand All @@ -637,11 +619,6 @@ def default(self, obj):

json.dumps(qobj.to_dict(), cls=QobjEncoder)


Args:
validate (bool): When set to true validate the output dictionary
against the jsonschema for qobj spec.

Returns:
dict: A dictionary representation of the QasmQobj object
"""
Expand All @@ -653,17 +630,6 @@ def default(self, obj):
"type": "QASM",
"experiments": [x.to_dict() for x in self.experiments],
}
if validate:
warnings.warn(
"The jsonschema validation included in qiskit-terra is "
"deprecated and will be removed in a future release. "
"If you're relying on this schema validation you should "
"pull the schemas from the Qiskit/ibmq-schemas and directly "
"validate your payloads with that",
DeprecationWarning,
stacklevel=2,
)
self._validate_json_schema(out_dict)
return out_dict

@classmethod
Expand Down
32 changes: 0 additions & 32 deletions qiskit/qobj/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@
"""Qobj utilities and enums."""

from enum import Enum, IntEnum
import warnings

from fastjsonschema.exceptions import JsonSchemaException

from qiskit.validation.jsonschema.exceptions import SchemaValidationError


class QobjType(str, Enum):
Expand All @@ -40,30 +35,3 @@ class MeasLevel(IntEnum):
RAW = 0
KERNELED = 1
CLASSIFIED = 2


def validate_qobj_against_schema(qobj):
"""Validates a QObj against the .json schema.

Args:
qobj (Qobj): Qobj to be validated.

Raises:
SchemaValidationError: if the qobj fails schema validation
"""
warnings.warn(
"The jsonschema validation included in qiskit-terra is "
"deprecated and will be removed in a future release. "
"If you're relying on this schema validation you should "
"pull the schemas from the Qiskit/ibmq-schemas and directly "
"validate your payloads with that",
DeprecationWarning,
stacklevel=2,
)
try:
qobj.to_dict(validate=True)
except JsonSchemaException as err:
raise SchemaValidationError(
f"Qobj validation failed. Specifically path: {err.path}" # pylint: disable=no-member
f" failed to fulfil {err.definition}"
) from err
Loading