qiskit 2.0.0rc2__cp39-abi3-macosx_11_0_arm64.whl → 2.0.2__cp39-abi3-macosx_11_0_arm64.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 (55) hide show
  1. qiskit/VERSION.txt +1 -1
  2. qiskit/__init__.py +1 -4
  3. qiskit/_accelerate.abi3.so +0 -0
  4. qiskit/circuit/__init__.py +11 -5
  5. qiskit/circuit/classical/expr/constructors.py +0 -12
  6. qiskit/circuit/library/__init__.py +449 -163
  7. qiskit/circuit/library/boolean_logic/quantum_or.py +2 -2
  8. qiskit/circuit/library/graph_state.py +1 -0
  9. qiskit/circuit/library/n_local/efficient_su2.py +1 -1
  10. qiskit/circuit/library/n_local/evolved_operator_ansatz.py +3 -1
  11. qiskit/circuit/library/n_local/excitation_preserving.py +1 -1
  12. qiskit/circuit/library/quantum_volume.py +9 -0
  13. qiskit/circuit/library/standard_gates/r.py +4 -3
  14. qiskit/circuit/library/standard_gates/x.py +1 -2
  15. qiskit/circuit/quantumcircuit.py +405 -80
  16. qiskit/converters/circuit_to_dag.py +2 -2
  17. qiskit/converters/dag_to_circuit.py +2 -3
  18. qiskit/dagcircuit/dagdependency_v2.py +3 -2
  19. qiskit/primitives/statevector_estimator.py +1 -1
  20. qiskit/qpy/__init__.py +21 -0
  21. qiskit/qpy/binary_io/circuits.py +5 -0
  22. qiskit/result/models.py +1 -2
  23. qiskit/result/result.py +10 -8
  24. qiskit/synthesis/discrete_basis/commutator_decompose.py +30 -6
  25. qiskit/synthesis/discrete_basis/gate_sequence.py +10 -4
  26. qiskit/synthesis/discrete_basis/generate_basis_approximations.py +1 -1
  27. qiskit/synthesis/discrete_basis/solovay_kitaev.py +36 -13
  28. qiskit/transpiler/passes/__init__.py +2 -0
  29. qiskit/transpiler/passes/basis/basis_translator.py +1 -1
  30. qiskit/transpiler/passes/layout/full_ancilla_allocation.py +2 -3
  31. qiskit/transpiler/passes/layout/sabre_layout.py +3 -1
  32. qiskit/transpiler/passes/layout/vf2_utils.py +2 -5
  33. qiskit/transpiler/passes/optimization/__init__.py +1 -0
  34. qiskit/transpiler/passes/optimization/consolidate_blocks.py +6 -1
  35. qiskit/transpiler/passes/scheduling/alignments/check_durations.py +1 -1
  36. qiskit/transpiler/passes/scheduling/padding/base_padding.py +2 -2
  37. qiskit/transpiler/passes/scheduling/padding/dynamical_decoupling.py +5 -5
  38. qiskit/transpiler/passes/scheduling/padding/pad_delay.py +1 -1
  39. qiskit/transpiler/passes/scheduling/time_unit_conversion.py +10 -6
  40. qiskit/transpiler/passes/synthesis/solovay_kitaev_synthesis.py +29 -19
  41. qiskit/transpiler/passes/synthesis/unitary_synthesis.py +2 -1
  42. qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py +13 -7
  43. qiskit/transpiler/target.py +11 -0
  44. qiskit/visualization/circuit/text.py +1 -1
  45. qiskit/visualization/counts_visualization.py +4 -0
  46. qiskit/visualization/library.py +4 -1
  47. qiskit/visualization/state_visualization.py +13 -2
  48. qiskit/visualization/timeline/core.py +1 -1
  49. qiskit/visualization/timeline/plotters/matplotlib.py +4 -1
  50. {qiskit-2.0.0rc2.dist-info → qiskit-2.0.2.dist-info}/METADATA +4 -3
  51. {qiskit-2.0.0rc2.dist-info → qiskit-2.0.2.dist-info}/RECORD +55 -55
  52. {qiskit-2.0.0rc2.dist-info → qiskit-2.0.2.dist-info}/WHEEL +1 -1
  53. {qiskit-2.0.0rc2.dist-info → qiskit-2.0.2.dist-info}/entry_points.txt +0 -0
  54. {qiskit-2.0.0rc2.dist-info → qiskit-2.0.2.dist-info/licenses}/LICENSE.txt +0 -0
  55. {qiskit-2.0.0rc2.dist-info → qiskit-2.0.2.dist-info}/top_level.txt +0 -0
