qiskit 1.3.2__cp39-abi3-win32.whl → 1.4.0__cp39-abi3-win32.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. qiskit/VERSION.txt +1 -1
  2. qiskit/__init__.py +1 -0
  3. qiskit/_accelerate.pyd +0 -0
  4. qiskit/circuit/__init__.py +5 -2
  5. qiskit/circuit/bit.py +12 -0
  6. qiskit/circuit/classicalfunction/__init__.py +13 -1
  7. qiskit/circuit/classicalfunction/boolean_expression.py +10 -1
  8. qiskit/circuit/classicalfunction/classicalfunction.py +10 -1
  9. qiskit/circuit/classicalfunction/exceptions.py +7 -1
  10. qiskit/circuit/delay.py +5 -0
  11. qiskit/circuit/library/generalized_gates/mcmt.py +5 -6
  12. qiskit/circuit/library/phase_oracle.py +24 -17
  13. qiskit/circuit/library/standard_gates/rz.py +7 -7
  14. qiskit/circuit/library/standard_gates/xx_minus_yy.py +0 -30
  15. qiskit/circuit/parametervector.py +25 -5
  16. qiskit/circuit/quantumcircuit.py +68 -2
  17. qiskit/circuit/register.py +13 -0
  18. qiskit/compiler/assembler.py +16 -8
  19. qiskit/compiler/transpiler.py +1 -1
  20. qiskit/dagcircuit/dagdependency_v2.py +4 -2
  21. qiskit/passmanager/passmanager.py +19 -1
  22. qiskit/primitives/backend_estimator_v2.py +17 -0
  23. qiskit/primitives/backend_sampler_v2.py +15 -0
  24. qiskit/providers/backend_compat.py +46 -11
  25. qiskit/providers/basic_provider/basic_simulator.py +15 -3
  26. qiskit/providers/exceptions.py +23 -2
  27. qiskit/providers/models/backendproperties.py +19 -1
  28. qiskit/providers/models/backendstatus.py +10 -0
  29. qiskit/providers/models/jobstatus.py +11 -0
  30. qiskit/pulse/schedule.py +1 -1
  31. qiskit/quantum_info/operators/channel/transformations.py +15 -0
  32. qiskit/result/result.py +109 -20
  33. qiskit/synthesis/evolution/product_formula.py +1 -2
  34. qiskit/synthesis/evolution/qdrift.py +1 -2
  35. qiskit/synthesis/evolution/suzuki_trotter.py +1 -2
  36. qiskit/transpiler/__init__.py +772 -542
  37. qiskit/transpiler/layout.py +6 -6
  38. qiskit/transpiler/passes/calibration/rzx_templates.py +7 -0
  39. qiskit/transpiler/passes/layout/dense_layout.py +12 -0
  40. qiskit/transpiler/passes/layout/sabre_layout.py +13 -0
  41. qiskit/transpiler/passes/layout/vf2_layout.py +11 -0
  42. qiskit/transpiler/passes/layout/vf2_post_layout.py +22 -0
  43. qiskit/transpiler/passes/optimization/normalize_rx_angle.py +8 -0
  44. qiskit/transpiler/passes/optimization/remove_identity_equiv.py +2 -3
  45. qiskit/transpiler/passes/routing/star_prerouting.py +17 -2
  46. qiskit/transpiler/passes/scheduling/scheduling/alap.py +1 -1
  47. qiskit/transpiler/passes/scheduling/scheduling/asap.py +1 -1
  48. qiskit/transpiler/passes/synthesis/unitary_synthesis.py +11 -0
  49. qiskit/transpiler/passmanager_config.py +11 -0
  50. qiskit/transpiler/preset_passmanagers/__init__.py +26 -6
  51. qiskit/transpiler/preset_passmanagers/builtin_plugins.py +188 -118
  52. qiskit/transpiler/preset_passmanagers/common.py +133 -83
  53. qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py +29 -3
  54. qiskit/transpiler/preset_passmanagers/plugin.py +33 -42
  55. qiskit/transpiler/target.py +41 -9
  56. qiskit/visualization/circuit/text.py +3 -2
  57. qiskit/visualization/gate_map.py +50 -0
  58. qiskit/visualization/pulse_v2/interface.py +0 -2
  59. qiskit/visualization/timeline/interface.py +3 -3
  60. {qiskit-1.3.2.dist-info → qiskit-1.4.0.dist-info}/METADATA +4 -7
  61. {qiskit-1.3.2.dist-info → qiskit-1.4.0.dist-info}/RECORD +65 -65
  62. {qiskit-1.3.2.dist-info → qiskit-1.4.0.dist-info}/LICENSE.txt +0 -0
  63. {qiskit-1.3.2.dist-info → qiskit-1.4.0.dist-info}/WHEEL +0 -0
  64. {qiskit-1.3.2.dist-info → qiskit-1.4.0.dist-info}/entry_points.txt +0 -0
  65. {qiskit-1.3.2.dist-info → qiskit-1.4.0.dist-info}/top_level.txt +0 -0
