qiskit 1.2.0rc1__cp38-abi3-macosx_10_9_universal2.whl → 1.2.1__cp38-abi3-macosx_10_9_universal2.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 (50) hide show
  1. qiskit/VERSION.txt +1 -1
  2. qiskit/_accelerate.abi3.so +0 -0
  3. qiskit/circuit/__init__.py +15 -2
  4. qiskit/circuit/library/basis_change/qft.py +3 -1
  5. qiskit/circuit/library/data_preparation/initializer.py +5 -2
  6. qiskit/circuit/library/data_preparation/state_preparation.py +2 -2
  7. qiskit/circuit/library/standard_gates/__init__.py +32 -25
  8. qiskit/circuit/quantumcircuit.py +43 -18
  9. qiskit/compiler/transpiler.py +1 -1
  10. qiskit/providers/basic_provider/basic_simulator.py +1 -1
  11. qiskit/providers/fake_provider/fake_openpulse_2q.py +3 -3
  12. qiskit/providers/fake_provider/fake_openpulse_3q.py +2 -3
  13. qiskit/providers/fake_provider/fake_pulse_backend.py +2 -1
  14. qiskit/providers/fake_provider/fake_qasm_backend.py +2 -1
  15. qiskit/providers/fake_provider/generic_backend_v2.py +434 -18
  16. qiskit/providers/models/__init__.py +47 -21
  17. qiskit/pulse/library/symbolic_pulses.py +4 -3
  18. qiskit/qasm3/exporter.py +7 -1
  19. qiskit/qpy/__init__.py +1 -1
  20. qiskit/quantum_info/operators/operator.py +24 -0
  21. qiskit/quantum_info/operators/symplectic/sparse_pauli_op.py +1 -1
  22. qiskit/synthesis/clifford/clifford_decompose_bm.py +1 -1
  23. qiskit/synthesis/clifford/clifford_decompose_greedy.py +1 -1
  24. qiskit/synthesis/linear/cnot_synth.py +1 -1
  25. qiskit/synthesis/one_qubit/one_qubit_decompose.py +2 -1
  26. qiskit/synthesis/permutation/permutation_full.py +2 -2
  27. qiskit/synthesis/permutation/permutation_lnn.py +3 -1
  28. qiskit/synthesis/two_qubit/two_qubit_decompose.py +2 -2
  29. qiskit/transpiler/instruction_durations.py +4 -0
  30. qiskit/transpiler/passes/__init__.py +2 -0
  31. qiskit/transpiler/passes/basis/basis_translator.py +2 -1
  32. qiskit/transpiler/passes/optimization/__init__.py +1 -0
  33. qiskit/transpiler/passes/optimization/consolidate_blocks.py +7 -1
  34. qiskit/transpiler/passes/optimization/hoare_opt.py +12 -8
  35. qiskit/transpiler/passes/optimization/split_2q_unitaries.py +16 -20
  36. qiskit/transpiler/passes/scheduling/alignments/pulse_gate_validation.py +1 -1
  37. qiskit/transpiler/passes/scheduling/padding/dynamical_decoupling.py +9 -3
  38. qiskit/transpiler/passes/synthesis/unitary_synthesis.py +1 -1
  39. qiskit/transpiler/preset_passmanagers/builtin_plugins.py +10 -54
  40. qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py +9 -0
  41. qiskit/utils/optionals.py +173 -150
  42. qiskit/visualization/bloch.py +44 -1
  43. qiskit/visualization/dag_visualization.py +10 -3
  44. qiskit/visualization/gate_map.py +28 -6
  45. {qiskit-1.2.0rc1.dist-info → qiskit-1.2.1.dist-info}/METADATA +20 -20
  46. {qiskit-1.2.0rc1.dist-info → qiskit-1.2.1.dist-info}/RECORD +50 -50
  47. {qiskit-1.2.0rc1.dist-info → qiskit-1.2.1.dist-info}/WHEEL +1 -1
  48. {qiskit-1.2.0rc1.dist-info → qiskit-1.2.1.dist-info}/LICENSE.txt +0 -0
  49. {qiskit-1.2.0rc1.dist-info → qiskit-1.2.1.dist-info}/entry_points.txt +0 -0
  50. {qiskit-1.2.0rc1.dist-info → qiskit-1.2.1.dist-info}/top_level.txt +0 -0
