Deprecate Qobj and assemble (#12649)

* deprecate qobj and assemble

* reno

* shallow deprecation of assemble

* test.python.compiler.test_disassembler

* fakebackend pulse

* test.python.circuit.test_parameters

* PulseQobjInstruction  is used by GenericBackendV2

* test.python.scheduler.test_basic_scheduler

* test.python.result.test_result

* test.python.pulse.test_calibration_entries

* test.python.compiler.test_assembler

* test.python.transpiler.test_star_prerouting

* test.python.pulse.test_instruction_schedule_map

* test.python.providers.basic_provider.test_basic_simulator

* test.python.primitives.test_backend_sampler_v2

* test.python.compiler.test_disassembler

* test.python.compiler.test_compiler

* test.python.circuit.test_scheduled_circuit

* test.python.providers.test_fake_backends

* test.python.circuit.test_unitary

* test.python.transpiler.test_sabre_swap

* test.python.providers.fake_provider.test_fake_backends

* Aer using Provider ABC

* aer warnings

* reno

* another pass on reno

* test.python.pulse

* test.python.compiler.test_compiler

* add module to fiterwarning

* test.python.compiler.test_transpiler

* fixing obscure expcetion handleing for comparison

* Apply suggestions from code review

Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>

* remove catch

* new deprecate warning message

* lint qiskit/assembler/assemble_circuits.py

* concurrency warnings

* ignore aer warnings

* Update test/python/providers/fake_provider/test_fake_backends.py

Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>

* Update test/python/circuit/test_parameters.py

Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>

* Update qiskit/providers/models/pulsedefaults.py

Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>

* Update test/python/providers/fake_provider/test_fake_backends.py

Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>

* Update test/python/providers/fake_provider/test_generic_backend_v2.py

Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>

* lint

* https://github.com/Qiskit/qiskit/pull/12649#discussion_r1686717954

* https://github.com/Qiskit/qiskit/pull/12649#discussion_r1686717732

* Update test/python/transpiler/test_sabre_swap.py

Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>

* Update qiskit/providers/models/pulsedefaults.py

Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>

* ignore Treating CircuitInstruction...

* another unnecessary catch from aer

* another unnecessary catch from aer, again

* removing more unnecesary catches

---------

Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>
This commit is contained in:
Luciano Bello 2024-07-25 12:11:56 +02:00 committed by GitHub
parent aaaf10760d
commit 6ce52505c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
40 changed files with 2160 additions and 1513 deletions

View File

@ -12,6 +12,7 @@
"""Assemble function for converting a list of circuits into a qobj."""
import copy
import warnings
from collections import defaultdict
from typing import Dict, List, Optional, Tuple
@ -35,6 +36,7 @@ from qiskit.qobj import (
QobjHeader,
)
from qiskit.utils.parallel import parallel_map
from qiskit.utils import deprecate_func
PulseLibrary = Dict[str, List[complex]]
@ -87,20 +89,26 @@ def _assemble_circuit(
metadata = circuit.metadata
if metadata is None:
metadata = {}
header = QobjExperimentHeader(
qubit_labels=qubit_labels,
n_qubits=num_qubits,
qreg_sizes=qreg_sizes,
clbit_labels=clbit_labels,
memory_slots=memory_slots,
creg_sizes=creg_sizes,
name=circuit.name,
global_phase=float(circuit.global_phase),
metadata=metadata,
)
with warnings.catch_warnings():
# The class QobjExperimentHeader is deprecated
warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
header = QobjExperimentHeader(
qubit_labels=qubit_labels,
n_qubits=num_qubits,
qreg_sizes=qreg_sizes,
clbit_labels=clbit_labels,
memory_slots=memory_slots,
creg_sizes=creg_sizes,
name=circuit.name,
global_phase=float(circuit.global_phase),
metadata=metadata,
)
# TODO: why do we need n_qubits and memory_slots in both the header and the config
config = QasmQobjExperimentConfig(n_qubits=num_qubits, memory_slots=memory_slots)
with warnings.catch_warnings():
# The class QasmQobjExperimentConfig is deprecated
warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
config = QasmQobjExperimentConfig(n_qubits=num_qubits, memory_slots=memory_slots)
calibrations, pulse_library = _assemble_pulse_gates(circuit, run_config)
if calibrations:
config.calibrations = calibrations
@ -118,7 +126,7 @@ def _assemble_circuit(
instructions = []
for op_context in circuit.data:
instruction = op_context.operation.assemble()
instruction = op_context.operation._assemble()
# Add register attributes to the instruction
qargs = op_context.qubits
@ -151,13 +159,16 @@ def _assemble_circuit(
]
conditional_reg_idx = memory_slots + max_conditional_idx
conversion_bfunc = QasmQobjInstruction(
name="bfunc",
mask="0x%X" % mask, # pylint: disable=consider-using-f-string
relation="==",
val="0x%X" % val, # pylint: disable=consider-using-f-string
register=conditional_reg_idx,
)
with warnings.catch_warnings():
# The class QasmQobjInstruction is deprecated
warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
conversion_bfunc = QasmQobjInstruction(
name="bfunc",
mask="0x%X" % mask, # pylint: disable=consider-using-f-string
relation="==",
val="0x%X" % val, # pylint: disable=consider-using-f-string
register=conditional_reg_idx,
)
instructions.append(conversion_bfunc)
instruction.conditional = conditional_reg_idx
max_conditional_idx += 1
@ -166,10 +177,13 @@ def _assemble_circuit(
del instruction._condition
instructions.append(instruction)
return (
QasmQobjExperiment(instructions=instructions, header=header, config=config),
pulse_library,
)
with warnings.catch_warnings():
# The class QasmQobjExperiment is deprecated
warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
return (
QasmQobjExperiment(instructions=instructions, header=header, config=config),
pulse_library,
)
def _assemble_pulse_gates(
@ -299,6 +313,106 @@ def _configure_experiment_los(
return experiments
def _assemble_circuits(
circuits: List[QuantumCircuit], run_config: RunConfig, qobj_id: int, qobj_header: QobjHeader
) -> QasmQobj:
with warnings.catch_warnings():
# Still constructs Qobj, that is deprecated. The message is hard to trace to a module,
# because concurrency is hard.
warnings.filterwarnings("ignore", category=DeprecationWarning)
experiments_and_pulse_libs = parallel_map(_assemble_circuit, circuits, [run_config])
experiments = []
pulse_library = {}
for exp, lib in experiments_and_pulse_libs:
experiments.append(exp)
if lib:
pulse_library.update(lib)
# extract common calibrations
experiments, calibrations = _extract_common_calibrations(experiments)
# configure LO freqs per circuit
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
lo_converter = converters.LoConfigConverter(
QasmQobjExperimentConfig, **run_config.to_dict()
)
experiments = _configure_experiment_los(experiments, lo_converter, run_config)
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
qobj_config = QasmQobjConfig()
if run_config:
qobj_config_dict = run_config.to_dict()
# remove LO ranges, not needed in qobj
qobj_config_dict.pop("qubit_lo_range", None)
qobj_config_dict.pop("meas_lo_range", None)
# convert LO frequencies to GHz, if they exist
if "qubit_lo_freq" in qobj_config_dict:
qobj_config_dict["qubit_lo_freq"] = [
freq / 1e9 for freq in qobj_config_dict["qubit_lo_freq"]
]
if "meas_lo_freq" in qobj_config_dict:
qobj_config_dict["meas_lo_freq"] = [
freq / 1e9 for freq in qobj_config_dict["meas_lo_freq"]
]
# override default los if single ``schedule_los`` entry set
schedule_los = qobj_config_dict.pop("schedule_los", [])
if len(schedule_los) == 1:
lo_dict = schedule_los[0]
q_los = lo_converter.get_qubit_los(lo_dict)
# Hz -> GHz
if q_los:
qobj_config_dict["qubit_lo_freq"] = [freq / 1e9 for freq in q_los]
m_los = lo_converter.get_meas_los(lo_dict)
if m_los:
qobj_config_dict["meas_lo_freq"] = [freq / 1e9 for freq in m_los]
with warnings.catch_warnings():
# The class QasmQobjConfig is deprecated
warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
qobj_config = QasmQobjConfig(**qobj_config_dict)
qubit_sizes = []
memory_slot_sizes = []
for circ in circuits:
num_qubits = 0
memory_slots = 0
for qreg in circ.qregs:
num_qubits += qreg.size
for creg in circ.cregs:
memory_slots += creg.size
qubit_sizes.append(num_qubits)
memory_slot_sizes.append(memory_slots)
qobj_config.memory_slots = max(memory_slot_sizes)
qobj_config.n_qubits = max(qubit_sizes)
if pulse_library:
qobj_config.pulse_library = [
PulseLibraryItem(name=name, samples=samples) for name, samples in pulse_library.items()
]
if calibrations and calibrations.gates:
qobj_config.calibrations = calibrations
with warnings.catch_warnings():
# The class QasmQobj is deprecated
warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
return QasmQobj(
qobj_id=qobj_id, config=qobj_config, experiments=experiments, header=qobj_header
)
@deprecate_func(
since="1.2",
removal_timeline="in the 2.0 release",
additional_msg="The `Qobj` class and related functionality are part of the deprecated `BackendV1` "
"workflow, and no longer necessary for `BackendV2`. If a user workflow requires "
"`Qobj` it likely relies on deprecated functionality and should be updated to "
"use `BackendV2`.",
)
def assemble_circuits(
circuits: List[QuantumCircuit], run_config: RunConfig, qobj_id: int, qobj_header: QobjHeader
) -> QasmQobj:
@ -334,75 +448,4 @@ def assemble_circuits(
run_config=RunConfig(shots=2000, memory=True, init_qubits=True))
"""
# assemble the circuit experiments
experiments_and_pulse_libs = parallel_map(_assemble_circuit, circuits, [run_config])
experiments = []
pulse_library = {}
for exp, lib in experiments_and_pulse_libs:
experiments.append(exp)
if lib:
pulse_library.update(lib)
# extract common calibrations
experiments, calibrations = _extract_common_calibrations(experiments)
# configure LO freqs per circuit
lo_converter = converters.LoConfigConverter(QasmQobjExperimentConfig, **run_config.to_dict())
experiments = _configure_experiment_los(experiments, lo_converter, run_config)
qobj_config = QasmQobjConfig()
if run_config:
qobj_config_dict = run_config.to_dict()
# remove LO ranges, not needed in qobj
qobj_config_dict.pop("qubit_lo_range", None)
qobj_config_dict.pop("meas_lo_range", None)
# convert LO frequencies to GHz, if they exist
if "qubit_lo_freq" in qobj_config_dict:
qobj_config_dict["qubit_lo_freq"] = [
freq / 1e9 for freq in qobj_config_dict["qubit_lo_freq"]
]
if "meas_lo_freq" in qobj_config_dict:
qobj_config_dict["meas_lo_freq"] = [
freq / 1e9 for freq in qobj_config_dict["meas_lo_freq"]
]
# override default los if single ``schedule_los`` entry set
schedule_los = qobj_config_dict.pop("schedule_los", [])
if len(schedule_los) == 1:
lo_dict = schedule_los[0]
q_los = lo_converter.get_qubit_los(lo_dict)
# Hz -> GHz
if q_los:
qobj_config_dict["qubit_lo_freq"] = [freq / 1e9 for freq in q_los]
m_los = lo_converter.get_meas_los(lo_dict)
if m_los:
qobj_config_dict["meas_lo_freq"] = [freq / 1e9 for freq in m_los]
qobj_config = QasmQobjConfig(**qobj_config_dict)
qubit_sizes = []
memory_slot_sizes = []
for circ in circuits:
num_qubits = 0
memory_slots = 0
for qreg in circ.qregs:
num_qubits += qreg.size
for creg in circ.cregs:
memory_slots += creg.size
qubit_sizes.append(num_qubits)
memory_slot_sizes.append(memory_slots)
qobj_config.memory_slots = max(memory_slot_sizes)
qobj_config.n_qubits = max(qubit_sizes)
if pulse_library:
qobj_config.pulse_library = [
PulseLibraryItem(name=name, samples=samples) for name, samples in pulse_library.items()
]
if calibrations and calibrations.gates:
qobj_config.calibrations = calibrations
return QasmQobj(
qobj_id=qobj_id, config=qobj_config, experiments=experiments, header=qobj_header
)
return _assemble_circuits(circuits, run_config, qobj_id, qobj_header)

View File

@ -23,6 +23,7 @@ from qiskit.circuit.quantumregister import QuantumRegister
from qiskit.qobj import PulseQobjInstruction
from qiskit.qobj.converters import QobjToInstructionConverter
from qiskit.utils import deprecate_func
# A ``CircuitModule`` is a representation of a circuit execution on the backend.
# It is currently a list of quantum circuits to execute, a run Qobj dictionary
@ -37,6 +38,14 @@ CircuitModule = NewType(
PulseModule = NewType("PulseModule", Tuple[List[pulse.Schedule], Dict[str, Any], Dict[str, Any]])
@deprecate_func(
since="1.2",
removal_timeline="in the 2.0 release",
additional_msg="The `Qobj` class and related functionality are part of the deprecated "
"`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user "
"workflow requires `Qobj` it likely relies on deprecated functionality and "
"should be updated to use `BackendV2`.",
)
def disassemble(qobj) -> Union[CircuitModule, PulseModule]:
"""Disassemble a qobj and return the circuits or pulse schedules, run_config, and user header.

View File

@ -34,6 +34,7 @@ The circuit itself keeps this context.
from __future__ import annotations
import copy
import warnings
from itertools import zip_longest
import math
from typing import List, Type
@ -47,7 +48,7 @@ from qiskit.circuit.parameter import ParameterExpression
from qiskit.circuit.operation import Operation
from qiskit.circuit.annotated_operation import AnnotatedOperation, InverseModifier
from qiskit.utils import deprecate_func
_CUTOFF_PRECISION = 1e-10
@ -359,9 +360,23 @@ class Instruction(Operation):
"""Set the time unit of duration."""
self._unit = unit
@deprecate_func(
since="1.2",
removal_timeline="in the 2.0 release",
additional_msg="The `Qobj` class and related functionality are part of the deprecated "
"`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user "
"workflow requires `Qobj` it likely relies on deprecated functionality and "
"should be updated to use `BackendV2`.",
)
def assemble(self):
"""Assemble a QasmQobjInstruction"""
instruction = QasmQobjInstruction(name=self.name)
return self._assemble()
def _assemble(self):
with warnings.catch_warnings():
# The class QasmQobjInstruction is deprecated
warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
instruction = QasmQobjInstruction(name=self.name)
# Evaluate parameters
if self.params:
params = [x.evalf(x) if hasattr(x, "evalf") else x for x in self.params]

View File

@ -20,7 +20,7 @@ from typing import Dict, List, Optional, Union
import numpy as np
from qiskit.assembler import assemble_circuits, assemble_schedules
from qiskit.assembler import assemble_schedules
from qiskit.assembler.run_config import RunConfig
from qiskit.circuit import Parameter, QuantumCircuit, Qubit
from qiskit.exceptions import QiskitError
@ -29,6 +29,8 @@ from qiskit.pulse import Instruction, LoConfig, Schedule, ScheduleBlock
from qiskit.pulse.channels import PulseChannel
from qiskit.qobj import QasmQobj, PulseQobj, QobjHeader
from qiskit.qobj.utils import MeasLevel, MeasReturnType
from qiskit.utils import deprecate_func
from qiskit.assembler.assemble_circuits import _assemble_circuits
logger = logging.getLogger(__name__)
@ -39,6 +41,14 @@ def _log_assembly_time(start_time, end_time):
# TODO: parallelize over the experiments (serialize each separately, then add global header/config)
@deprecate_func(
since="1.2",
removal_timeline="in the 2.0 release",
additional_msg="The `Qobj` class and related functionality are part of the deprecated "
"`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user "
"workflow requires `Qobj` it likely relies on deprecated functionality and "
"should be updated to use `BackendV2`.",
)
def assemble(
experiments: Union[
QuantumCircuit,
@ -81,7 +91,7 @@ def assemble(
to create ``Qobj`` "experiments". It further annotates the experiment payload with
header and configurations.
NOTE: Backend.options is not used within assemble. The required values
NOTE: ``Backend.options`` is not used within assemble. The required values
(previously given by backend.set_options) should be manually extracted
from options and supplied directly when calling.
@ -153,27 +163,92 @@ def assemble(
Raises:
QiskitError: if the input cannot be interpreted as either circuits or schedules
"""
start_time = time()
experiments = experiments if isinstance(experiments, list) else [experiments]
pulse_qobj = any(isinstance(exp, (ScheduleBlock, Schedule, Instruction)) for exp in experiments)
qobj_id, qobj_header, run_config_common_dict = _parse_common_args(
return _assemble(
experiments,
backend,
qobj_id,
qobj_header,
shots,
memory,
seed_simulator,
init_qubits,
rep_delay,
qubit_lo_freq,
meas_lo_freq,
qubit_lo_range,
meas_lo_range,
schedule_los,
pulse_qobj=pulse_qobj,
meas_level,
meas_return,
meas_map,
memory_slot_size,
rep_time,
rep_delay,
parameter_binds,
parametric_pulses,
init_qubits,
**run_config,
)
def _assemble(
experiments: Union[
QuantumCircuit,
List[QuantumCircuit],
Schedule,
List[Schedule],
ScheduleBlock,
List[ScheduleBlock],
],
backend: Optional[Backend] = None,
qobj_id: Optional[str] = None,
qobj_header: Optional[Union[QobjHeader, Dict]] = None,
shots: Optional[int] = None,
memory: Optional[bool] = False,
seed_simulator: Optional[int] = None,
qubit_lo_freq: Optional[List[float]] = None,
meas_lo_freq: Optional[List[float]] = None,
qubit_lo_range: Optional[List[float]] = None,
meas_lo_range: Optional[List[float]] = None,
schedule_los: Optional[
Union[
List[Union[Dict[PulseChannel, float], LoConfig]],
Union[Dict[PulseChannel, float], LoConfig],
]
] = None,
meas_level: Union[int, MeasLevel] = MeasLevel.CLASSIFIED,
meas_return: Union[str, MeasReturnType] = MeasReturnType.AVERAGE,
meas_map: Optional[List[List[Qubit]]] = None,
memory_slot_size: int = 100,
rep_time: Optional[int] = None,
rep_delay: Optional[float] = None,
parameter_binds: Optional[List[Dict[Parameter, float]]] = None,
parametric_pulses: Optional[List[str]] = None,
init_qubits: bool = True,
**run_config: Dict,
) -> Union[QasmQobj, PulseQobj]:
start_time = time()
experiments = experiments if isinstance(experiments, list) else [experiments]
pulse_qobj = any(isinstance(exp, (ScheduleBlock, Schedule, Instruction)) for exp in experiments)
with warnings.catch_warnings():
# The Qobj is deprecated
warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
qobj_id, qobj_header, run_config_common_dict = _parse_common_args(
backend,
qobj_id,
qobj_header,
shots,
memory,
seed_simulator,
init_qubits,
rep_delay,
qubit_lo_freq,
meas_lo_freq,
qubit_lo_range,
meas_lo_range,
schedule_los,
pulse_qobj=pulse_qobj,
**run_config,
)
# assemble either circuits or schedules
if all(isinstance(exp, QuantumCircuit) for exp in experiments):
run_config = _parse_circuit_args(
@ -191,7 +266,7 @@ def assemble(
)
end_time = time()
_log_assembly_time(start_time, end_time)
return assemble_circuits(
return _assemble_circuits(
circuits=bound_experiments,
qobj_id=qobj_id,
qobj_header=qobj_header,

View File

@ -525,7 +525,7 @@ class BasicSimulator(BackendV2):
}
"""
# TODO: replace assemble with new run flow
from qiskit.compiler import assemble
from qiskit.compiler.assembler import _assemble
out_options = {}
for key, value in backend_options.items():
@ -535,7 +535,7 @@ class BasicSimulator(BackendV2):
)
else:
out_options[key] = value
qobj = assemble(run_input, self, **out_options)
qobj = _assemble(run_input, self, **out_options)
qobj_options = qobj.config
self._set_options(qobj_config=qobj_options, backend_options=backend_options)
job_id = str(uuid.uuid4())

View File

@ -14,6 +14,7 @@
Fake backend supporting OpenPulse.
"""
import datetime
import warnings
from qiskit.providers.models import (
GateConfig,
@ -126,152 +127,159 @@ class FakeOpenPulse2Q(FakeBackend):
description="A fake test backend with pulse defaults",
)
self._defaults = PulseDefaults.from_dict(
{
"qubit_freq_est": [4.9, 5.0],
"meas_freq_est": [6.5, 6.6],
"buffer": 10,
"pulse_library": [
{"name": "x90p_d0", "samples": 2 * [0.1 + 0j]},
{"name": "x90p_d1", "samples": 2 * [0.1 + 0j]},
{"name": "x90m_d0", "samples": 2 * [-0.1 + 0j]},
{"name": "x90m_d1", "samples": 2 * [-0.1 + 0j]},
{"name": "y90p_d0", "samples": 2 * [0.1j]},
{"name": "y90p_d1", "samples": 2 * [0.1j]},
{"name": "xp_d0", "samples": 2 * [0.2 + 0j]},
{"name": "ym_d0", "samples": 2 * [-0.2j]},
{"name": "cr90p_u0", "samples": 9 * [0.1 + 0j]},
{"name": "cr90m_u0", "samples": 9 * [-0.1 + 0j]},
{"name": "measure_m0", "samples": 10 * [0.1 + 0j]},
{"name": "measure_m1", "samples": 10 * [0.1 + 0j]},
],
"cmd_def": [
Command.from_dict(
{
"name": "u1",
"qubits": [0],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d0", t0=0, phase="-P0"
).to_dict()
],
}
).to_dict(),
Command.from_dict(
{
"name": "u1",
"qubits": [1],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d1", t0=0, phase="-P0"
).to_dict()
],
}
).to_dict(),
Command.from_dict(
{
"name": "u2",
"qubits": [0],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d0", t0=0, phase="-P1"
).to_dict(),
PulseQobjInstruction(name="y90p_d0", ch="d0", t0=0).to_dict(),
PulseQobjInstruction(
name="fc", ch="d0", t0=2, phase="-P0"
).to_dict(),
],
}
).to_dict(),
Command.from_dict(
{
"name": "u2",
"qubits": [1],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d1", t0=0, phase="-P1"
).to_dict(),
PulseQobjInstruction(name="y90p_d1", ch="d1", t0=0).to_dict(),
PulseQobjInstruction(
name="fc", ch="d1", t0=2, phase="-P0"
).to_dict(),
],
}
).to_dict(),
Command.from_dict(
{
"name": "u3",
"qubits": [0],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d0", t0=0, phase="-P2"
).to_dict(),
PulseQobjInstruction(name="x90p_d0", ch="d0", t0=0).to_dict(),
PulseQobjInstruction(
name="fc", ch="d0", t0=2, phase="-P0"
).to_dict(),
PulseQobjInstruction(name="x90m_d0", ch="d0", t0=2).to_dict(),
PulseQobjInstruction(
name="fc", ch="d0", t0=4, phase="-P1"
).to_dict(),
],
}
).to_dict(),
Command.from_dict(
{
"name": "u3",
"qubits": [1],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d1", t0=0, phase="-P2"
).to_dict(),
PulseQobjInstruction(name="x90p_d1", ch="d1", t0=0).to_dict(),
PulseQobjInstruction(
name="fc", ch="d1", t0=2, phase="-P0"
).to_dict(),
PulseQobjInstruction(name="x90m_d1", ch="d1", t0=2).to_dict(),
PulseQobjInstruction(
name="fc", ch="d1", t0=4, phase="-P1"
).to_dict(),
],
}
).to_dict(),
Command.from_dict(
{
"name": "cx",
"qubits": [0, 1],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d0", t0=0, phase=1.57
).to_dict(),
PulseQobjInstruction(name="ym_d0", ch="d0", t0=0).to_dict(),
PulseQobjInstruction(name="xp_d0", ch="d0", t0=11).to_dict(),
PulseQobjInstruction(name="x90p_d1", ch="d1", t0=0).to_dict(),
PulseQobjInstruction(name="cr90p_u0", ch="u0", t0=2).to_dict(),
PulseQobjInstruction(name="cr90m_u0", ch="u0", t0=13).to_dict(),
],
}
).to_dict(),
Command.from_dict(
{
"name": "measure",
"qubits": [0, 1],
"sequence": [
PulseQobjInstruction(name="measure_m0", ch="m0", t0=0).to_dict(),
PulseQobjInstruction(name="measure_m1", ch="m1", t0=0).to_dict(),
PulseQobjInstruction(
name="acquire",
duration=10,
t0=0,
qubits=[0, 1],
memory_slot=[0, 1],
).to_dict(),
],
}
).to_dict(),
],
}
)
with warnings.catch_warnings():
# The class PulseQobjInstruction is deprecated
warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
self._defaults = PulseDefaults.from_dict(
{
"qubit_freq_est": [4.9, 5.0],
"meas_freq_est": [6.5, 6.6],
"buffer": 10,
"pulse_library": [
{"name": "x90p_d0", "samples": 2 * [0.1 + 0j]},
{"name": "x90p_d1", "samples": 2 * [0.1 + 0j]},
{"name": "x90m_d0", "samples": 2 * [-0.1 + 0j]},
{"name": "x90m_d1", "samples": 2 * [-0.1 + 0j]},
{"name": "y90p_d0", "samples": 2 * [0.1j]},
{"name": "y90p_d1", "samples": 2 * [0.1j]},
{"name": "xp_d0", "samples": 2 * [0.2 + 0j]},
{"name": "ym_d0", "samples": 2 * [-0.2j]},
{"name": "cr90p_u0", "samples": 9 * [0.1 + 0j]},
{"name": "cr90m_u0", "samples": 9 * [-0.1 + 0j]},
{"name": "measure_m0", "samples": 10 * [0.1 + 0j]},
{"name": "measure_m1", "samples": 10 * [0.1 + 0j]},
],
"cmd_def": [
Command.from_dict(
{
"name": "u1",
"qubits": [0],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d0", t0=0, phase="-P0"
).to_dict()
],
}
).to_dict(),
Command.from_dict(
{
"name": "u1",
"qubits": [1],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d1", t0=0, phase="-P0"
).to_dict()
],
}
).to_dict(),
Command.from_dict(
{
"name": "u2",
"qubits": [0],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d0", t0=0, phase="-P1"
).to_dict(),
PulseQobjInstruction(name="y90p_d0", ch="d0", t0=0).to_dict(),
PulseQobjInstruction(
name="fc", ch="d0", t0=2, phase="-P0"
).to_dict(),
],
}
).to_dict(),
Command.from_dict(
{
"name": "u2",
"qubits": [1],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d1", t0=0, phase="-P1"
).to_dict(),
PulseQobjInstruction(name="y90p_d1", ch="d1", t0=0).to_dict(),
PulseQobjInstruction(
name="fc", ch="d1", t0=2, phase="-P0"
).to_dict(),
],
}
).to_dict(),
Command.from_dict(
{
"name": "u3",
"qubits": [0],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d0", t0=0, phase="-P2"
).to_dict(),
PulseQobjInstruction(name="x90p_d0", ch="d0", t0=0).to_dict(),
PulseQobjInstruction(
name="fc", ch="d0", t0=2, phase="-P0"
).to_dict(),
PulseQobjInstruction(name="x90m_d0", ch="d0", t0=2).to_dict(),
PulseQobjInstruction(
name="fc", ch="d0", t0=4, phase="-P1"
).to_dict(),
],
}
).to_dict(),
Command.from_dict(
{
"name": "u3",
"qubits": [1],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d1", t0=0, phase="-P2"
).to_dict(),
PulseQobjInstruction(name="x90p_d1", ch="d1", t0=0).to_dict(),
PulseQobjInstruction(
name="fc", ch="d1", t0=2, phase="-P0"
).to_dict(),
PulseQobjInstruction(name="x90m_d1", ch="d1", t0=2).to_dict(),
PulseQobjInstruction(
name="fc", ch="d1", t0=4, phase="-P1"
).to_dict(),
],
}
).to_dict(),
Command.from_dict(
{
"name": "cx",
"qubits": [0, 1],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d0", t0=0, phase=1.57
).to_dict(),
PulseQobjInstruction(name="ym_d0", ch="d0", t0=0).to_dict(),
PulseQobjInstruction(name="xp_d0", ch="d0", t0=11).to_dict(),
PulseQobjInstruction(name="x90p_d1", ch="d1", t0=0).to_dict(),
PulseQobjInstruction(name="cr90p_u0", ch="u0", t0=2).to_dict(),
PulseQobjInstruction(name="cr90m_u0", ch="u0", t0=13).to_dict(),
],
}
).to_dict(),
Command.from_dict(
{
"name": "measure",
"qubits": [0, 1],
"sequence": [
PulseQobjInstruction(
name="measure_m0", ch="m0", t0=0
).to_dict(),
PulseQobjInstruction(
name="measure_m1", ch="m1", t0=0
).to_dict(),
PulseQobjInstruction(
name="acquire",
duration=10,
t0=0,
qubits=[0, 1],
memory_slot=[0, 1],
).to_dict(),
],
}
).to_dict(),
],
}
)
mock_time = datetime.datetime.now()
dt = 1.3333

View File

@ -13,6 +13,7 @@
"""
Fake backend supporting OpenPulse.
"""
import warnings
from qiskit.providers.models import (
GateConfig,
@ -109,223 +110,231 @@ class FakeOpenPulse3Q(FakeBackend):
},
},
)
self._defaults = PulseDefaults.from_dict(
{
"qubit_freq_est": [4.9, 5.0, 4.8],
"meas_freq_est": [6.5, 6.6, 6.4],
"buffer": 10,
"pulse_library": [
{"name": "x90p_d0", "samples": 2 * [0.1 + 0j]},
{"name": "x90p_d1", "samples": 2 * [0.1 + 0j]},
{"name": "x90p_d2", "samples": 2 * [0.1 + 0j]},
{"name": "x90m_d0", "samples": 2 * [-0.1 + 0j]},
{"name": "x90m_d1", "samples": 2 * [-0.1 + 0j]},
{"name": "x90m_d2", "samples": 2 * [-0.1 + 0j]},
{"name": "y90p_d0", "samples": 2 * [0.1j]},
{"name": "y90p_d1", "samples": 2 * [0.1j]},
{"name": "y90p_d2", "samples": 2 * [0.1j]},
{"name": "xp_d0", "samples": 2 * [0.2 + 0j]},
{"name": "ym_d0", "samples": 2 * [-0.2j]},
{"name": "xp_d1", "samples": 2 * [0.2 + 0j]},
{"name": "ym_d1", "samples": 2 * [-0.2j]},
{"name": "cr90p_u0", "samples": 9 * [0.1 + 0j]},
{"name": "cr90m_u0", "samples": 9 * [-0.1 + 0j]},
{"name": "cr90p_u1", "samples": 9 * [0.1 + 0j]},
{"name": "cr90m_u1", "samples": 9 * [-0.1 + 0j]},
{"name": "measure_m0", "samples": 10 * [0.1 + 0j]},
{"name": "measure_m1", "samples": 10 * [0.1 + 0j]},
{"name": "measure_m2", "samples": 10 * [0.1 + 0j]},
],
"cmd_def": [
Command.from_dict(
{
"name": "u1",
"qubits": [0],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d0", t0=0, phase="-P0"
).to_dict()
],
}
).to_dict(),
Command.from_dict(
{
"name": "u1",
"qubits": [1],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d1", t0=0, phase="-P0"
).to_dict()
],
}
).to_dict(),
Command.from_dict(
{
"name": "u1",
"qubits": [2],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d2", t0=0, phase="-P0"
).to_dict()
],
}
).to_dict(),
Command.from_dict(
{
"name": "u2",
"qubits": [0],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d0", t0=0, phase="-P1"
).to_dict(),
PulseQobjInstruction(name="y90p_d0", ch="d0", t0=0).to_dict(),
PulseQobjInstruction(
name="fc", ch="d0", t0=2, phase="-P0"
).to_dict(),
],
}
).to_dict(),
Command.from_dict(
{
"name": "u2",
"qubits": [1],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d1", t0=0, phase="-P1"
).to_dict(),
PulseQobjInstruction(name="y90p_d1", ch="d1", t0=0).to_dict(),
PulseQobjInstruction(
name="fc", ch="d1", t0=2, phase="-P0"
).to_dict(),
],
}
).to_dict(),
Command.from_dict(
{
"name": "u2",
"qubits": [2],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d2", t0=0, phase="-P1"
).to_dict(),
PulseQobjInstruction(name="y90p_d2", ch="d2", t0=0).to_dict(),
PulseQobjInstruction(
name="fc", ch="d2", t0=2, phase="-P0"
).to_dict(),
],
}
).to_dict(),
Command.from_dict(
{
"name": "u3",
"qubits": [0],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d0", t0=0, phase="-P2"
).to_dict(),
PulseQobjInstruction(name="x90p_d0", ch="d0", t0=0).to_dict(),
PulseQobjInstruction(
name="fc", ch="d0", t0=2, phase="-P0"
).to_dict(),
PulseQobjInstruction(name="x90m_d0", ch="d0", t0=2).to_dict(),
PulseQobjInstruction(
name="fc", ch="d0", t0=4, phase="-P1"
).to_dict(),
],
}
).to_dict(),
Command.from_dict(
{
"name": "u3",
"qubits": [1],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d1", t0=0, phase="-P2"
).to_dict(),
PulseQobjInstruction(name="x90p_d1", ch="d1", t0=0).to_dict(),
PulseQobjInstruction(
name="fc", ch="d1", t0=2, phase="-P0"
).to_dict(),
PulseQobjInstruction(name="x90m_d1", ch="d1", t0=2).to_dict(),
PulseQobjInstruction(
name="fc", ch="d1", t0=4, phase="-P1"
).to_dict(),
],
}
).to_dict(),
Command.from_dict(
{
"name": "u3",
"qubits": [2],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d2", t0=0, phase="-P2"
).to_dict(),
PulseQobjInstruction(name="x90p_d2", ch="d2", t0=0).to_dict(),
PulseQobjInstruction(
name="fc", ch="d2", t0=2, phase="-P0"
).to_dict(),
PulseQobjInstruction(name="x90m_d2", ch="d2", t0=2).to_dict(),
PulseQobjInstruction(
name="fc", ch="d2", t0=4, phase="-P1"
).to_dict(),
],
}
).to_dict(),
Command.from_dict(
{
"name": "cx",
"qubits": [0, 1],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d0", t0=0, phase=1.57
).to_dict(),
PulseQobjInstruction(name="ym_d0", ch="d0", t0=0).to_dict(),
PulseQobjInstruction(name="xp_d0", ch="d0", t0=11).to_dict(),
PulseQobjInstruction(name="x90p_d1", ch="d1", t0=0).to_dict(),
PulseQobjInstruction(name="cr90p_u0", ch="u0", t0=2).to_dict(),
PulseQobjInstruction(name="cr90m_u0", ch="u0", t0=13).to_dict(),
],
}
).to_dict(),
Command.from_dict(
{
"name": "cx",
"qubits": [1, 2],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d1", t0=0, phase=1.57
).to_dict(),
PulseQobjInstruction(name="ym_d1", ch="d1", t0=0).to_dict(),
PulseQobjInstruction(name="xp_d1", ch="d1", t0=11).to_dict(),
PulseQobjInstruction(name="x90p_d2", ch="d2", t0=0).to_dict(),
PulseQobjInstruction(name="cr90p_u1", ch="u1", t0=2).to_dict(),
PulseQobjInstruction(name="cr90m_u1", ch="u1", t0=13).to_dict(),
],
}
).to_dict(),
Command.from_dict(
{
"name": "measure",
"qubits": [0, 1, 2],
"sequence": [
PulseQobjInstruction(name="measure_m0", ch="m0", t0=0).to_dict(),
PulseQobjInstruction(name="measure_m1", ch="m1", t0=0).to_dict(),
PulseQobjInstruction(name="measure_m2", ch="m2", t0=0).to_dict(),
PulseQobjInstruction(
name="acquire",
duration=10,
t0=0,
qubits=[0, 1, 2],
memory_slot=[0, 1, 2],
).to_dict(),
],
}
).to_dict(),
],
}
)
with warnings.catch_warnings():
# The class PulseQobjInstruction is deprecated
warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
self._defaults = PulseDefaults.from_dict(
{
"qubit_freq_est": [4.9, 5.0, 4.8],
"meas_freq_est": [6.5, 6.6, 6.4],
"buffer": 10,
"pulse_library": [
{"name": "x90p_d0", "samples": 2 * [0.1 + 0j]},
{"name": "x90p_d1", "samples": 2 * [0.1 + 0j]},
{"name": "x90p_d2", "samples": 2 * [0.1 + 0j]},
{"name": "x90m_d0", "samples": 2 * [-0.1 + 0j]},
{"name": "x90m_d1", "samples": 2 * [-0.1 + 0j]},
{"name": "x90m_d2", "samples": 2 * [-0.1 + 0j]},
{"name": "y90p_d0", "samples": 2 * [0.1j]},
{"name": "y90p_d1", "samples": 2 * [0.1j]},
{"name": "y90p_d2", "samples": 2 * [0.1j]},
{"name": "xp_d0", "samples": 2 * [0.2 + 0j]},
{"name": "ym_d0", "samples": 2 * [-0.2j]},
{"name": "xp_d1", "samples": 2 * [0.2 + 0j]},
{"name": "ym_d1", "samples": 2 * [-0.2j]},
{"name": "cr90p_u0", "samples": 9 * [0.1 + 0j]},
{"name": "cr90m_u0", "samples": 9 * [-0.1 + 0j]},
{"name": "cr90p_u1", "samples": 9 * [0.1 + 0j]},
{"name": "cr90m_u1", "samples": 9 * [-0.1 + 0j]},
{"name": "measure_m0", "samples": 10 * [0.1 + 0j]},
{"name": "measure_m1", "samples": 10 * [0.1 + 0j]},
{"name": "measure_m2", "samples": 10 * [0.1 + 0j]},
],
"cmd_def": [
Command.from_dict(
{
"name": "u1",
"qubits": [0],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d0", t0=0, phase="-P0"
).to_dict()
],
}
).to_dict(),
Command.from_dict(
{
"name": "u1",
"qubits": [1],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d1", t0=0, phase="-P0"
).to_dict()
],
}
).to_dict(),
Command.from_dict(
{
"name": "u1",
"qubits": [2],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d2", t0=0, phase="-P0"
).to_dict()
],
}
).to_dict(),
Command.from_dict(
{
"name": "u2",
"qubits": [0],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d0", t0=0, phase="-P1"
).to_dict(),
PulseQobjInstruction(name="y90p_d0", ch="d0", t0=0).to_dict(),
PulseQobjInstruction(
name="fc", ch="d0", t0=2, phase="-P0"
).to_dict(),
],
}
).to_dict(),
Command.from_dict(
{
"name": "u2",
"qubits": [1],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d1", t0=0, phase="-P1"
).to_dict(),
PulseQobjInstruction(name="y90p_d1", ch="d1", t0=0).to_dict(),
PulseQobjInstruction(
name="fc", ch="d1", t0=2, phase="-P0"
).to_dict(),
],
}
).to_dict(),
Command.from_dict(
{
"name": "u2",
"qubits": [2],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d2", t0=0, phase="-P1"
).to_dict(),
PulseQobjInstruction(name="y90p_d2", ch="d2", t0=0).to_dict(),
PulseQobjInstruction(
name="fc", ch="d2", t0=2, phase="-P0"
).to_dict(),
],
}
).to_dict(),
Command.from_dict(
{
"name": "u3",
"qubits": [0],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d0", t0=0, phase="-P2"
).to_dict(),
PulseQobjInstruction(name="x90p_d0", ch="d0", t0=0).to_dict(),
PulseQobjInstruction(
name="fc", ch="d0", t0=2, phase="-P0"
).to_dict(),
PulseQobjInstruction(name="x90m_d0", ch="d0", t0=2).to_dict(),
PulseQobjInstruction(
name="fc", ch="d0", t0=4, phase="-P1"
).to_dict(),
],
}
).to_dict(),
Command.from_dict(
{
"name": "u3",
"qubits": [1],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d1", t0=0, phase="-P2"
).to_dict(),
PulseQobjInstruction(name="x90p_d1", ch="d1", t0=0).to_dict(),
PulseQobjInstruction(
name="fc", ch="d1", t0=2, phase="-P0"
).to_dict(),
PulseQobjInstruction(name="x90m_d1", ch="d1", t0=2).to_dict(),
PulseQobjInstruction(
name="fc", ch="d1", t0=4, phase="-P1"
).to_dict(),
],
}
).to_dict(),
Command.from_dict(
{
"name": "u3",
"qubits": [2],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d2", t0=0, phase="-P2"
).to_dict(),
PulseQobjInstruction(name="x90p_d2", ch="d2", t0=0).to_dict(),
PulseQobjInstruction(
name="fc", ch="d2", t0=2, phase="-P0"
).to_dict(),
PulseQobjInstruction(name="x90m_d2", ch="d2", t0=2).to_dict(),
PulseQobjInstruction(
name="fc", ch="d2", t0=4, phase="-P1"
).to_dict(),
],
}
).to_dict(),
Command.from_dict(
{
"name": "cx",
"qubits": [0, 1],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d0", t0=0, phase=1.57
).to_dict(),
PulseQobjInstruction(name="ym_d0", ch="d0", t0=0).to_dict(),
PulseQobjInstruction(name="xp_d0", ch="d0", t0=11).to_dict(),
PulseQobjInstruction(name="x90p_d1", ch="d1", t0=0).to_dict(),
PulseQobjInstruction(name="cr90p_u0", ch="u0", t0=2).to_dict(),
PulseQobjInstruction(name="cr90m_u0", ch="u0", t0=13).to_dict(),
],
}
).to_dict(),
Command.from_dict(
{
"name": "cx",
"qubits": [1, 2],
"sequence": [
PulseQobjInstruction(
name="fc", ch="d1", t0=0, phase=1.57
).to_dict(),
PulseQobjInstruction(name="ym_d1", ch="d1", t0=0).to_dict(),
PulseQobjInstruction(name="xp_d1", ch="d1", t0=11).to_dict(),
PulseQobjInstruction(name="x90p_d2", ch="d2", t0=0).to_dict(),
PulseQobjInstruction(name="cr90p_u1", ch="u1", t0=2).to_dict(),
PulseQobjInstruction(name="cr90m_u1", ch="u1", t0=13).to_dict(),
],
}
).to_dict(),
Command.from_dict(
{
"name": "measure",
"qubits": [0, 1, 2],
"sequence": [
PulseQobjInstruction(
name="measure_m0", ch="m0", t0=0
).to_dict(),
PulseQobjInstruction(
name="measure_m1", ch="m1", t0=0
).to_dict(),
PulseQobjInstruction(
name="measure_m2", ch="m2", t0=0
).to_dict(),
PulseQobjInstruction(
name="acquire",
duration=10,
t0=0,
qubits=[0, 1, 2],
memory_slot=[0, 1, 2],
).to_dict(),
],
}
).to_dict(),
],
}
)
super().__init__(configuration)
def defaults(self): # pylint: disable=missing-function-docstring

View File

@ -266,27 +266,36 @@ class GenericBackendV2(BackendV2):
# Note that the calibration pulses are different for
# 1q gates vs 2q gates vs measurement instructions.
if inst == "measure":
sequence = [
PulseQobjInstruction(
name="acquire",
duration=1792,
t0=0,
qubits=qargs,
memory_slot=qargs,
)
] + [PulseQobjInstruction(name=pulse_library[1].name, ch=f"m{i}", t0=0) for i in qargs]
with warnings.catch_warnings():
# The class PulseQobjInstruction is deprecated
warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
sequence = [
PulseQobjInstruction(
name="acquire",
duration=1792,
t0=0,
qubits=qargs,
memory_slot=qargs,
)
] + [
PulseQobjInstruction(name=pulse_library[1].name, ch=f"m{i}", t0=0)
for i in qargs
]
return sequence
if num_qubits == 1:
with warnings.catch_warnings():
# The class PulseQobjInstruction is deprecated
warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
if num_qubits == 1:
return [
PulseQobjInstruction(name="fc", ch=f"u{qargs[0]}", t0=0, phase="-P0"),
PulseQobjInstruction(name=pulse_library[0].name, ch=f"d{qargs[0]}", t0=0),
]
return [
PulseQobjInstruction(name="fc", ch=f"u{qargs[0]}", t0=0, phase="-P0"),
PulseQobjInstruction(name=pulse_library[0].name, ch=f"d{qargs[0]}", t0=0),
PulseQobjInstruction(name=pulse_library[1].name, ch=f"d{qargs[0]}", t0=0),
PulseQobjInstruction(name=pulse_library[2].name, ch=f"u{qargs[0]}", t0=0),
PulseQobjInstruction(name=pulse_library[1].name, ch=f"d{qargs[1]}", t0=0),
PulseQobjInstruction(name="fc", ch=f"d{qargs[1]}", t0=0, phase=2.1),
]
return [
PulseQobjInstruction(name=pulse_library[1].name, ch=f"d{qargs[0]}", t0=0),
PulseQobjInstruction(name=pulse_library[2].name, ch=f"u{qargs[0]}", t0=0),
PulseQobjInstruction(name=pulse_library[1].name, ch=f"d{qargs[1]}", t0=0),
PulseQobjInstruction(name="fc", ch=f"d{qargs[1]}", t0=0, phase=2.1),
]
def _generate_calibration_defaults(self) -> PulseDefaults:
"""Generate pulse calibration defaults as specified with `self._calibrate_instructions`.

View File

@ -12,6 +12,7 @@
"""Model and schema for pulse defaults."""
import warnings
from typing import Any, Dict, List
from qiskit.pulse.instruction_schedule_map import InstructionScheduleMap, PulseQobjDef
@ -271,7 +272,7 @@ class PulseDefaults:
PulseDefaults: The PulseDefaults from the input dictionary.
"""
schema = {
"pulse_library": PulseLibraryItem,
"pulse_library": PulseLibraryItem, # The class PulseLibraryItem is deprecated
"cmd_def": Command,
"meas_kernel": MeasurementKernel,
"discriminator": Discriminator,
@ -282,10 +283,13 @@ class PulseDefaults:
in_data = {}
for key, value in data.items():
if key in schema:
if isinstance(value, list):
in_data[key] = list(map(schema[key].from_dict, value))
else:
in_data[key] = schema[key].from_dict(value)
with warnings.catch_warnings():
# The class PulseLibraryItem is deprecated
warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
if isinstance(value, list):
in_data[key] = list(map(schema[key].from_dict, value))
else:
in_data[key] = schema[key].from_dict(value)
else:
in_data[key] = value

View File

@ -13,6 +13,8 @@
"""Module providing definitions of common Qobj classes."""
from types import SimpleNamespace
from qiskit.utils import deprecate_func
class QobjDictField(SimpleNamespace):
"""A class used to represent a dictionary field in Qobj
@ -21,6 +23,14 @@ class QobjDictField(SimpleNamespace):
previously constructed using marshmallow.
"""
@deprecate_func(
since="1.2",
removal_timeline="in the 2.0 release",
additional_msg="The `Qobj` class and related functionality are part of the deprecated "
"`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user "
"workflow requires `Qobj` it likely relies on deprecated functionality and "
"should be updated to use `BackendV2`.",
)
def __init__(self, **kwargs):
"""Instantiate a new Qobj dict field object.

View File

@ -15,6 +15,7 @@
from qiskit.pulse.channels import DriveChannel, MeasureChannel
from qiskit.pulse.configuration import LoConfig
from qiskit.exceptions import QiskitError
from qiskit.utils import deprecate_func
class LoConfigConverter:
@ -23,6 +24,14 @@ class LoConfigConverter:
``get_qubit_los`` and ``get_meas_los`` to align with your backend.
"""
@deprecate_func(
since="1.2",
removal_timeline="in the 2.0 release",
additional_msg="The `Qobj` class and related functionality are part of the deprecated "
"`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user "
"workflow requires `Qobj` it likely relies on deprecated functionality and "
"should be updated to use `BackendV2`.",
)
def __init__(
self,
qobj_model,

View File

@ -30,6 +30,7 @@ from qiskit.pulse.parser import parse_string_expr
from qiskit.pulse.schedule import Schedule
from qiskit.qobj import QobjMeasurementOption, PulseLibraryItem, PulseQobjInstruction
from qiskit.qobj.utils import MeasLevel
from qiskit.utils import deprecate_func
class ParametricPulseShapes(Enum):
@ -107,6 +108,14 @@ class InstructionToQobjConverter:
where ``NewInstruction`` must be a class name of Qiskit Pulse instruction.
"""
@deprecate_func(
since="1.2",
removal_timeline="in the 2.0 release",
additional_msg="The `Qobj` class and related functionality are part of the deprecated "
"`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user "
"workflow requires `Qobj` it likely relies on deprecated functionality and "
"should be updated to use `BackendV2`.",
)
def __init__(
self,
qobj_model: PulseQobjInstruction,

View File

@ -23,11 +23,20 @@ import numpy
from qiskit.qobj.common import QobjDictField
from qiskit.qobj.common import QobjHeader
from qiskit.qobj.common import QobjExperimentHeader
from qiskit.utils import deprecate_func
class QobjMeasurementOption:
"""An individual measurement option."""
@deprecate_func(
since="1.2",
removal_timeline="in the 2.0 release",
additional_msg="The `Qobj` class and related functionality are part of the deprecated "
"`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user "
"workflow requires `Qobj` it likely relies on deprecated functionality and "
"should be updated to use `BackendV2`.",
)
def __init__(self, name, params=None):
"""Instantiate a new QobjMeasurementOption object.
@ -89,6 +98,14 @@ class PulseQobjInstruction:
"parameters",
]
@deprecate_func(
since="1.2",
removal_timeline="in the 2.0 release",
additional_msg="The `Qobj` class and related functionality are part of the deprecated "
"`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user "
"workflow requires `Qobj` it likely relies on deprecated functionality and "
"should be updated to use `BackendV2`.",
)
def __init__(
self,
name,
@ -282,6 +299,14 @@ def _to_complex(value: Union[List[float], complex]) -> complex:
class PulseQobjConfig(QobjDictField):
"""A configuration for a Pulse Qobj."""
@deprecate_func(
since="1.2",
removal_timeline="in the 2.0 release",
additional_msg="The `Qobj` class and related functionality are part of the deprecated "
"`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user "
"workflow requires `Qobj` it likely relies on deprecated functionality and "
"should be updated to use `BackendV2`.",
)
def __init__(
self,
meas_level,
@ -383,6 +408,14 @@ class PulseQobjExperiment:
experiment as part of a larger Pulse Qobj.
"""
@deprecate_func(
since="1.2",
removal_timeline="in the 2.0 release",
additional_msg="The `Qobj` class and related functionality are part of the deprecated "
"`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user "
"workflow requires `Qobj` it likely relies on deprecated functionality and "
"should be updated to use `BackendV2`.",
)
def __init__(self, instructions, config=None, header=None):
"""Instantiate a PulseQobjExperiment.
@ -473,6 +506,14 @@ class PulseQobjExperiment:
class PulseQobjExperimentConfig(QobjDictField):
"""A config for a single Pulse experiment in the qobj."""
@deprecate_func(
since="1.2",
removal_timeline="in the 2.0 release",
additional_msg="The `Qobj` class and related functionality are part of the deprecated "
"`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user "
"workflow requires `Qobj` it likely relies on deprecated functionality and "
"should be updated to use `BackendV2`.",
)
def __init__(self, qubit_lo_freq=None, meas_lo_freq=None, **kwargs):
"""Instantiate a PulseQobjExperimentConfig object.
@ -492,6 +533,14 @@ class PulseQobjExperimentConfig(QobjDictField):
class PulseLibraryItem:
"""An item in a pulse library."""
@deprecate_func(
since="1.2",
removal_timeline="in the 2.0 release",
additional_msg="The `Qobj` class and related functionality are part of the deprecated "
"`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user "
"workflow requires `Qobj` it likely relies on deprecated functionality and "
"should be updated to use `BackendV2`.",
)
def __init__(self, name, samples):
"""Instantiate a pulse library item.
@ -542,6 +591,14 @@ class PulseLibraryItem:
class PulseQobj:
"""A Pulse Qobj."""
@deprecate_func(
since="1.2",
removal_timeline="in the 2.0 release",
additional_msg="The `Qobj` class and related functionality are part of the deprecated "
"`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user "
"workflow requires `Qobj` it likely relies on deprecated functionality and "
"should be updated to use `BackendV2`.",
)
def __init__(self, qobj_id, config, experiments, header=None):
"""Instantiate a new Pulse Qobj Object.

View File

@ -18,11 +18,20 @@ from types import SimpleNamespace
from qiskit.circuit.parameterexpression import ParameterExpression
from qiskit.qobj.pulse_qobj import PulseQobjInstruction, PulseLibraryItem
from qiskit.qobj.common import QobjDictField, QobjHeader
from qiskit.utils import deprecate_func
class QasmQobjInstruction:
"""A class representing a single instruction in an QasmQobj Experiment."""
@deprecate_func(
since="1.2",
removal_timeline="in the 2.0 release",
additional_msg="The `Qobj` class and related functionality are part of the deprecated "
"`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user "
"workflow requires `Qobj` it likely relies on deprecated functionality and "
"should be updated to use `BackendV2`.",
)
def __init__(
self,
name,
@ -200,6 +209,14 @@ class QasmQobjExperiment:
part of a larger OpenQASM 2 qobj.
"""
@deprecate_func(
since="1.2",
removal_timeline="in the 2.0 release",
additional_msg="The `Qobj` class and related functionality are part of the deprecated "
"`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user "
"workflow requires `Qobj` it likely relies on deprecated functionality and "
"should be updated to use `BackendV2`.",
)
def __init__(self, config=None, header=None, instructions=None):
"""Instantiate a QasmQobjExperiment.
@ -276,6 +293,14 @@ class QasmQobjExperiment:
class QasmQobjConfig(SimpleNamespace):
"""A configuration for an OpenQASM 2 Qobj."""
@deprecate_func(
since="1.2",
removal_timeline="in the 2.0 release",
additional_msg="The `Qobj` class and related functionality are part of the deprecated "
"`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user "
"workflow requires `Qobj` it likely relies on deprecated functionality and "
"should be updated to use `BackendV2`.",
)
def __init__(
self,
shots=None,
@ -410,6 +435,14 @@ class QasmQobjExperimentHeader(QobjDictField):
class QasmQobjExperimentConfig(QobjDictField):
"""Configuration for a single OpenQASM 2 experiment in the qobj."""
@deprecate_func(
since="1.2",
removal_timeline="in the 2.0 release",
additional_msg="The `Qobj` class and related functionality are part of the deprecated "
"`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user "
"workflow requires `Qobj` it likely relies on deprecated functionality and "
"should be updated to use `BackendV2`.",
)
def __init__(self, calibrations=None, qubit_lo_freq=None, meas_lo_freq=None, **kwargs):
"""
Args:
@ -446,6 +479,14 @@ class QasmExperimentCalibrations:
GateCalibrations.
"""
@deprecate_func(
since="1.2",
removal_timeline="in the 2.0 release",
additional_msg="The `Qobj` class and related functionality are part of the deprecated "
"`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user "
"workflow requires `Qobj` it likely relies on deprecated functionality and "
"should be updated to use `BackendV2`.",
)
def __init__(self, gates):
"""
Initialize a container for calibrations.
@ -486,6 +527,14 @@ class GateCalibration:
"""Each calibration specifies a unique gate by name, qubits and params, and
contains the Pulse instructions to implement it."""
@deprecate_func(
since="1.2",
removal_timeline="in the 2.0 release",
additional_msg="The `Qobj` class and related functionality are part of the deprecated "
"`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user "
"workflow requires `Qobj` it likely relies on deprecated functionality and "
"should be updated to use `BackendV2`.",
)
def __init__(self, name, qubits, params, instructions):
"""
Initialize a single gate calibration. Instructions may reference waveforms which should be
@ -541,6 +590,14 @@ class GateCalibration:
class QasmQobj:
"""An OpenQASM 2 Qobj."""
@deprecate_func(
since="1.2",
removal_timeline="in the 2.0 release",
additional_msg="The `Qobj` class and related functionality are part of the deprecated "
"`BackendV1` workflow, and no longer necessary for `BackendV2`. If a user "
"workflow requires `Qobj` it likely relies on deprecated functionality and "
"should be updated to use `BackendV2`.",
)
def __init__(self, qobj_id=None, config=None, experiments=None, header=None):
"""Instantiate a new OpenQASM 2 Qobj Object.

View File

@ -14,7 +14,16 @@
from enum import Enum, IntEnum
from qiskit.utils import deprecate_func
@deprecate_func(
since="1.2",
removal_timeline="in the 2.0 release",
additional_msg="The `Qobj` class and related functionality are part of the deprecated `BackendV1` "
"workflow, and no longer necessary for `BackendV2`. If a user workflow requires `Qobj` it likely "
"relies on deprecated functionality and should be updated to use `BackendV2`.",
)
class QobjType(str, Enum):
"""Qobj.type allowed values."""

View File

@ -13,6 +13,7 @@
"""Schema and helper models for schema-conformant Results."""
import copy
import warnings
from qiskit.qobj.utils import MeasReturnType, MeasLevel
from qiskit.qobj import QobjExperimentHeader
@ -223,7 +224,10 @@ class ExperimentResult:
in_data = copy.copy(data)
data_obj = ExperimentResultData.from_dict(in_data.pop("data"))
if "header" in in_data:
in_data["header"] = QobjExperimentHeader.from_dict(in_data.pop("header"))
with warnings.catch_warnings():
# The class QobjExperimentHeader is deprecated
warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
in_data["header"] = QobjExperimentHeader.from_dict(in_data.pop("header"))
shots = in_data.pop("shots")
success = in_data.pop("success")

View File

@ -125,7 +125,9 @@ class Result:
in_data = copy.copy(data)
in_data["results"] = [ExperimentResult.from_dict(x) for x in in_data.pop("results")]
if in_data.get("header") is not None:
in_data["header"] = QobjHeader.from_dict(in_data.pop("header"))
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
in_data["header"] = QobjHeader.from_dict(in_data.pop("header"))
return cls(**in_data)
def data(self, experiment=None):

View File

@ -0,0 +1,7 @@
---
deprecations_providers:
- |
The `Qobj` structure and related classes are now deprecated, they were introduced as part of the `BackendV1` workflow and are no longer necessary for interacting with :class:`.BackendV2` backends. Remote backend interaction should be done via `QPY` or `OpenQASM` instead.
deprecations_transpiler:
- |
The `assemble` function is now deprecated and will be removed in the 2.0 release. The function was primarily used to create a `Qobj`, which is no longer necessary in :class:`.BackendV2`-based workflows. It was also used for binding parameters, a functionality fully covered by :meth:`~.QuantumCircuit.assign_parameters`.

View File

@ -46,4 +46,6 @@ class DisassemblerBenchmarks:
self.qobj = assemble(self.circuits)
def time_disassemble_circuit(self, _, __, ___):
# TODO: QObj is getting deprecated. Remove once that happens
# https://github.com/Qiskit/qiskit/pull/12649
disassemble(self.qobj)

View File

@ -75,11 +75,13 @@ class TestDiagonalGate(QiskitTestCase):
all(isinstance(p, complex) and not isinstance(p, np.number) for p in params)
)
qobj = assemble(qc)
params = qobj.experiments[0].instructions[0].params
self.assertTrue(
all(isinstance(p, complex) and not isinstance(p, np.number) for p in params)
)
with self.assertWarns(DeprecationWarning):
# REMOVE this assertion (not the full test) once ASSEMBLE is removed.
qobj = assemble(qc)
params = qobj.experiments[0].instructions[0].params
self.assertTrue(
all(isinstance(p, complex) and not isinstance(p, np.number) for p in params)
)
def _get_diag_gate_matrix(diag):

View File

@ -131,7 +131,8 @@ class TestHamiltonianCircuit(QiskitTestCase):
np.testing.assert_almost_equal(dnode.op.to_matrix(), 1j * matrix.data)
def test_qobj_with_hamiltonian(self):
"""test qobj output with hamiltonian"""
"""test qobj output with hamiltonian
REMOVE once Qobj gets removed"""
qr = QuantumRegister(4)
qc = QuantumCircuit(qr)
qc.rx(np.pi / 4, qr[0])
@ -141,7 +142,8 @@ class TestHamiltonianCircuit(QiskitTestCase):
qc.append(uni, [qr[0], qr[1], qr[3]])
qc.cx(qr[3], qr[2])
qc = qc.assign_parameters({theta: np.pi / 2})
qobj = qiskit.compiler.assemble(qc)
with self.assertWarns(DeprecationWarning):
qobj = qiskit.compiler.assemble(qc)
instr = qobj.experiments[0].instructions[1]
self.assertEqual(instr.name, "hamiltonian")
# Also test label

View File

@ -481,7 +481,8 @@ class TestInstructionParam(QiskitTestCase):
all(isinstance(p, complex) and not isinstance(p, np.number) for p in params)
)
qobj = assemble(qc)
with self.assertWarns(DeprecationWarning):
qobj = assemble(qc)
params = qobj.experiments[0].instructions[0].params
self.assertTrue(
all(isinstance(p, complex) and not isinstance(p, np.number) for p in params)

View File

@ -793,7 +793,8 @@ class TestParameters(QiskitTestCase):
theta_list = numpy.linspace(0, numpy.pi, 20)
for theta_i in theta_list:
circs.append(qc_aer.assign_parameters({theta: theta_i}))
qobj = assemble(circs)
with self.assertWarns(DeprecationWarning):
qobj = assemble(circs)
for index, theta_i in enumerate(theta_list):
res = float(qobj.experiments[index].instructions[0].params[0])
self.assertTrue(math.isclose(res, theta_i), f"{res} != {theta_i}")
@ -980,8 +981,9 @@ class TestParameters(QiskitTestCase):
self.assertEqual(hash(x1), hash(x1_expr))
self.assertEqual(hash(x2), hash(x2_expr))
def test_binding_parameterized_circuits_built_in_multiproc(self):
"""Verify subcircuits built in a subprocess can still be bound."""
def test_binding_parameterized_circuits_built_in_multiproc_(self):
"""Verify subcircuits built in a subprocess can still be bound.
REMOVE this test once assemble is REMOVED"""
# ref: https://github.com/Qiskit/qiskit-terra/issues/2429
num_processes = 4
@ -1001,11 +1003,12 @@ class TestParameters(QiskitTestCase):
parameter_values = [{x: 1.0 for x in parameters}]
qobj = assemble(
circuit,
backend=BasicSimulator(),
parameter_binds=parameter_values,
)
with self.assertWarns(DeprecationWarning):
qobj = assemble(
circuit,
backend=BasicSimulator(),
parameter_binds=parameter_values,
)
self.assertEqual(len(qobj.experiments), 1)
self.assertEqual(len(qobj.experiments[0].instructions), 4)
@ -1018,6 +1021,39 @@ class TestParameters(QiskitTestCase):
)
)
def test_binding_parameterized_circuits_built_in_multiproc(self):
"""Verify subcircuits built in a subprocess can still be bound."""
# ref: https://github.com/Qiskit/qiskit-terra/issues/2429
num_processes = 4
qr = QuantumRegister(3)
cr = ClassicalRegister(3)
circuit = QuantumCircuit(qr, cr)
parameters = [Parameter(f"x{i}") for i in range(num_processes)]
results = parallel_map(
_construct_circuit, parameters, task_args=(qr,), num_processes=num_processes
)
for qc in results:
circuit.compose(qc, inplace=True)
parameter_values = {x: 1.0 for x in parameters}
bind_circuit = circuit.assign_parameters(parameter_values)
self.assertEqual(len(bind_circuit.data), 4)
self.assertTrue(
all(
len(inst.operation.params) == 1
and isinstance(inst.operation.params[0], float)
and float(inst.operation.params[0]) == 1
for inst in bind_circuit.data
)
)
def test_transpiling_multiple_parameterized_circuits(self):
"""Verify several parameterized circuits can be transpiled at once."""
# ref: https://github.com/Qiskit/qiskit-terra/issues/2864

View File

@ -66,11 +66,6 @@ class TestScheduledCircuit(QiskitTestCase):
self.assertEqual(sc.data[4].operation.name, "delay")
self.assertEqual(sc.data[4].operation.duration, 450450)
self.assertEqual(sc.data[4].operation.unit, "dt")
qobj = assemble(sc, self.backend_with_dt)
self.assertEqual(qobj.experiments[0].instructions[0].name, "delay")
self.assertEqual(qobj.experiments[0].instructions[0].params[0], 450450)
self.assertEqual(qobj.experiments[0].instructions[4].name, "delay")
self.assertEqual(qobj.experiments[0].instructions[4].params[0], 450450)
def test_schedule_circuit_when_transpile_option_tells_dt(self):
"""dt is known to transpiler by transpile option"""
@ -119,7 +114,7 @@ class TestScheduledCircuit(QiskitTestCase):
self.assertEqual(sc.data[4].operation.name, "delay")
self.assertAlmostEqual(sc.data[4].operation.duration, 1.0e-4 + 1.0e-7)
self.assertEqual(sc.data[4].operation.unit, "s")
with self.assertRaises(QiskitError):
with self.assertRaises(DeprecationWarning):
assemble(sc, self.backend_without_dt)
def test_cannot_schedule_circuit_with_mixed_SI_and_dt_when_no_one_tells_dt(self):
@ -377,7 +372,8 @@ class TestScheduledCircuit(QiskitTestCase):
qc.delay(100, 0, "ns")
circ = transpile(qc, self.simulator_backend)
self.assertEqual(circ.duration, None) # not scheduled
qobj = assemble(circ, self.simulator_backend)
with self.assertWarns(DeprecationWarning):
qobj = assemble(circ, self.simulator_backend)
self.assertEqual(qobj.experiments[0].instructions[0].name, "delay")
self.assertEqual(qobj.experiments[0].instructions[0].params[0], 1e-7)
@ -389,7 +385,8 @@ class TestScheduledCircuit(QiskitTestCase):
qc.measure(0, 0)
circ = transpile(qc, self.simulator_backend)
self.assertEqual(circ.duration, None) # not scheduled
qobj = assemble(circ, self.simulator_backend)
with self.assertWarns(DeprecationWarning):
qobj = assemble(circ, self.simulator_backend)
self.assertEqual(qobj.experiments[0].instructions[1].name, "delay")
self.assertAlmostEqual(qobj.experiments[0].instructions[1].params[0], 1e-7)
@ -415,7 +412,8 @@ class TestScheduledCircuit(QiskitTestCase):
qc.measure(0, 0)
circ = transpile(qc, self.backend_with_dt)
circ = circ.assign_parameters({idle_dur: 0.1})
qobj = assemble(circ, self.backend_with_dt)
with self.assertWarns(DeprecationWarning):
qobj = assemble(circ, self.backend_with_dt)
self.assertEqual(qobj.experiments[0].instructions[1].name, "delay")
self.assertEqual(qobj.experiments[0].instructions[1].params[0], 450)
@ -440,7 +438,7 @@ class TestScheduledCircuit(QiskitTestCase):
qc.delay(idle_dur, 0, "us")
qc.measure(0, 0)
qc = transpile(qc, self.backend_with_dt)
with self.assertRaises(QiskitError):
with self.assertRaises(DeprecationWarning):
assemble(qc, self.backend_with_dt)
@data("asap", "alap")

View File

@ -168,7 +168,8 @@ class TestUnitaryCircuit(QiskitTestCase):
uni = UnitaryGate(matrix)
qc.append(uni, [qr[0], qr[1], qr[3]])
qc.cx(qr[3], qr[2])
qobj = qiskit.compiler.assemble(qc)
with self.assertWarns(DeprecationWarning):
qobj = qiskit.compiler.assemble(qc)
instr = qobj.experiments[0].instructions[1]
self.assertEqual(instr.name, "unitary")
assert_allclose(numpy.array(instr.params[0]).astype(numpy.complex64), matrix)
@ -197,7 +198,8 @@ class TestUnitaryCircuit(QiskitTestCase):
matrix = numpy.kron(sigmax, sigmay)
uni = UnitaryGate(matrix, label="xy")
qc.append(uni, [qr[0], qr[1]])
qobj = qiskit.compiler.assemble(qc)
with self.assertWarns(DeprecationWarning):
qobj = qiskit.compiler.assemble(qc)
instr = qobj.experiments[0].instructions[0]
self.assertEqual(instr.name, "unitary")
self.assertEqual(instr.label, "xy")

File diff suppressed because it is too large Load Diff

View File

@ -197,7 +197,8 @@ class TestCompiler(QiskitTestCase):
qc.cx(qr[0], qr[k])
qc.measure(qr[5], cr[0])
qlist = [qc for k in range(10)]
qobj = assemble(transpile(qlist, backend=backend))
with self.assertWarns(DeprecationWarning):
qobj = assemble(transpile(qlist, backend=backend))
self.assertEqual(len(qobj.experiments), 10)
def test_no_conflict_backend_passmanager(self):
@ -240,7 +241,8 @@ class TestCompiler(QiskitTestCase):
circuit2 = transpile(
circuit, backend=None, coupling_map=cmap, basis_gates=["u2"], initial_layout=layout
)
qobj = assemble(circuit2)
with self.assertWarns(DeprecationWarning):
qobj = assemble(circuit2)
compiled_instruction = qobj.experiments[0].instructions[0]
@ -504,7 +506,8 @@ class TestCompiler(QiskitTestCase):
circ1.cx(qr[0], qr[1])
circ1.rz(0.7, qr[1])
circ1.rx(1.570796, qr[1])
qobj1 = assemble(transpile(circ1, backend))
with self.assertWarns(DeprecationWarning):
qobj1 = assemble(transpile(circ1, backend))
self.assertIsInstance(qobj1, QasmQobj)
circ2 = QuantumCircuit(qr)
@ -512,7 +515,8 @@ class TestCompiler(QiskitTestCase):
circ2.h(qr[0])
circ2.s(qr[0])
circ2.h(qr[0])
qobj2 = assemble(transpile(circ2, backend))
with self.assertWarns(DeprecationWarning):
qobj2 = assemble(transpile(circ2, backend))
self.assertIsInstance(qobj2, QasmQobj)

View File

@ -10,7 +10,9 @@
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.
"""Assembler Test."""
"""Assembler Test.
FULLY REMOVE ONCE Qobj, assemble AND disassemble ARE REMOVED.
"""
import unittest
@ -55,14 +57,15 @@ class TestQuantumCircuitDisassembler(QiskitTestCase):
qubit_lo_freq = [5e9, 5e9]
meas_lo_freq = [6.7e9, 6.7e9]
qobj = assemble(
circ,
shots=2000,
memory=True,
qubit_lo_freq=qubit_lo_freq,
meas_lo_freq=meas_lo_freq,
)
circuits, run_config_out, headers = disassemble(qobj)
with self.assertWarns(DeprecationWarning):
qobj = assemble(
circ,
shots=2000,
memory=True,
qubit_lo_freq=qubit_lo_freq,
meas_lo_freq=meas_lo_freq,
)
circuits, run_config_out, headers = disassemble(qobj)
run_config_out = RunConfig(**run_config_out)
self.assertEqual(run_config_out.n_qubits, 2)
self.assertEqual(run_config_out.memory_slots, 2)
@ -91,8 +94,9 @@ class TestQuantumCircuitDisassembler(QiskitTestCase):
circ1.cx(qr1[0], qr1[2])
circ1.measure(qr1, qc1)
qobj = assemble([circ0, circ1], shots=100, memory=False, seed=6)
circuits, run_config_out, headers = disassemble(qobj)
with self.assertWarns(DeprecationWarning):
qobj = assemble([circ0, circ1], shots=100, memory=False, seed=6)
circuits, run_config_out, headers = disassemble(qobj)
run_config_out = RunConfig(**run_config_out)
self.assertEqual(run_config_out.n_qubits, 3)
self.assertEqual(run_config_out.memory_slots, 3)
@ -113,8 +117,9 @@ class TestQuantumCircuitDisassembler(QiskitTestCase):
circ.cx(qr[0], qr[1])
circ.measure(qr, qc)
qobj = assemble(circ)
circuits, run_config_out, headers = disassemble(qobj)
with self.assertWarns(DeprecationWarning):
qobj = assemble(circ)
circuits, run_config_out, headers = disassemble(qobj)
run_config_out = RunConfig(**run_config_out)
self.assertEqual(run_config_out.n_qubits, 2)
self.assertEqual(run_config_out.memory_slots, 2)
@ -128,8 +133,9 @@ class TestQuantumCircuitDisassembler(QiskitTestCase):
circ = QuantumCircuit(q, name="circ")
circ.initialize([1 / np.sqrt(2), 0, 0, 1 / np.sqrt(2)], q[:])
qobj = assemble(circ)
circuits, run_config_out, header = disassemble(qobj)
with self.assertWarns(DeprecationWarning):
qobj = assemble(circ)
circuits, run_config_out, header = disassemble(qobj)
run_config_out = RunConfig(**run_config_out)
self.assertEqual(run_config_out.n_qubits, 2)
self.assertEqual(run_config_out.memory_slots, 0)
@ -142,8 +148,9 @@ class TestQuantumCircuitDisassembler(QiskitTestCase):
q = QuantumRegister(2, name="q")
circ = QuantumCircuit(q, name="circ")
circ.append(Isometry(qi.random_unitary(4).data, 0, 0), circ.qubits)
qobj = assemble(circ)
circuits, run_config_out, header = disassemble(qobj)
with self.assertWarns(DeprecationWarning):
qobj = assemble(circ)
circuits, run_config_out, header = disassemble(qobj)
run_config_out = RunConfig(**run_config_out)
self.assertEqual(run_config_out.n_qubits, 2)
self.assertEqual(run_config_out.memory_slots, 0)
@ -166,8 +173,9 @@ class TestQuantumCircuitDisassembler(QiskitTestCase):
c = ClassicalRegister(4, name="c")
circ = QuantumCircuit(q, c, name="circ")
circ.append(opaque_inst, [q[0], q[2], q[5], q[3]], [c[3], c[0]])
qobj = assemble(circ)
circuits, run_config_out, header = disassemble(qobj)
with self.assertWarns(DeprecationWarning):
qobj = assemble(circ)
circuits, run_config_out, header = disassemble(qobj)
run_config_out = RunConfig(**run_config_out)
self.assertEqual(run_config_out.n_qubits, 6)
self.assertEqual(run_config_out.memory_slots, 4)
@ -184,8 +192,9 @@ class TestQuantumCircuitDisassembler(QiskitTestCase):
qc.measure(qr[0], cr1) # Measure not required for a later conditional
qc.measure(qr[1], cr2[1]) # Measure required for a later conditional
qc.h(qr[1]).c_if(cr2, 3)
qobj = assemble(qc)
circuits, run_config_out, header = disassemble(qobj)
with self.assertWarns(DeprecationWarning):
qobj = assemble(qc)
circuits, run_config_out, header = disassemble(qobj)
run_config_out = RunConfig(**run_config_out)
self.assertEqual(run_config_out.n_qubits, 2)
self.assertEqual(run_config_out.memory_slots, 3)
@ -199,8 +208,9 @@ class TestQuantumCircuitDisassembler(QiskitTestCase):
cr = ClassicalRegister(1)
qc = QuantumCircuit(qr, cr)
qc.h(qr[0]).c_if(cr, 1)
qobj = assemble(qc)
circuits, run_config_out, header = disassemble(qobj)
with self.assertWarns(DeprecationWarning):
qobj = assemble(qc)
circuits, run_config_out, header = disassemble(qobj)
run_config_out = RunConfig(**run_config_out)
self.assertEqual(run_config_out.n_qubits, 1)
self.assertEqual(run_config_out.memory_slots, 1)
@ -219,8 +229,10 @@ class TestQuantumCircuitDisassembler(QiskitTestCase):
cr = ClassicalRegister(2)
qc = QuantumCircuit(qr, cr)
qc.h(qr[0]).c_if(cr[0], 1)
qobj = assemble(qc)
circuits, run_config_out, header = disassemble(qobj)
with self.assertWarns(DeprecationWarning):
qobj = assemble(qc)
circuits, run_config_out, header = disassemble(qobj)
run_config_out = RunConfig(**run_config_out)
self.assertEqual(run_config_out.n_qubits, len(qr))
self.assertEqual(run_config_out.memory_slots, len(cr))
@ -234,8 +246,9 @@ class TestQuantumCircuitDisassembler(QiskitTestCase):
cr = ClassicalRegister(5)
qc = QuantumCircuit(qr, cr)
qc.mcx([0, 1, 2], 4)
qobj = assemble(qc)
circuits, run_config_out, header = disassemble(qobj)
with self.assertWarns(DeprecationWarning):
qobj = assemble(qc)
circuits, run_config_out, header = disassemble(qobj)
run_config_out = RunConfig(**run_config_out)
self.assertEqual(run_config_out.n_qubits, 5)
self.assertEqual(run_config_out.memory_slots, 5)
@ -257,8 +270,9 @@ class TestQuantumCircuitDisassembler(QiskitTestCase):
qc.cx(qr[1], qr[0]).c_if(cr3, 14)
qc.ccx(qr[0], qr[2], qr[1]).c_if(cr4, 1)
qc.h(qr).c_if(cr1, 3)
qobj = assemble(qc)
circuits, run_config_out, header = disassemble(qobj)
with self.assertWarns(DeprecationWarning):
qobj = assemble(qc)
circuits, run_config_out, header = disassemble(qobj)
run_config_out = RunConfig(**run_config_out)
self.assertEqual(run_config_out.n_qubits, 3)
self.assertEqual(run_config_out.memory_slots, 15)
@ -272,8 +286,9 @@ class TestQuantumCircuitDisassembler(QiskitTestCase):
cr = ClassicalRegister(2)
qc = QuantumCircuit(qr, cr)
qc.h(qr[0]).c_if(cr[1], True)
qobj = assemble(qc)
circuits, run_config_out, header = disassemble(qobj)
with self.assertWarns(DeprecationWarning):
qobj = assemble(qc)
circuits, run_config_out, header = disassemble(qobj)
run_config_out = RunConfig(**run_config_out)
self.assertEqual(run_config_out.n_qubits, 2)
self.assertEqual(run_config_out.memory_slots, 2)
@ -290,8 +305,9 @@ class TestQuantumCircuitDisassembler(QiskitTestCase):
qc.h(qr[0]).c_if(cr1[1], False)
qc.h(qr[1]).c_if(cr[0], True)
qc.cx(qr[0], qr[1]).c_if(cr1[0], False)
qobj = assemble(qc)
circuits, run_config_out, header = disassemble(qobj)
with self.assertWarns(DeprecationWarning):
qobj = assemble(qc)
circuits, run_config_out, header = disassemble(qobj)
run_config_out = RunConfig(**run_config_out)
self.assertEqual(run_config_out.n_qubits, 2)
self.assertEqual(run_config_out.memory_slots, 4)
@ -330,8 +346,9 @@ class TestQuantumCircuitDisassembler(QiskitTestCase):
qc.add_calibration("h", [0], h_sched)
qc.add_calibration(RXGate(np.pi), [0], x180)
qobj = assemble(qc, FakeOpenPulse2Q())
output_circuits, _, _ = disassemble(qobj)
with self.assertWarns(DeprecationWarning):
qobj = assemble(qc, FakeOpenPulse2Q())
output_circuits, _, _ = disassemble(qobj)
self.assertCircuitCalibrationsEqual([qc], output_circuits)
@ -344,11 +361,12 @@ class TestQuantumCircuitDisassembler(QiskitTestCase):
qc.h(0)
qc.add_calibration("h", [0], h_sched)
backend = FakeOpenPulse2Q()
backend.configuration().parametric_pulses = ["drag"]
with self.assertWarns(DeprecationWarning):
backend = FakeOpenPulse2Q()
backend.configuration().parametric_pulses = ["drag"]
qobj = assemble(qc, backend)
output_circuits, _, _ = disassemble(qobj)
qobj = assemble(qc, backend)
output_circuits, _, _ = disassemble(qobj)
out_qc = output_circuits[0]
self.assertCircuitCalibrationsEqual([qc], output_circuits)
@ -377,8 +395,9 @@ class TestQuantumCircuitDisassembler(QiskitTestCase):
qc_1.h(0)
circuits = [qc_0, qc_1]
qobj = assemble(circuits, FakeOpenPulse2Q())
output_circuits, _, _ = disassemble(qobj)
with self.assertWarns(DeprecationWarning):
qobj = assemble(circuits, FakeOpenPulse2Q())
output_circuits, _, _ = disassemble(qobj)
self.assertCircuitCalibrationsEqual(circuits, output_circuits)
@ -398,8 +417,9 @@ class TestQuantumCircuitDisassembler(QiskitTestCase):
qc_1.add_calibration(RXGate(np.pi), [1], sched)
circuits = [qc_0, qc_1]
qobj = assemble(circuits, FakeOpenPulse2Q())
output_circuits, _, _ = disassemble(qobj)
with self.assertWarns(DeprecationWarning):
qobj = assemble(circuits, FakeOpenPulse2Q())
output_circuits, _, _ = disassemble(qobj)
self.assertCircuitCalibrationsEqual(circuits, output_circuits)
@ -413,8 +433,9 @@ class TestQuantumCircuitDisassembler(QiskitTestCase):
qc.add_calibration("test", [0], test_sched)
qobj = assemble(qc, FakeOpenPulse2Q())
output_circuits, _, _ = disassemble(qobj)
with self.assertWarns(DeprecationWarning):
qobj = assemble(qc, FakeOpenPulse2Q())
output_circuits, _, _ = disassemble(qobj)
self.assertEqual(len(qc.calibrations), len(output_circuits[0].calibrations))
self.assertEqual(qc.calibrations.keys(), output_circuits[0].calibrations.keys())
@ -456,8 +477,9 @@ class TestPulseScheduleDisassembler(QiskitTestCase):
pulse.play(pulse.library.Constant(8, 0.1), d1)
pulse.measure_all()
qobj = assemble(sched, backend=self.backend, shots=2000)
scheds, run_config_out, _ = disassemble(qobj)
with self.assertWarns(DeprecationWarning):
qobj = assemble(sched, backend=self.backend, shots=2000)
scheds, run_config_out, _ = disassemble(qobj)
run_config_out = RunConfig(**run_config_out)
self.assertEqual(run_config_out.memory_slots, 2)
self.assertEqual(run_config_out.shots, 2000)
@ -498,8 +520,9 @@ class TestPulseScheduleDisassembler(QiskitTestCase):
pulse.play(pulse.library.Constant(8, 0.4), d1)
pulse.measure_all()
qobj = assemble([sched0, sched1], backend=self.backend, shots=2000)
scheds, run_config_out, _ = disassemble(qobj)
with self.assertWarns(DeprecationWarning):
qobj = assemble([sched0, sched1], backend=self.backend, shots=2000)
scheds, run_config_out, _ = disassemble(qobj)
run_config_out = RunConfig(**run_config_out)
self.assertEqual(run_config_out.memory_slots, 2)
self.assertEqual(run_config_out.shots, 2000)
@ -518,8 +541,9 @@ class TestPulseScheduleDisassembler(QiskitTestCase):
pulse.play(pulse.library.GaussianSquare(10, 1.0, 2.0, 3), d0)
pulse.play(pulse.library.Drag(10, 1.0, 2.0, 0.1), d0)
qobj = assemble(sched, backend=self.backend, shots=2000)
scheds, _, _ = disassemble(qobj)
with self.assertWarns(DeprecationWarning):
qobj = assemble(sched, backend=self.backend, shots=2000)
scheds, _, _ = disassemble(qobj)
self.assertEqual(scheds[0], target_qobj_transform(sched))
def test_disassemble_schedule_los(self):
@ -536,8 +560,9 @@ class TestPulseScheduleDisassembler(QiskitTestCase):
{d0: 4.5e9, d1: 5e9, m0: 6e9, m1: 7e9},
{d0: 5e9, d1: 4.5e9, m0: 7e9, m1: 6e9},
]
qobj = assemble([sched0, sched1], backend=self.backend, schedule_los=schedule_los)
_, run_config_out, _ = disassemble(qobj)
with self.assertWarns(DeprecationWarning):
qobj = assemble([sched0, sched1], backend=self.backend, schedule_los=schedule_los)
_, run_config_out, _ = disassemble(qobj)
run_config_out = RunConfig(**run_config_out)
self.assertEqual(run_config_out.schedule_los, schedule_los)

View File

@ -17,7 +17,7 @@ import unittest
import numpy as np
from qiskit import ClassicalRegister, QuantumCircuit, QuantumRegister
from qiskit.compiler import transpile, assemble
from qiskit.compiler import transpile
from qiskit.providers.basic_provider import BasicSimulator
from qiskit.qasm2 import dumps
from test import QiskitTestCase # pylint: disable=wrong-import-order
@ -47,7 +47,6 @@ class TestBasicSimulator(QiskitTestCase, BasicProviderBackendTestMixin):
qcirc = QuantumCircuit.from_qasm_file(qasm_filename)
qcirc.name = "test"
self.transpiled_circuit = transpile(qcirc, backend=self.backend)
self.qobj = assemble(self.transpiled_circuit, shots=1000, seed_simulator=self.seed)
def test_basic_simulator_single_shot(self):
"""Test single shot run."""

View File

@ -17,6 +17,7 @@ import datetime
import itertools
import operator
import unittest
import warnings
from test import combine
from ddt import ddt, data
@ -142,7 +143,8 @@ class TestFakeBackends(QiskitTestCase):
def test_qobj_failure(self):
backend = BACKENDS[-1]
tqc = transpile(self.circuit, backend)
qobj = assemble(tqc, backend)
with self.assertWarns(DeprecationWarning):
qobj = assemble(tqc, backend)
with self.assertRaises(QiskitError):
backend.run(qobj)
@ -226,7 +228,10 @@ class TestFakeBackends(QiskitTestCase):
self.assertIsInstance(backend_v2, BackendV2)
res = transpile(self.circuit, backend_v2, optimization_level=opt_level)
job = backend_v2.run(res)
result = job.result()
with warnings.catch_warnings():
# TODO remove this catch once Aer stops using QobjDictField
warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
result = job.result()
counts = result.get_counts()
max_count = max(counts.items(), key=operator.itemgetter(1))[0]
self.assertEqual(max_count, "11")

View File

@ -281,29 +281,31 @@ class TestPulseQobj(QiskitTestCase):
def setUp(self):
super().setUp()
self.converter = QobjToInstructionConverter(
pulse_library=[
PulseLibraryItem(name="waveform", samples=[0.3, 0.1, 0.2, 0.2, 0.3]),
]
)
with self.assertWarns(DeprecationWarning):
self.converter = QobjToInstructionConverter(
pulse_library=[
PulseLibraryItem(name="waveform", samples=[0.3, 0.1, 0.2, 0.2, 0.3]),
]
)
def test_add_qobj(self):
"""Basic test PulseQobj format."""
serialized_program = [
PulseQobjInstruction(
name="parametric_pulse",
t0=0,
ch="d0",
label="TestPulse",
pulse_shape="constant",
parameters={"amp": 0.1 + 0j, "duration": 10},
),
PulseQobjInstruction(
name="waveform",
t0=20,
ch="d0",
),
]
with self.assertWarns(DeprecationWarning):
serialized_program = [
PulseQobjInstruction(
name="parametric_pulse",
t0=0,
ch="d0",
label="TestPulse",
pulse_shape="constant",
parameters={"amp": 0.1 + 0j, "duration": 10},
),
PulseQobjInstruction(
name="waveform",
t0=20,
ch="d0",
),
]
entry = PulseQobjDef(converter=self.converter, name="my_gate")
entry.define(serialized_program)
@ -328,13 +330,14 @@ class TestPulseQobj(QiskitTestCase):
def test_missing_waveform(self):
"""Test incomplete Qobj should raise warning and calibration returns None."""
serialized_program = [
PulseQobjInstruction(
name="waveform_123456",
t0=20,
ch="d0",
),
]
with self.assertWarns(DeprecationWarning):
serialized_program = [
PulseQobjInstruction(
name="waveform_123456",
t0=20,
ch="d0",
),
]
entry = PulseQobjDef(converter=self.converter, name="my_gate")
entry.define(serialized_program)
@ -355,22 +358,23 @@ class TestPulseQobj(QiskitTestCase):
Note that pulse parameter cannot be parameterized by convention.
"""
serialized_program = [
PulseQobjInstruction(
name="parametric_pulse",
t0=0,
ch="d0",
label="TestPulse",
pulse_shape="constant",
parameters={"amp": 0.1, "duration": 10},
),
PulseQobjInstruction(
name="fc",
t0=0,
ch="d0",
phase="P1",
),
]
with self.assertWarns(DeprecationWarning):
serialized_program = [
PulseQobjInstruction(
name="parametric_pulse",
t0=0,
ch="d0",
label="TestPulse",
pulse_shape="constant",
parameters={"amp": 0.1, "duration": 10},
),
PulseQobjInstruction(
name="fc",
t0=0,
ch="d0",
phase="P1",
),
]
entry = PulseQobjDef(converter=self.converter, name="my_gate")
entry.define(serialized_program)
@ -395,27 +399,27 @@ class TestPulseQobj(QiskitTestCase):
def test_equality(self):
"""Test equality evaluation between the pulse qobj entries."""
serialized_program1 = [
PulseQobjInstruction(
name="parametric_pulse",
t0=0,
ch="d0",
label="TestPulse",
pulse_shape="constant",
parameters={"amp": 0.1, "duration": 10},
)
]
serialized_program2 = [
PulseQobjInstruction(
name="parametric_pulse",
t0=0,
ch="d0",
label="TestPulse",
pulse_shape="constant",
parameters={"amp": 0.2, "duration": 10},
)
]
with self.assertWarns(DeprecationWarning):
serialized_program1 = [
PulseQobjInstruction(
name="parametric_pulse",
t0=0,
ch="d0",
label="TestPulse",
pulse_shape="constant",
parameters={"amp": 0.1, "duration": 10},
)
]
serialized_program2 = [
PulseQobjInstruction(
name="parametric_pulse",
t0=0,
ch="d0",
label="TestPulse",
pulse_shape="constant",
parameters={"amp": 0.2, "duration": 10},
)
]
entry1 = PulseQobjDef(name="my_gate1")
entry1.define(serialized_program1)
@ -435,16 +439,17 @@ class TestPulseQobj(QiskitTestCase):
Because the pulse qobj entry is a subclass of the schedule entry,
these instances can be compared by the generated definition, i.e. Schedule.
"""
serialized_program = [
PulseQobjInstruction(
name="parametric_pulse",
t0=0,
ch="d0",
label="TestPulse",
pulse_shape="constant",
parameters={"amp": 0.1, "duration": 10},
)
]
with self.assertWarns(DeprecationWarning):
serialized_program = [
PulseQobjInstruction(
name="parametric_pulse",
t0=0,
ch="d0",
label="TestPulse",
pulse_shape="constant",
parameters={"amp": 0.1, "duration": 10},
)
]
entry1 = PulseQobjDef(name="qobj_entry")
entry1.define(serialized_program)
@ -470,13 +475,14 @@ class TestPulseQobj(QiskitTestCase):
In this situation, parsed calibration data must become None,
instead of raising an error.
"""
serialized_program = [
PulseQobjInstruction(
name="SomeMissingPulse",
t0=0,
ch="d0",
)
]
with self.assertWarns(DeprecationWarning):
serialized_program = [
PulseQobjInstruction(
name="SomeMissingPulse",
t0=0,
ch="d0",
)
]
entry = PulseQobjDef(name="qobj_entry")
entry.define(serialized_program)

View File

@ -305,12 +305,13 @@ class TestInstructionScheduleMap(QiskitTestCase):
def test_sequenced_parameterized_schedule(self):
"""Test parameterized schedule consists of multiple instruction."""
converter = QobjToInstructionConverter([], buffer=0)
qobjs = [
PulseQobjInstruction(name="fc", ch="d0", t0=10, phase="P1"),
PulseQobjInstruction(name="fc", ch="d0", t0=20, phase="P2"),
PulseQobjInstruction(name="fc", ch="d0", t0=30, phase="P3"),
]
with self.assertWarns(DeprecationWarning):
converter = QobjToInstructionConverter([], buffer=0)
qobjs = [
PulseQobjInstruction(name="fc", ch="d0", t0=10, phase="P1"),
PulseQobjInstruction(name="fc", ch="d0", t0=20, phase="P2"),
PulseQobjInstruction(name="fc", ch="d0", t0=30, phase="P3"),
]
converted_instruction = [converter(qobj) for qobj in qobjs]
inst_map = InstructionScheduleMap()

View File

@ -56,29 +56,33 @@ class TestInstructionToQobjConverter(QiskitTestCase):
def test_drive_instruction(self):
"""Test converted qobj from Play."""
converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2)
instruction = Play(Waveform(np.arange(0, 0.01), name="linear"), DriveChannel(0))
valid_qobj = PulseQobjInstruction(name="linear", ch="d0", t0=0)
self.assertEqual(converter(0, instruction), valid_qobj)
with self.assertWarns(DeprecationWarning):
converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2)
instruction = Play(Waveform(np.arange(0, 0.01), name="linear"), DriveChannel(0))
valid_qobj = PulseQobjInstruction(name="linear", ch="d0", t0=0)
self.assertEqual(converter(0, instruction), valid_qobj)
def test_gaussian_pulse_instruction(self):
"""Test that parametric pulses are correctly converted to PulseQobjInstructions."""
amp = 0.3
angle = -0.7
converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2)
with self.assertWarns(DeprecationWarning):
converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2)
instruction = Play(Gaussian(duration=25, sigma=15, amp=amp, angle=angle), DriveChannel(0))
valid_qobj = PulseQobjInstruction(
name="parametric_pulse",
pulse_shape="gaussian",
ch="d0",
t0=0,
parameters={"duration": 25, "sigma": 15, "amp": amp * np.exp(1j * angle)},
)
self.assertEqual(converter(0, instruction), valid_qobj)
with self.assertWarns(DeprecationWarning):
valid_qobj = PulseQobjInstruction(
name="parametric_pulse",
pulse_shape="gaussian",
ch="d0",
t0=0,
parameters={"duration": 25, "sigma": 15, "amp": amp * np.exp(1j * angle)},
)
self.assertEqual(converter(0, instruction), valid_qobj)
def test_gaussian_square_pulse_instruction(self):
"""Test that parametric pulses are correctly converted to PulseQobjInstructions."""
converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2)
with self.assertWarns(DeprecationWarning):
converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2)
amp = 0.7
angle = -0.6
instruction = Play(
@ -86,110 +90,129 @@ class TestInstructionToQobjConverter(QiskitTestCase):
MeasureChannel(1),
)
valid_qobj = PulseQobjInstruction(
name="parametric_pulse",
pulse_shape="gaussian_square",
ch="m1",
t0=10,
parameters={
"duration": 1500,
"sigma": 15,
"amp": amp * np.exp(1j * angle),
"width": 1300,
},
)
self.assertEqual(converter(10, instruction), valid_qobj)
with self.assertWarns(DeprecationWarning):
valid_qobj = PulseQobjInstruction(
name="parametric_pulse",
pulse_shape="gaussian_square",
ch="m1",
t0=10,
parameters={
"duration": 1500,
"sigma": 15,
"amp": amp * np.exp(1j * angle),
"width": 1300,
},
)
self.assertEqual(converter(10, instruction), valid_qobj)
def test_constant_pulse_instruction(self):
"""Test that parametric pulses are correctly converted to PulseQobjInstructions."""
converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2)
with self.assertWarns(DeprecationWarning):
converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2)
instruction = Play(Constant(duration=25, amp=1, angle=np.pi), ControlChannel(2))
valid_qobj = PulseQobjInstruction(
name="parametric_pulse",
pulse_shape="constant",
ch="u2",
t0=20,
parameters={"duration": 25, "amp": 1 * np.exp(1j * np.pi)},
)
self.assertEqual(converter(20, instruction), valid_qobj)
with self.assertWarns(DeprecationWarning):
valid_qobj = PulseQobjInstruction(
name="parametric_pulse",
pulse_shape="constant",
ch="u2",
t0=20,
parameters={"duration": 25, "amp": 1 * np.exp(1j * np.pi)},
)
self.assertEqual(converter(20, instruction), valid_qobj)
def test_drag_pulse_instruction(self):
"""Test that parametric pulses are correctly converted to PulseQobjInstructions."""
amp = 0.7
angle = -0.6
converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2)
with self.assertWarns(DeprecationWarning):
converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2)
instruction = Play(
Drag(duration=25, sigma=15, amp=amp, angle=angle, beta=0.5), DriveChannel(0)
)
valid_qobj = PulseQobjInstruction(
name="parametric_pulse",
pulse_shape="drag",
ch="d0",
t0=30,
parameters={"duration": 25, "sigma": 15, "amp": amp * np.exp(1j * angle), "beta": 0.5},
)
self.assertEqual(converter(30, instruction), valid_qobj)
with self.assertWarns(DeprecationWarning):
valid_qobj = PulseQobjInstruction(
name="parametric_pulse",
pulse_shape="drag",
ch="d0",
t0=30,
parameters={
"duration": 25,
"sigma": 15,
"amp": amp * np.exp(1j * angle),
"beta": 0.5,
},
)
self.assertEqual(converter(30, instruction), valid_qobj)
def test_frame_change(self):
"""Test converted qobj from ShiftPhase."""
converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2)
valid_qobj = PulseQobjInstruction(name="fc", ch="d0", t0=0, phase=0.1)
instruction = ShiftPhase(0.1, DriveChannel(0))
self.assertEqual(converter(0, instruction), valid_qobj)
with self.assertWarns(DeprecationWarning):
converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2)
valid_qobj = PulseQobjInstruction(name="fc", ch="d0", t0=0, phase=0.1)
instruction = ShiftPhase(0.1, DriveChannel(0))
self.assertEqual(converter(0, instruction), valid_qobj)
def test_set_phase(self):
"""Test converted qobj from ShiftPhase."""
converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2)
instruction = SetPhase(3.14, DriveChannel(0))
with self.assertWarns(DeprecationWarning):
converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2)
instruction = SetPhase(3.14, DriveChannel(0))
valid_qobj = PulseQobjInstruction(name="setp", ch="d0", t0=0, phase=3.14)
valid_qobj = PulseQobjInstruction(name="setp", ch="d0", t0=0, phase=3.14)
self.assertEqual(converter(0, instruction), valid_qobj)
self.assertEqual(converter(0, instruction), valid_qobj)
def test_set_frequency(self):
"""Test converted qobj from SetFrequency."""
converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2)
instruction = SetFrequency(8.0e9, DriveChannel(0))
with self.assertWarns(DeprecationWarning):
converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2)
instruction = SetFrequency(8.0e9, DriveChannel(0))
valid_qobj = PulseQobjInstruction(name="setf", ch="d0", t0=0, frequency=8.0)
valid_qobj = PulseQobjInstruction(name="setf", ch="d0", t0=0, frequency=8.0)
self.assertEqual(converter(0, instruction), valid_qobj)
self.assertEqual(converter(0, instruction), valid_qobj)
def test_shift_frequency(self):
"""Test converted qobj from ShiftFrequency."""
converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2)
instruction = ShiftFrequency(8.0e9, DriveChannel(0))
with self.assertWarns(DeprecationWarning):
converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2)
instruction = ShiftFrequency(8.0e9, DriveChannel(0))
valid_qobj = PulseQobjInstruction(name="shiftf", ch="d0", t0=0, frequency=8.0)
valid_qobj = PulseQobjInstruction(name="shiftf", ch="d0", t0=0, frequency=8.0)
self.assertEqual(converter(0, instruction), valid_qobj)
self.assertEqual(converter(0, instruction), valid_qobj)
def test_acquire(self):
"""Test converted qobj from AcquireInstruction."""
converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2)
with self.assertWarns(DeprecationWarning):
converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2)
instruction = Acquire(10, AcquireChannel(0), MemorySlot(0), RegisterSlot(0))
valid_qobj = PulseQobjInstruction(
name="acquire", t0=0, duration=10, qubits=[0], memory_slot=[0], register_slot=[0]
)
self.assertEqual(converter(0, instruction), valid_qobj)
with self.assertWarns(DeprecationWarning):
valid_qobj = PulseQobjInstruction(
name="acquire", t0=0, duration=10, qubits=[0], memory_slot=[0], register_slot=[0]
)
self.assertEqual(converter(0, instruction), valid_qobj)
# without register
instruction = Acquire(10, AcquireChannel(0), MemorySlot(0))
valid_qobj = PulseQobjInstruction(
name="acquire", t0=0, duration=10, qubits=[0], memory_slot=[0]
)
self.assertEqual(converter(0, instruction), valid_qobj)
with self.assertWarns(DeprecationWarning):
valid_qobj = PulseQobjInstruction(
name="acquire", t0=0, duration=10, qubits=[0], memory_slot=[0]
)
self.assertEqual(converter(0, instruction), valid_qobj)
def test_snapshot(self):
"""Test converted qobj from Snapshot."""
converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2)
with self.assertWarns(DeprecationWarning):
converter = InstructionToQobjConverter(PulseQobjInstruction, meas_level=2)
instruction = Snapshot(label="label", snapshot_type="type")
valid_qobj = PulseQobjInstruction(name="snapshot", t0=0, label="label", type="type")
with self.assertWarns(DeprecationWarning):
valid_qobj = PulseQobjInstruction(name="snapshot", t0=0, label="label", type="type")
self.assertEqual(converter(0, instruction), valid_qobj)
self.assertEqual(converter(0, instruction), valid_qobj)
class TestQobjToInstructionConverter(QiskitTestCase):
@ -198,9 +221,10 @@ class TestQobjToInstructionConverter(QiskitTestCase):
def setUp(self):
super().setUp()
self.linear = Waveform(np.arange(0, 0.01), name="linear")
self.pulse_library = [
PulseLibraryItem(name=self.linear.name, samples=self.linear.samples.tolist())
]
with self.assertWarns(DeprecationWarning):
self.pulse_library = [
PulseLibraryItem(name=self.linear.name, samples=self.linear.samples.tolist())
]
self.converter = QobjToInstructionConverter(self.pulse_library, buffer=0)
self.num_qubits = 2
@ -208,7 +232,8 @@ class TestQobjToInstructionConverter(QiskitTestCase):
def test_drive_instruction(self):
"""Test converted qobj from PulseInstruction."""
instruction = Play(self.linear, DriveChannel(0))
qobj = PulseQobjInstruction(name="linear", ch="d0", t0=10)
with self.assertWarns(DeprecationWarning):
qobj = PulseQobjInstruction(name="linear", ch="d0", t0=10)
converted_instruction = self.converter(qobj)
self.assertEqual(converted_instruction.instructions[0][-1], instruction)
@ -218,14 +243,15 @@ class TestQobjToInstructionConverter(QiskitTestCase):
Gaussian(duration=25, sigma=15, amp=0.5, angle=np.pi / 2, name="pulse1"),
DriveChannel(0),
)
qobj = PulseQobjInstruction(
name="parametric_pulse",
label="pulse1",
pulse_shape="gaussian",
ch="d0",
t0=0,
parameters={"duration": 25, "sigma": 15, "amp": 0.5j},
)
with self.assertWarns(DeprecationWarning):
qobj = PulseQobjInstruction(
name="parametric_pulse",
label="pulse1",
pulse_shape="gaussian",
ch="d0",
t0=0,
parameters={"duration": 25, "sigma": 15, "amp": 0.5j},
)
converted_instruction = self.converter(qobj)
self.assertEqual(converted_instruction.start_time, 0)
self.assertEqual(converted_instruction.duration, 25)
@ -238,19 +264,21 @@ class TestQobjToInstructionConverter(QiskitTestCase):
short_pulse_id = hashlib.md5(base_str.encode("utf-8")).hexdigest()[:4]
pulse_name = f"gaussian_{short_pulse_id}"
qobj = PulseQobjInstruction(
name="parametric_pulse",
pulse_shape="gaussian",
ch="d0",
t0=0,
parameters={"duration": 25, "sigma": 15, "amp": -0.5 + 0.2j},
)
with self.assertWarns(DeprecationWarning):
qobj = PulseQobjInstruction(
name="parametric_pulse",
pulse_shape="gaussian",
ch="d0",
t0=0,
parameters={"duration": 25, "sigma": 15, "amp": -0.5 + 0.2j},
)
converted_instruction = self.converter(qobj)
self.assertEqual(converted_instruction.instructions[0][-1].pulse.name, pulse_name)
def test_frame_change(self):
"""Test converted qobj from ShiftPhase."""
qobj = PulseQobjInstruction(name="fc", ch="m0", t0=0, phase=0.1)
with self.assertWarns(DeprecationWarning):
qobj = PulseQobjInstruction(name="fc", ch="m0", t0=0, phase=0.1)
converted_instruction = self.converter(qobj)
instruction = ShiftPhase(0.1, MeasureChannel(0))
@ -263,7 +291,8 @@ class TestQobjToInstructionConverter(QiskitTestCase):
instruction = ShiftPhase(4.0, MeasureChannel(0))
shifted = instruction << 10
qobj = PulseQobjInstruction(name="fc", ch="m0", t0=10, phase="P1*2")
with self.assertWarns(DeprecationWarning):
qobj = PulseQobjInstruction(name="fc", ch="m0", t0=10, phase="P1*2")
converted_instruction = self.converter(qobj)
self.assertIsInstance(converted_instruction, Schedule)
@ -277,7 +306,8 @@ class TestQobjToInstructionConverter(QiskitTestCase):
def test_set_phase(self):
"""Test converted qobj from SetPhase."""
qobj = PulseQobjInstruction(name="setp", ch="m0", t0=0, phase=3.14)
with self.assertWarns(DeprecationWarning):
qobj = PulseQobjInstruction(name="setp", ch="m0", t0=0, phase=3.14)
converted_instruction = self.converter(qobj)
instruction = SetPhase(3.14, MeasureChannel(0))
@ -287,7 +317,8 @@ class TestQobjToInstructionConverter(QiskitTestCase):
def test_parameterized_set_phase(self):
"""Test converted qobj from SetPhase, with parameterized phase."""
qobj = PulseQobjInstruction(name="setp", ch="m0", t0=0, phase="p/2")
with self.assertWarns(DeprecationWarning):
qobj = PulseQobjInstruction(name="setp", ch="m0", t0=0, phase="p/2")
converted_instruction = self.converter(qobj)
self.assertIsInstance(converted_instruction, Schedule)
@ -303,7 +334,8 @@ class TestQobjToInstructionConverter(QiskitTestCase):
"""Test converted qobj from SetFrequency."""
instruction = SetFrequency(8.0e9, DriveChannel(0))
qobj = PulseQobjInstruction(name="setf", ch="d0", t0=0, frequency=8.0)
with self.assertWarns(DeprecationWarning):
qobj = PulseQobjInstruction(name="setf", ch="d0", t0=0, frequency=8.0)
converted_instruction = self.converter(qobj)
self.assertEqual(converted_instruction.start_time, 0)
@ -313,7 +345,8 @@ class TestQobjToInstructionConverter(QiskitTestCase):
def test_parameterized_set_frequency(self):
"""Test converted qobj from SetFrequency, when passing a parameterized frequency."""
qobj = PulseQobjInstruction(name="setf", ch="d0", t0=2, frequency="f")
with self.assertWarns(DeprecationWarning):
qobj = PulseQobjInstruction(name="setf", ch="d0", t0=2, frequency="f")
self.assertTrue("frequency" in qobj.to_dict())
converted_instruction = self.converter(qobj)
@ -332,7 +365,8 @@ class TestQobjToInstructionConverter(QiskitTestCase):
"""Test converted qobj from ShiftFrequency."""
instruction = ShiftFrequency(8.0e9, DriveChannel(0))
qobj = PulseQobjInstruction(name="shiftf", ch="d0", t0=0, frequency=8.0)
with self.assertWarns(DeprecationWarning):
qobj = PulseQobjInstruction(name="shiftf", ch="d0", t0=0, frequency=8.0)
converted_instruction = self.converter(qobj)
self.assertEqual(converted_instruction.start_time, 0)
@ -342,9 +376,8 @@ class TestQobjToInstructionConverter(QiskitTestCase):
def test_parameterized_shift_frequency(self):
"""Test converted qobj from ShiftFrequency, with a parameterized frequency."""
instruction = ShiftFrequency(8.0e9, DriveChannel(0))
qobj = PulseQobjInstruction(name="shiftf", ch="d0", t0=1, frequency="f / 1000")
with self.assertWarns(DeprecationWarning):
qobj = PulseQobjInstruction(name="shiftf", ch="d0", t0=1, frequency="f / 1000")
self.assertTrue("frequency" in qobj.to_dict())
converted_instruction = self.converter(qobj)
@ -363,7 +396,8 @@ class TestQobjToInstructionConverter(QiskitTestCase):
"""Test converted qobj from Delay."""
instruction = Delay(10, DriveChannel(0))
qobj = PulseQobjInstruction(name="delay", ch="d0", t0=0, duration=10)
with self.assertWarns(DeprecationWarning):
qobj = PulseQobjInstruction(name="delay", ch="d0", t0=0, duration=10)
converted_instruction = self.converter(qobj)
self.assertTrue("delay" in qobj.to_dict().values())
@ -382,17 +416,19 @@ class TestQobjToInstructionConverter(QiskitTestCase):
kernel=Kernel(name="test_kern", test_params="test"),
discriminator=Discriminator(name="test_disc", test_params=1.0),
)
qobj = PulseQobjInstruction(
name="acquire",
t0=0,
duration=10,
qubits=[0, 1],
memory_slot=[0, 1],
register_slot=[0, 1],
kernels=[QobjMeasurementOption(name="test_kern", params={"test_params": "test"})],
discriminators=[QobjMeasurementOption(name="test_disc", params={"test_params": 1.0})],
)
with self.assertWarns(DeprecationWarning):
qobj = PulseQobjInstruction(
name="acquire",
t0=0,
duration=10,
qubits=[0, 1],
memory_slot=[0, 1],
register_slot=[0, 1],
kernels=[QobjMeasurementOption(name="test_kern", params={"test_params": "test"})],
discriminators=[
QobjMeasurementOption(name="test_disc", params={"test_params": 1.0})
],
)
converted_instruction = self.converter(qobj)
self.assertEqual(converted_instruction.start_time, 0)
@ -408,7 +444,8 @@ class TestQobjToInstructionConverter(QiskitTestCase):
instruction = Snapshot(label="label", snapshot_type="type")
shifted = instruction << 10
qobj = PulseQobjInstruction(name="snapshot", t0=10, label="label", type="type")
with self.assertWarns(DeprecationWarning):
qobj = PulseQobjInstruction(name="snapshot", t0=10, label="label", type="type")
converted_instruction = self.converter(qobj)
self.assertEqual(converted_instruction.start_time, shifted.start_time)
@ -417,17 +454,22 @@ class TestQobjToInstructionConverter(QiskitTestCase):
def test_instruction_name_collision(self):
"""Avoid command name collision of pulse library items."""
pulse_library_from_backend_x = [
PulseLibraryItem(name="pulse123", samples=[0.1, 0.1, 0.1]),
PulseLibraryItem(name="pulse456", samples=[0.3, 0.3, 0.3]),
]
with self.assertWarns(DeprecationWarning):
pulse_library_from_backend_x = [
PulseLibraryItem(name="pulse123", samples=[0.1, 0.1, 0.1]),
PulseLibraryItem(name="pulse456", samples=[0.3, 0.3, 0.3]),
]
converter_of_backend_x = QobjToInstructionConverter(pulse_library_from_backend_x, buffer=0)
pulse_library_from_backend_y = [PulseLibraryItem(name="pulse123", samples=[0.2, 0.2, 0.2])]
with self.assertWarns(DeprecationWarning):
pulse_library_from_backend_y = [
PulseLibraryItem(name="pulse123", samples=[0.2, 0.2, 0.2])
]
converter_of_backend_y = QobjToInstructionConverter(pulse_library_from_backend_y, buffer=0)
qobj1 = PulseQobjInstruction(name="pulse123", qubits=[0], t0=0, ch="d0")
qobj2 = PulseQobjInstruction(name="pulse456", qubits=[0], t0=0, ch="d0")
with self.assertWarns(DeprecationWarning):
qobj1 = PulseQobjInstruction(name="pulse123", qubits=[0], t0=0, ch="d0")
qobj2 = PulseQobjInstruction(name="pulse456", qubits=[0], t0=0, ch="d0")
sched_out_x = converter_of_backend_x(qobj1)
sched_out_y = converter_of_backend_y(qobj1)
@ -446,21 +488,23 @@ class TestLoConverter(QiskitTestCase):
def test_qubit_los(self):
"""Test qubit channel configuration."""
user_lo_config = LoConfig({DriveChannel(0): 1.3e9})
converter = LoConfigConverter(
PulseQobjExperimentConfig, [1.2e9], [3.4e9], [(0.0, 5e9)], [(0.0, 5e9)]
)
with self.assertWarns(DeprecationWarning):
converter = LoConfigConverter(
PulseQobjExperimentConfig, [1.2e9], [3.4e9], [(0.0, 5e9)], [(0.0, 5e9)]
)
valid_qobj = PulseQobjExperimentConfig(qubit_lo_freq=[1.3])
valid_qobj = PulseQobjExperimentConfig(qubit_lo_freq=[1.3])
self.assertEqual(converter(user_lo_config), valid_qobj)
with self.assertWarns(DeprecationWarning):
self.assertEqual(converter(user_lo_config), valid_qobj)
def test_meas_los(self):
"""Test measurement channel configuration."""
user_lo_config = LoConfig({MeasureChannel(0): 3.5e9})
converter = LoConfigConverter(
PulseQobjExperimentConfig, [1.2e9], [3.4e9], [(0.0, 5e9)], [(0.0, 5e9)]
)
with self.assertWarns(DeprecationWarning):
converter = LoConfigConverter(
PulseQobjExperimentConfig, [1.2e9], [3.4e9], [(0.0, 5e9)], [(0.0, 5e9)]
)
valid_qobj = PulseQobjExperimentConfig(meas_lo_freq=[3.5])
valid_qobj = PulseQobjExperimentConfig(meas_lo_freq=[3.5])
self.assertEqual(converter(user_lo_config), valid_qobj)
self.assertEqual(converter(user_lo_config), valid_qobj)