@@ -14,6 +14,7 @@
14
14
  from __future__ import annotations
15
15
 
16
16
  import logging
17
+ import warnings
17
18
  from abc import ABC, abstractmethod
18
19
  from collections.abc import Callable, Iterable
19
20
  from itertools import chain
@@ -29,6 +30,8 @@ from .compilation_status import PropertySet, WorkflowStatus, PassManagerState
29
30
 
30
31
  logger = logging.getLogger(__name__)
31
32
 
33
+ _MISSING = object()
34
+
32
35
 
33
36
  class BasePassManager(ABC):
34
37
  """Pass manager base class."""
@@ -174,6 +177,8 @@ class BasePassManager(ABC):
174
177
  in_programs: Any | list[Any],
175
178
  callback: Callable = None,
176
179
  num_processes: int = None,
180
+ *,
181
+ property_set: object = _MISSING,
177
182
  **kwargs,
178
183
  ) -> Any:
179
184
  """Run all the passes on the specified ``in_programs``.
@@ -211,12 +216,25 @@ class BasePassManager(ABC):
211
216
  execution is enabled. This argument overrides ``num_processes`` in the user
212
217
  configuration file, and the ``QISKIT_NUM_PROCS`` environment variable. If set
213
218
  to ``None`` the system default or local user configuration will be used.
214
-
219
+ property_set: Currently a key that will be interpreted as all other arbitrary
220
+ ``kwargs``. In Qiskit 2.0, this will instead seed the :class:`.PropertySet` of the
221
+ compilation (but does not do so in this version).
215
222
  kwargs: Arbitrary arguments passed to the compiler frontend and backend.
216
223
 
217
224
  Returns:
218
225
  The transformed program(s).
219
226
  """
227
+ if property_set is not _MISSING:
228
+ warnings.warn(
229
+ "From Qiskit 2.0, 'property_set' will be a reserved keyword argument of"
230
+ " 'BasePassManager.run', and not passed on to the conversion functions."
231
+ " This subclass of 'BasePassManager' needs to use a different keyword argument"
232
+ " for passing on this data.",
233
+ FutureWarning,
234
+ stacklevel=2,
235
+ )
236
+ kwargs["property_set"] = property_set
237
+
220
238
  if not self._tasks and not kwargs and callback is None:
221
239
  return in_programs
222
240
 
@@ -15,6 +15,7 @@
15
15
  from __future__ import annotations
16
16
 
17
17
  import math
18
+ import warnings
18
19
  from collections import defaultdict
19
20
  from collections.abc import Iterable
20
21
  from dataclasses import dataclass
@@ -131,12 +132,28 @@ class BackendEstimatorV2(BaseEstimatorV2):
131
132
  options: dict | None = None,
132
133
  ):
133
134
  """
135
+ .. deprecated:: 1.4
136
+ The method ``BackendEstimatorV2.__init__`` will stop supporting inputs of type
137
+ :class:`.BackendV1` in the `backend` parameter in a future release no
138
+ earlier than 2.0. :class:`.BackendV1` is deprecated and implementations should
139
+ move to :class:`.BackendV2`.
140
+
134
141
  Args:
135
142
  backend: The backend to run the primitive on.
136
143
  options: The options to control the default precision (``default_precision``),
137
144
  the operator grouping (``abelian_grouping``), and
138
145
  the random seed for the simulator (``seed_simulator``).
139
146
  """