@@ -16,6 +16,7 @@ from __future__ import annotations
16
16
  import warnings
17
17
 
18
18
  from collections.abc import Iterable
19
+ from typing import List, Dict, Any, Union
19
20
  import numpy as np
20
21
 
21
22
  from qiskit import pulse
@@ -35,12 +36,12 @@ from qiskit.transpiler import CouplingMap, Target, InstructionProperties, QubitP
35
36
  from qiskit.providers import Options
36
37
  from qiskit.providers.basic_provider import BasicSimulator
37
38
  from qiskit.providers.backend import BackendV2
38
- from qiskit.providers.models import (
39
- PulseDefaults,
40
- Command,
41
- )
42
- from qiskit.qobj import PulseQobjInstruction, PulseLibraryItem
43
39
  from qiskit.utils import optionals as _optionals
40
+ from qiskit.providers.models.pulsedefaults import Command
41
+ from qiskit.qobj.converters.pulse_instruction import QobjToInstructionConverter
42
+ from qiskit.pulse.calibration_entries import PulseQobjDef
43
+ from qiskit.providers.models.pulsedefaults import MeasurementKernel, Discriminator
44
+ from qiskit.qobj.pulse_qobj import QobjMeasurementOption
44
45
 
45
46
  # Noise default values/ranges for duration and error of supported
46
47
  # instructions. There are two possible formats:
@@ -74,17 +75,432 @@ _QUBIT_PROPERTIES = {
74
75
  "frequency": (5e9, 5.5e9),
75
76
  }
76
77
 
