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.
- qiskit/VERSION.txt +1 -1
- qiskit/_accelerate.abi3.so +0 -0
- qiskit/assembler/__init__.py +5 -10
- qiskit/circuit/__init__.py +21 -153
- qiskit/circuit/_classical_resource_map.py +3 -0
- qiskit/circuit/classical/expr/__init__.py +1 -1
- qiskit/circuit/classical/types/__init__.py +5 -4
- qiskit/circuit/classicalfunction/__init__.py +9 -0
- qiskit/circuit/library/__init__.py +3 -19
- qiskit/circuit/library/data_preparation/pauli_feature_map.py +1 -1
- qiskit/circuit/library/n_local/two_local.py +1 -1
- qiskit/circuit/library/standard_gates/x.py +2 -0
- qiskit/circuit/parameterexpression.py +3 -0
- qiskit/circuit/parametervector.py +22 -16
- qiskit/circuit/quantumcircuit.py +1100 -200
- qiskit/converters/__init__.py +17 -2
- qiskit/dagcircuit/dagcircuit.py +8 -1
- qiskit/passmanager/passmanager.py +11 -11
- qiskit/primitives/__init__.py +15 -9
- qiskit/primitives/containers/__init__.py +1 -0
- qiskit/primitives/containers/bit_array.py +6 -2
- qiskit/primitives/containers/shape.py +3 -3
- qiskit/providers/__init__.py +49 -17
- qiskit/providers/backend.py +0 -6
- qiskit/providers/basic_provider/__init__.py +2 -23
- qiskit/providers/fake_provider/__init__.py +1 -1
- qiskit/providers/fake_provider/generic_backend_v2.py +5 -0
- qiskit/providers/models/__init__.py +2 -2
- qiskit/pulse/builder.py +2 -2
- qiskit/pulse/schedule.py +3 -3
- qiskit/qasm2/parse.py +8 -0
- qiskit/qasm3/exporter.py +2 -2
- qiskit/qobj/converters/pulse_instruction.py +6 -6
- qiskit/qpy/__init__.py +60 -62
- qiskit/qpy/binary_io/value.py +1 -1
- qiskit/quantum_info/operators/symplectic/pauli.py +18 -13
- qiskit/quantum_info/operators/symplectic/sparse_pauli_op.py +8 -4
- qiskit/result/__init__.py +6 -0
- qiskit/scheduler/__init__.py +10 -1
- qiskit/scheduler/methods/__init__.py +1 -8
- qiskit/synthesis/__init__.py +1 -6
- qiskit/synthesis/discrete_basis/generate_basis_approximations.py +1 -1
- qiskit/synthesis/discrete_basis/solovay_kitaev.py +22 -12
- qiskit/transpiler/__init__.py +5 -5
- qiskit/transpiler/layout.py +3 -3
- qiskit/transpiler/passes/__init__.py +4 -2
- qiskit/transpiler/passes/basis/basis_translator.py +2 -2
- qiskit/transpiler/passes/layout/vf2_layout.py +10 -4
- qiskit/transpiler/passes/layout/vf2_utils.py +2 -2
- qiskit/transpiler/passes/optimization/collect_cliffords.py +6 -15
- qiskit/transpiler/passes/routing/commuting_2q_gate_routing/commuting_2q_gate_router.py +8 -1
- qiskit/transpiler/passes/routing/commuting_2q_gate_routing/pauli_2q_evolution_commutation.py +5 -1
- qiskit/transpiler/passes/routing/star_prerouting.py +5 -5
- qiskit/transpiler/passes/synthesis/unitary_synthesis.py +3 -0
- qiskit/transpiler/preset_passmanagers/__init__.py +29 -3
- qiskit/transpiler/target.py +1 -1
- qiskit/utils/__init__.py +3 -2
- qiskit/utils/parallel.py +24 -15
- qiskit/visualization/bloch.py +44 -1
- qiskit/visualization/dag_visualization.py +10 -3
- qiskit/visualization/gate_map.py +9 -1
- qiskit/visualization/pass_manager_visualization.py +9 -9
- qiskit/visualization/pulse_v2/device_info.py +58 -31
- {qiskit-1.1.0rc1.dist-info → qiskit-1.1.2.dist-info}/METADATA +18 -18
- {qiskit-1.1.0rc1.dist-info → qiskit-1.1.2.dist-info}/RECORD +69 -69
- {qiskit-1.1.0rc1.dist-info → qiskit-1.1.2.dist-info}/WHEEL +1 -1
- {qiskit-1.1.0rc1.dist-info → qiskit-1.1.2.dist-info}/LICENSE.txt +0 -0
- {qiskit-1.1.0rc1.dist-info → qiskit-1.1.2.dist-info}/entry_points.txt +0 -0
- {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.
|
1
|
+
1.1.2
|
qiskit/_accelerate.abi3.so
CHANGED
Binary file
|
qiskit/assembler/__init__.py
CHANGED
@@ -17,23 +17,18 @@ Circuit and Schedule Assembler (:mod:`qiskit.assembler`)
|
|
17
17
|
|
18
18
|
.. currentmodule:: qiskit.assembler
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
Functions
|
21
|
+
=========
|
22
22
|
|
23
|
-
.. autofunction:: assemble_circuits
|
24
23
|
|
25
|
-
|
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
|
-
|
36
|
-
|
30
|
+
Classes
|
31
|
+
=======
|
37
32
|
|
38
33
|
.. autosummary::
|
39
34
|
:toctree: ../stubs/
|
qiskit/circuit/__init__.py
CHANGED
@@ -203,8 +203,8 @@ virtual qubit
|
|
203
203
|
|
204
204
|
.. _circuit-module-api:
|
205
205
|
|
206
|
-
API overview of
|
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
|
-
..
|
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
|
-
|
604
|
-
|
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
|
-
|
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
|
-
|
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.
|
839
|
-
field, and may assume that these are numeric
|
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
|
51
|
-
only in manipulations of the expression tree;
|
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
|
-
|
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
|
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", "
|
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
|
81
|
+
return iter(self.params)
|
89
82
|
|
90
83
|
def __len__(self):
|
91
|
-
return self.
|
84
|
+
return len(self._params)
|
92
85
|
|
93
86
|
def __str__(self):
|
94
|
-
return f"{self.name}, {[str(item) for item in self.params
|
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
|
-
|
103
|
-
|
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
|
-
|
119
|
+
else:
|
120
|
+
del self._params[length:]
|