qiskit 1.1.0rc1__cp38-abi3-win32.whl → 1.1.2__cp38-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 (69) hide show
  1. qiskit/VERSION.txt +1 -1
  2. qiskit/_accelerate.pyd +0 -0
  3. qiskit/assembler/__init__.py +5 -10
  4. qiskit/circuit/__init__.py +21 -153
  5. qiskit/circuit/_classical_resource_map.py +3 -0
  6. qiskit/circuit/classical/expr/__init__.py +1 -1
  7. qiskit/circuit/classical/types/__init__.py +5 -4
  8. qiskit/circuit/classicalfunction/__init__.py +9 -0
  9. qiskit/circuit/library/__init__.py +3 -19
  10. qiskit/circuit/library/data_preparation/pauli_feature_map.py +1 -1
  11. qiskit/circuit/library/n_local/two_local.py +1 -1
  12. qiskit/circuit/library/standard_gates/x.py +2 -0
  13. qiskit/circuit/parameterexpression.py +3 -0
  14. qiskit/circuit/parametervector.py +22 -16
  15. qiskit/circuit/quantumcircuit.py +1100 -200
  16. qiskit/converters/__init__.py +17 -2
  17. qiskit/dagcircuit/dagcircuit.py +8 -1
  18. qiskit/passmanager/passmanager.py +11 -11
  19. qiskit/primitives/__init__.py +15 -9
  20. qiskit/primitives/containers/__init__.py +1 -0
  21. qiskit/primitives/containers/bit_array.py +6 -2
  22. qiskit/primitives/containers/shape.py +3 -3
  23. qiskit/providers/__init__.py +49 -17
  24. qiskit/providers/backend.py +0 -6
  25. qiskit/providers/basic_provider/__init__.py +2 -23
  26. qiskit/providers/fake_provider/__init__.py +1 -1
  27. qiskit/providers/fake_provider/generic_backend_v2.py +5 -0
  28. qiskit/providers/models/__init__.py +2 -2
  29. qiskit/pulse/builder.py +2 -2
  30. qiskit/pulse/schedule.py +3 -3
  31. qiskit/qasm2/parse.py +8 -0
  32. qiskit/qasm3/exporter.py +2 -2
  33. qiskit/qobj/converters/pulse_instruction.py +6 -6
  34. qiskit/qpy/__init__.py +60 -62
  35. qiskit/qpy/binary_io/value.py +1 -1
  36. qiskit/quantum_info/operators/symplectic/pauli.py +18 -13
  37. qiskit/quantum_info/operators/symplectic/sparse_pauli_op.py +8 -4
  38. qiskit/result/__init__.py +6 -0
  39. qiskit/scheduler/__init__.py +10 -1
  40. qiskit/scheduler/methods/__init__.py +1 -8
  41. qiskit/synthesis/__init__.py +1 -6
  42. qiskit/synthesis/discrete_basis/generate_basis_approximations.py +1 -1
  43. qiskit/synthesis/discrete_basis/solovay_kitaev.py +22 -12
  44. qiskit/transpiler/__init__.py +5 -5
  45. qiskit/transpiler/layout.py +3 -3
  46. qiskit/transpiler/passes/__init__.py +4 -2
  47. qiskit/transpiler/passes/basis/basis_translator.py +2 -2
  48. qiskit/transpiler/passes/layout/vf2_layout.py +10 -4
  49. qiskit/transpiler/passes/layout/vf2_utils.py +2 -2
  50. qiskit/transpiler/passes/optimization/collect_cliffords.py +6 -15
  51. qiskit/transpiler/passes/routing/commuting_2q_gate_routing/commuting_2q_gate_router.py +8 -1
  52. qiskit/transpiler/passes/routing/commuting_2q_gate_routing/pauli_2q_evolution_commutation.py +5 -1
  53. qiskit/transpiler/passes/routing/star_prerouting.py +5 -5
  54. qiskit/transpiler/passes/synthesis/unitary_synthesis.py +3 -0
  55. qiskit/transpiler/preset_passmanagers/__init__.py +29 -3
  56. qiskit/transpiler/target.py +1 -1
  57. qiskit/utils/__init__.py +3 -2
  58. qiskit/utils/parallel.py +24 -15
  59. qiskit/visualization/bloch.py +44 -1
  60. qiskit/visualization/dag_visualization.py +10 -3
  61. qiskit/visualization/gate_map.py +9 -1
  62. qiskit/visualization/pass_manager_visualization.py +9 -9
  63. qiskit/visualization/pulse_v2/device_info.py +58 -31
  64. {qiskit-1.1.0rc1.dist-info → qiskit-1.1.2.dist-info}/METADATA +18 -18
  65. {qiskit-1.1.0rc1.dist-info → qiskit-1.1.2.dist-info}/RECORD +69 -69
  66. {qiskit-1.1.0rc1.dist-info → qiskit-1.1.2.dist-info}/WHEEL +1 -1
  67. {qiskit-1.1.0rc1.dist-info → qiskit-1.1.2.dist-info}/LICENSE.txt +0 -0
  68. {qiskit-1.1.0rc1.dist-info → qiskit-1.1.2.dist-info}/entry_points.txt +0 -0
  69. {qiskit-1.1.0rc1.dist-info → qiskit-1.1.2.dist-info}/top_level.txt +0 -0
