qiskit 1.1.0rc1__cp38-abi3-macosx_10_9_universal2.whl → 1.1.2__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 (69) hide show
  1. qiskit/VERSION.txt +1 -1
  2. qiskit/_accelerate.abi3.so +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
qiskit/VERSION.txt CHANGED
@@ -1 +1 @@
1
- 1.1.0rc1
1
+ 1.1.2
Binary file
@@ -17,23 +17,18 @@ Circuit and Schedule Assembler (:mod:`qiskit.assembler`)
17
17
 
18
18
  .. currentmodule:: qiskit.assembler
19
19
 
20
- Circuit Assembler
21
- =================
20
+ Functions
21
+ =========
22
22
 
23
- .. autofunction:: assemble_circuits
24
23
 
25
- Schedule Assembler
26
- ==================
24
+ .. autofunction:: assemble_circuits
27
25
 
28
26
  .. autofunction:: assemble_schedules
29
27
 
30
- Disassembler
31
- ============
32
-
33
28
  .. autofunction:: disassemble
34
29
 
35
- RunConfig
36
- =========
30
+ Classes
31
+ =======
37
32
 
38
33
  .. autosummary::
39
34
  :toctree: ../stubs/
@@ -203,8 +203,8 @@ virtual qubit
203
203
 
204
204
  .. _circuit-module-api:
205
205
 
206
- API overview of :mod:`qiskit.circuit`
207
- =====================================
206
+ API overview of qiskit.circuit
207
+ ==============================
208
208
 
209
209
  All objects here are described in more detail, and in their greater context in the following
210
210
  sections. This section provides an overview of the API elements documented here.
@@ -321,16 +321,6 @@ an abstract circuit or a physical circuit. There is much more information about
321
321
  :class:`QuantumCircuit` class itself and the multitude of available methods on it in its class
322
322
  documentation.
323
323
 
324
- ..
325
- TODO: the intention is to replace this `autosummary` directive with a proper entry in the API
326
- toctree once the `QuantumCircuit` class-level documentation has been completely rewritten into
327
- more of this style. For now, this just ensures it gets *any* page generated.
328
-
329
- .. autosummary::
330
- :toctree: ../stubs/
331
-
332
- QuantumCircuit
333
-
334
324
  Internally, a :class:`QuantumCircuit` contains the qubits, classical bits, compile-time parameters,
335
325
  real-time variables, and other tracking information about the data it acts on and how it is
336
326
  parametrized. It then contains a sequence of :class:`CircuitInstruction`\ s, which contain
@@ -390,7 +380,7 @@ hardware.
390
380
  Circuits track registers, but registers themselves impart almost no behavioral differences on
391
381
  circuits. The only exception is that :class:`ClassicalRegister`\ s can be implicitly cast to