@@ -133,6 +133,34 @@ class QuantumCircuit:
133
133
  different regimes of quantum-circuit descriptions in Qiskit, see the module-level
134
134
  documentation of :mod:`qiskit.circuit`.
135
135
 
136
+ Example:
137
+
138
+ .. plot::
139
+ :include-source:
140
+ :nofigs:
141
+
142
+ from qiskit import QuantumCircuit
143
+
144
+ # Create a new circuit with two qubits
145
+ qc = QuantumCircuit(2)
146
+
147
+ # Add a Hadamard gate to qubit 0
148
+ qc.h(0)
149
+
150
+ # Perform a controlled-X gate on qubit 1, controlled by qubit 0
151
+ qc.cx(0, 1)
152
+
153
+ # Return a text drawing of the circuit.
154
+ qc.draw()
155
+
156
+ .. code-block:: text
157
+
158
+ ┌───┐
159
+ q_0: ┤ H ├──■──
160
+ └───┘┌─┴─┐
161
+ q_1: ─────┤ X ├
162
+ └───┘
163
+
136
164
  Circuit attributes
137
165
  ==================
138
166
 
@@ -142,50 +170,55 @@ class QuantumCircuit:
142
170
  A small handful of the attributes are intentionally mutable, the rest are data attributes that
143
171
  should be considered immutable.
144
172
 
145
- ========================= ======================================================================
146
- Mutable attribute Summary
147
- ========================= ======================================================================
148
- :attr:`global_phase` The global phase of the circuit, measured in radians.
149
- :attr:`metadata` Arbitrary user mapping, which Qiskit will preserve through the
150
- transpiler, but otherwise completely ignore.
151
- :attr:`name` An optional string name for the circuit.
152
- ========================= ======================================================================
153
-
154
- ========================= ======================================================================
155
- Immutable data attribute Summary
156
- ========================= ======================================================================
157
- :attr:`ancillas` List of :class:`AncillaQubit`\\ s tracked by the circuit.
158
- :attr:`cregs` List of :class:`ClassicalRegister`\\ s tracked by the circuit.
159
-
160
- :attr:`clbits` List of :class:`Clbit`\\ s tracked by the circuit.
161
- :attr:`data` List of individual :class:`CircuitInstruction`\\ s that make up the
162
- circuit.
163
- :attr:`duration` Total duration of the circuit, added by scheduling transpiler passes.
164
- This attribute is deprecated and :meth:`.estimate_duration` should
165
- be used instead.
166
-
167
- :attr:`layout` Hardware layout and routing information added by the transpiler.
168
- :attr:`num_ancillas` The number of ancilla qubits in the circuit.
169
- :attr:`num_clbits` The number of clbits in the circuit.
170
- :attr:`num_captured_vars` Number of captured real-time classical variables.
171
-
172
- :attr:`num_declared_vars` Number of locally declared real-time classical variables in the outer
173
- circuit scope.
174
- :attr:`num_input_vars` Number of input real-time classical variables.
175
- :attr:`num_parameters` Number of compile-time :class:`Parameter`\\ s in the circuit.
176
- :attr:`num_qubits` Number of qubits in the circuit.
177
-
178
- :attr:`num_vars` Total number of real-time classical variables in the outer circuit
179
- scope.
180
- :attr:`op_start_times` Start times of scheduled operations, added by scheduling transpiler
181
- passes.
182
- :attr:`parameters` Ordered set-like view of the compile-time :class:`Parameter`\\ s
183
- tracked by the circuit.
184
- :attr:`qregs` List of :class:`QuantumRegister`\\ s tracked by the circuit.
185
-
186
- :attr:`qubits` List of :class:`Qubit`\\ s tracked by the circuit.
187
- :attr:`unit` The unit of the :attr:`duration` field.
188
- ========================= ======================================================================
173
+ ============================== =================================================================
174
+ Mutable attribute Summary
175
+ ============================== =================================================================
176
+ :attr:`global_phase` The global phase of the circuit, measured in radians.
177
+ :attr:`metadata` Arbitrary user mapping, which Qiskit will preserve through the
178
+ transpiler, but otherwise completely ignore.
179
+ :attr:`name` An optional string name for the circuit.
180
+ ============================== =================================================================
181
+
182
+ ============================== =================================================================
183
+ Immutable data attribute Summary
184
+ ============================== =================================================================
185
+ :attr:`ancillas` List of :class:`AncillaQubit`\\ s tracked by the circuit.
186
+ :attr:`cregs` List of :class:`ClassicalRegister`\\ s tracked by the circuit.
187
+
188
+ :attr:`clbits` List of :class:`Clbit`\\ s tracked by the circuit.
189
+ :attr:`data` List of individual :class:`CircuitInstruction`\\ s that make up
190
+ the circuit.
191
+ :attr:`duration` Total duration of the circuit, added by scheduling transpiler
192
+ passes.
193
+ This attribute is deprecated and :meth:`.estimate_duration`
194
+ should be used instead.
195
+
196
+ :attr:`layout` Hardware layout and routing information added by the transpiler.
197
+ :attr:`num_ancillas` The number of ancilla qubits in the circuit.
198
+ :attr:`num_clbits` The number of clbits in the circuit.
199
+ :attr:`num_captured_vars` Number of captured real-time classical variables.
200
+ :attr:`num_captured_stretches` Number of captured stretches.
201
+ :attr:`num_declared_vars` Number of locally declared real-time classical variables in the
202
+ outer circuit scope.
203
+ :attr:`num_declared_stretches` Number of locally declared stretches in the outer circuit scope.
204
+ :attr:`num_input_vars` Number of input real-time classical variables.
205
+ :attr:`num_parameters` Number of compile-time :class:`Parameter`\\ s in the circuit.
206
+ :attr:`num_qubits` Number of qubits in the circuit.
207
+
208
+ :attr:`num_vars` Total number of real-time classical variables in the outer
209
+ circuit scope.
210
+ :attr:`num_stretches` Total number of stretches in the outer circuit scope.
211
+ :attr:`num_identifiers` Total number of both variables and stretches in the outer
212
+ circuit.
213
+ :attr:`op_start_times` Start times of scheduled operations, added by scheduling
214
+ transpiler passes.
215
+ :attr:`parameters` Ordered set-like view of the compile-time :class:`Parameter`\\ s
216
+ tracked by the circuit.
217
+ :attr:`qregs` List of :class:`QuantumRegister`\\ s tracked by the circuit.
218
+
219
+ :attr:`qubits` List of :class:`Qubit`\\ s tracked by the circuit.
220
+ :attr:`unit` The unit of the :attr:`duration` field.
221
+ ============================== =================================================================
189
222
 
