Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove marshmallow from Qobj #3383

Merged
merged 60 commits into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
8a24c77
Remove marshmallow from Qobj
mtreinish Oct 22, 2019
b6eb9c2
Apply suggestions from code review
mtreinish Nov 4, 2019
d9eed64
Simplify __eq__ methods and dedup dict classes
mtreinish Nov 4, 2019
d206aeb
Refactor instruction classes to be attribute based
mtreinish Nov 4, 2019
889b07e
Add error messages to raised attribute errors
mtreinish Nov 6, 2019
c902e0d
Fix copy paste error
mtreinish Nov 6, 2019
130be5d
Rebase fixes
mtreinish Dec 11, 2019
1a8b2a2
Merge branch 'master' into fast-qobj-replacement
mtreinish Jan 8, 2020
afce0c9
Add backwards compat shim for Qobj class
mtreinish Jan 8, 2020
767eff6
Fix lint
mtreinish Jan 9, 2020
5eae6b2
Fix lint again
mtreinish Jan 9, 2020
a84b9db
Merge branch 'master' into fast-qobj-replacement
mtreinish Jan 22, 2020
b09a07b
Merge branch 'master' into fast-qobj-replacement
mtreinish Feb 3, 2020
ba9c3b1
Fix lint failure
mtreinish Feb 3, 2020
1998dd2
Add support for parametric pulses
mtreinish Feb 4, 2020
e084891
Add back missing type hint
mtreinish Feb 4, 2020
a9c9474
Fix tests
mtreinish Feb 4, 2020
cb74ed8
Merge branch 'master' into fast-qobj-replacement
mtreinish Feb 4, 2020
30cb464
Merge branch 'master' into fast-qobj-replacement
mtreinish Feb 5, 2020
7fce95a
Merge branch 'master' into fast-qobj-replacement
mtreinish Feb 15, 2020
41e5d5c
Make PulseQobjInstruction.discriminators a QobjMeasurementOption list
mtreinish Feb 15, 2020
50452e1
Preserve required fields in PulseQobjConfig
mtreinish Feb 15, 2020
66bd484
Remove unnecessary super calls
mtreinish Feb 15, 2020
d1b54f8
Fix config type on PulsqQobj docstring
mtreinish Feb 15, 2020
93650c7
Add missing attributes from PulseQobj
mtreinish Feb 15, 2020
6c806d2
Update discriminators from_dict() too
mtreinish Feb 15, 2020
9fddb3d
Fix docstring typo in QasmQobjInstruction
mtreinish Feb 15, 2020
531a7a0
Update input checks for QasmQobjInstruction.__init__
mtreinish Feb 15, 2020
13eed65
Deduplicate eq check for QobjDictField subclasses
mtreinish Feb 15, 2020
1ad9770
Make qobj_id and config required for pulse
mtreinish Feb 15, 2020
69e084b
Use attributes instead of dict for QobjMeasurementOption
mtreinish Feb 18, 2020
20ff357
Merge branch 'master' into fast-qobj-replacement
mtreinish Feb 19, 2020
a2ff39b
Make experiments a required field on PulseQobj
mtreinish Feb 19, 2020
05590e3
Make instructions a required param in PulseQobjExperiment
mtreinish Feb 19, 2020
d476b12
Add missing kwargs from PulseQobjExperimentConfig
mtreinish Feb 19, 2020
0c0f50d
Move pulse jsonschema validation into a separate method
mtreinish Feb 19, 2020
1e9e3f9
Fix lint again
mtreinish Feb 19, 2020
8096d7f
Merge branch 'master' into fast-qobj-replacement
mtreinish Feb 19, 2020
d1fa31d
Use QobjDictField for pulse qobj classes
mtreinish Feb 19, 2020
decaba8
Merge branch 'master' into fast-qobj-replacement
mtreinish Feb 19, 2020
fc7b9bb
Merge branch 'master' into fast-qobj-replacement
mtreinish Feb 20, 2020
4e021aa
Merge branch 'master' into fast-qobj-replacement
mtreinish Feb 23, 2020
8f2cdc5
Merge branch 'master' into fast-qobj-replacement
mtreinish Feb 24, 2020
54e9f96
Merge branch 'master' into fast-qobj-replacement
mtreinish Feb 25, 2020
92b1f69
Merge branch 'master' into fast-qobj-replacement
mtreinish Mar 2, 2020
14eb518
Pivot arbitrary key value classes to SimpleNamespace
mtreinish Mar 2, 2020
b89e795
Fix lint again
mtreinish Mar 2, 2020
261824e
Merge branch 'master' into fast-qobj-replacement
mtreinish Mar 5, 2020
3229a62
Merge branch 'master' into fast-qobj-replacement
mtreinish Mar 5, 2020
2d23b6c
Apply suggestions from code review
mtreinish Mar 9, 2020
443efea
Merge branch 'master' into fast-qobj-replacement
mtreinish Mar 9, 2020
afc8349
Merge branch 'master' into fast-qobj-replacement
mtreinish Mar 10, 2020
b9c64d4
Fix docs warnings
mtreinish Mar 10, 2020
15f6f6e
Update SimpleNamespace usage
mtreinish Mar 10, 2020
ae7f7bf
Fix pulse qobj docstring
mtreinish Mar 10, 2020
e10bbc9
Update qasm qobj based on review comments
mtreinish Mar 10, 2020
e726f82
Merge branch 'master' into fast-qobj-replacement
mtreinish Mar 10, 2020
075fda4
Fix docs builds
mtreinish Mar 10, 2020
cf51543
Merge branch 'master' into fast-qobj-replacement
mtreinish Mar 10, 2020
a720b3f
Merge branch 'master' into fast-qobj-replacement
mergify[bot] Mar 10, 2020
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
3 changes: 1 addition & 2 deletions qiskit/assembler/assemble_circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ def assemble_circuits(circuits, run_config, qobj_id, qobj_header):
mask="0x%X" % mask,
relation='==',
val="0x%X" % val,
register=conditional_reg_idx,
validate=False)
register=conditional_reg_idx)
lcapelluto marked this conversation as resolved.
Show resolved Hide resolved
instructions.append(conversion_bfunc)
instruction.conditional = conditional_reg_idx
max_conditional_idx += 1
Expand Down
4 changes: 2 additions & 2 deletions qiskit/circuit/instruction.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from qiskit.circuit.exceptions import CircuitError
from qiskit.circuit.quantumregister import QuantumRegister
from qiskit.circuit.classicalregister import ClassicalRegister
from qiskit.qobj.models.qasm import QasmQobjInstruction
from qiskit.qobj.qasm_qobj import QasmQobjInstruction
from qiskit.circuit.parameter import ParameterExpression