77
- # The number of samples determines the pulse durations of the corresponding
78
- # instructions. This default defines pulses with durations in multiples of
79
- # 16 dt for consistency with the pulse granularity of real IBM devices, but
80
- # keeps the number smaller than what would be realistic for
81
- # manageability. If needed, more realistic durations could be added in the
82
- # future (order of 160dt for 1q gates, 1760dt for 2q gates and measure).
83
- _PULSE_LIBRARY = [
84
- PulseLibraryItem(name="pulse_1", samples=np.linspace(0, 1.0, 16, dtype=np.complex128)), # 16dt
85
- PulseLibraryItem(name="pulse_2", samples=np.linspace(0, 1.0, 32, dtype=np.complex128)), # 32dt
86
- PulseLibraryItem(name="pulse_3", samples=np.linspace(0, 1.0, 64, dtype=np.complex128)), # 64dt
87
- ]
78
+
79
+ class PulseDefaults:
80
+ """Internal - Description of default settings for Pulse systems. These are instructions
81
+ or settings that
82
+ may be good starting points for the Pulse user. The user may modify these defaults for custom
83
+ scheduling.
84
+ """
85
+
86
+ # Copy from the deprecated from qiskit.providers.models.pulsedefaults.PulseDefaults
87
+
88
+ _data = {}
89
+
90
+ def __init__(
91
+ self,
92
+ qubit_freq_est: List[float],
93
+ meas_freq_est: List[float],
94
+ buffer: int,
95
+ pulse_library: List[PulseLibraryItem],
96
+ cmd_def: List[Command],
97
+ meas_kernel: MeasurementKernel = None,
98
+ discriminator: Discriminator = None,
99
+ **kwargs: Dict[str, Any],
100
+ ):
101
+ """
102
+ Validate and reformat transport layer inputs to initialize.
103
+ Args:
104
+ qubit_freq_est: Estimated qubit frequencies in GHz.
105
+ meas_freq_est: Estimated measurement cavity frequencies in GHz.
106
+ buffer: Default buffer time (in units of dt) between pulses.
107
+ pulse_library: Pulse name and sample definitions.
108
+ cmd_def: Operation name and definition in terms of Commands.
109
+ meas_kernel: The measurement kernels
110
+ discriminator: The discriminators
111
+ **kwargs: Other attributes for the super class.
112
+ """
113
+ self._data = {}
114
+ self.buffer = buffer
115
+ self.qubit_freq_est = [freq * 1e9 for freq in qubit_freq_est]
116
+ """Qubit frequencies in Hertz."""
117
+ self.meas_freq_est = [freq * 1e9 for freq in meas_freq_est]
118
+ """Measurement frequencies in Hertz."""
119
+ self.pulse_library = pulse_library
120
+ self.cmd_def = cmd_def
121
+ self.instruction_schedule_map = InstructionScheduleMap()
122
+ self.converter = QobjToInstructionConverter(pulse_library)
123
+
124
+ for inst in cmd_def:
125
+ entry = PulseQobjDef(converter=self.converter, name=inst.name)
126
+ entry.define(inst.sequence, user_provided=False)
127
+ self.instruction_schedule_map._add(
128
+ instruction_name=inst.name,
129
+ qubits=tuple(inst.qubits),
130
+ entry=entry,
131
+ )
132
+
133
+ if meas_kernel is not None:
134
+ self.meas_kernel = meas_kernel
135
+ if discriminator is not None:
136
+ self.discriminator = discriminator
137
+
138
+ self._data.update(kwargs)
139
+
140
+ def __getattr__(self, name):
141
+ try:
142
+ return self._data[name]
143
+ except KeyError as ex:
144
+ raise AttributeError(f"Attribute {name} is not defined") from ex
145
+
146
+ def to_dict(self):
147
+ """Return a dictionary format representation of the PulseDefaults.
148
+ Returns:
149
+ dict: The dictionary form of the PulseDefaults.
150
+ """
151
+ out_dict = {
152
+ "qubit_freq_est": self.qubit_freq_est,
153
+ "meas_freq_est": self.qubit_freq_est,
154
+ "buffer": self.buffer,
155
+ "pulse_library": [x.to_dict() for x in self.pulse_library],
156
+ "cmd_def": [x.to_dict() for x in self.cmd_def],
157
+ }
158
+ if hasattr(self, "meas_kernel"):
159
+ out_dict["meas_kernel"] = self.meas_kernel.to_dict()
160
+ if hasattr(self, "discriminator"):
161
+ out_dict["discriminator"] = self.discriminator.to_dict()
162
+ for key, value in self.__dict__.items():
163
+ if key not in [
164
+ "qubit_freq_est",
165
+ "meas_freq_est",
166
+ "buffer",
167
+ "pulse_library",
168
+ "cmd_def",
169
+ "meas_kernel",
170
+ "discriminator",
171
+ "converter",
172
+ "instruction_schedule_map",
173
+ ]:
174
+ out_dict[key] = value
175
+ out_dict.update(self._data)
176
+
177
+ out_dict["qubit_freq_est"] = [freq * 1e-9 for freq in self.qubit_freq_est]
178
+ out_dict["meas_freq_est"] = [freq * 1e-9 for freq in self.meas_freq_est]
179
+ return out_dict
180
+
181
+ @classmethod
182
+ def from_dict(cls, data):
183
+ """Create a new PulseDefaults object from a dictionary.
184
+
185
+ Args:
186
+ data (dict): A dictionary representing the PulseDefaults
187
+ to create. It will be in the same format as output by
188
+ :meth:`to_dict`.
189
+ Returns:
190
+ PulseDefaults: The PulseDefaults from the input dictionary.
191
+ """
192
+ schema = {
193
+ "pulse_library": PulseLibraryItem, # The class PulseLibraryItem is deprecated
194
+ "cmd_def": Command,
195
+ "meas_kernel": MeasurementKernel,
196
+ "discriminator": Discriminator,
197
+ }
198
+
199
+ # Pulse defaults data is nested dictionary.
200
+ # To avoid deepcopy and avoid mutating the source object, create new dict here.
201
+ in_data = {}
202
+ for key, value in data.items():
203
+ if key in schema:
204
+ with warnings.catch_warnings():
205
+ # The class PulseLibraryItem is deprecated
206
+ warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
207
+ if isinstance(value, list):
208
+ in_data[key] = list(map(schema[key].from_dict, value))
209
+ else:
210
+ in_data[key] = schema[key].from_dict(value)
211
+ else:
212
+ in_data[key] = value
213
+
214
+ return cls(**in_data)
215
+
216
+ def __str__(self):
217
+ qubit_freqs = [freq / 1e9 for freq in self.qubit_freq_est]
218
+ meas_freqs = [freq / 1e9 for freq in self.meas_freq_est]
219
+ qfreq = f"Qubit Frequencies [GHz]\n{qubit_freqs}"
220
+ mfreq = f"Measurement Frequencies [GHz]\n{meas_freqs} "
221
+ return f"<{self.__class__.__name__}({str(self.instruction_schedule_map)}{qfreq}\n{mfreq})>"
222
+
223
+
224
+ def _to_complex(value: Union[List[float], complex]) -> complex:
225
+ """Convert the input value to type ``complex``.
226
+ Args:
227
+ value: Value to be converted.
228
+ Returns:
229
+ Input value in ``complex``.
230
+ Raises:
231
+ TypeError: If the input value is not in the expected format.
232
+ """
233
+ if isinstance(value, list) and len(value) == 2:
234
+ return complex(value[0], value[1])
235
+ elif isinstance(value, complex):
236
+ return value
237
+
238
+ raise TypeError(f"{value} is not in a valid complex number format.")
239
+
240
+
241
+ class PulseLibraryItem:
242
+ """INTERNAL - An item in a pulse library."""
243
+
244
+ # Copy from the deprecated from qiskit.qobj.PulseLibraryItem
245
+ def __init__(self, name, samples):
246
+ """Instantiate a pulse library item.
247
+
248
+ Args:
249
+ name (str): A name for the pulse.
250
+ samples (list[complex]): A list of complex values defining pulse
251
+ shape.
252
+ """
253
+ self.name = name
254
+ if isinstance(samples[0], list):
255
+ self.samples = np.array([complex(sample[0], sample[1]) for sample in samples])
256
+ else:
257
+ self.samples = samples
258
+
259
+ def to_dict(self):
260
+ """Return a dictionary format representation of the pulse library item.
261
+
262
+ Returns:
263
+ dict: The dictionary form of the PulseLibraryItem.
264
+ """
265
+ return {"name": self.name, "samples": self.samples}
266
+
267
+ @classmethod
268
+ def from_dict(cls, data):
269
+ """Create a new PulseLibraryItem object from a dictionary.
270
+
271
+ Args:
272
+ data (dict): A dictionary for the experiment config
273
+
274
+ Returns:
275
+ PulseLibraryItem: The object from the input dictionary.
276
+ """
277
+ return cls(**data)
278
+
279
+ def __repr__(self):
280
+ return f"PulseLibraryItem({self.name}, {repr(self.samples)})"
281
+
282
+ def __str__(self):
283
+ return f"Pulse Library Item:\n\tname: {self.name}\n\tsamples: {self.samples}"
284
+
285
+ def __eq__(self, other):
286
+ if isinstance(other, PulseLibraryItem):
287
+ if self.to_dict() == other.to_dict():
288
+ return True
289
+ return False
290
+
291
+
292
+ class PulseQobjInstruction:
293
+ """Internal - A class representing a single instruction in a PulseQobj Experiment."""
294
+
295
+ # Copy from the deprecated from qiskit.qobj.PulseQobjInstruction
296
+
297
+ _COMMON_ATTRS = [
298
+ "ch",
299
+ "conditional",
300
+ "val",
301
+ "phase",
302
+ "frequency",
303
+ "duration",
304
+ "qubits",
305
+ "memory_slot",
306
+ "register_slot",
307
+ "label",
308
+ "type",
309
+ "pulse_shape",
310
+ "parameters",
311
+ ]
312
+
313
+ def __init__(
314
+ self,
315
+ name,
316
+ t0,
317
+ ch=None,
318
+ conditional=None,
319
+ val=None,
320
+ phase=None,
321
+ duration=None,
322
+ qubits=None,
323
+ memory_slot=None,
324
+ register_slot=None,
325
+ kernels=None,
326
+ discriminators=None,
327
+ label=None,
328
+ type=None, # pylint: disable=invalid-name,redefined-builtin
329
+ pulse_shape=None,
330
+ parameters=None,
331
+ frequency=None,
332
+ ):
333
+ """Instantiate a new PulseQobjInstruction object.
334
+
335
+ Args:
336
+ name (str): The name of the instruction
337
+ t0 (int): Pulse start time in integer **dt** units.
338
+ ch (str): The channel to apply the pulse instruction.
339
+ conditional (int): The register to use for a conditional for this
340
+ instruction
341
+ val (complex): Complex value to apply, bounded by an absolute value
342
+ of 1.
343
+ phase (float): if a ``fc`` instruction, the frame change phase in
344
+ radians.
345
+ frequency (float): if a ``sf`` instruction, the frequency in Hz.
346
+ duration (int): The duration of the pulse in **dt** units.
347
+ qubits (list): A list of ``int`` representing the qubits the
348
+ instruction operates on
349
+ memory_slot (list): If a ``measure`` instruction this is a list
350
+ of ``int`` containing the list of memory slots to store the
351
+ measurement results in (must be the same length as qubits).
352
+ If a ``bfunc`` instruction this is a single ``int`` of the
353
+ memory slot to store the boolean function result in.
354
+ register_slot (list): If a ``measure`` instruction this is a list
355
+ of ``int`` containing the list of register slots in which to
356
+ store the measurement results (must be the same length as
357
+ qubits). If a ``bfunc`` instruction this is a single ``int``
358
+ of the register slot in which to store the result.
359
+ kernels (list): List of :class:`QobjMeasurementOption` objects
360
+ defining the measurement kernels and set of parameters if the
361
+ measurement level is 1 or 2. Only used for ``acquire``
362
+ instructions.
363
+ discriminators (list): A list of :class:`QobjMeasurementOption`
364
+ used to set the discriminators to be used if the measurement
365
+ level is 2. Only used for ``acquire`` instructions.
366
+ label (str): Label of instruction
367
+ type (str): Type of instruction
368
+ pulse_shape (str): The shape of the parametric pulse
369
+ parameters (dict): The parameters for a parametric pulse
370
+ """
371
+ self.name = name
372
+ self.t0 = t0
373
+ if ch is not None:
374
+ self.ch = ch
375
+ if conditional is not None:
376
+ self.conditional = conditional
377
+ if val is not None:
378
+ self.val = val
379
+ if phase is not None:
380
+ self.phase = phase
381
+ if frequency is not None:
382
+ self.frequency = frequency
383
+ if duration is not None:
384
+ self.duration = duration
385
+ if qubits is not None:
386
+ self.qubits = qubits
387
+ if memory_slot is not None:
388
+ self.memory_slot = memory_slot
389
+ if register_slot is not None:
390
+ self.register_slot = register_slot
391
+ if kernels is not None:
392
+ self.kernels = kernels
393
+ if discriminators is not None:
394
+ self.discriminators = discriminators
395
+ if label is not None:
396
+ self.label = label
397
+ if type is not None:
398
+ self.type = type
399
+ if pulse_shape is not None:
400
+ self.pulse_shape = pulse_shape
401
+ if parameters is not None:
402
+ self.parameters = parameters
403
+
404
+ def to_dict(self):
405
+ """Return a dictionary format representation of the Instruction.
406
+
407
+ Returns:
408
+ dict: The dictionary form of the PulseQobjInstruction.
409
+ """
410
+ out_dict = {"name": self.name, "t0": self.t0}
411
+ for attr in self._COMMON_ATTRS:
412
+ if hasattr(self, attr):
413
+ out_dict[attr] = getattr(self, attr)
414
+ if hasattr(self, "kernels"):
415
+ out_dict["kernels"] = [x.to_dict() for x in self.kernels]
416
+ if hasattr(self, "discriminators"):
417
+ out_dict["discriminators"] = [x.to_dict() for x in self.discriminators]
418
+ return out_dict
419
+
420
+ def __repr__(self):
421
+ out = f'PulseQobjInstruction(name="{self.name}", t0={self.t0}'
422
+ for attr in self._COMMON_ATTRS:
423
+ attr_val = getattr(self, attr, None)
424
+ if attr_val is not None:
425
+ if isinstance(attr_val, str):
426
+ out += f', {attr}="{attr_val}"'
427
+ else:
428
+ out += f", {attr}={attr_val}"
429
+ out += ")"
430
+ return out
431
+
432
+ def __str__(self):
433
+ out = f"Instruction: {self.name}\n"
434
+ out += f"\t\tt0: {self.t0}\n"
435
+ for attr in self._COMMON_ATTRS:
436
+ if hasattr(self, attr):
437
+ out += f"\t\t{attr}: {getattr(self, attr)}\n"
438
+ return out
439
+
440
+ @classmethod
441
+ def from_dict(cls, data):
442
+ """Create a new PulseQobjExperimentConfig object from a dictionary.
443
+
444
+ Args:
445
+ data (dict): A dictionary for the experiment config
446
+
447
+ Returns:
448
+ PulseQobjInstruction: The object from the input dictionary.
449
+ """
450
+ schema = {
451
+ "discriminators": QobjMeasurementOption,
452
+ "kernels": QobjMeasurementOption,
453
+ }
454
+ skip = ["t0", "name"]
455
+
456
+ # Pulse instruction data is nested dictionary.
457
+ # To avoid deepcopy and avoid mutating the source object, create new dict here.
458
+ in_data = {}
459
+ for key, value in data.items():
460
+ if key in skip:
461
+ continue
462
+ if key == "parameters":
463
+ # This is flat dictionary of parametric pulse parameters
464
+ formatted_value = value.copy()
465
+ if "amp" in formatted_value:
466
+ formatted_value["amp"] = _to_complex(formatted_value["amp"])
467
+ in_data[key] = formatted_value
468
+ continue
469
+ if key in schema:
470
+ if isinstance(value, list):
471
+ in_data[key] = list(map(schema[key].from_dict, value))
472
+ else:
473
+ in_data[key] = schema[key].from_dict(value)
474
+ else:
475
+ in_data[key] = value
476
+
477
+ return cls(data["name"], data["t0"], **in_data)
478
+
479
+ def __eq__(self, other):
480
+ if isinstance(other, PulseQobjInstruction):
481
+ if self.to_dict() == other.to_dict():
482
+ return True
483
+ return False
484
+
485
+
486
+ def _pulse_library():
487
+ # The number of samples determines the pulse durations of the corresponding
488
+ # instructions. This default defines pulses with durations in multiples of
489
+ # 16 dt for consistency with the pulse granularity of real IBM devices, but
490
+ # keeps the number smaller than what would be realistic for
491
+ # manageability. If needed, more realistic durations could be added in the
492
+ # future (order of 160dt for 1q gates, 1760dt for 2q gates and measure).
493
+ return [
494
+ PulseLibraryItem(
495
+ name="pulse_1", samples=np.linspace(0, 1.0, 16, dtype=np.complex128)
496
+ ), # 16dt
497
+ PulseLibraryItem(
498
+ name="pulse_2", samples=np.linspace(0, 1.0, 32, dtype=np.complex128)
499
+ ), # 32dt
500
+ PulseLibraryItem(
501
+ name="pulse_3", samples=np.linspace(0, 1.0, 64, dtype=np.complex128)
502
+ ), # 64dt
503
+ ]
88
504
 