190
223
  The core attribute is :attr:`data`. This is a sequence-like object that exposes the
191
224
  :class:`CircuitInstruction`\\ s contained in an ordered form. You generally should not mutate
@@ -255,10 +288,14 @@ class QuantumCircuit:
255
288
  .. autoattribute:: num_ancillas
256
289
  .. autoattribute:: num_clbits
257
290
  .. autoattribute:: num_captured_vars
291
+ .. autoattribute:: num_captured_stretches
258
292
  .. autoattribute:: num_declared_vars
293
+ .. autoattribute:: num_declared_stretches
259
294
  .. autoattribute:: num_input_vars
295
+ .. autoattribute:: num_identifiers
260
296
  .. autoattribute:: num_parameters
261
297
  .. autoattribute:: num_qubits
298
+ .. autoattribute:: num_stretches
262
299
  .. autoattribute:: num_vars
263
300
 
264
301
  Creating new circuits
@@ -325,8 +362,10 @@ class QuantumCircuit:
325
362
  :meth:`add_bits` :class:`.Qubit`\\ s and :class:`.Clbit`\\ s.
326
363
  :meth:`add_register` :class:`.QuantumRegister` and :class:`.ClassicalRegister`.
327
364
  :meth:`add_var` :class:`~.expr.Var` nodes with local scope and initializers.
365
+ :meth:`add_stretch` :class:`~.expr.Stretch` nodes with local scope.
328
366
  :meth:`add_input` :class:`~.expr.Var` nodes that are treated as circuit inputs.
329
- :meth:`add_capture` :class:`~.expr.Var` nodes captured from containing scopes.
367
+ :meth:`add_capture` :class:`~.expr.Var` or :class:`~.expr.Stretch` nodes captured
368
+ from containing scopes.
330
369
  :meth:`add_uninitialized_var` :class:`~.expr.Var` nodes with local scope and undefined state.
331
370
  ============================= =================================================================
332
371
 
@@ -356,10 +395,12 @@ class QuantumCircuit:
356
395
  to instantiate these separately to a circuit (see :meth:`.Var.new`), but it is often more
357
396
  convenient to use circuit methods that will automatically manage the types and expression
358
397
  initialization for you. The two most common methods are :meth:`add_var` (locally scoped
359
- variables) and :meth:`add_input` (inputs to the circuit).
398
+ variables) and :meth:`add_input` (inputs to the circuit). Additionally, the method
399
+ :meth:`add_stretch` can be used to add stretches to the circuit.
360
400
 