_CUTOFF_PRECISION = 1E-10
Expand Down Expand Up @@ -222,7 +222,7 @@ def definition(self, array):

def assemble(self):
"""Assemble a QasmQobjInstruction"""
instruction = QasmQobjInstruction(name=self.name, validate=False)
instruction = QasmQobjInstruction(name=self.name)
# Evaluate parameters
if self.params:
params = [
Expand Down
5 changes: 4 additions & 1 deletion qiskit/providers/models/pulsedefaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

# pylint: disable=missing-type-doc

"""Model and schema for pulse defaults."""
import warnings

Expand All @@ -20,7 +22,8 @@

from qiskit.validation import BaseModel, BaseSchema, bind_schema, fields
from qiskit.validation.base import ObjSchema
from qiskit.qobj import PulseLibraryItemSchema, PulseQobjInstructionSchema, PulseLibraryItem
from qiskit.qobj.models.pulse import PulseLibraryItemSchema, PulseQobjInstructionSchema
from qiskit.qobj import PulseLibraryItem
from qiskit.qobj.converters import QobjToInstructionConverter
from qiskit.pulse.instruction_schedule_map import InstructionScheduleMap
from qiskit.pulse.schedule import ParameterizedSchedule
Expand Down
37 changes: 27 additions & 10 deletions qiskit/qobj/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,34 @@
validate_qobj_against_schema
"""

from .models.base import (QobjInstruction, QobjExperimentHeader, QobjExperimentConfig,
QobjExperiment, QobjConfig, QobjHeader)
import warnings

from qiskit.qobj.pulse_qobj import PulseQobj
taalexander marked this conversation as resolved.
Show resolved Hide resolved
from qiskit.qobj.pulse_qobj import PulseQobjInstruction
from qiskit.qobj.pulse_qobj import PulseQobjExperimentConfig
from qiskit.qobj.pulse_qobj import PulseQobjExperiment
from qiskit.qobj.pulse_qobj import PulseQobjConfig
from qiskit.qobj.pulse_qobj import QobjMeasurementOption
from qiskit.qobj.pulse_qobj import PulseLibraryItem

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 .models.pulse import (PulseQobjInstruction, PulseQobjExperimentConfig,
PulseQobjExperiment, PulseQobjConfig,
QobjMeasurementOption, PulseLibraryItem,
PulseLibraryItemSchema, PulseQobjInstructionSchema)
from .utils import validate_qobj_against_schema

from .models.qasm import (QasmQobjInstruction, QasmQobjExperimentConfig,
QasmQobjExperiment, QasmQobjConfig)

from .qobj import Qobj, QasmQobj, PulseQobj
class Qobj(QasmQobj):
"""A backwards compat alias for QasmQobj."""

from .utils import validate_qobj_against_schema
def __init__(self, qobj_id=None, config=None, experiments=None,
header=None):
"""Initialize a Qobj object."""
warnings.warn('qiskit.qobj.Qobj is deprecated use either QasmQobj or '
'PulseQobj depending on your application instead.',
DeprecationWarning, stacklevel=2)
super(Qobj, self).__init__()
161 changes: 4 additions & 157 deletions qiskit/qobj/models/pulse.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@

"""The pulse qobj models."""

from marshmallow.validate import Range, Regexp, Length, OneOf
from marshmallow.validate import Range, Regexp, Length

from qiskit.qobj.utils import MeasReturnType, MeasLevel
from qiskit.validation import BaseSchema, bind_schema, BaseModel
from qiskit.validation.fields import (Integer, String, Number, Float, Complex, List,
from qiskit.validation import BaseSchema
from qiskit.validation.fields import (Integer, String, Float, Complex, List,
Nested, DictParameters, ByType)
from .base import (QobjInstructionSchema, QobjExperimentConfigSchema, QobjExperimentSchema,
QobjConfigSchema, QobjInstruction, QobjExperimentConfig,
QobjExperiment, QobjConfig)
from .base import QobjInstructionSchema


class QobjMeasurementOptionSchema(BaseSchema):
Expand Down Expand Up @@ -63,153 +60,3 @@ class PulseQobjInstructionSchema(QobjInstructionSchema):
label = String()
type = String()
parameters = DictParameters(valid_value_types=(int, float, bool, complex))

taalexander marked this conversation as resolved.
Show resolved Hide resolved

class PulseQobjExperimentConfigSchema(QobjExperimentConfigSchema):
"""Schema for PulseQobjExperimentConfig."""

# Optional properties.
qubit_lo_freq = List(Number())
meas_lo_freq = List(Number())


class PulseQobjExperimentSchema(QobjExperimentSchema):
"""Schema for PulseQobjExperiment."""

# Required properties.
instructions = Nested(PulseQobjInstructionSchema, required=True, many=True,
validate=Length(min=1))

# Optional properties.
config = Nested(PulseQobjExperimentConfigSchema)


class PulseQobjConfigSchema(QobjConfigSchema):
"""Schema for PulseQobjConfig of device backend."""

# Required properties.
meas_level = Integer(required=True, validate=OneOf(choices=(MeasLevel.RAW,
MeasLevel.KERNELED,
MeasLevel.CLASSIFIED)))
meas_return = String(required=True, validate=OneOf(choices=(MeasReturnType.AVERAGE,
MeasReturnType.SINGLE)))
pulse_library = Nested(PulseLibraryItemSchema, required=True, many=True)
qubit_lo_freq = List(Number(validate=Range(min=0)), required=True)
meas_lo_freq = List(Number(validate=Range(min=0)), required=True)

# Optional properties.
memory_slot_size = Integer(validate=Range(min=1))
rep_time = Integer(validate=Range(min=0))


@bind_schema(QobjMeasurementOptionSchema)
class QobjMeasurementOption(BaseModel):
"""Model for QobjMeasurementOption.

Please note that this class only describes the required fields. For the
full description of the model, please check ``QobjMeasurementOptionSchema``.

Attributes:
name (str): name of option specified in the backend
params (dict): measurement parameter
"""
def __init__(self, name, params, **kwargs):
self.name = name
self.params = params

super().__init__(**kwargs)


@bind_schema(PulseLibraryItemSchema)
class PulseLibraryItem(BaseModel):
"""Model for PulseLibraryItem.

Please note that this class only describes the required fields. For the
full description of the model, please check ``PulseLibraryItemSchema``.

Attributes:
name (str): name of pulse
samples (list[complex]]): list of complex values defining pulse shape
"""

def __init__(self, name, samples, **kwargs):
self.name = name
self.samples = samples

super().__init__(**kwargs)


@bind_schema(PulseQobjInstructionSchema)
class PulseQobjInstruction(QobjInstruction):
"""Model for PulseQobjInstruction inherit from QobjInstruction.