89
505
 
90
506
  class GenericBackendV2(BackendV2):
@@ -262,7 +678,7 @@ class GenericBackendV2(BackendV2):
262
678
  acting on qargs.
263
679
  """
264
680
 
265
- pulse_library = _PULSE_LIBRARY
681
+ pulse_library = _pulse_library()
266
682
  # Note that the calibration pulses are different for
267
683
  # 1q gates vs 2q gates vs measurement instructions.
268
684
  if inst == "measure":
@@ -352,7 +768,7 @@ class GenericBackendV2(BackendV2):
352
768
  qubit_freq_est=qubit_freq_est,
353
769
  meas_freq_est=meas_freq_est,
354
770
  buffer=0,
355
- pulse_library=_PULSE_LIBRARY,
771
+ pulse_library=_pulse_library(),
356
772
  cmd_def=cmd_def,
357
773
  )
358
774
 
@@ -38,26 +38,52 @@ Classes
38
38
  GateProperties
39
39
  Nduv
40
40
  """
41
+ # pylint: disable=undefined-all-variable
42
+ __all__ = [
43
+ "BackendConfiguration",
44
+ "PulseBackendConfiguration",
45
+ "QasmBackendConfiguration",
46
+ "UchannelLO",
47
+ "GateConfig",
48
+ "BackendProperties",
49
+ "GateProperties",
50
+ "Nduv",
51
+ "BackendStatus",
52
+ "JobStatus",
53
+ "PulseDefaults",
54
+ "Command",
55
+ ]
56
+
57
+ import importlib
41
58
  import warnings