361
401
  .. automethod:: add_var
362
402
  .. automethod:: add_input
403
+ .. automethod:: add_stretch
363
404
 
364
405
  In addition, there are two lower-level methods that can be useful for programmatic generation of
365
406
  circuits. When working interactively, you will most likely not need these; most uses of
@@ -427,26 +468,37 @@ class QuantumCircuit:
427
468
  as a whole.
428
469
 
429
470
  :ref:`circuit-adding-data-objects`
430
- The methods for adding new :class:`~.expr.Var` variables to a circuit after
431
- initialization.
471
+ The methods for adding new :class:`~.expr.Var` or :class:`~.expr.Stretch` identifiers
472
+ to a circuit after initialization.
432
473
 
433
- You can retrive a :class:`~.expr.Var` instance attached to a circuit by using its variable name
434
- using :meth:`get_var`, or check if a circuit contains a given variable with :meth:`has_var`.
474
+ You can retrieve identifiers attached to a circuit (e.g. a :class:`~.expr.Var` or
475
+ :class:`~.expr.Stretch`) by name with methods :meth:`get_var`, :meth:`get_stretch`, or
476
+ :meth:`get_identifier`. You can also check if a circuit
477
+ contains a given identifier with :meth:`has_var`, :meth:`has_stretch`, or
478
+ :meth:`has_identifier`.
435
479
 
436
480
  .. automethod:: get_var
481
+ .. automethod:: get_stretch
482
+ .. automethod:: get_identifier
437
483
  .. automethod:: has_var
484
+ .. automethod:: has_stretch
485
+ .. automethod:: has_identifier
486
+
438
487
 
439
- There are also several iterator methods that you can use to get the full set of variables
488
+ There are also several iterator methods that you can use to get the full set of identifiers
440
489
  tracked by a circuit. At least one of :meth:`iter_input_vars` and :meth:`iter_captured_vars`
441
490
  will be empty, as inputs and captures are mutually exclusive. All of the iterators have
442
491
  corresponding dynamic properties on :class:`QuantumCircuit` that contain their length:
443
- :attr:`num_vars`, :attr:`num_input_vars`, :attr:`num_captured_vars` and
444
- :attr:`num_declared_vars`.
492
+ :attr:`num_vars`, :attr:`num_stretches`, :attr:`num_input_vars`, :attr:`num_captured_vars`,
493
+ :attr:`num_captured_stretches`, :attr:`num_declared_vars`, or :attr:`num_declared_stretches`.
445
494
 
446
495
  .. automethod:: iter_vars
496
+ .. automethod:: iter_stretches
447
497
  .. automethod:: iter_input_vars
448
498
  .. automethod:: iter_captured_vars
499
+ .. automethod:: iter_captured_stretches
449
500
  .. automethod:: iter_declared_vars
501
+ .. automethod:: iter_declared_stretches
450
502
 
451
503
 
452
504
  .. _circuit-adding-operations:
@@ -1046,7 +1098,24 @@ class QuantumCircuit:
1046
1098
  regs = tuple(int(reg) for reg in regs) # cast to int
1047
1099
  self._base_name = None
1048
1100
  self.name: str
1049
- """A human-readable name for the circuit."""
1101
+ """A human-readable name for the circuit.
1102
+
1103
+ Example:
1104
+
1105
+ .. plot::
1106
+ :include-source:
1107
+ :nofigs:
1108
+ :context: reset
1109
+
1110
+ from qiskit import QuantumCircuit
1111
+
1112
+ qc = QuantumCircuit(2, 2, name="my_circuit")
1113
+ print(qc.name)
1114
+
1115
+ .. code-block:: text
1116
+
1117
+ my_circuit
1118
+ """
1050
1119
  if name is None:
1051
1120
  self._base_name = self._cls_prefix()
1052
1121
  self._name_update()
@@ -1104,10 +1173,27 @@ class QuantumCircuit:
1104
1173
  self._duration = None
1105
1174
  self._unit = "dt"
1106
1175
  self.metadata = {} if metadata is None else metadata
1107
- """Arbitrary user-defined metadata for the circuit.
1176
+ """Arbitrary user-defined dictionary of metadata for the circuit.
1108
1177
 
1109
1178
  Qiskit will not examine the content of this mapping, but it will pass it through the