392
382
  unsigned integers for use in conditional comparisons of :ref:`control flow operations
393
- <circuit-control-flow>`.
383
+ <circuit-control-flow-repr>`.
394
384
 
395
385
  Classical registers and bits were the original way of representing classical data in Qiskit, and
396
386
  remain the most supported currently. Longer term, the data model is moving towards a more complete
@@ -433,6 +423,8 @@ methods to perform post-append mutations on instructions (which *will* be propag
433
423
  circuit), but these are now discouraged and you should use the alternatives noted in those methods.
434
424
 
435
425
 
426
+ .. _circuit-operations-instructions:
427
+
436
428
  Operations, instructions and gates
437
429
  ----------------------------------
438
430
 
@@ -598,17 +590,14 @@ The :class:`Store` instruction is particularly special, in that it allows writin
598
590
  Real-time classical computation
599
591
  -------------------------------
600
592
 
601
- .. note::
593
+ .. seealso::
594
+ :mod:`qiskit.circuit.classical`
595
+ Module-level documentation for how the variable-, expression- and type-systems work, the
596
+ objects used to represent them, and the classical operations available.
602
597
 
603
- The primary documentation for real-time classical computation is in the module-level
604
- documentation of :mod:`qiskit.circuit.classical`.
605
-
606
- You might also want to read about the circuit methods for working with real-time variables on
607
- the :class:`QuantumCircuit` class page.
608
-
609
- ..
610
- TODO: write a section in the QuantumCircuit-level guide about real-time-variable methods and
611
- cross-ref to it.
598
+ :ref:`circuit-real-time-methods`
599
+ The :class:`QuantumCircuit` methods for working with these variables in the context of a
600
+ single circuit.
612
601
 
613
602
  Qiskit has rudimentary low-level support for representing real-time classical computations, which
614
603
  happen during the QPU execution and affect the results. We are still relatively early into hardware
@@ -674,7 +663,7 @@ avoid you needing to come up with many names), you can use the convenience const
674
663
 
675
664
  ParameterVector
676
665
 
677
- .. _circuit-control-flow:
666
+ .. _circuit-control-flow-repr:
678
667
 
679
668
  Control flow in circuits
680
669
  ------------------------
@@ -718,11 +707,8 @@ that affect the flow of control when within loops. These correspond to typical
718
707
  The classes representations are documented here, but please note that manually constructing
719
708
  these classes is a low-level operation that we do not expect users to need to do frequently.
720
709
 
721
- ..
722
- TODO: make this below statement valid, and reinsert.
723
-
724
- Users should read :ref:`circuit-creating-control-flow` for the recommended workflows for
725
- building control-flow-enabled circuits.
710
+ Users should read :ref:`circuit-control-flow-methods` for the recommended workflows for building
711
+ control-flow-enabled circuits.
726
712
 
727
713
  Since :class:`ControlFlowOp` subclasses are also :class:`Instruction` subclasses, this means that
728
714
  the way they are stored in :class:`CircuitInstruction` instances has them "applied" to a sequence of
@@ -772,11 +758,8 @@ them to the block using :meth:`~QuantumCircuit.add_capture` (or the ``captures``
772
758
  argument), but user code will typically use the control-flow builder interface, which handles this
773
759
  automatically.
774
760
 
775
- ..
776
- TODO: make the below sentence valid, then re-insert.
777
-
778
- Consult :ref:`the control-flow construction documentation <circuit-creating-control-flow>` for
779
- more information on how to build circuits with control flow.
761
+ Consult :ref:`the control-flow construction documentation <circuit-control-flow-methods>` for more
762
+ information on how to build circuits with control flow.
780
763
 
781
764
  .. _circuit-custom-gates:
782
765
 
@@ -833,10 +816,11 @@ method <https://numpy.org/devdocs/user/basics.interoperability.html#the-array-me
833
816
  ``__array__``. This is used by :meth:`Gate.to_matrix`, and has the signature:
834
817
 
835
818
  .. currentmodule:: None
836
- .. py:method:: __array__(dtype=None, copy=None)
819
+ .. py:method:: object.__array__(dtype=None, copy=None)
837
820
 
838
- Return a Numpy array representing the gate. This can use the gate's :attr:`~Instruction.params`
839
- field, and may assume that these are numeric values (assuming the subclass expects that) and not
821
+ Return a Numpy array representing the gate. This can use the gate's
822
+ :attr:`~qiskit.circuit.Instruction.params` field, and may assume that these are numeric
823
+ values (assuming the subclass expects that) and not
840
824
  :ref:`compile-time parameters <circuit-compile-time-parameters>`.
841
825
 
842
826
  For greatest efficiency, the returned array should default to a dtype of :class:`complex`.
@@ -920,122 +904,6 @@ After this, for the duration of the Python interpreter session, translators like
920
904
  Working with circuit-level objects
921
905
  ==================================
922
906
 
923
- Circuit properties
924
- ------------------
925
-
926
- ..
927
- TODO: rewrite this section and move it into the `QuantumCircuit` class-level overview of its
928
- functions.
929
-
930
- When constructing quantum circuits, there are several properties that help quantify
931
- the "size" of the circuits, and their ability to be run on a noisy quantum device.
932
- Some of these, like number of qubits, are straightforward to understand, while others
933
- like depth and number of tensor components require a bit more explanation. Here we will
934
- explain all of these properties, and, in preparation for understanding how circuits change
935
- when run on actual devices, highlight the conditions under which they change.
936
-
937
- Consider the following circuit:
938
-
939
- .. plot::
940
- :include-source:
941
-
942
- from qiskit import QuantumCircuit
943
- qc = QuantumCircuit(12)
944
- for idx in range(5):
945
- qc.h(idx)
946
- qc.cx(idx, idx+5)
947
-
948
- qc.cx(1, 7)
949
- qc.x(8)
950
- qc.cx(1, 9)
951
- qc.x(7)
952
- qc.cx(1, 11)
953
- qc.swap(6, 11)
954
- qc.swap(6, 9)
955
- qc.swap(6, 10)
956
- qc.x(6)
957
- qc.draw('mpl')
958
-
959
- From the plot, it is easy to see that this circuit has 12 qubits, and a collection of
960
- Hadamard, CNOT, X, and SWAP gates. But how to quantify this programmatically? Because we
961
- can do single-qubit gates on all the qubits simultaneously, the number of qubits in this
962
- circuit is equal to the **width** of the circuit:
963
-
964
- .. code-block::
965
-
966
- qc.width()
967
-
968
- .. parsed-literal::
969
-
970
- 12
971
-
972
- We can also just get the number of qubits directly:
973
-
974
- .. code-block::
975
-
976
- qc.num_qubits
977
-
978
- .. parsed-literal::
979
-
980
- 12
981
-
982
- .. important::
983
-
984
- For a quantum circuit composed from just qubits, the circuit width is equal
985
- to the number of qubits. This is the definition used in quantum computing. However,
986
- for more complicated circuits with classical registers, and classically controlled gates,
987
- this equivalence breaks down. As such, from now on we will not refer to the number of
988
- qubits in a quantum circuit as the width.
989
-
990
-
991
- It is also straightforward to get the number and type of the gates in a circuit using
992
- :meth:`QuantumCircuit.count_ops`:
993
-
994
- .. code-block::
995
-
996
- qc.count_ops()
997
-
998
- .. parsed-literal::
999
-
1000
- OrderedDict([('cx', 8), ('h', 5), ('x', 3), ('swap', 3)])
1001
-
1002
- We can also get just the raw count of operations by computing the circuits
1003
- :meth:`QuantumCircuit.size`:
1004
-
1005
- .. code-block::
1006
-
1007
- qc.size()
1008
-
1009
- .. parsed-literal::
1010
-
1011
- 19
1012
-
1013
- A particularly important circuit property is known as the circuit **depth**. The depth
1014
- of a quantum circuit is a measure of how many "layers" of quantum gates, executed in
1015
- parallel, it takes to complete the computation defined by the circuit. Because quantum
1016
- gates take time to implement, the depth of a circuit roughly corresponds to the amount of
1017
- time it takes the quantum computer to execute the circuit. Thus, the depth of a circuit
1018
- is one important quantity used to measure if a quantum circuit can be run on a device.
1019
-
1020
- The depth of a quantum circuit has a mathematical definition as the longest path in a
1021
- directed acyclic graph (DAG). However, such a definition is a bit hard to grasp, even for
1022
- experts. Fortunately, the depth of a circuit can be easily understood by anyone familiar
1023
- with playing `Tetris <https://en.wikipedia.org/wiki/Tetris>`_. Lets see how to compute this
1024
- graphically:
1025
-
1026
- .. image:: /source_images/depth.gif
1027
-
1028
-
1029
- We can verify our graphical result using :meth:`QuantumCircuit.depth`:
1030
-
1031
- .. code-block::
1032
-
1033
- qc.depth()
1034
-
1035
- .. parsed-literal::
1036
-
1037
- 9
1038
-
1039
907
  .. _circuit-abstract-to-physical:
1040
908
 
1041
909
  Converting abstract circuits to physical circuits
@@ -143,3 +143,6 @@ class VariableMapper(expr.ExprVisitor[expr.Expr]):
143
143
 
144
144
  def visit_cast(self, node, /):
145
145
  return expr.Cast(node.operand.accept(self), node.type, implicit=node.implicit)
146
+
147
+ def visit_index(self, node, /):
148
+ return expr.Index(node.target.accept(self), node.index.accept(self), node.type)
@@ -43,7 +43,7 @@ The base for dynamic variables is the :class:`Var`, which can be either an arbit
43
43
  real-time variable, or a wrapper around a :class:`.Clbit` or :class:`.ClassicalRegister`.
44
44
 
45
45
  .. autoclass:: Var
46
- :members: var, name
46
+ :members: var, name, new
47
47
 
48
48
  Similarly, literals used in expressions (such as integers) should be lifted to :class:`Value` nodes
49
49
  with associated types.
@@ -47,13 +47,14 @@ type, which may be slightly different to the 'classical' programming languages y
47
47
  Working with types
48
48
  ==================
49
49
 
50
- There are some functions on these types exposed here as well. These are mostly expected to be used
51
- only in manipulations of the expression tree; users who are building expressions using the
50
+ There are some additional functions on these types documented in the subsequent sections.
51
+ These are mostly expected to be used only in manipulations of the expression tree;
52
+ users who are building expressions using the
52
53
  :ref:`user-facing construction interface <circuit-classical-expressions-expr-construction>` should
53
54
  not need to use these.
54
55
 
55
56
  Partial ordering of types
56
- -------------------------
57
+ =========================
57
58
 
58
59
  The type system is equipped with a partial ordering, where :math:`a < b` is interpreted as
59
60
  ":math:`a` is a strict subtype of :math:`b`". Note that the partial ordering is a subset of the
@@ -78,7 +79,7 @@ Some helper methods are then defined in terms of this low-level :func:`order` pr
78
79
 
79
80
 
80
81
  Casting between types
81
- ---------------------
82
+ =====================
82
83
 
83
84
  It is common to need to cast values of one type to another type. The casting rules for this are
84
85
  embedded into the :mod:`types` module. You can query the casting kinds using :func:`cast_kind`:
@@ -51,6 +51,14 @@ QuantumCircuit:
51
51
  Following Qiskit's little-endian bit ordering convention, the left-most bit (``a``) is the most
52
52
  significant bit and the right-most bit (``d``) is the least significant bit.
53
53
 
54
+ .. warning::
55
+
56
+ The functionality of `qiskit.circuit.classicalfunction` requires `tweedledum`,
57
+ which isn't available on all platforms (up to Python version 3.11).
58
+ See `tweedledum installation guide
59
+ <https://github.com/boschmitt/tweedledum/tree/master?tab=readme-ov-file#installation>`_
60
+ for more details.
61
+
54
62
  Supplementary Information
55
63
  =========================
56
64
 
@@ -81,6 +89,7 @@ classical_function
81
89
 
82
90
  Decorator for a classical function that returns a `ClassicalFunction` object.
83
91
 
92
+ .. autofunction:: classical_function
84
93
 
85
94
  ClassicalFunction
86
95
  -----------------
@@ -129,35 +129,19 @@ For example:
129
129
  Standard Directives
130
130
  ===================
131
131
 
132
- ..
133
- This summary table deliberately does not generate toctree entries; these directives are "owned"
134
- by ``qiskit.circuit``.
135
-
136
132
  Directives are operations to the quantum stack that are meant to be interpreted by the backend or
137
133
  the transpiler. In general, the transpiler or backend might optionally ignore them if there is no
138
134
  implementation for them.
139
135
 
140
- ..
141
- This summary table deliberately does not generate toctree entries; these directives are "owned"
142
- by ``qiskit.circuit``.
143
-
144
- .. autosummary::
145
-
146
- Barrier
136
+ * :class:`qiskit.circuit.Barrier`
147
137
 
148
138
  Standard Operations
149
139
  ===================
150
140
 
151
141
  Operations are non-reversible changes in the quantum state of the circuit.
152
142
 
153
- ..
154
- This summary table deliberately does not generate toctree entries; these directives are "owned"
155
- by ``qiskit.circuit``.
156
-
157
- .. autosummary::
158
-
159
- Measure
160
- Reset
143
+ * :class:`qiskit.circuit.Measure`
144
+ * :class:`qiskit.circuit.Reset`
161
145
 
162
146
  Generalized Gates
163
147
  =================
@@ -97,7 +97,7 @@ class PauliFeatureMap(NLocal):
97
97
  >>> from qiskit.circuit.library import EfficientSU2
98
98
  >>> prep = PauliFeatureMap(3, reps=3, paulis=['Z', 'YY', 'ZXZ'])
99
99
  >>> wavefunction = EfficientSU2(3)