42
59
 
43
- from .backendconfiguration import (
44
- BackendConfiguration,
45
- PulseBackendConfiguration,
46
- QasmBackendConfiguration,
47
- UchannelLO,
48
- GateConfig,
49
- )
50
- from .backendproperties import BackendProperties, GateProperties, Nduv
51
- from .backendstatus import BackendStatus
52
- from .jobstatus import JobStatus
53
- from .pulsedefaults import PulseDefaults, Command
54
-
55
-
56
- warnings.warn(
57
- "qiskit.providers.models is deprecated since Qiskit 1.2 and will be removed in Qiskit 2.0."
58
- "With the removal of Qobj, there is no need for these schema-conformant objects. If you still need"
59
- "to use them, it could be because you are using a BackendV1, which is also deprecated in favor"
60
- "of BackendV2",
61
- DeprecationWarning,
62
- 2,
63
- )
60
+
61
+ _NAME_MAP = {
62
+ # public object name mapped to containing module
63
+ "BackendConfiguration": "qiskit.providers.models.backendconfiguration",
64
+ "PulseBackendConfiguration": "qiskit.providers.models.backendconfiguration",
65
+ "QasmBackendConfiguration": "qiskit.providers.models.backendconfiguration",
66
+ "UchannelLO": "qiskit.providers.models.backendconfiguration",
67
+ "GateConfig": "qiskit.providers.models.backendconfiguration",
68
+ "BackendProperties": "qiskit.providers.models.backendproperties",
69
+ "GateProperties": "qiskit.providers.models.backendproperties",
70
+ "Nduv": "qiskit.providers.models.backendproperties",
71
+ "BackendStatus": "qiskit.providers.models.backendstatus",
72
+ "JobStatus": "qiskit.providers.models.jobstatus",
73
+ "PulseDefaults": "qiskit.providers.models.pulsedefaults",
74
+ "Command": "qiskit.providers.models.pulsedefaults",
75
+ }
76
+
77
+
78
+ def __getattr__(name):
79
+ if (module_name := _NAME_MAP.get(name)) is not None:
80
+ warnings.warn(
81
+ "qiskit.providers.models is deprecated since Qiskit 1.2 and will be "
82
+ "removed in Qiskit 2.0. With the removal of Qobj, there is no need for these "
83
+ "schema-conformant objects. If you still need to use them, it could be because "
84
+ "you are using a BackendV1, which is also deprecated in favor of BackendV2.",
85
+ DeprecationWarning,
86
+ stacklevel=2,
87
+ )
88
+ return getattr(importlib.import_module(module_name), name)
89
+ raise AttributeError(f"module 'qiskit.providers.models' has no attribute '{name}'")
@@ -1773,12 +1773,13 @@ def Square(
1773
1773
  is the sign function with the convention :math:`\\text{sign}\\left(0\\right)=1`.
1774
1774
 
1775
1775
  Args:
1776
- duration: Pulse length in terms of the sampling period `dt`.
1777
- amp: The magnitude of the amplitude of the square wave. Wave range is [-`amp`,`amp`].
1776
+ duration: Pulse length in terms of the sampling period ``dt``.
1777
+ amp: The magnitude of the amplitude of the square wave. Wave range is
1778
+ :math:`\\left[-\\texttt{amp},\\texttt{amp}\\right]`.
1778
1779
  phase: The phase of the square wave (note that this is not equivalent to the angle of
1779
1780
  the complex amplitude).
1780
1781
  freq: The frequency of the square wave, in terms of 1 over sampling period.
1781
- If not provided defaults to a single cycle (i.e :math:'\\frac{1}{\\text{duration}}').
1782
+ If not provided defaults to a single cycle (i.e :math:`\\frac{1}{\\text{duration}}`).
1782
1783
  The frequency is limited to the range :math:`\\left(0,0.5\\right]` (the Nyquist frequency).
1783
1784
  angle: The angle in radians of the complex phase factor uniformly
1784
1785
  scaling the pulse. Default value 0.
qiskit/qasm3/exporter.py CHANGED
@@ -626,7 +626,13 @@ class QASM3Builder:
626
626
  if builtin in _BUILTIN_GATES:
627
627
  # It's built into the langauge; we don't need to re-add it.
628
628
  continue
629
- self.symbols.register_gate_without_definition(builtin, None)
629
+ try:
630
+ self.symbols.register_gate_without_definition(builtin, None)
631
+ except QASM3ExporterError as exc:
632
+ raise QASM3ExporterError(
633
+ f"Cannot use '{builtin}' as a basis gate for the reason in the prior exception."
634
+ " Consider renaming the gate if needed, or omitting this basis gate if not."
635
+ ) from exc
630
636
 
631
637
  header = ast.Header(ast.Version("3.0"), list(self.build_includes()))
632
638
 
qiskit/qpy/__init__.py CHANGED
@@ -774,7 +774,7 @@ In addition, new payload MAP_ITEM is defined to implement the :ref:`qpy_mapping`
774
774
 
775
775
  With the support of :class:`.~ScheduleBlock`, now :class:`~.QuantumCircuit` can be
776
776
  serialized together with :attr:`~.QuantumCircuit.calibrations`, or
777
- `Pulse Gates <https://docs.quantum.ibm.com/build/pulse>`_.
777
+ `Pulse Gates <https://docs.quantum.ibm.com/guides/pulse>`_.
778
778
  In QPY version 5 and above, :ref:`qpy_circuit_calibrations` payload is
779
779
  packed after the :ref:`qpy_instructions` block.
780
780
 
@@ -55,6 +55,30 @@ class Operator(LinearOp):
55
55
  .. math::
56
56
 
57
57
  \rho \mapsto M \rho M^\dagger.
58
+
59
+ For example, the following operator :math:`M = X` applied to the zero state
60
+ :math:`|\psi\rangle=|0\rangle (\rho = |0\rangle\langle 0|)` changes it to the
61
+ one state :math:`|\psi\rangle=|1\rangle (\rho = |1\rangle\langle 1|)`:
62
+
63
+ .. code-block:: python
64
+
65
+ >>> import numpy as np
66
+ >>> from qiskit.quantum_info import Operator
67
+ >>> op = Operator(np.array([[0.0, 1.0], [1.0, 0.0]])) # Represents Pauli X operator
68
+
69
+ >>> from qiskit.quantum_info import Statevector
70
+ >>> sv = Statevector(np.array([1.0, 0.0]))
71
+ >>> sv.evolve(op)
72
+ Statevector([0.+0.j, 1.+0.j],
73
+ dims=(2,))
74
+
75
+ >>> from qiskit.quantum_info import DensityMatrix
76
+ >>> dm = DensityMatrix(np.array([[1.0, 0.0], [0.0, 0.0]]))
77
+ >>> dm.evolve(op)
78
+ DensityMatrix([[0.+0.j, 0.+0.j],
79
+ [0.+0.j, 1.+0.j]],
80
+ dims=(2,))
81
+
58
82
  """
59
83
 
60
84
  def __init__(
@@ -937,7 +937,7 @@ class SparsePauliOp(LinearOp):
937
937
  array (the default).
938
938
  force_serial: if ``True``, use an unthreaded implementation, regardless of the state of
939
939
  the `Qiskit threading-control environment variables
940
- <https://docs.quantum.ibm.com/start/configure-qiskit-local#environment-variables>`__.
940
+ <https://docs.quantum.ibm.com/guides/configure-qiskit-local#environment-variables>`__.
941
941
  By default, this will use threaded parallelism over the available CPUs.
942
942
 
943
943
  Returns:
@@ -41,7 +41,7 @@ def synth_clifford_bm(clifford: Clifford) -> QuantumCircuit:
41
41
  `arXiv:2003.09412 [quant-ph] <https://arxiv.org/abs/2003.09412>`_
42
42
  """
43
43
  circuit = QuantumCircuit._from_circuit_data(
44
- synth_clifford_bm_inner(clifford.tableau.astype(bool))
44
+ synth_clifford_bm_inner(clifford.tableau.astype(bool)), add_regs=True
45
45
  )
46
46
  circuit.name = str(clifford)
47
47
  return circuit
@@ -51,7 +51,7 @@ def synth_clifford_greedy(clifford: Clifford) -> QuantumCircuit:
51
51
  `arXiv:2105.02291 [quant-ph] <https://arxiv.org/abs/2105.02291>`_
52
52
  """
53
53
  circuit = QuantumCircuit._from_circuit_data(
54
- synth_clifford_greedy_inner(clifford.tableau.astype(bool))
54
+ synth_clifford_greedy_inner(clifford.tableau.astype(bool)), add_regs=True
55
55
  )
56
56
  circuit.name = str(clifford)
57
57
  return circuit
@@ -66,4 +66,4 @@ def synth_cnot_count_full_pmh(
66
66
  circuit_data = fast_pmh(normalized, section_size)
67
67
 
68
68
  # construct circuit from the data
69
- return QuantumCircuit._from_circuit_data(circuit_data)
69
+ return QuantumCircuit._from_circuit_data(circuit_data, add_regs=True)