1110
- transpiler and reattach it to the output, so you can track your own metadata."""
1179
+ transpiler and reattach it to the output, so you can track your own metadata.
1180
+
1181
+ Example:
1182
+
1183
+ .. plot::
1184
+ :include-source:
1185
+ :nofigs:
1186
+
1187
+ from qiskit import QuantumCircuit
1188
+
1189
+ qc = QuantumCircuit(2, 2, metadata={'experiment_type': 'Bell state experiment'})
1190
+
1191
+ print(qc.metadata)
1192
+
1193
+ .. code-block:: text
1194
+
1195
+ {'experiment_type': 'Bell state experiment'}
1196
+ """
1111
1197
 
1112
1198
  @property
1113
1199
  @deprecate_func(since="1.3.0", removal_timeline="in Qiskit 3.0.0", is_property=True)
@@ -1204,7 +1290,7 @@ class QuantumCircuit:
1204
1290
 
1205
1291
  @property
1206
1292
  def layout(self) -> Optional[TranspileLayout]:
1207
- r"""Return any associated layout information about the circuit
1293
+ """Return any associated layout information about the circuit.
1208
1294
 
1209
1295
  This attribute contains an optional :class:`~.TranspileLayout`
1210
1296
  object. This is typically set on the output from :func:`~.transpile`
@@ -1212,10 +1298,47 @@ class QuantumCircuit:
1212
1298
  permutations caused on the input circuit by transpilation.
1213
1299
 
1214
1300
  There are two types of permutations caused by the :func:`~.transpile`
1215
- function, an initial layout which permutes the qubits based on the
1216
- selected physical qubits on the :class:`~.Target`, and a final layout
1217
- which is an output permutation caused by :class:`~.SwapGate`\s
1301
+ function: an initial layout that permutes the qubits based on the
1302
+ selected physical qubits on the :class:`~.Target`, and a final layout,
1303
+ which is an output permutation caused by :class:`~.SwapGate`\\ s
1218
1304
  inserted during routing.
1305
+
1306
+ Example:
1307
+
1308
+ .. plot::
1309
+ :include-source:
1310
+ :nofigs:
1311
+
1312
+ from qiskit import QuantumCircuit
1313
+ from qiskit.providers.fake_provider import GenericBackendV2
1314
+ from qiskit.transpiler import generate_preset_pass_manager
1315
+
1316
+ # Create circuit to test transpiler on
1317
+ qc = QuantumCircuit(3, 3)
1318
+ qc.h(0)
1319
+ qc.cx(0, 1)
1320
+ qc.swap(1, 2)
1321
+ qc.cx(0, 1)
1322
+
1323
+ # Add measurements to the circuit
1324
+ qc.measure([0, 1, 2], [0, 1, 2])
1325
+
1326
+ # Specify the QPU to target
1327
+ backend = GenericBackendV2(3)
1328
+
1329
+ # Transpile the circuit
1330
+ pass_manager = generate_preset_pass_manager(
1331
+ optimization_level=1, backend=backend
1332
+ )
1333
+ transpiled = pass_manager.run(qc)
1334
+
1335
+ # Print the layout after transpilation
1336
+ print(transpiled.layout.routing_permutation())
1337
+
1338
+ .. code-block:: text
1339
+
1340
+ [0, 1, 2]
1341
+
1219
1342
  """
1220
1343
  return self._layout
1221
1344
 
@@ -1223,9 +1346,26 @@ class QuantumCircuit:
1223
1346
  def data(self) -> QuantumCircuitData:
1224
1347
  """The circuit data (instructions and context).
1225
1348
 
1349
+ Example:
1350
+
1351
+ .. plot::
1352
+ :include-source:
1353
+ :nofigs:
1354
+
1355
+ from qiskit import QuantumCircuit
1356
+
1357
+ qc = QuantumCircuit(2, 2)
1358
+ qc.measure([0], [1])
1359
+ print(qc.data)
1360
+
1361
+ .. code-block:: text
1362
+
1363
+ [CircuitInstruction(operation=Instruction(name='measure', num_qubits=1,
1364
+ num_clbits=1, params=[]), qubits=(Qubit(QuantumRegister(2, 'q'), 0),),
1365
+ clbits=(Clbit(ClassicalRegister(2, 'c'), 1),))]
1366
+
1226
1367
  Returns:
1227
- QuantumCircuitData: a list-like object containing the :class:`.CircuitInstruction`\\ s
1228
- for each instruction.
1368
+ A list-like object containing the :class:`.CircuitInstruction` instances in the circuit.
1229
1369
  """
1230
1370
  return QuantumCircuitData(self)
1231
1371
 
@@ -1271,6 +1411,69 @@ class QuantumCircuit:
1271
1411
  This attribute is enabled once one of scheduling analysis passes
1272
1412
  runs on the quantum circuit.
1273
1413
 
1414
+ Example:
1415
+
1416
+ .. plot::
1417
+ :include-source:
1418
+ :nofigs:
1419
+
1420
+ from qiskit import QuantumCircuit
1421
+ from qiskit.providers.fake_provider import GenericBackendV2
1422
+ from qiskit.transpiler import generate_preset_pass_manager
1423
+
1424
+ qc = QuantumCircuit(2)
1425
+ qc.h(0)
1426
+ qc.cx(0, 1)
1427
+ qc.measure_all()
1428
+
1429
+ # Print the original circuit
1430
+ print("Original circuit:")
1431
+ print(qc)
1432
+
1433
+ # Transpile the circuit with a specific basis gates list and print the resulting circuit
1434
+ backend = GenericBackendV2(2, basis_gates=['u1', 'u2', 'u3', 'cx'])
1435
+ pm = generate_preset_pass_manager(
1436
+ optimization_level=1, backend=backend, scheduling_method="alap"
1437
+ )
1438
+ transpiled_qc = pm.run(qc)
1439
+ print("Transpiled circuit with basis gates ['u1', 'u2', 'u3', 'cx']:")
1440
+ print(transpiled_qc)
1441
+
1442
+ # Print the start times of each instruction in the transpiled circuit
1443
+ print("Start times of instructions in the transpiled circuit:")
1444
+ for instruction, start_time in zip(transpiled_qc.data, transpiled_qc.op_start_times):
1445
+ print(f"{instruction.operation.name}: {start_time}")
1446
+
1447
+ .. code-block:: text
1448
+
1449
+
1450
+ Original circuit:
1451
+ ┌───┐ ░ ┌─┐
1452
+ q_0: ┤ H ├──■───░─┤M├───
1453
+ └───┘┌─┴─┐ ░ └╥┘┌─┐
1454
+ q_1: ─────┤ X ├─░──╫─┤M├
1455
+ └───┘ ░ ║ └╥┘
1456
+ meas: 2/══════════════╩══╩═
1457
+ 0 1
1458
+
1459
+ Transpiled circuit with basis gates ['u1', 'u2', 'u3', 'cx']:
1460
+ ┌─────────┐ ░ ┌─────────────────┐┌─┐
1461
+ q_0 -> 0 ───┤ U2(0,π) ├──────■───░─┤ Delay(1255[dt]) ├┤M├
1462
+ ┌──┴─────────┴───┐┌─┴─┐ ░ └───────┬─┬───────┘└╥┘
1463
+ q_1 -> 1 ┤ Delay(196[dt]) ├┤ X ├─░─────────┤M├─────────╫─
1464
+ └────────────────┘└───┘ ░ └╥┘ ║
1465
+ meas: 2/═══════════════════════════════════╩══════════╩═
1466
+ 1 0
1467
+
1468
+ Start times of instructions in the transpiled circuit:
1469
+ u2: 0
1470
+ delay: 0
1471
+ cx: 196
1472
+ barrier: 2098
1473
+ delay: 2098
1474
+ measure: 3353
1475
+ measure: 2098
1476
+
1274
1477
  Returns:
1275
1478
  List of integers representing instruction estimated start times.
1276
1479
  The index corresponds to the index of instruction in :attr:`QuantumCircuit.data`.
@@ -1287,14 +1490,34 @@ class QuantumCircuit:
1287
1490
 
1288
1491
  @property
1289
1492
  def metadata(self) -> dict:
1290
- """The user provided metadata associated with the circuit.
1493
+ """The user-provided metadata associated with the circuit.
1291
1494
 
1292
- The metadata for the circuit is a user provided ``dict`` of metadata
1495
+ The metadata for the circuit is a user-provided ``dict`` of metadata
1293
1496
  for the circuit. It will not be used to influence the execution or
1294
1497
  operation of the circuit, but it is expected to be passed between
1295
- all transforms of the circuit (ie transpilation) and that providers will
1498
+ all transforms of the circuit (i.e., transpilation) and that providers will
1296
1499
  associate any circuit metadata with the results it returns from
1297
1500
  execution of that circuit.
1501
+
1502
+ Example:
1503
+
1504
+ .. plot::
1505
+ :include-source:
1506
+ :nofigs:
1507
+
1508
+ from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
1509
+
1510
+ q = QuantumRegister(2)
1511
+ c = ClassicalRegister(2)
1512
+ qc = QuantumCircuit(q, c)
1513
+
1514
+ qc.metadata = {'experiment_type': 'Bell state experiment'}
1515
+
1516
+ print(qc.metadata)
1517
+
1518
+ .. code-block:: text
1519
+
1520
+ {'experiment_type': 'Bell state experiment'}
1298
1521
  """