Please note that this class only describes the required fields. For the
full description of the model, please check ``PulseQobjInstructionSchema``.

Attributes:
name (str): name of the instruction
t0 (int): timing of executing the instruction
"""
def __init__(self, name, t0, **kwargs):
# pylint: disable=invalid-name
self.t0 = t0

super().__init__(name=name,
t0=t0,
**kwargs)


@bind_schema(PulseQobjExperimentConfigSchema)
class PulseQobjExperimentConfig(QobjExperimentConfig):
"""Model for PulseQobjExperimentConfig inherit from QobjExperimentConfig.

Please note that this class only describes the required fields. For the
full description of the model, please check ``PulseQobjExperimentConfigSchema``.
"""
pass


@bind_schema(PulseQobjExperimentSchema)
class PulseQobjExperiment(QobjExperiment):
"""Model for PulseQobjExperiment inherit from QobjExperiment.

Please note that this class only describes the required fields. For the
full description of the model, please check ``PulseQobjExperimentSchema``.

Attributes:
instructions (list[PulseQobjInstruction]): list of instructions.
"""
def __init__(self, instructions, **kwargs):

super().__init__(instructions=instructions,
**kwargs)


@bind_schema(PulseQobjConfigSchema)
class PulseQobjConfig(QobjConfig):
"""Model for PulseQobjConfig inherit from QobjConfig.

Please note that this class only describes the required fields. For the
full description of the model, please check ``PulseQobjConfigSchema``.

Attributes:
meas_level (int or MeasLevel): a value represents the level of measurement.
meas_lo_freq (list[float]): local oscillator frequency of measurement pulse.
meas_return (str or MeasReturn): a level of measurement information.
pulse_library (list[qiskit.qobj.PulseLibraryItem]): a pulse library.
qubit_lo_freq (list[float]): local oscillator frequency of driving pulse.
"""
def __init__(self, meas_level, meas_return, pulse_library,
qubit_lo_freq, meas_lo_freq, **kwargs):
self.meas_level = meas_level
self.meas_return = meas_return
self.pulse_library = pulse_library
self.qubit_lo_freq = qubit_lo_freq
self.meas_lo_freq = meas_lo_freq

super().__init__(meas_level=meas_level,
meas_return=meas_return,
pulse_library=pulse_library,
qubit_lo_freq=qubit_lo_freq,
meas_lo_freq=meas_lo_freq,
**kwargs)
110 changes: 0 additions & 110 deletions qiskit/qobj/models/qasm.py

This file was deleted.

Loading