@@ -17,12 +17,27 @@ Circuit Converters (:mod:`qiskit.converters`)
17
17
 
18
18
  .. currentmodule:: qiskit.converters
19
19
 
20
- .. autofunction:: circuit_to_dag
21
- .. autofunction:: dag_to_circuit
20
+ QuantumCircuit -> circuit components
21
+ ====================================
22
+
22
23
  .. autofunction:: circuit_to_instruction
23
24
  .. autofunction:: circuit_to_gate
25
+
26
+ QuantumCircuit <-> DagCircuit
27
+ =============================
28
+
29
+ .. autofunction:: circuit_to_dag
30
+ .. autofunction:: dag_to_circuit
31
+
32
+ QuantumCircuit <-> DagDependency
33
+ ================================
34
+
24
35
  .. autofunction:: dagdependency_to_circuit
25
36
  .. autofunction:: circuit_to_dagdependency
37
+
38
+ DagCircuit <-> DagDependency
39
+ ============================
40
+
26
41
  .. autofunction:: dag_to_dagdependency
27
42
  .. autofunction:: dagdependency_to_dag
28
43
  """
@@ -544,7 +544,7 @@ class DAGCircuit:
544
544
 
545
545
  def remove_qregs(self, *qregs):
546
546
  """
547
- Remove classical registers from the circuit, leaving underlying bits
547
+ Remove quantum registers from the circuit, leaving underlying bits
548
548
  in place.
549
549
 
550
550
  Raises:
@@ -1343,6 +1343,13 @@ class DAGCircuit:
1343
1343
  block_cargs.sort(key=wire_pos_map.get)
1344
1344
  new_node = DAGOpNode(op, block_qargs, block_cargs, dag=self)
1345
1345
 
1346
+ # check the op to insert matches the number of qubits we put it on
1347
+ if op.num_qubits != len(block_qargs):
1348
+ raise DAGCircuitError(
1349
+ f"Number of qubits in the replacement operation ({op.num_qubits}) is not equal to "
1350
+ f"the number of qubits in the block ({len(block_qargs)})!"
1351
+ )
1352
+
1346
1353
  try:
1347
1354
  new_node._node_id = self._multi_graph.contract_nodes(
1348
1355
  block_ids, new_node, check_cycle=cycle_check
@@ -21,7 +21,7 @@ from typing import Any
21
21
 
22
22
  import dill
23
23
 
24
- from qiskit.utils.parallel import parallel_map
24
+ from qiskit.utils.parallel import parallel_map, should_run_in_parallel
25
25
  from .base_tasks import Task, PassManagerIR
26
26
  from .exceptions import PassManagerError
27
27
  from .flow_controllers import FlowControllerLinear
@@ -225,16 +225,16 @@ class BasePassManager(ABC):
225
225
  in_programs = [in_programs]
226
226
  is_list = False
227
227
 
228
- if len(in_programs) == 1:
229
- out_program = _run_workflow(
230
- program=in_programs[0],
231
- pass_manager=self,
232
- callback=callback,
233
- **kwargs,
234
- )
235
- if is_list:
236
- return [out_program]
237
- return out_program
228
+ # If we're not going to run in parallel, we want to avoid spending time `dill` serialising
229
+ # ourselves, since that can be quite expensive.
230
+ if len(in_programs) == 1 or not should_run_in_parallel(num_processes):
231
+ out = [
232
+ _run_workflow(program=program, pass_manager=self, callback=callback, **kwargs)
233
+ for program in in_programs
234
+ ]
235
+ if len(in_programs) == 1 and not is_list:
236
+ return out[0]
237
+ return out
238
238
 
239
239
  del callback
240
240
  del kwargs
@@ -51,7 +51,7 @@ define a computation unit of work for the estimator to complete:
51
51
  * a collection parameter value sets to bind the circuit against, :math:`\theta_k`.
52
52
 
53
53
  Running an estimator returns a :class:`~qiskit.primitives.BasePrimitiveJob` object, where calling
54
- the method :meth:`~qiskit.primitives.BasePrimitiveJob.result` results in expectation value estimates
54
+ the method :meth:`~qiskit.primitives.BasePrimitiveJob.result` results in expectation value estimates
55
55
  and metadata for each pub:
56
56
 
57
57
  .. math::
@@ -95,7 +95,7 @@ Here is an example of how an estimator is used.
95
95
  # [<psi2(theta2)|H2|psi2(theta2)>] ]
96
96
  job2 = estimator.run(
97
97
  [
98
- (psi1, [H1, H3], [theta1, theta3]),
98
+ (psi1, [H1, H3], [theta1, theta3]),
99
99
  (psi2, H2, theta2)
100
100
  ],
101
101
  precision=0.01
@@ -103,7 +103,7 @@ Here is an example of how an estimator is used.
103
103
  job_result = job2.result()
104
104
  print(f"The primitive-job finished with result {job_result}")
105
105
 
106
-
106
+
107
107
  Overview of SamplerV2
108
108
  =====================
109
109
 
@@ -153,12 +153,12 @@ Here is an example of how a sampler is used.
153
153
  # collect 128 shots from the Bell circuit
154
154
  job = sampler.run([bell], shots=128)
155
155
  job_result = job.result()
156
- print(f"The primitive-job finished with result {job_result}"))
156
+ print(f"The primitive-job finished with result {job_result}")
157
157
 
158
158
  # run a sampler job on the parameterized circuits
159
- job2 = sampler.run([(pqc, theta1), (pqc2, theta2)]
159
+ job2 = sampler.run([(pqc, theta1), (pqc2, theta2)])
160
160
  job_result = job2.result()
161
- print(f"The primitive-job finished with result {job_result}"))
161
+ print(f"The primitive-job finished with result {job_result}")
162
162
 
163
163
 
164
164
  Overview of EstimatorV1
@@ -214,14 +214,14 @@ Here is an example of how the estimator is used.
214
214
  # calculate [ <psi1(theta1)|H1|psi1(theta1)> ]
215
215
  job = estimator.run([psi1], [H1], [theta1])
216
216
  job_result = job.result() # It will block until the job finishes.
217
- print(f"The primitive-job finished with result {job_result}"))
217
+ print(f"The primitive-job finished with result {job_result}")
218
218
 
219
219
  # calculate [ <psi1(theta1)|H1|psi1(theta1)>,
220
220
  # <psi2(theta2)|H2|psi2(theta2)>,
221
221
  # <psi1(theta3)|H3|psi1(theta3)> ]
222
222
  job2 = estimator.run(
223
- [psi1, psi2, psi1],
224
- [H1, H2, H3],
223
+ [psi1, psi2, psi1],
224
+ [H1, H2, H3],
225
225
  [theta1, theta2, theta3]
226
226
  )
227
227
  job_result = job2.result()
@@ -417,8 +417,10 @@ Results V2
417
417
  DataBin
418
418
  PrimitiveResult
419
419
  PubResult
420
+ SamplerPubResult
420
421
  BasePrimitiveJob
421
422
  PrimitiveJob
423
+ Shaped
422
424
 
423
425
  Estimator V1
424
426
  ------------
@@ -464,12 +466,16 @@ from .containers import (
464
466
  DataBin,
465
467
  PrimitiveResult,
466
468
  PubResult,
469
+ SamplerPubResult,
467
470
  EstimatorPubLike,
468
471
  SamplerPubLike,
469
472
  BindingsArrayLike,
470
473
  ObservableLike,
471
474
  ObservablesArrayLike,
475
+ Shaped,
472
476
  )
477
+
478
+
473
479
  from .estimator import Estimator
474
480
  from .primitive_job import BasePrimitiveJob, PrimitiveJob
475
481
  from .sampler import Sampler
@@ -24,3 +24,4 @@ from .primitive_result import PrimitiveResult
24
24
  from .pub_result import PubResult
25
25
  from .sampler_pub import SamplerPubLike
26
26
  from .sampler_pub_result import SamplerPubResult
27
+ from .shape import Shaped
@@ -130,6 +130,7 @@ class BitArray(ShapedMixin):
130
130
  return f"BitArray({desc})"
131
131
 
132
132
  def __getitem__(self, indices):
133
+ """Slices the array along an existing axis of the array."""
133
134
  if isinstance(indices, tuple) and len(indices) >= self.ndim + 2:
134
135
  raise ValueError(
135
136
  "BitArrays cannot be sliced along the bits axis, see slice_bits() instead."
@@ -230,7 +231,7 @@ class BitArray(ShapedMixin):
230
231
  Args:
231
232
  counts: One or more counts-like mappings with the same number of shots.
232
233
  num_bits: The desired number of bits per shot. If unset, the biggest value found sets
233
- this value.
234
+ this value, with a minimum of one bit.
234
235
 
235
236
  Returns:
236
237
  A new bit array with shape ``()`` for single input counts, or ``(N,)`` for an iterable
@@ -274,7 +275,7 @@ class BitArray(ShapedMixin):
274
275
  Args:
275
276
  samples: A list of bitstrings, a list of integers, or a list of hexstrings.
276
277
  num_bits: The desired number of bits per sample. If unset, the biggest sample provided
277
- is used to determine this value.
278
+ is used to determine this value, with a minimum of one bit.
278
279
 
279
280
  Returns:
280
281
  A new bit array.
@@ -297,6 +298,9 @@ class BitArray(ShapedMixin):
297
298
  # we are forced to prematurely look at every iterand in this case
298
299
  ints = list(ints)
299
300
  num_bits = max(map(int.bit_length, ints))
301
+ # convention: if the only value is 0, represent with one bit:
302
+ if num_bits == 0:
303
+ num_bits = 1
300
304
 
301
305
  num_bytes = _min_num_bytes(num_bits)
302
306
  data = b"".join(val.to_bytes(num_bytes, "big") for val in ints)
@@ -59,15 +59,15 @@ class ShapedMixin(Shaped):
59
59
  return f"{type(self).__name__}(<{self.shape}>)"
60
60
 
61
61
  @property
62
- def shape(self):
62
+ def shape(self) -> tuple[int, ...]:
63
63
  return self._shape
64
64
 
65
65
  @property
66
- def ndim(self):
66
+ def ndim(self) -> int:
67
67
  return len(self._shape)
68
68
 
69
69
  @property
70
- def size(self):
70
+ def size(self) -> int:
71
71
  return int(np.prod(self._shape, dtype=int))
72
72
 
73
73
 
@@ -131,7 +131,6 @@ Exceptions
131
131
  .. autoexception:: JobTimeoutError
132
132
  .. autoexception:: BackendConfigurationError
133
133
 
134
- =====================
135
134
  Writing a New Backend
136
135
  =====================
137
136
 
@@ -164,7 +163,7 @@ For a simple example of a provider, see the
164
163
  `qiskit-aqt-provider <https://github.com/Qiskit-Partners/qiskit-aqt-provider>`__
165
164
 
166
165
  Provider
167
- ========
166
+ --------
168
167
 
169
168
  A provider class serves a single purpose: to get backend objects that enable
170
169
  executing circuits on a device or simulator. The expectation is that any
@@ -195,7 +194,7 @@ authentication (if required) are present in the class and that the backends
195
194
  method matches the required interface. The rest is up to the specific provider on how to implement.
196
195
 
197
196
  Backend
198
- =======
197
+ -------
199
198
 
200
199
  The backend classes are the core to the provider. These classes are what
201
200
  provide the interface between Qiskit and the hardware or simulator that will
@@ -276,8 +275,8 @@ example would be something like::
276
275
  return MyJob(self. job_handle, job_json, circuit)
277
276
 
278
277
 
279
- Transpiler Interface
280
- --------------------
278
+ Backend's Transpiler Interface
279
+ ------------------------------
281
280
 
282
281
  The key piece of the :class:`~qiskit.providers.Backend` object is how it describes itself to the
283
282
  compiler. This is handled with the :class:`~qiskit.transpiler.Target` class which defines
@@ -453,8 +452,45 @@ This way if these two compilation steps are **required** for running or providin
453
452
  efficient output on ``Mybackend`` the transpiler will be able to perform these
454
453
  custom steps without any manual user input.
455
454
 
456
- Run Method
457
- ----------
455
+ .. _providers-guide-real-time-variables:
456
+
457
+ Real-time variables
458
+ ^^^^^^^^^^^^^^^^^^^
459
+
460
+ The transpiler will automatically handle real-time typed classical variables (see
461
+ :mod:`qiskit.circuit.classical`) and treat the :class:`.Store` instruction as a built-in
462
+ "directive", similar to :class:`.Barrier`. No special handling from backends is necessary to permit
463
+ this.
464
+
465
+ If your backend is *unable* to handle classical variables and storage, we recommend that you comment
466
+ on this in your documentation, and insert a check into your :meth:`~.BackendV2.run` method (see
467
+ :ref:`providers-guide-backend-run`) to eagerly reject circuits containing them. You can examine
468
+ :attr:`.QuantumCircuit.num_vars` for the presence of variables at the top level. If you accept
469
+ :ref:`control-flow operations <circuit-control-flow-repr>`, you might need to recursively search the
470
+ internal :attr:`~.ControlFlowOp.blocks` of each for scope-local variables with
471
+ :attr:`.QuantumCircuit.num_declared_vars`.
472
+
473
+ For example, a function to check for the presence of any manual storage locations, or manual stores
474
+ to memory::
475
+
476
+ from qiskit.circuit import Store, ControlFlowOp, QuantumCircuit
477
+
478
+ def has_realtime_logic(circuit: QuantumCircuit) -> bool:
479
+ if circuit.num_vars:
480
+ return True
481
+ for instruction in circuit.data:
482
+ if isinstance(instruction.operation, Store):
483
+ return True
484
+ elif isinstance(instruction.operation, ControlFlowOp):
485
+ for block in instruction.operation.blocks:
486
+ if has_realtime_logic(block):
487
+ return True
488
+ return False
489
+
490
+ .. _providers-guide-backend-run:
491
+
492
+ Backend.run Method
493
+ ------------------
458
494
 
459
495
  Of key importance is the :meth:`~qiskit.providers.BackendV2.run` method, which
460
496
  is used to actually submit circuits to a device or simulator. The run method
@@ -484,8 +520,8 @@ An example run method would be something like::
484
520
  job_handle = submit_to_backend(job_jsonb)
485
521
  return MyJob(self. job_handle, job_json, circuit)
486
522
 
487
- Options
488
- -------
523
+ Backend Options
524
+ ---------------
489
525
 
490
526
  There are often several options for a backend that control how a circuit is run.
491
527
  The typical example of this is something like the number of ``shots`` which is
@@ -515,7 +551,7 @@ for a full list of validation options.
515
551
 
516
552
 
517
553
  Job
518
- ===
554
+ ---
519
555
 
520
556
  The output from the :obj:`~qiskit.providers.BackendV2.run` method is a :class:`~qiskit.providers.JobV1`
521
557
  object. Each provider is expected to implement a custom job subclass that
@@ -612,7 +648,7 @@ and for a sync job::
612
648
  return JobStatus.DONE
613
649
 
614
650
  Primitives
615
- ==========
651
+ ----------
616
652
 
617
653
  While not directly part of the provider interface, the :mod:`qiskit.primitives`
618
654
  module is tightly coupled with providers. Specifically the primitive
@@ -640,12 +676,8 @@ implementations. Also the built-in implementations: :class:`~.Sampler`,
640
676
  :class:`~.Estimator`, :class:`~.BackendSampler`, and :class:`~.BackendEstimator`
641
677
  can serve as references/models on how to implement these as well.
642
678
 
643
- ======================================
644
- Migrating between Backend API Versions
645
- ======================================
646
-
647
- BackendV1 -> BackendV2
648
- ======================
679
+ Migrating from BackendV1 to BackendV2
680
+ =====================================
649
681
 
650
682
  The :obj:`~BackendV2` class re-defined user access for most properties of a
651
683
  backend to make them work with native Qiskit data structures and have flatter
@@ -88,12 +88,6 @@ class BackendV1(Backend, ABC):
88
88
  This next bit is necessary just because autosummary generally won't summarise private
89
89
  methods; changing that behaviour would have annoying knock-on effects through all the
90
90
  rest of the documentation, so instead we just hard-code the automethod directive.
91
-
92
- In addition to the public abstract methods, subclasses should also implement the following
93
- private methods:
94
-
95
- .. automethod:: _default_options
96
- :noindex:
97
91
  """
98
92
  self._configuration = configuration
99
93
  self._options = self._default_options()
@@ -27,36 +27,15 @@ via the `BasicProvider` provider, e.g.:
27
27
  backend = BasicProvider().get_backend('basic_simulator')
28
28
 
29
29
 
30
- Simulators
31
- ==========
30
+ Classes
31
+ =======
32
32
 
33
33
  .. autosummary::
34
34
  :toctree: ../stubs/
35
35
 
36
36
  BasicSimulator
37
-
38
- Provider
39
- ========
40
-
41
- .. autosummary::
42
- :toctree: ../stubs/
43
-
44
37
  BasicProvider
45
-
46
- Job Class
47
- =========
48
-
49
- .. autosummary::
50
- :toctree: ../stubs/
51
-
52
38
  BasicProviderJob
53
-
54
- Exceptions
55
- ==========
56
-
57
- .. autosummary::
58
- :toctree: ../stubs/
59
-
60
39
  BasicProviderError
61
40
  """
62
41
 
@@ -24,7 +24,7 @@ The fake provider module in Qiskit contains fake (simulated) backend classes
24
24
  useful for testing the transpiler and other backend-facing functionality.
25
25
 
26
26
  Example Usage
27
- =============
27
+ -------------
28
28
 
29
29
  Here is an example of using a simulated backend for transpilation and running.
30
30
 
@@ -375,6 +375,11 @@ class GenericBackendV2(BackendV2):
375
375
  f"in the standard qiskit circuit library."
376
376
  )
377
377
  gate = self._supported_gates[name]
378
+ if self.num_qubits < gate.num_qubits:
379
+ raise QiskitError(
380
+ f"Provided basis gate {name} needs more qubits than {self.num_qubits}, "
381
+ f"which is the size of the backend."
382
+ )
378
383
  noise_params = self._get_noise_defaults(name, gate.num_qubits)
379
384
  self._add_noisy_instruction_to_target(gate, noise_params, calibration_inst_map)
380
385
 
@@ -19,8 +19,8 @@ Backend Objects (:mod:`qiskit.providers.models`)
19
19
 
20
20
  Qiskit schema-conformant objects used by the backends and providers.
21
21
 
22
- Backend Objects
23
- ===============
22
+ Classes
23
+ =======
24
24
 
25
25
  .. autosummary::
26
26
  :toctree: ../stubs/
qiskit/pulse/builder.py CHANGED
@@ -74,8 +74,8 @@ a pulse:
74
74
 
75
75
  The builder initializes a :class:`.pulse.Schedule`, ``pulse_prog``
76
76
  and then begins to construct the program within the context. The output pulse
77
- schedule will survive after the context is exited and can be transpiled and executed like a
78
- normal Qiskit schedule using ``backend.run(transpile(pulse_prog, backend))``.
77
+ schedule will survive after the context is exited and can be used like a
78
+ normal Qiskit schedule.
79
79
 