100
- >>> classifier = prep.compose(wavefunction
100
+ >>> classifier = prep.compose(wavefunction)
101
101
  >>> classifier.num_parameters
102
102
  27
103
103
  >>> classifier.count_ops()
@@ -110,7 +110,7 @@ class TwoLocal(NLocal):
110
110
 
111
111
  >>> entangler_map = [[0, 3], [0, 2]] # entangle the first and last two-way
112
112
  >>> two = TwoLocal(4, [], 'cry', entangler_map, reps=1)
113
- >>> circuit = two + two
113
+ >>> circuit = two.compose(two)
114
114
  >>> print(circuit.decompose().draw()) # note, that the parameters are the same!
115
115
  q_0: ─────■───────────■───────────■───────────■──────
116
116
  │ │ │ │
@@ -21,6 +21,7 @@ from qiskit.circuit.quantumregister import QuantumRegister
21
21
  from qiskit.circuit._utils import _ctrl_state_to_int, with_gate_array, with_controlled_gate_array
22
22
 
23
23
  _X_ARRAY = [[0, 1], [1, 0]]
24
+ _SX_ARRAY = [[0.5 + 0.5j, 0.5 - 0.5j], [0.5 - 0.5j, 0.5 + 0.5j]]
24
25
 
25
26
 
26
27
  @with_gate_array(_X_ARRAY)
@@ -562,6 +563,7 @@ class RCCXGate(SingletonGate):
562
563
  return isinstance(other, RCCXGate)
563
564
 
564
565
 
566
+ @with_controlled_gate_array(_SX_ARRAY, num_ctrl_qubits=3, cached_states=(7,))
565
567
  class C3SXGate(SingletonControlledGate):
566
568
  """The 3-qubit controlled sqrt-X gate.
567
569
 
@@ -439,6 +439,9 @@ class ParameterExpression:
439
439
  raise TypeError("could not cast expression to int") from exc
440
440
 
441
441
  def __hash__(self):
442
+ if not self._parameter_symbols:
443
+ # For fully bound expressions, fall back to the underlying value
444
+ return hash(self.numeric())
442
445
  return hash((self._parameter_keys, self._symbol_expr))
443
446
 
444
447
  def __copy__(self):
@@ -50,11 +50,10 @@ class ParameterVectorElement(Parameter):
50
50
  class ParameterVector:
51
51
  """ParameterVector class to quickly generate lists of parameters."""
52
52
 
53
- __slots__ = ("_name", "_params", "_size", "_root_uuid")
53
+ __slots__ = ("_name", "_params", "_root_uuid")
54
54
 
55
55
  def __init__(self, name, length=0):
56
56
  self._name = name
57
- self._size = length
58
57
  self._root_uuid = uuid4()
59
58
  root_uuid_int = self._root_uuid.int
60
59
  self._params = [
@@ -76,32 +75,38 @@ class ParameterVector:
76
75
  return self._params.index(value)
77
76
 
78
77
  def __getitem__(self, key):
79
- if isinstance(key, slice):
80
- start, stop, step = key.indices(self._size)
81
- return self.params[start:stop:step]
82
-
83
- if key > self._size:
84
- raise IndexError(f"Index out of range: {key} > {self._size}")
85
78
  return self.params[key]
86
79
 
87
80
  def __iter__(self):
88
- return iter(self.params[: self._size])
81
+ return iter(self.params)
89
82
 
90
83
  def __len__(self):
91
- return self._size
84
+ return len(self._params)
92
85
 
93
86
  def __str__(self):
94
- return f"{self.name}, {[str(item) for item in self.params[: self._size]]}"
87
+ return f"{self.name}, {[str(item) for item in self.params]}"
95
88
 
96
89
  def __repr__(self):
97
90
  return f"{self.__class__.__name__}(name={self.name}, length={len(self)})"
98
91
 
99
92
  def resize(self, length):
100
- """Resize the parameter vector.
101
-
102
- If necessary, new elements are generated. If length is smaller than before, the
103
- previous elements are cached and not re-generated if the vector is enlarged again.
93
+ """Resize the parameter vector. If necessary, new elements are generated.
94
+
95
+ Note that the UUID of each :class:`.Parameter` element will be generated
96
+ deterministically given the root UUID of the ``ParameterVector`` and the index
97
+ of the element. In particular, if a ``ParameterVector`` is resized to
98
+ be smaller and then later resized to be larger, the UUID of the later
99
+ generated element at a given index will be the same as the UUID of the
100
+ previous element at that index.
104
101
  This is to ensure that the parameter instances do not change.
102
+
103
+ >>> from qiskit.circuit import ParameterVector
104
+ >>> pv = ParameterVector("theta", 20)
105
+ >>> elt_19 = pv[19]
106
+ >>> rv.resize(10)
107
+ >>> rv.resize(20)
108
+ >>> pv[19] == elt_19
109
+ True
105
110
  """
106
111
  if length > len(self._params):
107
112
  root_uuid_int = self._root_uuid.int
@@ -111,4 +116,5 @@ class ParameterVector:
111
116
  for i in range(len(self._params), length)
112
117
  ]
113
118
  )
114
- self._size = length
119
+ else:
120
+ del self._params[length:]