View File

@ -41,19 +41,20 @@ class TestQASMQobj(QiskitTestCase):
def setUp(self):
super().setUp()
self.valid_qobj = QasmQobj(
qobj_id="12345",
header=QobjHeader(),
config=QasmQobjConfig(shots=1024, memory_slots=2),
experiments=[
QasmQobjExperiment(
instructions=[
QasmQobjInstruction(name="u1", qubits=[1], params=[0.4]),
QasmQobjInstruction(name="u2", qubits=[1], params=[0.4, 0.2]),
]
)
],
)
with self.assertWarns(DeprecationWarning):
self.valid_qobj = QasmQobj(
qobj_id="12345",
header=QobjHeader(),
config=QasmQobjConfig(shots=1024, memory_slots=2),
experiments=[
QasmQobjExperiment(
instructions=[
QasmQobjInstruction(name="u1", qubits=[1], params=[0.4]),
QasmQobjInstruction(name="u2", qubits=[1], params=[0.4, 0.2]),
]
)
],
)
self.valid_dict = {
"qobj_id": "12345",
@ -70,55 +71,59 @@ class TestQASMQobj(QiskitTestCase):
}
],
}
self.bad_qobj = copy.deepcopy(self.valid_qobj)
with self.assertWarns(DeprecationWarning):
self.bad_qobj = copy.deepcopy(self.valid_qobj)
self.bad_qobj.experiments = []
def test_from_dict_per_class(self):
"""Test Qobj and its subclass representations given a dictionary."""
test_parameters = {
QasmQobj: (self.valid_qobj, self.valid_dict),
QasmQobjConfig: (
QasmQobjConfig(shots=1, memory_slots=2),
{"shots": 1, "memory_slots": 2},
),
QasmQobjExperiment: (
QasmQobjExperiment(
instructions=[QasmQobjInstruction(name="u1", qubits=[1], params=[0.4])]
with self.assertWarns(DeprecationWarning):
test_parameters = {
QasmQobj: (self.valid_qobj, self.valid_dict),
QasmQobjConfig: (
QasmQobjConfig(shots=1, memory_slots=2),
{"shots": 1, "memory_slots": 2},
),
{"instructions": [{"name": "u1", "qubits": [1], "params": [0.4]}]},
),
QasmQobjInstruction: (
QasmQobjInstruction(name="u1", qubits=[1], params=[0.4]),
{"name": "u1", "qubits": [1], "params": [0.4]},
),
}
QasmQobjExperiment: (
QasmQobjExperiment(
instructions=[QasmQobjInstruction(name="u1", qubits=[1], params=[0.4])]
),
{"instructions": [{"name": "u1", "qubits": [1], "params": [0.4]}]},
),
QasmQobjInstruction: (
QasmQobjInstruction(name="u1", qubits=[1], params=[0.4]),
{"name": "u1", "qubits": [1], "params": [0.4]},
),
}
for qobj_class, (qobj_item, expected_dict) in test_parameters.items():
with self.subTest(msg=str(qobj_class)):
self.assertEqual(qobj_item, qobj_class.from_dict(expected_dict))
with self.assertWarns(DeprecationWarning):
qobj = qobj_class.from_dict(expected_dict)
self.assertEqual(qobj_item, qobj)
def test_snapshot_instruction_to_dict(self):
"""Test snapshot instruction to dict."""
valid_qobj = QasmQobj(
qobj_id="12345",
header=QobjHeader(),
config=QasmQobjConfig(shots=1024, memory_slots=2),
experiments=[
QasmQobjExperiment(
instructions=[
QasmQobjInstruction(name="u1", qubits=[1], params=[0.4]),
QasmQobjInstruction(name="u2", qubits=[1], params=[0.4, 0.2]),
QasmQobjInstruction(
name="snapshot",
qubits=[1],
snapshot_type="statevector",
label="my_snap",
),
]
)
],
)
with self.assertWarns(DeprecationWarning):
valid_qobj = QasmQobj(
qobj_id="12345",
header=QobjHeader(),
config=QasmQobjConfig(shots=1024, memory_slots=2),
experiments=[
QasmQobjExperiment(
instructions=[
QasmQobjInstruction(name="u1", qubits=[1], params=[0.4]),
QasmQobjInstruction(name="u2", qubits=[1], params=[0.4, 0.2]),
QasmQobjInstruction(
name="snapshot",
qubits=[1],
snapshot_type="statevector",
label="my_snap",
),
]
)
],
)
res = valid_qobj.to_dict()
expected_dict = {
"qobj_id": "12345",
@ -147,25 +152,26 @@ class TestQASMQobj(QiskitTestCase):
def test_snapshot_instruction_from_dict(self):
"""Test snapshot instruction from dict."""
expected_qobj = QasmQobj(
qobj_id="12345",
header=QobjHeader(),
config=QasmQobjConfig(shots=1024, memory_slots=2),
experiments=[
QasmQobjExperiment(
instructions=[
QasmQobjInstruction(name="u1", qubits=[1], params=[0.4]),
QasmQobjInstruction(name="u2", qubits=[1], params=[0.4, 0.2]),
QasmQobjInstruction(
name="snapshot",
qubits=[1],
snapshot_type="statevector",
label="my_snap",
),
]
)
],
)
with self.assertWarns(DeprecationWarning):
expected_qobj = QasmQobj(
qobj_id="12345",
header=QobjHeader(),
config=QasmQobjConfig(shots=1024, memory_slots=2),
experiments=[
QasmQobjExperiment(
instructions=[
QasmQobjInstruction(name="u1", qubits=[1], params=[0.4]),
QasmQobjInstruction(name="u2", qubits=[1], params=[0.4, 0.2]),
QasmQobjInstruction(
name="snapshot",
qubits=[1],
snapshot_type="statevector",
label="my_snap",
),
]
)
],
)
qobj_dict = {
"qobj_id": "12345",
"type": "QASM",
@ -187,7 +193,9 @@ class TestQASMQobj(QiskitTestCase):
}
],
}
self.assertEqual(expected_qobj, QasmQobj.from_dict(qobj_dict))
with self.assertWarns(DeprecationWarning):
qobj = QasmQobj.from_dict(qobj_dict)
self.assertEqual(expected_qobj, qobj)
def test_change_qobj_after_compile(self):
"""Test modifying Qobj parameters after compile."""
@ -202,7 +210,8 @@ class TestQASMQobj(QiskitTestCase):
qc1.measure(qr, cr)
qc2.measure(qr, cr)
circuits = [qc1, qc2]
qobj1 = assemble(circuits, shots=1024, seed=88)
with self.assertWarns(DeprecationWarning):
qobj1 = assemble(circuits, shots=1024, seed=88)
qobj1.experiments[0].config.shots = 50
qobj1.experiments[1].config.shots = 1
self.assertTrue(qobj1.experiments[0].config.shots == 50)
@ -211,27 +220,28 @@ class TestQASMQobj(QiskitTestCase):
def test_gate_calibrations_to_dict(self):
"""Test gate calibrations to dict."""
pulse_library = [PulseLibraryItem(name="test", samples=[1j, 1j])]
valid_qobj = QasmQobj(
qobj_id="12345",
header=QobjHeader(),
config=QasmQobjConfig(shots=1024, memory_slots=2, pulse_library=pulse_library),
experiments=[
QasmQobjExperiment(
instructions=[QasmQobjInstruction(name="u1", qubits=[1], params=[0.4])],
config=QasmQobjConfig(
calibrations=QasmExperimentCalibrations(
gates=[
GateCalibration(
name="u1", qubits=[1], params=[0.4], instructions=[]
)
]
)
),
)
],
)
with self.assertWarns(DeprecationWarning):
pulse_library = [PulseLibraryItem(name="test", samples=[1j, 1j])]
with self.assertWarns(DeprecationWarning):
valid_qobj = QasmQobj(
qobj_id="12345",
header=QobjHeader(),
config=QasmQobjConfig(shots=1024, memory_slots=2, pulse_library=pulse_library),
experiments=[
QasmQobjExperiment(
instructions=[QasmQobjInstruction(name="u1", qubits=[1], params=[0.4])],
config=QasmQobjConfig(
calibrations=QasmExperimentCalibrations(
gates=[
GateCalibration(
name="u1", qubits=[1], params=[0.4], instructions=[]
)
]
)
),
)
],
)
res = valid_qobj.to_dict()
expected_dict = {
"qobj_id": "12345",
@ -265,48 +275,51 @@ class TestPulseQobj(QiskitTestCase):
def setUp(self):
super().setUp()
self.valid_qobj = PulseQobj(
qobj_id="12345",
header=QobjHeader(),
config=PulseQobjConfig(
shots=1024,
memory_slots=2,
meas_level=1,
memory_slot_size=8192,
meas_return="avg",
pulse_library=[
PulseLibraryItem(name="pulse0", samples=[0.0 + 0.0j, 0.5 + 0.0j, 0.0 + 0.0j])
with self.assertWarns(DeprecationWarning):
self.valid_qobj = PulseQobj(
qobj_id="12345",
header=QobjHeader(),
config=PulseQobjConfig(
shots=1024,
memory_slots=2,
meas_level=1,
memory_slot_size=8192,
meas_return="avg",
pulse_library=[
PulseLibraryItem(
name="pulse0", samples=[0.0 + 0.0j, 0.5 + 0.0j, 0.0 + 0.0j]
)
],
qubit_lo_freq=[4.9],
meas_lo_freq=[6.9],
rep_time=1000,
),
experiments=[
PulseQobjExperiment(
instructions=[
PulseQobjInstruction(name="pulse0", t0=0, ch="d0"),
PulseQobjInstruction(name="fc", t0=5, ch="d0", phase=1.57),
PulseQobjInstruction(name="fc", t0=5, ch="d0", phase=0.0),
PulseQobjInstruction(name="fc", t0=5, ch="d0", phase="P1"),
PulseQobjInstruction(name="setp", t0=10, ch="d0", phase=3.14),
PulseQobjInstruction(name="setf", t0=10, ch="d0", frequency=8.0),
PulseQobjInstruction(name="shiftf", t0=10, ch="d0", frequency=4.0),
PulseQobjInstruction(
name="acquire",
t0=15,
duration=5,
qubits=[0],
memory_slot=[0],
kernels=[
QobjMeasurementOption(
name="boxcar", params={"start_window": 0, "stop_window": 5}
)
],
),
]
)
],
qubit_lo_freq=[4.9],
meas_lo_freq=[6.9],
rep_time=1000,
),
experiments=[
PulseQobjExperiment(
instructions=[
PulseQobjInstruction(name="pulse0", t0=0, ch="d0"),
PulseQobjInstruction(name="fc", t0=5, ch="d0", phase=1.57),
PulseQobjInstruction(name="fc", t0=5, ch="d0", phase=0.0),
PulseQobjInstruction(name="fc", t0=5, ch="d0", phase="P1"),
PulseQobjInstruction(name="setp", t0=10, ch="d0", phase=3.14),
PulseQobjInstruction(name="setf", t0=10, ch="d0", frequency=8.0),
PulseQobjInstruction(name="shiftf", t0=10, ch="d0", frequency=4.0),
PulseQobjInstruction(
name="acquire",
t0=15,
duration=5,
qubits=[0],
memory_slot=[0],
kernels=[
QobjMeasurementOption(
name="boxcar", params={"start_window": 0, "stop_window": 5}
)
],
),
]
)
],
)
)
self.valid_dict = {
"qobj_id": "12345",
"type": "PULSE",
@ -350,87 +363,91 @@ class TestPulseQobj(QiskitTestCase):
def test_from_dict_per_class(self):
"""Test converting to Qobj and its subclass representations given a dictionary."""
test_parameters = {
PulseQobj: (self.valid_qobj, self.valid_dict),
PulseQobjConfig: (
PulseQobjConfig(
meas_level=1,
memory_slot_size=8192,
meas_return="avg",
pulse_library=[PulseLibraryItem(name="pulse0", samples=[0.1 + 0.0j])],
qubit_lo_freq=[4.9],
meas_lo_freq=[6.9],
rep_time=1000,
with self.assertWarns(DeprecationWarning):
test_parameters = {
PulseQobj: (self.valid_qobj, self.valid_dict),
PulseQobjConfig: (
PulseQobjConfig(
meas_level=1,
memory_slot_size=8192,
meas_return="avg",
pulse_library=[PulseLibraryItem(name="pulse0", samples=[0.1 + 0.0j])],
qubit_lo_freq=[4.9],
meas_lo_freq=[6.9],
rep_time=1000,
),
{
"meas_level": 1,
"memory_slot_size": 8192,
"meas_return": "avg",
"pulse_library": [{"name": "pulse0", "samples": [0.1 + 0j]}],
"qubit_lo_freq": [4.9],
"meas_lo_freq": [6.9],
"rep_time": 1000,
},
),
{
"meas_level": 1,
"memory_slot_size": 8192,
"meas_return": "avg",
"pulse_library": [{"name": "pulse0", "samples": [0.1 + 0j]}],
"qubit_lo_freq": [4.9],
"meas_lo_freq": [6.9],
"rep_time": 1000,
},
),
PulseLibraryItem: (
PulseLibraryItem(name="pulse0", samples=[0.1 + 0.0j]),
{"name": "pulse0", "samples": [0.1 + 0j]},
),
PulseQobjExperiment: (
PulseQobjExperiment(
instructions=[PulseQobjInstruction(name="pulse0", t0=0, ch="d0")]
PulseLibraryItem: (
PulseLibraryItem(name="pulse0", samples=[0.1 + 0.0j]),
{"name": "pulse0", "samples": [0.1 + 0j]},
),
{"instructions": [{"name": "pulse0", "t0": 0, "ch": "d0"}]},
),
PulseQobjInstruction: (
PulseQobjInstruction(name="pulse0", t0=0, ch="d0"),
{"name": "pulse0", "t0": 0, "ch": "d0"},
),
}
PulseQobjExperiment: (
PulseQobjExperiment(
instructions=[PulseQobjInstruction(name="pulse0", t0=0, ch="d0")]
),
{"instructions": [{"name": "pulse0", "t0": 0, "ch": "d0"}]},
),
PulseQobjInstruction: (
PulseQobjInstruction(name="pulse0", t0=0, ch="d0"),
{"name": "pulse0", "t0": 0, "ch": "d0"},
),
}
for qobj_class, (qobj_item, expected_dict) in test_parameters.items():
with self.subTest(msg=str(qobj_class)):
self.assertEqual(qobj_item, qobj_class.from_dict(expected_dict))
with self.assertWarns(DeprecationWarning):
qobj = qobj_class.from_dict(expected_dict)
self.assertEqual(qobj_item, qobj)
def test_to_dict_per_class(self):
"""Test converting from Qobj and its subclass representations given a dictionary."""
test_parameters = {
PulseQobj: (self.valid_qobj, self.valid_dict),
PulseQobjConfig: (
PulseQobjConfig(
meas_level=1,
memory_slot_size=8192,
meas_return="avg",
pulse_library=[PulseLibraryItem(name="pulse0", samples=[0.1 + 0.0j])],
qubit_lo_freq=[4.9],
meas_lo_freq=[6.9],
rep_time=1000,
with self.assertWarns(DeprecationWarning):
test_parameters = {
PulseQobj: (self.valid_qobj, self.valid_dict),
PulseQobjConfig: (
PulseQobjConfig(
meas_level=1,
memory_slot_size=8192,
meas_return="avg",
pulse_library=[PulseLibraryItem(name="pulse0", samples=[0.1 + 0.0j])],
qubit_lo_freq=[4.9],
meas_lo_freq=[6.9],
rep_time=1000,
),
{
"meas_level": 1,
"memory_slot_size": 8192,
"meas_return": "avg",
"pulse_library": [{"name": "pulse0", "samples": [0.1 + 0j]}],
"qubit_lo_freq": [4.9],
"meas_lo_freq": [6.9],
"rep_time": 1000,
},
),
{
"meas_level": 1,
"memory_slot_size": 8192,
"meas_return": "avg",
"pulse_library": [{"name": "pulse0", "samples": [0.1 + 0j]}],
"qubit_lo_freq": [4.9],
"meas_lo_freq": [6.9],
"rep_time": 1000,
},
),
PulseLibraryItem: (
PulseLibraryItem(name="pulse0", samples=[0.1 + 0.0j]),
{"name": "pulse0", "samples": [0.1 + 0j]},
),
PulseQobjExperiment: (
PulseQobjExperiment(
instructions=[PulseQobjInstruction(name="pulse0", t0=0, ch="d0")]
PulseLibraryItem: (
PulseLibraryItem(name="pulse0", samples=[0.1 + 0.0j]),
{"name": "pulse0", "samples": [0.1 + 0j]},
),
{"instructions": [{"name": "pulse0", "t0": 0, "ch": "d0"}]},
),
PulseQobjInstruction: (
PulseQobjInstruction(name="pulse0", t0=0, ch="d0"),
{"name": "pulse0", "t0": 0, "ch": "d0"},
),
}
PulseQobjExperiment: (
PulseQobjExperiment(
instructions=[PulseQobjInstruction(name="pulse0", t0=0, ch="d0")]
),
{"instructions": [{"name": "pulse0", "t0": 0, "ch": "d0"}]},
),
PulseQobjInstruction: (
PulseQobjInstruction(name="pulse0", t0=0, ch="d0"),
{"name": "pulse0", "t0": 0, "ch": "d0"},
),
}
for qobj_class, (qobj_item, expected_dict) in test_parameters.items():
with self.subTest(msg=str(qobj_class)):

View File

@ -36,7 +36,8 @@ class TestQobjIdentifiers(QiskitTestCase):
self.circuits = [qc]
def test_qobj_identifiers(self):
qobj = assemble(self.circuits)
with self.assertWarns(DeprecationWarning):
qobj = assemble(self.circuits)
exp = qobj.experiments[0]
self.assertIn(self.qr_name, (x[0] for x in exp.header.qubit_labels))
self.assertIn(self.cr_name, (x[0] for x in exp.header.clbit_labels))

View File

@ -42,7 +42,8 @@ class TestResultOperations(QiskitTestCase):
memory = [hex(ii) for ii in range(8)]
counts = {m: 1 for m in memory}
data_1 = models.ExperimentResultData(counts=counts, memory=memory)
exp_result_header_1 = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4)
with self.assertWarns(DeprecationWarning):
exp_result_header_1 = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4)
exp_result_1 = models.ExperimentResult(
shots=8, success=True, data=data_1, header=exp_result_header_1
)
@ -67,9 +68,10 @@ class TestResultOperations(QiskitTestCase):
raw_counts = {"0x0": 4, "0x2": 10}
processed_counts = {"0 0 00": 4, "0 0 10": 10}
data = models.ExperimentResultData(counts=raw_counts)
exp_result_header = QobjExperimentHeader(
creg_sizes=[["c0", 2], ["c0", 1], ["c1", 1]], memory_slots=4
)
with self.assertWarns(DeprecationWarning):
exp_result_header = QobjExperimentHeader(
creg_sizes=[["c0", 2], ["c0", 1], ["c1", 1]], memory_slots=4
)
exp_result = models.ExperimentResult(
shots=14, success=True, meas_level=2, data=data, header=exp_result_header
)
@ -82,9 +84,10 @@ class TestResultOperations(QiskitTestCase):
raw_counts = {"0x0": 4, "0x2": 10}
processed_counts = {"0 0 00": 4, "0 0 10": 10}
data = models.ExperimentResultData(counts=raw_counts)
exp_result_header = QobjExperimentHeader(
creg_sizes=[["c0", 2], ["c0", 1], ["c1", 1]], memory_slots=4, name="a_name"
)
with self.assertWarns(DeprecationWarning):
exp_result_header = QobjExperimentHeader(
creg_sizes=[["c0", 2], ["c0", 1], ["c1", 1]], memory_slots=4, name="a_name"
)
exp_result = models.ExperimentResult(
shots=14, success=True, meas_level=2, data=data, header=exp_result_header
)
@ -95,7 +98,8 @@ class TestResultOperations(QiskitTestCase):
def test_counts_duplicate_name(self):
"""Test results containing multiple entries of a single name will warn."""
data = models.ExperimentResultData(counts={})
exp_result_header = QobjExperimentHeader(name="foo")
with self.assertWarns(DeprecationWarning):
exp_result_header = QobjExperimentHeader(name="foo")
exp_result = models.ExperimentResult(
shots=14, success=True, data=data, header=exp_result_header
)
@ -108,9 +112,10 @@ class TestResultOperations(QiskitTestCase):
"""Test that repr is constructed correctly for a results object."""
raw_counts = {"0x0": 4, "0x2": 10}
data = models.ExperimentResultData(counts=raw_counts)
exp_result_header = QobjExperimentHeader(
creg_sizes=[["c0", 2], ["c0", 1], ["c1", 1]], memory_slots=4
)
with self.assertWarns(DeprecationWarning):
exp_result_header = QobjExperimentHeader(
creg_sizes=[["c0", 2], ["c0", 1], ["c1", 1]], memory_slots=4
)
exp_result = models.ExperimentResult(
shots=14, success=True, meas_level=2, data=data, header=exp_result_header
)
@ -137,7 +142,8 @@ class TestResultOperations(QiskitTestCase):
raw_counts_1 = {"0x0": 5, "0x3": 12, "0x5": 9, "0xD": 6, "0xE": 2}
processed_counts_1 = {"0000": 5, "0011": 12, "0101": 9, "1101": 6, "1110": 2}
data_1 = models.ExperimentResultData(counts=raw_counts_1)
exp_result_header_1 = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4)
with self.assertWarns(DeprecationWarning):
exp_result_header_1 = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4)
exp_result_1 = models.ExperimentResult(
shots=14, success=True, meas_level=2, data=data_1, header=exp_result_header_1
)
@ -145,7 +151,8 @@ class TestResultOperations(QiskitTestCase):
raw_counts_2 = {"0x1": 0, "0x4": 3, "0x6": 6, "0xA": 1, "0xB": 2}
processed_counts_2 = {"0001": 0, "0100": 3, "0110": 6, "1010": 1, "1011": 2}
data_2 = models.ExperimentResultData(counts=raw_counts_2)
exp_result_header_2 = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4)
with self.assertWarns(DeprecationWarning):
exp_result_header_2 = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4)
exp_result_2 = models.ExperimentResult(
shots=14, success=True, meas_level=2, data=data_2, header=exp_result_header_2
)
@ -153,7 +160,8 @@ class TestResultOperations(QiskitTestCase):
raw_counts_3 = {"0xC": 27, "0xF": 20}
processed_counts_3 = {"1100": 27, "1111": 20}
data_3 = models.ExperimentResultData(counts=raw_counts_3)
exp_result_header_3 = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4)
with self.assertWarns(DeprecationWarning):
exp_result_header_3 = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4)
exp_result_3 = models.ExperimentResult(
shots=14, success=True, meas_level=2, data=data_3, header=exp_result_header_3
)
@ -172,7 +180,8 @@ class TestResultOperations(QiskitTestCase):
"""Test that counts are marginalized correctly."""
raw_counts = {"0x0": 4, "0x1": 7, "0x2": 10, "0x6": 5, "0x9": 11, "0xD": 9, "0xE": 8}
data = models.ExperimentResultData(counts=raw_counts)
exp_result_header = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4)
with self.assertWarns(DeprecationWarning):
exp_result_header = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4)
exp_result = models.ExperimentResult(
shots=54, success=True, data=data, header=exp_result_header
)
@ -186,7 +195,8 @@ class TestResultOperations(QiskitTestCase):
"""Test that counts are marginalized correctly."""
raw_counts = {"0x0": 4, "0x1": 7, "0x2": 10, "0x6": 5, "0x9": 11, "0xD": 9, "0xE": 8}
data = models.ExperimentResultData(counts=raw_counts)
exp_result_header = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4)
with self.assertWarns(DeprecationWarning):
exp_result_header = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4)
exp_result = models.ExperimentResult(
shots=54, success=True, data=data, header=exp_result_header
)
@ -200,7 +210,10 @@ class TestResultOperations(QiskitTestCase):
self.assertEqual(marginal_distribution(result.get_counts(), [1, 0]), expected_reverse)
# test with register spacing, bitstrings are in form of "00 00" for register split
data = models.ExperimentResultData(counts=raw_counts)
exp_result_header = QobjExperimentHeader(creg_sizes=[["c0", 2], ["c1", 2]], memory_slots=4)
with self.assertWarns(DeprecationWarning):
exp_result_header = QobjExperimentHeader(
creg_sizes=[["c0", 2], ["c1", 2]], memory_slots=4
)
exp_result = models.ExperimentResult(
shots=54, success=True, data=data, header=exp_result_header
)
@ -214,14 +227,16 @@ class TestResultOperations(QiskitTestCase):
"""Test that a Result object containing counts marginalizes correctly."""
raw_counts_1 = {"0x0": 4, "0x1": 7, "0x2": 10, "0x6": 5, "0x9": 11, "0xD": 9, "0xE": 8}
data_1 = models.ExperimentResultData(counts=raw_counts_1)
exp_result_header_1 = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4)
with self.assertWarns(DeprecationWarning):
exp_result_header_1 = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4)
exp_result_1 = models.ExperimentResult(
shots=54, success=True, data=data_1, header=exp_result_header_1
)
raw_counts_2 = {"0x2": 5, "0x3": 8}
data_2 = models.ExperimentResultData(counts=raw_counts_2)
exp_result_header_2 = QobjExperimentHeader(creg_sizes=[["c0", 2]], memory_slots=2)
with self.assertWarns(DeprecationWarning):
exp_result_header_2 = QobjExperimentHeader(creg_sizes=[["c0", 2]], memory_slots=2)
exp_result_2 = models.ExperimentResult(
shots=13, success=True, data=data_2, header=exp_result_header_2
)
@ -240,14 +255,20 @@ class TestResultOperations(QiskitTestCase):
"1110": 8,
}
self.assertEqual(marginal_counts(result, [0, 1]).get_counts(0), expected_marginal_counts_1)
self.assertEqual(marginal_counts(result, [0]).get_counts(1), expected_marginal_counts_2)
self.assertEqual(marginal_counts(result, None).get_counts(0), expected_marginal_counts_none)
with self.assertWarns(DeprecationWarning):
self.assertEqual(
marginal_counts(result, [0, 1]).get_counts(0), expected_marginal_counts_1
)
self.assertEqual(marginal_counts(result, [0]).get_counts(1), expected_marginal_counts_2)
self.assertEqual(
marginal_counts(result, None).get_counts(0), expected_marginal_counts_none
)
def test_marginal_counts_result_memory(self):
"""Test that a Result object containing memory marginalizes correctly."""
result = self.generate_qiskit_result()
marginal_result = marginal_counts(result, indices=[0])
with self.assertWarns(DeprecationWarning):
marginal_result = marginal_counts(result, indices=[0])
marginal_memory = marginal_result.results[0].data.memory
self.assertEqual(marginal_memory, [hex(ii % 2) for ii in range(8)])
@ -255,7 +276,8 @@ class TestResultOperations(QiskitTestCase):
"""Test that a Result object containing memory marginalizes correctly."""
result = self.generate_qiskit_result()
index = 2
marginal_result = marginal_counts(result, indices=[index])
with self.assertWarns(DeprecationWarning):
marginal_result = marginal_counts(result, indices=[index])
marginal_memory = marginal_result.results[0].data.memory
mask = 1 << index
expected = [hex((ii & mask) >> index) for ii in range(8)]
@ -266,7 +288,8 @@ class TestResultOperations(QiskitTestCase):
result = self.generate_qiskit_result()
memory = "should not be touched"
result.results[0].data.memory = memory
marginal_result = marginal_counts(result, indices=None)
with self.assertWarns(DeprecationWarning):
marginal_result = marginal_counts(result, indices=None)
marginal_memory = marginal_result.results[0].data.memory
self.assertEqual(marginal_memory, memory)
@ -297,17 +320,20 @@ class TestResultOperations(QiskitTestCase):
self.assertTrue(hasattr(marginal_result.results[0].data, "memory"))
result = self.generate_qiskit_result()
marginal_result = marginal_counts(
result, indices=[0], inplace=False, marginalize_memory=False
)
with self.assertWarns(DeprecationWarning):
marginal_result = marginal_counts(
result, indices=[0], inplace=False, marginalize_memory=False
)
self.assertFalse(hasattr(marginal_result.results[0].data, "memory"))
marginal_result = marginal_counts(
result, indices=[0], inplace=False, marginalize_memory=None
)
with self.assertWarns(DeprecationWarning):
marginal_result = marginal_counts(
result, indices=[0], inplace=False, marginalize_memory=None
)
self.assertTrue(hasattr(marginal_result.results[0].data, "memory"))
marginal_result = marginal_counts(
result, indices=[0], inplace=False, marginalize_memory=True
)
with self.assertWarns(DeprecationWarning):
marginal_result = marginal_counts(
result, indices=[0], inplace=False, marginalize_memory=True
)
self.assertTrue(hasattr(marginal_result.results[0].data, "memory"))
def test_marginal_counts_result_inplace(self):
@ -323,7 +349,10 @@ class TestResultOperations(QiskitTestCase):
"""Test that marginal_counts with Result input properly changes creg_sizes."""
raw_counts = {"0x0": 4, "0x1": 7, "0x2": 10, "0x6": 5, "0x9": 11, "0xD": 9, "0xE": 8}
data = models.ExperimentResultData(counts=raw_counts)
exp_result_header = QobjExperimentHeader(creg_sizes=[["c0", 1], ["c1", 3]], memory_slots=4)
with self.assertWarns(DeprecationWarning):
exp_result_header = QobjExperimentHeader(
creg_sizes=[["c0", 1], ["c1", 3]], memory_slots=4
)
exp_result = models.ExperimentResult(
shots=54, success=True, data=data, header=exp_result_header
)
@ -333,7 +362,8 @@ class TestResultOperations(QiskitTestCase):
expected_marginal_counts = {"0 0": 14, "0 1": 18, "1 0": 13, "1 1": 9}
expected_creg_sizes = [["c0", 1], ["c1", 1]]
expected_memory_slots = 2
marginal_counts_result = marginal_counts(result, [0, 2])
with self.assertWarns(DeprecationWarning):
marginal_counts_result = marginal_counts(result, [0, 2])
self.assertEqual(marginal_counts_result.results[0].header.creg_sizes, expected_creg_sizes)
self.assertEqual(
marginal_counts_result.results[0].header.memory_slots, expected_memory_slots
@ -344,9 +374,10 @@ class TestResultOperations(QiskitTestCase):
"""Test that marginal_counts with format_marginal true properly formats output."""
raw_counts_1 = {"0x0": 4, "0x1": 7, "0x2": 10, "0x6": 5, "0x9": 11, "0xD": 9, "0x12": 8}
data_1 = models.ExperimentResultData(counts=raw_counts_1)
exp_result_header_1 = QobjExperimentHeader(
creg_sizes=[["c0", 2], ["c1", 3]], memory_slots=5
)
with self.assertWarns(DeprecationWarning):
exp_result_header_1 = QobjExperimentHeader(
creg_sizes=[["c0", 2], ["c1", 3]], memory_slots=5
)
exp_result_1 = models.ExperimentResult(
shots=54, success=True, data=data_1, header=exp_result_header_1
)
@ -369,14 +400,16 @@ class TestResultOperations(QiskitTestCase):
"""Test marginal_counts(Result, inplace = True)"""
raw_counts_1 = {"0x0": 4, "0x1": 7, "0x2": 10, "0x6": 5, "0x9": 11, "0xD": 9, "0xE": 8}
data_1 = models.ExperimentResultData(counts=raw_counts_1)
exp_result_header_1 = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4)
with self.assertWarns(DeprecationWarning):
exp_result_header_1 = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4)
exp_result_1 = models.ExperimentResult(
shots=54, success=True, data=data_1, header=exp_result_header_1
)
raw_counts_2 = {"0x2": 5, "0x3": 8}
data_2 = models.ExperimentResultData(counts=raw_counts_2)
exp_result_header_2 = QobjExperimentHeader(creg_sizes=[["c0", 2]], memory_slots=2)
with self.assertWarns(DeprecationWarning):
exp_result_header_2 = QobjExperimentHeader(creg_sizes=[["c0", 2]], memory_slots=2)
exp_result_2 = models.ExperimentResult(
shots=13, success=True, data=data_2, header=exp_result_header_2
)
@ -394,14 +427,16 @@ class TestResultOperations(QiskitTestCase):
"""Test marginal_counts(Result, inplace=False)"""
raw_counts_1 = {"0x0": 4, "0x1": 7, "0x2": 10, "0x6": 5, "0x9": 11, "0xD": 9, "0xE": 8}
data_1 = models.ExperimentResultData(counts=raw_counts_1)
exp_result_header_1 = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4)
with self.assertWarns(DeprecationWarning):
exp_result_header_1 = QobjExperimentHeader(creg_sizes=[["c0", 4]], memory_slots=4)
exp_result_1 = models.ExperimentResult(
shots=54, success=True, data=data_1, header=exp_result_header_1
)
raw_counts_2 = {"0x2": 5, "0x3": 8}
data_2 = models.ExperimentResultData(counts=raw_counts_2)
exp_result_header_2 = QobjExperimentHeader(creg_sizes=[["c0", 2]], memory_slots=2)
with self.assertWarns(DeprecationWarning):
exp_result_header_2 = QobjExperimentHeader(creg_sizes=[["c0", 2]], memory_slots=2)
exp_result_2 = models.ExperimentResult(
shots=13, success=True, data=data_2, header=exp_result_header_2
)
@ -410,9 +445,10 @@ class TestResultOperations(QiskitTestCase):
expected_marginal_counts = {"0": 27, "1": 27}
self.assertEqual(
marginal_counts(result, [0], inplace=False).get_counts(0), expected_marginal_counts
)
with self.assertWarns(DeprecationWarning):
self.assertEqual(
marginal_counts(result, [0], inplace=False).get_counts(0), expected_marginal_counts
)
self.assertNotEqual(result.get_counts(0), expected_marginal_counts)
def test_marginal_counts_with_dict(self):
@ -465,9 +501,10 @@ class TestResultOperations(QiskitTestCase):
"0 0 10",
]
data = models.ExperimentResultData(memory=raw_memory)
exp_result_header = QobjExperimentHeader(
creg_sizes=[["c0", 2], ["c0", 1], ["c1", 1]], memory_slots=4
)
with self.assertWarns(DeprecationWarning):
exp_result_header = QobjExperimentHeader(
creg_sizes=[["c0", 2], ["c0", 1], ["c1", 1]], memory_slots=4
)
exp_result = models.ExperimentResult(
shots=14, success=True, meas_level=2, memory=True, data=data, header=exp_result_header
)
@ -703,9 +740,10 @@ class TestResultOperationsFailed(QiskitTestCase):
"""Test that fails when get_count is called with a nonexistent name."""
raw_counts = {"0x0": 4, "0x2": 10}
data = models.ExperimentResultData(counts=raw_counts)
exp_result_header = QobjExperimentHeader(
creg_sizes=[["c0", 2], ["c0", 1], ["c1", 1]], memory_slots=4, name="a_name"
)
with self.assertWarns(DeprecationWarning):
exp_result_header = QobjExperimentHeader(
creg_sizes=[["c0", 2], ["c0", 1], ["c1", 1]], memory_slots=4, name="a_name"
)
exp_result = models.ExperimentResult(
shots=14, success=True, meas_level=2, data=data, header=exp_result_header
)
@ -736,13 +774,15 @@ class TestResultOperationsFailed(QiskitTestCase):
"""Test that marginal_counts without cregs See qiskit-terra/6430."""
raw_counts_1 = {"0x0": 4, "0x1": 7, "0x2": 10, "0x6": 5, "0x9": 11, "0xD": 9, "0x12": 8}
data_1 = models.ExperimentResultData(counts=raw_counts_1)
exp_result_header_1 = QobjExperimentHeader(memory_slots=5)
with self.assertWarns(DeprecationWarning):
exp_result_header_1 = QobjExperimentHeader(memory_slots=5)
exp_result_1 = models.ExperimentResult(
shots=54, success=True, data=data_1, header=exp_result_header_1
)
result = Result(results=[exp_result_1], **self.base_result_args)
_ = marginal_counts(result, indices=[0])
marginal_counts_result = marginal_counts(result, indices=[0])
with self.assertWarns(DeprecationWarning):
_ = marginal_counts(result, indices=[0])
marginal_counts_result = marginal_counts(result, indices=[0])
self.assertEqual(marginal_counts_result.get_counts(), {"0": 27, "1": 27})

View File

@ -21,7 +21,7 @@ import numpy as np
from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister
from qiskit.circuit import Qubit, Gate, ControlFlowOp, ForLoopOp
from qiskit.compiler import transpile, assemble
from qiskit.compiler import transpile
from qiskit.transpiler import CouplingMap, Layout, PassManager, TranspilerError, Target
from qiskit.circuit.library import U2Gate, U3Gate, QuantumVolume, CXGate, CZGate, XGate
from qiskit.transpiler.passes import (
@ -684,15 +684,15 @@ class TestInitialLayouts(QiskitTestCase):
}
backend = GenericBackendV2(num_qubits=16, coupling_map=RUESCHLIKON_CMAP, seed=42)
qc_b = transpile(qc, backend, initial_layout=initial_layout, optimization_level=level)
qobj = assemble(qc_b)
self.assertEqual(qc_b._layout.initial_layout._p2v, final_layout)
compiled_ops = qobj.experiments[0].instructions
for operation in compiled_ops:
if operation.name == "cx":
self.assertIn(tuple(operation.qubits), backend.coupling_map)
self.assertIn(operation.qubits, [[15, 0], [15, 2]])
for inst in qc_b.data:
if inst.operation.name == "cx":
self.assertIn(
tuple(qc_b.find_bit(bit).index for bit in inst.qubits), backend.coupling_map
)
self.assertIn([qc_b.find_bit(bit).index for bit in inst.qubits], [[15, 0], [15, 2]])
@data(0, 1, 2, 3)
def test_layout_2532(self, level):

View File

@ -15,6 +15,7 @@
import unittest
import itertools
import ddt
import numpy.random
@ -278,8 +279,7 @@ class TestSabreSwap(QiskitTestCase):
from qiskit_aer import Aer
with self.assertWarns(DeprecationWarning):
sim = Aer.get_backend("aer_simulator")
sim = Aer.get_backend("aer_simulator")
in_results = sim.run(qc, shots=4096).result().get_counts()
out_results = sim.run(routed, shots=4096).result().get_counts()
self.assertEqual(set(in_results), set(out_results))

View File

@ -15,6 +15,7 @@
"""Test the StarPreRouting pass"""
import unittest
from test import QiskitTestCase
import ddt

View File

@ -123,12 +123,30 @@ class QiskitTestCase(BaseTestCase):
# Safe to remove once https://github.com/Qiskit/qiskit-aer/pull/2179 is in a release version
# of Aer.
warnings.filterwarnings(
"default",
"ignore", # If "default", it floods the CI output
category=DeprecationWarning,
message="Treating CircuitInstruction as an iterable is deprecated",
module=r"qiskit_aer(\.[a-zA-Z0-9_]+)*",
)
# Safe to remove once https://github.com/Qiskit/qiskit-aer/issues/2065 is in a release version
# of Aer.
warnings.filterwarnings(
"ignore", # If "default", it floods the CI output
category=DeprecationWarning,
message=r".*The `Qobj` class and related functionality.*",
module=r"qiskit_aer",
)
# Safe to remove once https://github.com/Qiskit/qiskit-aer/pull/2184 is in a release version
# of Aer.
warnings.filterwarnings(
"ignore", # If "default", it floods the CI output
category=DeprecationWarning,
message=r".*The abstract Provider and ProviderV1 classes are deprecated.*",
module="qiskit_aer",
)
allow_DeprecationWarning_message = [
r"The property ``qiskit\.circuit\.bit\.Bit\.(register|index)`` is deprecated.*",
]