80
80
  Pulse programming has a simple imperative style. This leaves the programmer
81
81
  to worry about the raw experimental physics of pulse programming and not
qiskit/pulse/schedule.py CHANGED
@@ -252,7 +252,7 @@ class Schedule:
252
252
 
253
253
  Notes:
254
254
  Nested schedules are returned as-is. If you want to collect only instructions,
255
- use py:meth:`~Schedule.instructions` instead.
255
+ use :py:meth:`~Schedule.instructions` instead.
256
256
 
257
257
  Returns:
258
258
  A tuple, where each element is a two-tuple containing the initial
@@ -490,7 +490,7 @@ class Schedule:
490
490
  ) -> "Schedule":
491
491
  """Return a ``Schedule`` with only the instructions from this Schedule *failing*
492
492
  at least one of the provided filters.
493
- This method is the complement of py:meth:`~self.filter`, so that::
493
+ This method is the complement of :py:meth:`~Schedule.filter`, so that::
494
494
 
495
495
  self.filter(args) | self.exclude(args) == self
496
496
 
@@ -1309,7 +1309,7 @@ class ScheduleBlock:
1309
1309
  ):
1310
1310
  """Return a new ``ScheduleBlock`` with only the instructions from this ``ScheduleBlock``
1311
1311
  *failing* at least one of the provided filters.
1312
- This method is the complement of py:meth:`~self.filter`, so that::
1312
+ This method is the complement of :py:meth:`~ScheduleBlock.filter`, so that::
1313
1313
 
1314
1314
  self.filter(args) + self.exclude(args) == self in terms of instructions included.
1315
1315
 
qiskit/qasm2/parse.py CHANGED
@@ -16,6 +16,8 @@ import dataclasses
16
16
  import math
17
17
  from typing import Iterable, Callable
18
18
 
19
+ import numpy as np
20
+
19
21
  from qiskit.circuit import (
20
22
  Barrier,
21
23
  CircuitInstruction,
@@ -30,6 +32,7 @@ from qiskit.circuit import (
30
32
  Reset,
31
33
  library as lib,
32
34
  )
35
+ from qiskit.quantum_info import Operator
33
36
  from qiskit._accelerate.qasm2 import (
34
37
  OpCode,
35
38
  UnaryOpCode,
@@ -315,6 +318,11 @@ class _DefinedGate(Gate):
315
318
  raise ValueError(f"received invalid bytecode to build gate: {op}")
316
319
  self._definition = qc
317
320
 
321
+ def __array__(self, dtype=None, copy=None):
322
+ if copy is False:
323
+ raise ValueError("unable to avoid copy while creating an array as requested")
324
+ return np.asarray(Operator(self.definition), dtype=dtype)
325
+
318
326
  # It's fiddly to implement pickling for PyO3 types (the bytecode stream), so instead if we need
319
327
  # to pickle ourselves, we just eagerly create the definition and pickle that.
320
328
 
qiskit/qasm3/exporter.py CHANGED
@@ -837,7 +837,7 @@ class QASM3Builder:
837
837
  statements.append(self.build_if_statement(instruction))
838
838
  elif isinstance(instruction.operation, SwitchCaseOp):
839
839
  statements.extend(self.build_switch_statement(instruction))
840
- else: # pragma: no cover
840
+ else:
841
841
  raise RuntimeError(f"unhandled control-flow construct: {instruction.operation}")
842
842
  continue
843
843
  # Build the node, ignoring any condition.
@@ -1130,7 +1130,7 @@ def _build_ast_type(type_: types.Type) -> ast.ClassicalType:
1130
1130
  return ast.BoolType()
1131
1131
  if type_.kind is types.Uint:
1132
1132
  return ast.UintType(type_.width)
1133
- raise RuntimeError(f"unhandled expr type '{type_}'") # pragma: no cover
1133
+ raise RuntimeError(f"unhandled expr type '{type_}'")
1134
1134
 
1135
1135
 
1136
1136
  class _ExprBuilder(expr.ExprVisitor[ast.Expression]):
@@ -234,7 +234,7 @@ class InstructionToQobjConverter:
234
234
  "name": "setf",
235
235
  "t0": time_offset + instruction.start_time,
236
236
  "ch": instruction.channel.name,
237
- "frequency": instruction.frequency / 1e9,
237
+ "frequency": instruction.frequency / 10**9,
238
238
  }
239
239
  return self._qobj_model(**command_dict)
240
240
 
@@ -257,7 +257,7 @@ class InstructionToQobjConverter:
257
257
  "name": "shiftf",
258
258
  "t0": time_offset + instruction.start_time,
259
259
  "ch": instruction.channel.name,
260
- "frequency": instruction.frequency / 1e9,
260
+ "frequency": instruction.frequency / 10**9,
261
261
  }
262
262
  return self._qobj_model(**command_dict)
263
263
 
@@ -746,7 +746,7 @@ class QobjToInstructionConverter:
746
746
  .. note::
747
747
 
748
748
  We assume frequency value is expressed in string with "GHz".
749
- Operand value is thus scaled by a factor of 1e9.
749
+ Operand value is thus scaled by a factor of 10^9.
750
750
 
751
751
  Args:
752
752
  instruction: SetFrequency qobj instruction
@@ -755,7 +755,7 @@ class QobjToInstructionConverter:
755
755
  Qiskit Pulse set frequency instructions
756
756
  """
757
757
  channel = self.get_channel(instruction.ch)
758
- frequency = self.disassemble_value(instruction.frequency) * 1e9
758
+ frequency = self.disassemble_value(instruction.frequency) * 10**9
759
759
 
760
760
  yield instructions.SetFrequency(frequency, channel)
761
761
 
@@ -768,7 +768,7 @@ class QobjToInstructionConverter:
768
768
  .. note::
769
769
 
770
770
  We assume frequency value is expressed in string with "GHz".
771
- Operand value is thus scaled by a factor of 1e9.
771
+ Operand value is thus scaled by a factor of 10^9.
772
772
 
773
773
  Args:
774
774
  instruction: ShiftFrequency qobj instruction
@@ -777,7 +777,7 @@ class QobjToInstructionConverter:
777
777
  Qiskit Pulse shift frequency schedule instructions
778
778
  """
779
779
  channel = self.get_channel(instruction.ch)
780
- frequency = self.disassemble_value(instruction.frequency) * 1e9
780
+ frequency = self.disassemble_value(instruction.frequency) * 10**9
781
781
 
782
782
  yield instructions.ShiftFrequency(frequency, channel)
783
783