147
+
148
+ if not isinstance(backend, BackendV2):
149
+ warnings.warn(
150
+ "The method `BackendEstimatorV2.__init__` will stop supporting inputs of "
151
+ f"type `BackendV1` ( {backend} ) in the `backend` parameter in a future "
152
+ "release no earlier than 2.0. `BackendV1` is deprecated and implementations "
153
+ "should move to `BackendV2`.",
154
+ category=DeprecationWarning,
155
+ stacklevel=2,
156
+ )
140
157
  self._backend = backend
141
158
  self._options = Options(**options) if options else Options()
142
159
 
@@ -123,11 +123,26 @@ class BackendSamplerV2(BaseSamplerV2):
123
123
  options: dict | None = None,
124
124
  ):
125
125
  """
126
+ .. deprecated:: 1.4
127
+ The method ``BackendSamplerV2.__init__`` will stop supporting inputs of type
128
+ :class:`.BackendV1` in the `backend` parameter in a future release no
129
+ earlier than 2.0. :class:`.BackendV1` is deprecated and implementations should
130
+ move to :class:`.BackendV2`.
131
+
126
132
  Args:
127
133
  backend: The backend to run the primitive on.
128
134
  options: The options to control the default shots (``default_shots``) and
129
135
  the random seed for the simulator (``seed_simulator``).
130
136
  """
137
+ if not isinstance(backend, BackendV2):
138
+ warnings.warn(
139
+ "The method `BackendSamplerV2.__init__` will stop supporting inputs of "
140
+ f"type `BackendV1` ( {backend} ) in the `backend` parameter in a future "
141
+ "release no earlier than 2.0. `BackendV1` is deprecated and implementations "
142
+ "should move to `BackendV2`.",
143
+ category=DeprecationWarning,
144
+ stacklevel=2,
145
+ )
131
146
  self._backend = backend
132
147
  self._options = Options(**options) if options else Options()
133
148
 
@@ -25,6 +25,7 @@ from qiskit.circuit.controlflow import CONTROL_FLOW_OP_NAMES
25
25
  from qiskit.providers.models.pulsedefaults import PulseDefaults
26
26
  from qiskit.providers.options import Options
27
27
  from qiskit.providers.exceptions import BackendPropertyError
28
+ from qiskit.utils import deprecate_func
28
29
  from qiskit.utils.deprecate_pulse import deprecate_pulse_arg, deprecate_pulse_dependency
29
30
 
30
31
 
@@ -59,9 +60,19 @@ def convert_to_target(
59
60
  Returns:
60
61
  A ``Target`` instance.
61
62
  """
62
- return _convert_to_target(
63
- configuration, properties, defaults, custom_name_mapping, add_delay, filter_faulty
64
- )
63
+ # If a deprecated error is raised during the conversion, we should not return the
64
+ # deprecation warning to the user,as it is not actionable for them.
65
+ with warnings.catch_warnings():
66
+ warnings.filterwarnings(
67
+ "ignore",
68
+ category=DeprecationWarning,
69
+ message=".*``qiskit.providers.exceptions.BackendPropertyError``",
70
+ module="qiskit",
71
+ )
72
+ target = _convert_to_target(
73
+ configuration, properties, defaults, custom_name_mapping, add_delay, filter_faulty
74
+ )
75
+ return target
65
76
 
66
77
 
67
78
  def _convert_to_target(
@@ -368,6 +379,12 @@ class BackendV2Converter(BackendV2):
368
379
  )
369
380
  """
370
381
 
382
+ @deprecate_func(
383
+ since="1.4",
384
+ removal_timeline="in the 2.0 release",
385
+ additional_msg="Since ``BackendV1`` is deprecated, this conversion tool from BackendV1 to "
386
+ "BackendV2 is going to be removed with BackendV1.",
387
+ )
371
388
  def __init__(
372
389
  self,
373
390
  backend: BackendV1,
@@ -426,14 +443,32 @@ class BackendV2Converter(BackendV2):
426
443
  :rtype: Target
427
444
  """
428
445
  if self._target is None:
429
- self._target = _convert_to_target(
430
- configuration=self._config,
431
- properties=self._properties,
432
- defaults=self._defaults,
433
- custom_name_mapping=self._name_mapping,
434
- add_delay=self._add_delay,
435
- filter_faulty=self._filter_faulty,
436
- )
446
+ # If a deprecated error is raised during the conversion,
447
+ # we should not return the deprecation warning to the user,
448
+ # as it is not actionable for them.
449
+ with warnings.catch_warnings():
450
+ warnings.filterwarnings(
451
+ "ignore",
452
+ category=DeprecationWarning,
453
+ message=".*``qiskit.providers.exceptions.BackendPropertyError``",
454
+ module="qiskit",
455
+ )
456
+ # convert_to_target is deprecated along BackendV2Converter
457
+ # They both need to be removed at the same time
458
+ warnings.filterwarnings(
459
+ "ignore",
460
+ category=DeprecationWarning,
461
+ message=r".+qiskit\.providers\.backend_compat\.convert_to_target.+",
462
+ module="qiskit",
463
+ )
464
+ self._target = _convert_to_target(
465
+ configuration=self._config,
466
+ properties=self._properties,
467
+ defaults=self._defaults,
468
+ custom_name_mapping=self._name_mapping,
469
+ add_delay=self._add_delay,
470
+ filter_faulty=self._filter_faulty,
471
+ )
437
472
  return self._target
438
473
 
439
474
  @property
@@ -576,8 +576,14 @@ class BasicSimulator(BackendV2):
576
576
  self._memory = getattr(qobj.config, "memory", False)
577
577
  self._qobj_config = qobj.config
578
578
  start = time.time()
579
- for experiment in qobj.experiments:
580
- result_list.append(self.run_experiment(experiment))
579
+ with warnings.catch_warnings():
580
+ warnings.filterwarnings(
581
+ "ignore",
582
+ category=DeprecationWarning,
583
+ message=r".+qiskit\.providers\.basic_provider\.basic_simulator\..+",
584
+ )
585
+ for experiment in qobj.experiments:
586
+ result_list.append(self.run_experiment(experiment))
581
587
  end = time.time()
582
588
  result = {
583
589
  "backend_name": self.name,
@@ -590,9 +596,15 @@ class BasicSimulator(BackendV2):
590
596
  "time_taken": (end - start),
591
597
  "header": qobj.header.to_dict(),
592
598
  }
593
-
594
599
  return Result.from_dict(result)
595
600
 
601
+ @deprecate_func(
602
+ since="1.4.0",
603
+ removal_timeline="in Qiskit 2.0.0",
604
+ additional_msg="This method takes a `QasmQobjExperiment` as input argument. "
605
+ "The `Qobj` class and related functionality are part of the deprecated "
606
+ "`BackendV1` workflow, and no longer necessary for `BackendV2`. Use `run` instead.",
607
+ )
596
608
  def run_experiment(self, experiment: QasmQobjExperiment) -> dict[str, ...]:
597
609
  """Run an experiment (circuit) and return a single experiment result.
598
610
 
@@ -13,6 +13,7 @@
13
13
  """Exceptions for errors raised while handling Backends and Jobs."""
14
14
 
15
15
  from qiskit.exceptions import QiskitError
16
+ from qiskit.utils import deprecate_func
16
17
 
17
18
 
18
19
  class JobError(QiskitError):
@@ -36,10 +37,30 @@ class QiskitBackendNotFoundError(QiskitError):
36
37
  class BackendPropertyError(QiskitError):
37
38
  """Base class for errors raised while looking for a backend property."""
38
39
 
39
- pass
40
+ @deprecate_func(
41
+ since="1.4",
42
+ removal_timeline="in the 2.0 release",
43
+ additional_msg="The models in ``qiskit.providers.models`` and related objects are part "
44
+ "of the deprecated `BackendV1` workflow, and no longer necessary for `BackendV2`. If a user "
45
+ "workflow requires these representations it likely relies on deprecated functionality and "
46
+ "should be updated to use `BackendV2`.",
47
+ stacklevel=2,
48
+ )
49
+ def __init__(self, *message):
50
+ super().__init__(*message)
40
51
 
41
52
 
42
53
  class BackendConfigurationError(QiskitError):
43
54
  """Base class for errors raised by the BackendConfiguration."""
44
55
 
45
- pass
56
+ @deprecate_func(
57
+ since="1.4",
58
+ removal_timeline="in the 2.0 release",
59
+ additional_msg="The models in ``qiskit.providers.models`` and related objects are part "
60
+ "of the deprecated `BackendV1` workflow, and no longer necessary for `BackendV2`. If a user "
61
+ "workflow requires these representations it likely relies on deprecated functionality and "
62
+ "should be updated to use `BackendV2`.",
63
+ stacklevel=2,
64
+ )
65
+ def __init__(self, *message):
66
+ super().__init__(*message)
@@ -34,6 +34,15 @@ class Nduv:
34
34
  value: value.
35
35
  """
36
36
 
37
+ @deprecate_func(
38
+ since="1.4",
39
+ removal_timeline="in the 2.0 release",
40
+ additional_msg="The models in ``qiskit.providers.models`` and related objects are part "
41
+ "of the deprecated `BackendV1` workflow, and no longer necessary for `BackendV2`. If a user "
42
+ "workflow requires these representations it likely relies on deprecated functionality and "
43
+ "should be updated to use `BackendV2`.",
44
+ stacklevel=2,
45
+ )
37
46
  def __init__(self, date, name, unit, value):
38
47
  """Initialize a new name-date-unit-value object
39
48
 
@@ -97,6 +106,15 @@ class GateProperties:
97
106
 
98
107
  _data = {}
99
108
 
109
+ @deprecate_func(
110
+ since="1.4",
111
+ removal_timeline="in the 2.0 release",
112
+ additional_msg="The models in ``qiskit.providers.models`` and related objects are part "
113
+ "of the deprecated `BackendV1` workflow, and no longer necessary for `BackendV2`. If a user "
114
+ "workflow requires these representations it likely relies on deprecated functionality and "
115
+ "should be updated to use `BackendV2`.",
116
+ stacklevel=2,
117
+ )
100
118
  def __init__(self, qubits, gate, parameters, **kwargs):
101
119
  """Initialize a new :class:`GateProperties` object
102
120
 
@@ -180,7 +198,7 @@ class BackendProperties:
180
198
  "of the deprecated `BackendV1` workflow, and no longer necessary for `BackendV2`. If a user "
181
199
  "workflow requires these representations it likely relies on deprecated functionality and "
182
200
  "should be updated to use `BackendV2`.",
183
- stacklevel=3,
201
+ stacklevel=2,
184
202
  )
185
203
  def __init__(
186
204
  self, backend_name, backend_version, last_update_date, qubits, gates, general, **kwargs
@@ -14,11 +14,21 @@
14
14
 
15
15
  import html
16
16
  from qiskit.exceptions import QiskitError
17
+ from qiskit.utils import deprecate_func
17
18
 
18
19
 
19
20
  class BackendStatus:
20
21
  """Class representing Backend Status."""
21
22
 
23
+ @deprecate_func(
24
+ since="1.4",
25
+ removal_timeline="in the 2.0 release",
26
+ additional_msg="The models in ``qiskit.providers.models`` and related objects are part "
27
+ "of the deprecated `BackendV1` workflow, and no longer necessary for `BackendV2`. If a user "
28
+ "workflow requires these representations it likely relies on deprecated functionality and "
29
+ "should be updated to use `BackendV2`.",
30
+ stacklevel=2,
31
+ )
22
32
  def __init__(
23
33
  self,
24
34
  backend_name: str,
@@ -12,6 +12,8 @@
12
12
 
13
13
  """Class for job status."""
14
14
 
15
+ from qiskit.utils import deprecate_func
16
+
15
17
 
16
18
  class JobStatus:
17
19
  """Model for JobStatus.
@@ -24,6 +26,15 @@ class JobStatus:
24
26
 
25
27
  _data = {}
26
28
 
29
+ @deprecate_func(
30
+ since="1.4",
31
+ removal_timeline="in the 2.0 release",
32
+ additional_msg="The models in ``qiskit.providers.models`` and related objects are part "
33
+ "of the deprecated `BackendV1` workflow, and no longer necessary for `BackendV2`. If a user "
34
+ "workflow requires these representations it likely relies on deprecated functionality and "
35
+ "should be updated to use `BackendV2`.",
36
+ stacklevel=2,
37
+ )
27
38
  def __init__(self, job_id, status, status_msg, **kwargs):
28
39
  self._data = {}
29
40
  self.job_id = job_id
qiskit/pulse/schedule.py CHANGED
@@ -1637,7 +1637,7 @@ def _common_method(*classes):
1637
1637
  return decorator
1638
1638
 
1639
1639
 
1640
- @deprecate_arg("show_barriers", new_alias="plot_barriers", since="1.1.0", pending=True)
1640
+ @deprecate_arg("show_barriers", new_alias="plot_barriers", since="1.4")
1641
1641
  @_common_method(Schedule, ScheduleBlock)
1642
1642
  def draw(
1643
1643
  self,
@@ -234,8 +234,23 @@ def _choi_to_kraus(data, input_dim, output_dim, atol=ATOL_DEFAULT):
234
234
  #
235
235
  # So the eigenvalues are on the diagonal, therefore the basis-transformation matrix must be
236
236
  # a spanning set of the eigenspace.
237
+ #
238
+ # In addition, to prevent `numpy.linalg` errors when the matrix A is ill-conditioned,
239
+ # we apply a small perturbation, replacing A by A + eI. Since (A + eI)x = kx is
240
+ # equivalent to Ax = (k-e)x, it means that the eigenvectors of A + eI and A are the same,
241
+ # and we can perfectly recover the eigenvalues of A from the eigenvalues of A + eI by
242
+ # subtracting e.
243
+ apply_perturbation = np.linalg.cond(data) >= 1e10
244
+
245
+ if apply_perturbation:
246
+ data += 1e-10 * np.eye(data.shape[0])
247
+
237
248
  triangular, vecs = scipy.linalg.schur(data)
238
249
  values = triangular.diagonal().real
250
+
251
+ if apply_perturbation:
252
+ values = values - 1e-10
253
+
239
254
  # If we're not a CP map, fall-through back to the generalization handling. Since we needed
240
255
  # to get the eigenvalues anyway, we can do the CP check manually rather than deferring to a
241
256
  # separate re-calculation.
qiskit/result/result.py CHANGED
@@ -12,6 +12,7 @@
12
12
 
13
13
  """Model for schema-conformant Results."""
14
14
 
15
+ from collections.abc import Iterable
15
16
  import copy
16
17
  import warnings
17
18
 
@@ -25,47 +26,135 @@ from qiskit.result.counts import Counts
25
26
  from qiskit.qobj.utils import MeasLevel
26
27
  from qiskit.qobj import QobjHeader
27
28
 
29
+ _MISSING = object()
30
+
28
31
 
29
32
  class Result:
30
33
  """Model for Results.
31
34
 
32
- Attributes:
33
- backend_name (str): backend name.
34
- backend_version (str): backend version, in the form X.Y.Z.
35
- qobj_id (str): user-generated Qobj id.
36
- job_id (str): unique execution id from the backend.
37
- success (bool): True if complete input qobj executed correctly. (Implies
35
+ .. deprecated:: 1.4
36
+ The use of positional arguments in the constructor of :class:`.Result`
37
+ is deprecated as of Qiskit 1.4, and will be disabled in Qiskit 2.0.
38
+ Please set all arguments using kwarg syntax, i.e: ``Result(backend_name="name", ....)``.
39
+ In addition to this, the ``qobj_id`` argument is deprecated and will no longer
40
+ be used in Qiskit 2.0. It will, however, still be possible to set ``qobj_id`` as a
41
+ generic kwarg, which will land in the metadata field with the other generic kwargs.
42
+
43
+ Args:
44
+ backend_name (str): (REQUIRED) backend name.
45
+ backend_version (str): (REQUIRED) backend version, in the form X.Y.Z.
46
+ qobj_id (str): (REQUIRED) user-generated Qobj id.
47
+ job_id (str): (REQUIRED) unique execution id from the backend.
48
+ success (bool): (REQUIRED) True if complete input qobj executed correctly. (Implies
38
49
  each experiment success)
39
- results (list[ExperimentResult]): corresponding results for array of
50
+ results (list[ExperimentResult]): (REQUIRED) corresponding results for array of
40
51
  experiments of the input qobj
52
+ date (str): (OPTIONAL) date of the experiment
53
+ header(dict): (OPTIONAL)experiment header
54
+ kwargs: generic keyword arguments. (OPTIONAL) These will be stored in the metadata field.
41
55
  """
42
56
 
43
57
  _metadata = {}
44
58
 
45
59
  def __init__(
46
60
  self,
47
- backend_name,
48
- backend_version,
49
- qobj_id,
50
- job_id,
51
- success,
52
- results,
61
+ *args,
53
62
  date=None,
54
63
  status=None,
55
64
  header=None,
56
65
  **kwargs,
57
66
  ):
67
+ # The following arguments are required.
68
+ required_args = {
69
+ "backend_name": _MISSING,
70
+ "backend_version": _MISSING,
71
+ "qobj_id": _MISSING,
72
+ "job_id": _MISSING,
73
+ "success": _MISSING,
74
+ "results": _MISSING,
75
+ }
76
+ # Step 1: iterate over kwargs.
77
+ # An item from required_args might be set as a kwarg, so we must separate
78
+ # true kwargs from "required_args" kwargs.
79
+ true_kwargs = {}
80
+ for key, value in kwargs.items():
81
+ if key in required_args:
82
+ required_args[key] = value
83
+ else:
84
+ true_kwargs[key] = value
85
+ # Step 2: iterate over args, which are expected in the order of the index_map below.
86
+ index_map = ["backend_name", "backend_version", "qobj_id", "job_id", "success", "results"]
87
+ raise_qobj = False
88
+ missing_args = []
89
+ for index, name in enumerate(index_map):
90
+ try:
91
+ value = args[index]
92
+ required_args[name] = value
93
+ # The use of args is deprecated in 1.4 and will be removed in 2.0.
94
+ # Furthermore, qobj_id will be ignored if set as a kwarg in 2.0.
95
+ if name == "qobj_id":
96
+ warnings.warn(
97
+ "The use of positional arguments in `qiskit.result.result.Result.__init__()` "
98
+ "is deprecated as of Qiskit 1.4, and will be disabled in Qiskit 2.0. "
99
+ "Please set this value using kwarg syntax, "
100
+ f"i.e: `Result(...,{name}={name}_value)`. "
101
+ "The `qobj_id` argument will no longer be used in Qiskit 2.0, "
102
+ "but it will still be possible to "
103
+ "set as a kwarg that will land in the metadata field.",
104
+ category=DeprecationWarning,
105
+ stacklevel=2,
106
+ )
107
+ else:
108
+ warnings.warn(
109
+ "The use of positional arguments in `qiskit.result.result.Result.__init__()` "
110
+ "is deprecated as of Qiskit 1.4, and will be disabled in Qiskit 2.0. "
111
+ "Please set this value using kwarg syntax, "
112
+ f"i.e: `Result(...,{name}={name}_value)`. ",
113
+ category=DeprecationWarning,
114
+ stacklevel=2,
115
+ )
116
+ except IndexError:
117
+ if required_args[name] is _MISSING:
118
+ missing_args = [
119
+ key for (key, value) in required_args.items() if value is _MISSING
120
+ ]
121
+ elif name == "qobj_id":
122
+ raise_qobj = True
123
+ break
124
+
125
+ # The deprecation warning should be raised outside of the try-except,
126
+ # not to show a confusing trace that points to the IndexError
127
+ if len(missing_args) > 1:
128
+ raise TypeError(
129
+ f"Result.__init__() missing {len(missing_args)} required arguments: {missing_args}"
130
+ )
131
+ if len(missing_args) == 1:
132
+ raise TypeError(f"Result.__init__() missing a required argument: {missing_args[0]}")
133
+ if raise_qobj:
134
+ # qobj_id will be ignored if set as a kwarg in 2.0.
135
+ warnings.warn(
136
+ "The `qobj_id` argument will no longer be used in Qiskit 2.0, "
137
+ "but it will still be possible to "
138
+ "set as a kwarg that will land in the metadata field.",
139
+ category=DeprecationWarning,
140
+ stacklevel=2,
141
+ )
142
+
58
143
  self._metadata = {}
59
- self.backend_name = backend_name
60
- self.backend_version = backend_version
61
- self.qobj_id = qobj_id
62
- self.job_id = job_id
63
- self.success = success
64
- self.results = results
144
+ self.backend_name = required_args["backend_name"]
145
+ self.backend_version = required_args["backend_version"]
146
+ self.qobj_id = required_args["qobj_id"]
147
+ self.job_id = required_args["job_id"]
148
+ self.success = required_args["success"]
149
+ self.results = (
150
+ [required_args["results"]]
151
+ if not isinstance(required_args["results"], Iterable)
152
+ else required_args["results"]
153
+ )
65
154
  self.date = date
66
155
  self.status = status
67
156
  self.header = header
68
- self._metadata.update(kwargs)
157
+ self._metadata.update(true_kwargs)
69
158
 
70
159
  def __repr__(self):
71
160
  out = (
@@ -44,7 +44,7 @@ class ProductFormula(EvolutionSynthesis):
44
44
 
45
45
  @deprecate_arg(
46
46
  name="atomic_evolution",
47
- since="1.2",
47
+ since="1.4",
48
48
  predicate=lambda callable: callable is not None
49
49
  and len(inspect.signature(callable).parameters) == 2,
50
50
  deprecation_description=(
@@ -55,7 +55,6 @@ class ProductFormula(EvolutionSynthesis):
55
55
  "Instead you should update your 'atomic_evolution' function to be of the following "
56
56
  "type: 'Callable[[QuantumCircuit, Pauli | SparsePauliOp, float], None]'."
57
57
  ),
58
- pending=True,
59
58
  )
60
59
  def __init__(
61
60
  self,
@@ -43,7 +43,7 @@ class QDrift(ProductFormula):
43
43
 
44
44
  @deprecate_arg(
45
45
  name="atomic_evolution",
46
- since="1.2",
46
+ since="1.4",
47
47
  predicate=lambda callable: callable is not None
48
48
  and len(inspect.signature(callable).parameters) == 2,
49
49
  deprecation_description=(
@@ -54,7 +54,6 @@ class QDrift(ProductFormula):
54
54
  "Instead you should update your 'atomic_evolution' function to be of the following "
55
55
  "type: 'Callable[[QuantumCircuit, Pauli | SparsePauliOp, float], None]'."
56
56
  ),
57
- pending=True,
58
57
  )
59
58
  def __init__(
60
59
  self,
@@ -62,7 +62,7 @@ class SuzukiTrotter(ProductFormula):
62
62
 
63
63
  @deprecate_arg(
64
64
  name="atomic_evolution",
65
- since="1.2",
65
+ since="1.4",
66
66
  predicate=lambda callable: callable is not None
67
67
  and len(inspect.signature(callable).parameters) == 2,
68
68
  deprecation_description=(
@@ -73,7 +73,6 @@ class SuzukiTrotter(ProductFormula):
73
73
  "Instead you should update your 'atomic_evolution' function to be of the following "
74
74
  "type: 'Callable[[QuantumCircuit, Pauli | SparsePauliOp, float], None]'."
75
75
  ),
76
- pending=True,
77
76
  )
78
77
  def __init__(
79
78
  self,