1299
1522
  return self._metadata
1300
1523
 
@@ -1420,8 +1643,8 @@ class QuantumCircuit:
1420
1643
  for instruction in reversed(self.data):
1421
1644
  reverse_circ._append(instruction.replace(operation=instruction.operation.reverse_ops()))
1422
1645
 
1423
- reverse_circ.duration = self.duration
1424
- reverse_circ.unit = self.unit
1646
+ reverse_circ._duration = self._duration
1647
+ reverse_circ._unit = self._unit
1425
1648
  return reverse_circ
1426
1649
 
1427
1650
  def reverse_bits(self) -> "QuantumCircuit":
@@ -2136,7 +2359,33 @@ class QuantumCircuit:
2136
2359
  @property
2137
2360
  def clbits(self) -> list[Clbit]:
2138
2361
  """A list of :class:`Clbit`\\ s in the order that they were added. You should not mutate
2139
- this."""
2362
+ this.
2363
+
2364
+ Example:
2365
+
2366
+ .. plot::
2367
+ :include-source:
2368
+ :nofigs:
2369
+ :context: reset
2370
+
2371
+ from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
2372
+
2373
+ qr1 = QuantumRegister(2)
2374
+ qr2 = QuantumRegister(1)
2375
+ cr1 = ClassicalRegister(2)
2376
+ cr2 = ClassicalRegister(1)
2377
+ qc = QuantumCircuit(qr1, qr2, cr1, cr2)
2378
+
2379
+ print("List the qubits in this circuit:", qc.qubits)
2380
+ print("List the classical bits in this circuit:", qc.clbits)
2381
+
2382
+ .. code-block:: text
2383
+
2384
+ List the qubits in this circuit: [Qubit(QuantumRegister(2, 'q0'), 0),
2385
+ Qubit(QuantumRegister(2, 'q0'), 1), Qubit(QuantumRegister(1, 'q1'), 0)]
2386
+ List the classical bits in this circuit: [Clbit(ClassicalRegister(2, 'c0'), 0),
2387
+ Clbit(ClassicalRegister(2, 'c0'), 1), Clbit(ClassicalRegister(1, 'c1'), 0)]
2388
+ """
2140
2389
  return self._data.clbits
2141
2390
 
2142
2391
  @property
@@ -2559,8 +2808,8 @@ class QuantumCircuit:
2559
2808
  """
2560
2809
  if _standard_gate:
2561
2810
  self._data.append(instruction)
2562
- self.duration = None
2563
- self.unit = "dt"
2811
+ self._duration = None
2812
+ self._unit = "dt"
2564
2813
  return instruction
2565
2814
 
2566
2815
  old_style = not isinstance(instruction, CircuitInstruction)
@@ -2582,8 +2831,8 @@ class QuantumCircuit:
2582
2831
  self._data.append_manual_params(instruction, params)
2583
2832
 
2584
2833
  # Invalidate whole circuit duration if an instruction is added
2585
- self.duration = None
2586
- self.unit = "dt"
2834
+ self._duration = None
2835
+ self._unit = "dt"
2587
2836
  return instruction.operation if old_style else instruction
2588
2837
 
2589
2838
  @typing.overload
@@ -3682,12 +3931,54 @@ class QuantumCircuit:
3682
3931
 
3683
3932
  @property
3684
3933
  def num_ancillas(self) -> int:
3685
- """Return the number of ancilla qubits."""
3934
+ """Return the number of ancilla qubits.
3935
+
3936
+ Example:
3937
+
3938
+ .. plot::
3939
+ :include-source:
3940
+ :nofigs:
3941
+
3942
+ from qiskit import QuantumCircuit, QuantumRegister, AncillaRegister
3943
+
3944
+ # Create a 2-qubit quantum circuit
3945
+ reg = QuantumRegister(2)
3946
+ qc = QuantumCircuit(reg)
3947
+
3948
+ # Create an ancilla register with 1 qubit
3949
+ anc = AncillaRegister(1)
3950
+ qc.add_register(anc) # Add the ancilla register to the circuit
3951
+
3952
+ print("Number of ancilla qubits:", qc.num_ancillas)
3953
+
3954
+ .. code-block:: text
3955
+
3956
+ Number of ancilla qubits: 1
3957
+ """
3686
3958
  return len(self.ancillas)
3687
3959
 
3688
3960
  @property
3689
3961
  def num_clbits(self) -> int:
3690
- """Return number of classical bits."""
3962
+ """Return number of classical bits.
3963
+
3964
+ Example:
3965
+
3966
+ .. plot::
3967
+ :include-source:
3968
+ :nofigs:
3969
+
3970
+ from qiskit import QuantumCircuit
3971
+
3972
+ # Create a new circuit with two qubits and one classical bit
3973
+ qc = QuantumCircuit(2, 1)
3974
+ print("Number of classical bits:", qc.num_clbits)
3975
+
3976
+ .. code-block:: text
3977
+
3978
+ Number of classical bits: 1
3979
+
3980
+
3981
+ """
3691
3982
  return self._data.num_clbits
3692
3983
 
3693
3984
  # The stringified return type is because OrderedDict can't be subscripted before Python 3.9, and
@@ -3889,7 +4180,7 @@ class QuantumCircuit:
3889
4180
  def _create_creg(self, length: int, name: str) -> ClassicalRegister:
3890
4181
  """Creates a creg, checking if ClassicalRegister with same name exists"""
3891
4182
  if name in [creg.name for creg in self.cregs]:
3892
- new_creg = ClassicalRegister(length, name=f"{name}{ClassicalRegister.instance_count}")
4183
+ new_creg = ClassicalRegister._new_with_prefix(length, name)
3893
4184
  else:
3894
4185
  new_creg = ClassicalRegister(length, name)
3895
4186
  return new_creg
@@ -3897,7 +4188,7 @@ class QuantumCircuit:
3897
4188
  def _create_qreg(self, length: int, name: str) -> QuantumRegister:
3898
4189
  """Creates a qreg, checking if QuantumRegister with same name exists"""
3899
4190
  if name in [qreg.name for qreg in self.qregs]:
3900
- new_qreg = QuantumRegister(length, name=f"{name}{QuantumRegister.instance_count}")
4191
+ new_qreg = QuantumRegister._new_with_prefix(length, name)
3901
4192
  else:
3902
4193
  new_qreg = QuantumRegister(length, name)
3903
4194
  return new_qreg
@@ -4251,7 +4542,41 @@ class QuantumCircuit:
4251
4542
 
4252
4543
  @property
4253
4544
  def global_phase(self) -> ParameterValueType:
4254
- """The global phase of the current circuit scope in radians."""
4545
+ """The global phase of the current circuit scope in radians.
4546
+
4547
+ Example:
4548
+
4549
+ .. plot::
4550
+ :include-source:
4551
+ :nofigs:
4552
+ :context: reset
4553
+
4554
+ from qiskit import QuantumCircuit
4555
+
4556
+ circuit = QuantumCircuit(2)
4557
+ circuit.h(0)
4558
+ circuit.cx(0, 1)
4559
+ print(circuit.global_phase)
4560
+
4561
+ .. code-block:: text
4562
+
4563
+ 0.0
4564
+
4565
+ .. plot::
4566
+ :include-source:
4567
+ :nofigs:
4568
+ :context:
4569
+
4570
+ from numpy import pi
4571
+
4572
+ circuit.global_phase = pi/4
4573
+ print(circuit.global_phase)
4574
+
4575
+ .. code-block:: text
4576
+
4577
+ 0.7853981633974483
4578
+ """
4579
+
4255
4580
  if self._control_flow_scopes:
4256
4581
  return self._control_flow_scopes[-1].global_phase
4257
4582
  return self._data.global_phase
@@ -6951,7 +7276,7 @@ class QuantumCircuit:
6951
7276
  Raises:
6952
7277
  CircuitError: if ``self`` is a not-yet scheduled circuit.
6953
7278
  """
6954
- if self.duration is None:
7279
+ if self._duration is None:
6955
7280
  # circuit has only delays, this is kind of scheduled
6956
7281
  for instruction in self._data:
6957
7282
  if not isinstance(instruction.operation, Delay):
@@ -6993,7 +7318,7 @@ class QuantumCircuit:
6993
7318
  Raises:
6994
7319
  CircuitError: if ``self`` is a not-yet scheduled circuit.
6995
7320
  """
6996
- if self.duration is None:
7321
+ if self._duration is None:
6997
7322
  # circuit has only delays, this is kind of scheduled
6998
7323
  for instruction in self._data:
6999
7324
  if not isinstance(instruction.operation, Delay):
@@ -7004,7 +7329,7 @@ class QuantumCircuit:
7004
7329
 
7005
7330
  qubits = [self.qubits[q] if isinstance(q, int) else q for q in qubits]
7006
7331
 
7007
- stops = {q: self.duration for q in qubits}
7332
+ stops = {q: self._duration for q in qubits}
7008
7333
  dones = {q: False for q in qubits}
7009
7334
  for instruction in reversed(self._data):
7010
7335
  for q in qubits: