qiskit 2.0.2__cp39-abi3-macosx_11_0_arm64.whl → 2.1.0rc1__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.
- qiskit/VERSION.txt +1 -1
- qiskit/__init__.py +19 -1
- qiskit/_accelerate.abi3.so +0 -0
- qiskit/circuit/__init__.py +13 -21
- qiskit/circuit/_add_control.py +57 -31
- qiskit/circuit/_classical_resource_map.py +4 -0
- qiskit/circuit/annotation.py +404 -0
- qiskit/circuit/classical/expr/__init__.py +1 -1
- qiskit/circuit/classical/expr/expr.py +104 -446
- qiskit/circuit/classical/expr/visitors.py +6 -0
- qiskit/circuit/classical/types/types.py +7 -130
- qiskit/circuit/controlflow/box.py +32 -7
- qiskit/circuit/delay.py +11 -9
- qiskit/circuit/library/arithmetic/adders/adder.py +5 -5
- qiskit/circuit/library/arithmetic/multipliers/multiplier.py +3 -3
- qiskit/circuit/library/arithmetic/piecewise_chebyshev.py +7 -3
- qiskit/circuit/library/arithmetic/piecewise_linear_pauli_rotations.py +23 -15
- qiskit/circuit/library/arithmetic/piecewise_polynomial_pauli_rotations.py +22 -14
- qiskit/circuit/library/arithmetic/quadratic_form.py +6 -0
- qiskit/circuit/library/arithmetic/weighted_adder.py +43 -24
- qiskit/circuit/library/basis_change/qft.py +2 -2
- qiskit/circuit/library/blueprintcircuit.py +6 -0
- qiskit/circuit/library/boolean_logic/inner_product.py +2 -2
- qiskit/circuit/library/boolean_logic/quantum_and.py +2 -2
- qiskit/circuit/library/boolean_logic/quantum_or.py +3 -3
- qiskit/circuit/library/boolean_logic/quantum_xor.py +2 -2
- qiskit/circuit/library/data_preparation/_z_feature_map.py +2 -2
- qiskit/circuit/library/data_preparation/_zz_feature_map.py +2 -2
- qiskit/circuit/library/data_preparation/pauli_feature_map.py +2 -2
- qiskit/circuit/library/fourier_checking.py +2 -2
- qiskit/circuit/library/generalized_gates/diagonal.py +5 -1
- qiskit/circuit/library/generalized_gates/gms.py +5 -1
- qiskit/circuit/library/generalized_gates/linear_function.py +2 -2
- qiskit/circuit/library/generalized_gates/permutation.py +5 -1
- qiskit/circuit/library/generalized_gates/uc.py +1 -1
- qiskit/circuit/library/generalized_gates/unitary.py +21 -2
- qiskit/circuit/library/graph_state.py +2 -2
- qiskit/circuit/library/grover_operator.py +2 -2
- qiskit/circuit/library/hidden_linear_function.py +2 -2
- qiskit/circuit/library/iqp.py +2 -2
- qiskit/circuit/library/n_local/efficient_su2.py +2 -2
- qiskit/circuit/library/n_local/evolved_operator_ansatz.py +1 -1
- qiskit/circuit/library/n_local/excitation_preserving.py +7 -9
- qiskit/circuit/library/n_local/n_local.py +4 -3
- qiskit/circuit/library/n_local/pauli_two_design.py +2 -2
- qiskit/circuit/library/n_local/real_amplitudes.py +2 -2
- qiskit/circuit/library/n_local/two_local.py +2 -2
- qiskit/circuit/library/overlap.py +2 -2
- qiskit/circuit/library/pauli_evolution.py +3 -2
- qiskit/circuit/library/phase_estimation.py +2 -2
- qiskit/circuit/library/standard_gates/dcx.py +11 -12
- qiskit/circuit/library/standard_gates/ecr.py +21 -24
- qiskit/circuit/library/standard_gates/equivalence_library.py +232 -96
- qiskit/circuit/library/standard_gates/global_phase.py +5 -6
- qiskit/circuit/library/standard_gates/h.py +22 -45
- qiskit/circuit/library/standard_gates/i.py +1 -1
- qiskit/circuit/library/standard_gates/iswap.py +13 -31
- qiskit/circuit/library/standard_gates/p.py +19 -26
- qiskit/circuit/library/standard_gates/r.py +11 -17
- qiskit/circuit/library/standard_gates/rx.py +21 -45
- qiskit/circuit/library/standard_gates/rxx.py +7 -22
- qiskit/circuit/library/standard_gates/ry.py +21 -39
- qiskit/circuit/library/standard_gates/ryy.py +13 -28
- qiskit/circuit/library/standard_gates/rz.py +18 -35
- qiskit/circuit/library/standard_gates/rzx.py +7 -22
- qiskit/circuit/library/standard_gates/rzz.py +7 -19
- qiskit/circuit/library/standard_gates/s.py +44 -39
- qiskit/circuit/library/standard_gates/swap.py +25 -38
- qiskit/circuit/library/standard_gates/sx.py +34 -41
- qiskit/circuit/library/standard_gates/t.py +18 -27
- qiskit/circuit/library/standard_gates/u.py +8 -24
- qiskit/circuit/library/standard_gates/u1.py +28 -52
- qiskit/circuit/library/standard_gates/u2.py +9 -9
- qiskit/circuit/library/standard_gates/u3.py +24 -40
- qiskit/circuit/library/standard_gates/x.py +190 -336
- qiskit/circuit/library/standard_gates/xx_minus_yy.py +12 -50
- qiskit/circuit/library/standard_gates/xx_plus_yy.py +13 -52
- qiskit/circuit/library/standard_gates/y.py +19 -23
- qiskit/circuit/library/standard_gates/z.py +31 -38
- qiskit/circuit/parameter.py +14 -5
- qiskit/circuit/parameterexpression.py +109 -75
- qiskit/circuit/quantumcircuit.py +168 -98
- qiskit/circuit/quantumcircuitdata.py +1 -0
- qiskit/circuit/random/__init__.py +37 -2
- qiskit/circuit/random/utils.py +445 -56
- qiskit/circuit/tools/pi_check.py +5 -13
- qiskit/compiler/transpiler.py +1 -1
- qiskit/converters/circuit_to_instruction.py +2 -2
- qiskit/dagcircuit/dagnode.py +8 -3
- qiskit/primitives/__init__.py +2 -2
- qiskit/primitives/base/base_estimator.py +2 -2
- qiskit/primitives/containers/data_bin.py +0 -3
- qiskit/primitives/containers/observables_array.py +192 -108
- qiskit/primitives/primitive_job.py +29 -10
- qiskit/providers/fake_provider/generic_backend_v2.py +2 -0
- qiskit/qasm3/__init__.py +106 -12
- qiskit/qasm3/ast.py +15 -1
- qiskit/qasm3/exporter.py +59 -36
- qiskit/qasm3/printer.py +12 -0
- qiskit/qpy/__init__.py +183 -7
- qiskit/qpy/binary_io/circuits.py +256 -24
- qiskit/qpy/binary_io/parse_sympy_repr.py +5 -0
- qiskit/qpy/binary_io/schedules.py +12 -32
- qiskit/qpy/binary_io/value.py +36 -18
- qiskit/qpy/common.py +11 -3
- qiskit/qpy/formats.py +17 -1
- qiskit/qpy/interface.py +52 -12
- qiskit/qpy/type_keys.py +7 -1
- qiskit/quantum_info/__init__.py +10 -0
- qiskit/quantum_info/operators/__init__.py +1 -0
- qiskit/quantum_info/operators/symplectic/__init__.py +1 -0
- qiskit/quantum_info/operators/symplectic/clifford_circuits.py +26 -0
- qiskit/quantum_info/operators/symplectic/pauli.py +2 -2
- qiskit/quantum_info/operators/symplectic/sparse_pauli_op.py +1 -1
- qiskit/result/sampled_expval.py +3 -1
- qiskit/synthesis/__init__.py +10 -0
- qiskit/synthesis/arithmetic/__init__.py +1 -1
- qiskit/synthesis/arithmetic/adders/__init__.py +1 -0
- qiskit/synthesis/arithmetic/adders/draper_qft_adder.py +6 -2
- qiskit/synthesis/arithmetic/adders/rv_ripple_carry_adder.py +156 -0
- qiskit/synthesis/discrete_basis/generate_basis_approximations.py +14 -126
- qiskit/synthesis/discrete_basis/solovay_kitaev.py +161 -121
- qiskit/synthesis/evolution/lie_trotter.py +10 -7
- qiskit/synthesis/evolution/product_formula.py +10 -7
- qiskit/synthesis/evolution/qdrift.py +10 -7
- qiskit/synthesis/evolution/suzuki_trotter.py +10 -7
- qiskit/synthesis/multi_controlled/__init__.py +4 -0
- qiskit/synthesis/multi_controlled/mcx_synthesis.py +402 -178
- qiskit/synthesis/multi_controlled/multi_control_rotation_gates.py +14 -15
- qiskit/synthesis/qft/qft_decompose_lnn.py +7 -25
- qiskit/synthesis/unitary/qsd.py +80 -9
- qiskit/transpiler/__init__.py +19 -8
- qiskit/transpiler/instruction_durations.py +2 -20
- qiskit/transpiler/passes/__init__.py +4 -2
- qiskit/transpiler/passes/layout/dense_layout.py +26 -6
- qiskit/transpiler/passes/layout/disjoint_utils.py +1 -166
- qiskit/transpiler/passes/layout/sabre_layout.py +22 -3
- qiskit/transpiler/passes/layout/sabre_pre_layout.py +1 -1
- qiskit/transpiler/passes/layout/vf2_layout.py +49 -13
- qiskit/transpiler/passes/layout/vf2_utils.py +13 -1
- qiskit/transpiler/passes/optimization/__init__.py +1 -1
- qiskit/transpiler/passes/optimization/optimize_1q_decomposition.py +2 -1
- qiskit/transpiler/passes/optimization/optimize_clifford_t.py +68 -0
- qiskit/transpiler/passes/optimization/template_matching/template_substitution.py +3 -9
- qiskit/transpiler/passes/routing/sabre_swap.py +12 -2
- qiskit/transpiler/passes/routing/star_prerouting.py +106 -81
- qiskit/transpiler/passes/scheduling/__init__.py +1 -1
- qiskit/transpiler/passes/scheduling/alignments/check_durations.py +1 -1
- qiskit/transpiler/passes/scheduling/padding/__init__.py +1 -0
- qiskit/transpiler/passes/scheduling/padding/context_aware_dynamical_decoupling.py +876 -0
- qiskit/transpiler/passes/synthesis/__init__.py +1 -0
- qiskit/transpiler/passes/synthesis/clifford_unitary_synth_plugin.py +123 -0
- qiskit/transpiler/passes/synthesis/hls_plugins.py +472 -92
- qiskit/transpiler/passes/synthesis/solovay_kitaev_synthesis.py +27 -22
- qiskit/transpiler/passmanager_config.py +3 -0
- qiskit/transpiler/preset_passmanagers/builtin_plugins.py +149 -28
- qiskit/transpiler/preset_passmanagers/common.py +101 -0
- qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py +6 -0
- qiskit/transpiler/preset_passmanagers/level3.py +2 -2
- qiskit/utils/optionals.py +6 -5
- qiskit/visualization/circuit/_utils.py +5 -3
- qiskit/visualization/circuit/latex.py +9 -2
- qiskit/visualization/circuit/matplotlib.py +26 -4
- qiskit/visualization/circuit/qcstyle.py +9 -157
- qiskit/visualization/dag/__init__.py +13 -0
- qiskit/visualization/dag/dagstyle.py +103 -0
- qiskit/visualization/dag/styles/__init__.py +13 -0
- qiskit/visualization/dag/styles/color.json +10 -0
- qiskit/visualization/dag/styles/plain.json +5 -0
- qiskit/visualization/dag_visualization.py +169 -98
- qiskit/visualization/style.py +223 -0
- {qiskit-2.0.2.dist-info → qiskit-2.1.0rc1.dist-info}/METADATA +14 -13
- {qiskit-2.0.2.dist-info → qiskit-2.1.0rc1.dist-info}/RECORD +177 -168
- {qiskit-2.0.2.dist-info → qiskit-2.1.0rc1.dist-info}/entry_points.txt +6 -0
- qiskit/synthesis/discrete_basis/commutator_decompose.py +0 -265
- qiskit/synthesis/discrete_basis/gate_sequence.py +0 -421
- {qiskit-2.0.2.dist-info → qiskit-2.1.0rc1.dist-info}/WHEEL +0 -0
- {qiskit-2.0.2.dist-info → qiskit-2.1.0rc1.dist-info}/licenses/LICENSE.txt +0 -0
- {qiskit-2.0.2.dist-info → qiskit-2.1.0rc1.dist-info}/top_level.txt +0 -0
qiskit/circuit/quantumcircuit.py
CHANGED
@@ -16,6 +16,7 @@
|
|
16
16
|
|
17
17
|
from __future__ import annotations
|
18
18
|
|
19
|
+
import warnings
|
19
20
|
import collections.abc
|
20
21
|
import copy as _copy
|
21
22
|
|
@@ -48,7 +49,7 @@ from qiskit.circuit.instruction import Instruction
|
|
48
49
|
from qiskit.circuit.gate import Gate
|
49
50
|
from qiskit.circuit.parameter import Parameter
|
50
51
|
from qiskit.circuit.exceptions import CircuitError
|
51
|
-
from qiskit.utils import deprecate_func
|
52
|
+
from qiskit.utils import deprecate_func, deprecate_arg
|
52
53
|
from . import ( # pylint: disable=cyclic-import
|
53
54
|
Bit,
|
54
55
|
QuantumRegister,
|
@@ -80,11 +81,12 @@ from .delay import Delay
|
|
80
81
|
from .store import Store
|
81
82
|
|
82
83
|
|
83
|
-
if typing.TYPE_CHECKING:
|
84
|
-
import qiskit
|
85
|
-
from qiskit.
|
84
|
+
if typing.TYPE_CHECKING: # pylint: disable=cyclic-import
|
85
|
+
import qiskit
|
86
|
+
from qiskit.circuit import Annotation
|
87
|
+
from qiskit.transpiler.layout import TranspileLayout
|
86
88
|
from qiskit.quantum_info.operators.base_operator import BaseOperator
|
87
|
-
from qiskit.quantum_info.states.statevector import Statevector
|
89
|
+
from qiskit.quantum_info.states.statevector import Statevector
|
88
90
|
|
89
91
|
|
90
92
|
# The following types are not marked private to avoid leaking this "private/public" abstraction out
|
@@ -826,6 +828,9 @@ class QuantumCircuit:
|
|
826
828
|
a block, even though it has no operations defined. In this case, you can use the :meth:`noop`
|
827
829
|
method.
|
828
830
|
|
831
|
+
To check whether a circuit contains a :class:`.ControlFlowOp` you can use the helper method
|
832
|
+
:meth:`.QuantumCircuit.has_control_flow_op`.
|
833
|
+
|
829
834
|
..
|
830
835
|
TODO: expand the examples of the builder interface.
|
831
836
|
|
@@ -838,6 +843,7 @@ class QuantumCircuit:
|
|
838
843
|
.. automethod:: switch
|
839
844
|
.. automethod:: while_loop
|
840
845
|
.. automethod:: noop
|
846
|
+
.. automethod:: has_control_flow_op
|
841
847
|
|
842
848
|
|
843
849
|
Converting circuits to single objects
|
@@ -1099,7 +1105,7 @@ class QuantumCircuit:
|
|
1099
1105
|
self._base_name = None
|
1100
1106
|
self.name: str
|
1101
1107
|
"""A human-readable name for the circuit.
|
1102
|
-
|
1108
|
+
|
1103
1109
|
Example:
|
1104
1110
|
|
1105
1111
|
.. plot::
|
@@ -1177,7 +1183,7 @@ class QuantumCircuit:
|
|
1177
1183
|
|
1178
1184
|
Qiskit will not examine the content of this mapping, but it will pass it through the
|
1179
1185
|
transpiler and reattach it to the output, so you can track your own metadata.
|
1180
|
-
|
1186
|
+
|
1181
1187
|
Example:
|
1182
1188
|
|
1183
1189
|
.. plot::
|
@@ -2248,7 +2254,7 @@ class QuantumCircuit:
|
|
2248
2254
|
|
2249
2255
|
Remember that in the little-endian convention the leftmost operation will be at the bottom
|
2250
2256
|
of the circuit. See also
|
2251
|
-
`the docs <https://
|
2257
|
+
`the docs <https://quantum.cloud.ibm.com/docs/guides/construct-circuits>`__
|
2252
2258
|
for more information.
|
2253
2259
|
|
2254
2260
|
.. code-block:: text
|
@@ -2718,6 +2724,8 @@ class QuantumCircuit:
|
|
2718
2724
|
if copy and is_parameter:
|
2719
2725
|
operation = _copy.deepcopy(operation)
|
2720
2726
|
if isinstance(operation, ControlFlowOp):
|
2727
|
+
if operation.name == "box" and operation.unit == "expr":
|
2728
|
+
_validate_expr(circuit_scope, operation.duration)
|
2721
2729
|
# Verify that any variable bindings are valid. Control-flow ops are already enforced
|
2722
2730
|
# by the class not to contain 'input' variables.
|
2723
2731
|
if bad_captures := {
|
@@ -3591,7 +3599,7 @@ class QuantumCircuit:
|
|
3591
3599
|
parameter_map: dict[Parameter, ParameterValueType] | None = None,
|
3592
3600
|
label: str | None = None,
|
3593
3601
|
) -> Gate:
|
3594
|
-
"""Create a :class:`.Gate` out of this circuit. The circuit must act only qubits and
|
3602
|
+
"""Create a :class:`.Gate` out of this circuit. The circuit must act only on qubits and
|
3595
3603
|
contain only unitary operations.
|
3596
3604
|
|
3597
3605
|
.. seealso::
|
@@ -4819,6 +4827,11 @@ class QuantumCircuit:
|
|
4819
4827
|
|
4820
4828
|
return None if inplace else target
|
4821
4829
|
|
4830
|
+
def has_control_flow_op(self) -> bool:
|
4831
|
+
"""Checks whether the circuit has an instance of :class:`.ControlFlowOp`
|
4832
|
+
present amongst its operations."""
|
4833
|
+
return self._data.has_control_flow_op()
|
4834
|
+
|
4822
4835
|
def _unroll_param_dict(
|
4823
4836
|
self, parameter_binds: Mapping[Parameter, ParameterValueType]
|
4824
4837
|
) -> Mapping[Parameter, ParameterValueType]:
|
@@ -4904,7 +4917,7 @@ class QuantumCircuit:
|
|
4904
4917
|
Returns:
|
4905
4918
|
A handle to the instructions created.
|
4906
4919
|
"""
|
4907
|
-
return self._append_standard_gate(StandardGate.
|
4920
|
+
return self._append_standard_gate(StandardGate.H, [qubit], ())
|
4908
4921
|
|
4909
4922
|
def ch(
|
4910
4923
|
self,
|
@@ -4931,7 +4944,7 @@ class QuantumCircuit:
|
|
4931
4944
|
# if the control state is |1> use the fast Rust version of the gate
|
4932
4945
|
if ctrl_state is None or ctrl_state in ["1", 1]:
|
4933
4946
|
return self._append_standard_gate(
|
4934
|
-
StandardGate.
|
4947
|
+
StandardGate.CH, [control_qubit, target_qubit], (), label=label
|
4935
4948
|
)
|
4936
4949
|
|
4937
4950
|
from .library.standard_gates.h import CHGate
|
@@ -4954,7 +4967,7 @@ class QuantumCircuit:
|
|
4954
4967
|
Returns:
|
4955
4968
|
A handle to the instructions created.
|
4956
4969
|
"""
|
4957
|
-
return self._append_standard_gate(StandardGate.
|
4970
|
+
return self._append_standard_gate(StandardGate.I, [qubit], ())
|
4958
4971
|
|
4959
4972
|
def ms(self, theta: ParameterValueType, qubits: Sequence[QubitSpecifier]) -> InstructionSet:
|
4960
4973
|
"""Apply :class:`~qiskit.circuit.library.MSGate`.
|
@@ -4985,7 +4998,7 @@ class QuantumCircuit:
|
|
4985
4998
|
Returns:
|
4986
4999
|
A handle to the instructions created.
|
4987
5000
|
"""
|
4988
|
-
return self._append_standard_gate(StandardGate.
|
5001
|
+
return self._append_standard_gate(StandardGate.Phase, [qubit], (theta,))
|
4989
5002
|
|
4990
5003
|
def cp(
|
4991
5004
|
self,
|
@@ -5014,7 +5027,7 @@ class QuantumCircuit:
|
|
5014
5027
|
# if the control state is |1> use the fast Rust version of the gate
|
5015
5028
|
if ctrl_state is None or ctrl_state in ["1", 1]:
|
5016
5029
|
return self._append_standard_gate(
|
5017
|
-
StandardGate.
|
5030
|
+
StandardGate.CPhase, [control_qubit, target_qubit], (theta,), label=label
|
5018
5031
|
)
|
5019
5032
|
|
5020
5033
|
from .library.standard_gates.p import CPhaseGate
|
@@ -5142,7 +5155,6 @@ class QuantumCircuit:
|
|
5142
5155
|
"""
|
5143
5156
|
# pylint: disable=cyclic-import
|
5144
5157
|
from .library.standard_gates.ry import RYGate
|
5145
|
-
from .library.standard_gates.x import MCXGate
|
5146
5158
|
from qiskit.synthesis.multi_controlled import (
|
5147
5159
|
_apply_cu,
|
5148
5160
|
_apply_mcu_graycode,
|
@@ -5161,17 +5173,33 @@ class QuantumCircuit:
|
|
5161
5173
|
# auto-select the best mode
|
5162
5174
|
if mode is None:
|
5163
5175
|
# if enough ancillary qubits are provided, use the 'v-chain' method
|
5164
|
-
additional_vchain =
|
5176
|
+
additional_vchain = max(0, len(control_qubits) - 2)
|
5165
5177
|
if len(ancillary_qubits) >= additional_vchain:
|
5166
5178
|
mode = "basic"
|
5167
5179
|
else:
|
5168
5180
|
mode = "noancilla"
|
5169
5181
|
|
5170
5182
|
if mode == "basic":
|
5183
|
+
from qiskit.synthesis.multi_controlled import synth_mcx_n_clean_m15
|
5184
|
+
|
5171
5185
|
self.ry(theta / 2, q_target)
|
5172
|
-
|
5186
|
+
if len(control_qubits) == 1:
|
5187
|
+
self.cx(control_qubits[0], q_target)
|
5188
|
+
elif len(control_qubits) == 2:
|
5189
|
+
self.ccx(control_qubits[0], control_qubits[1], q_target)
|
5190
|
+
else:
|
5191
|
+
qubits = control_qubits + [target_qubit] + ancillary_qubits
|
5192
|
+
mcx = synth_mcx_n_clean_m15(len(control_qubits))
|
5193
|
+
self.compose(mcx, qubits, inplace=True)
|
5173
5194
|
self.ry(-theta / 2, q_target)
|
5174
|
-
|
5195
|
+
if len(control_qubits) == 1:
|
5196
|
+
self.cx(control_qubits[0], q_target)
|
5197
|
+
elif len(control_qubits) == 2:
|
5198
|
+
self.ccx(control_qubits[0], control_qubits[1], q_target)
|
5199
|
+
else:
|
5200
|
+
qubits = control_qubits + [target_qubit] + ancillary_qubits
|
5201
|
+
mcx = synth_mcx_n_clean_m15(len(control_qubits))
|
5202
|
+
self.compose(mcx, qubits, inplace=True)
|
5175
5203
|
elif mode == "noancilla":
|
5176
5204
|
n_c = len(control_qubits)
|
5177
5205
|
if n_c == 1: # cu
|
@@ -5265,7 +5293,7 @@ class QuantumCircuit:
|
|
5265
5293
|
Returns:
|
5266
5294
|
A handle to the instructions created.
|
5267
5295
|
"""
|
5268
|
-
return self._append_standard_gate(StandardGate.
|
5296
|
+
return self._append_standard_gate(StandardGate.R, [qubit], [theta, phi])
|
5269
5297
|
|
5270
5298
|
def rv(
|
5271
5299
|
self,
|
@@ -5313,7 +5341,7 @@ class QuantumCircuit:
|
|
5313
5341
|
A handle to the instructions created.
|
5314
5342
|
"""
|
5315
5343
|
return self._append_standard_gate(
|
5316
|
-
StandardGate.
|
5344
|
+
StandardGate.RCCX, [control_qubit1, control_qubit2, target_qubit], ()
|
5317
5345
|
)
|
5318
5346
|
|
5319
5347
|
def rcccx(
|
@@ -5337,7 +5365,7 @@ class QuantumCircuit:
|
|
5337
5365
|
A handle to the instructions created.
|
5338
5366
|
"""
|
5339
5367
|
return self._append_standard_gate(
|
5340
|
-
StandardGate.
|
5368
|
+
StandardGate.RC3X,
|
5341
5369
|
[control_qubit1, control_qubit2, control_qubit3, target_qubit],
|
5342
5370
|
(),
|
5343
5371
|
)
|
@@ -5357,7 +5385,7 @@ class QuantumCircuit:
|
|
5357
5385
|
Returns:
|
5358
5386
|
A handle to the instructions created.
|
5359
5387
|
"""
|
5360
|
-
return self._append_standard_gate(StandardGate.
|
5388
|
+
return self._append_standard_gate(StandardGate.RX, [qubit], [theta], label=label)
|
5361
5389
|
|
5362
5390
|
def crx(
|
5363
5391
|
self,
|
@@ -5386,7 +5414,7 @@ class QuantumCircuit:
|
|
5386
5414
|
# if the control state is |1> use the fast Rust version of the gate
|
5387
5415
|
if ctrl_state is None or ctrl_state in ["1", 1]:
|
5388
5416
|
return self._append_standard_gate(
|
5389
|
-
StandardGate.
|
5417
|
+
StandardGate.CRX, [control_qubit, target_qubit], [theta], label=label
|
5390
5418
|
)
|
5391
5419
|
|
5392
5420
|
from .library.standard_gates.rx import CRXGate
|
@@ -5413,7 +5441,7 @@ class QuantumCircuit:
|
|
5413
5441
|
Returns:
|
5414
5442
|
A handle to the instructions created.
|
5415
5443
|
"""
|
5416
|
-
return self._append_standard_gate(StandardGate.
|
5444
|
+
return self._append_standard_gate(StandardGate.RXX, [qubit1, qubit2], [theta])
|
5417
5445
|
|
5418
5446
|
def ry(
|
5419
5447
|
self, theta: ParameterValueType, qubit: QubitSpecifier, label: str | None = None
|
@@ -5430,7 +5458,7 @@ class QuantumCircuit:
|
|
5430
5458
|
Returns:
|
5431
5459
|
A handle to the instructions created.
|
5432
5460
|
"""
|
5433
|
-
return self._append_standard_gate(StandardGate.
|
5461
|
+
return self._append_standard_gate(StandardGate.RY, [qubit], [theta], label=label)
|
5434
5462
|
|
5435
5463
|
def cry(
|
5436
5464
|
self,
|
@@ -5459,7 +5487,7 @@ class QuantumCircuit:
|
|
5459
5487
|
# if the control state is |1> use the fast Rust version of the gate
|
5460
5488
|
if ctrl_state is None or ctrl_state in ["1", 1]:
|
5461
5489
|
return self._append_standard_gate(
|
5462
|
-
StandardGate.
|
5490
|
+
StandardGate.CRY, [control_qubit, target_qubit], [theta], label=label
|
5463
5491
|
)
|
5464
5492
|
|
5465
5493
|
from .library.standard_gates.ry import CRYGate
|
@@ -5486,7 +5514,7 @@ class QuantumCircuit:
|
|
5486
5514
|
Returns:
|
5487
5515
|
A handle to the instructions created.
|
5488
5516
|
"""
|
5489
|
-
return self._append_standard_gate(StandardGate.
|
5517
|
+
return self._append_standard_gate(StandardGate.RYY, [qubit1, qubit2], [theta])
|
5490
5518
|
|
5491
5519
|
def rz(self, phi: ParameterValueType, qubit: QubitSpecifier) -> InstructionSet:
|
5492
5520
|
"""Apply :class:`~qiskit.circuit.library.RZGate`.
|
@@ -5500,7 +5528,7 @@ class QuantumCircuit:
|
|
5500
5528
|
Returns:
|
5501
5529
|
A handle to the instructions created.
|
5502
5530
|
"""
|
5503
|
-
return self._append_standard_gate(StandardGate.
|
5531
|
+
return self._append_standard_gate(StandardGate.RZ, [qubit], [phi])
|
5504
5532
|
|
5505
5533
|
def crz(
|
5506
5534
|
self,
|
@@ -5529,7 +5557,7 @@ class QuantumCircuit:
|
|
5529
5557
|
# if the control state is |1> use the fast Rust version of the gate
|
5530
5558
|
if ctrl_state is None or ctrl_state in ["1", 1]:
|
5531
5559
|
return self._append_standard_gate(
|
5532
|
-
StandardGate.
|
5560
|
+
StandardGate.CRZ, [control_qubit, target_qubit], [theta], label=label
|
5533
5561
|
)
|
5534
5562
|
|
5535
5563
|
from .library.standard_gates.rz import CRZGate
|
@@ -5556,7 +5584,7 @@ class QuantumCircuit:
|
|
5556
5584
|
Returns:
|
5557
5585
|
A handle to the instructions created.
|
5558
5586
|
"""
|
5559
|
-
return self._append_standard_gate(StandardGate.
|
5587
|
+
return self._append_standard_gate(StandardGate.RZX, [qubit1, qubit2], [theta])
|
5560
5588
|
|
5561
5589
|
def rzz(
|
5562
5590
|
self, theta: ParameterValueType, qubit1: QubitSpecifier, qubit2: QubitSpecifier
|
@@ -5573,7 +5601,7 @@ class QuantumCircuit:
|
|
5573
5601
|
Returns:
|
5574
5602
|
A handle to the instructions created.
|
5575
5603
|
"""
|
5576
|
-
return self._append_standard_gate(StandardGate.
|
5604
|
+
return self._append_standard_gate(StandardGate.RZZ, [qubit1, qubit2], [theta])
|
5577
5605
|
|
5578
5606
|
def ecr(self, qubit1: QubitSpecifier, qubit2: QubitSpecifier) -> InstructionSet:
|
5579
5607
|
"""Apply :class:`~qiskit.circuit.library.ECRGate`.
|
@@ -5586,7 +5614,7 @@ class QuantumCircuit:
|
|
5586
5614
|
Returns:
|
5587
5615
|
A handle to the instructions created.
|
5588
5616
|
"""
|
5589
|
-
return self._append_standard_gate(StandardGate.
|
5617
|
+
return self._append_standard_gate(StandardGate.ECR, [qubit1, qubit2], ())
|
5590
5618
|
|
5591
5619
|
def s(self, qubit: QubitSpecifier) -> InstructionSet:
|
5592
5620
|
"""Apply :class:`~qiskit.circuit.library.SGate`.
|
@@ -5599,7 +5627,7 @@ class QuantumCircuit:
|
|
5599
5627
|
Returns:
|
5600
5628
|
A handle to the instructions created.
|
5601
5629
|
"""
|
5602
|
-
return self._append_standard_gate(StandardGate.
|
5630
|
+
return self._append_standard_gate(StandardGate.S, [qubit], ())
|
5603
5631
|
|
5604
5632
|
def sdg(self, qubit: QubitSpecifier) -> InstructionSet:
|
5605
5633
|
"""Apply :class:`~qiskit.circuit.library.SdgGate`.
|
@@ -5612,7 +5640,7 @@ class QuantumCircuit:
|
|
5612
5640
|
Returns:
|
5613
5641
|
A handle to the instructions created.
|
5614
5642
|
"""
|
5615
|
-
return self._append_standard_gate(StandardGate.
|
5643
|
+
return self._append_standard_gate(StandardGate.Sdg, [qubit], ())
|
5616
5644
|
|
5617
5645
|
def cs(
|
5618
5646
|
self,
|
@@ -5639,7 +5667,7 @@ class QuantumCircuit:
|
|
5639
5667
|
# if the control state is |1> use the fast Rust version of the gate
|
5640
5668
|
if ctrl_state is None or ctrl_state in ["1", 1]:
|
5641
5669
|
return self._append_standard_gate(
|
5642
|
-
StandardGate.
|
5670
|
+
StandardGate.CS, [control_qubit, target_qubit], (), label=label
|
5643
5671
|
)
|
5644
5672
|
|
5645
5673
|
from .library.standard_gates.s import CSGate
|
@@ -5676,7 +5704,7 @@ class QuantumCircuit:
|
|
5676
5704
|
# if the control state is |1> use the fast Rust version of the gate
|
5677
5705
|
if ctrl_state is None or ctrl_state in ["1", 1]:
|
5678
5706
|
return self._append_standard_gate(
|
5679
|
-
StandardGate.
|
5707
|
+
StandardGate.CSdg, [control_qubit, target_qubit], (), label=label
|
5680
5708
|
)
|
5681
5709
|
|
5682
5710
|
from .library.standard_gates.s import CSdgGate
|
@@ -5700,7 +5728,7 @@ class QuantumCircuit:
|
|
5700
5728
|
A handle to the instructions created.
|
5701
5729
|
"""
|
5702
5730
|
return self._append_standard_gate(
|
5703
|
-
StandardGate.
|
5731
|
+
StandardGate.Swap,
|
5704
5732
|
[qubit1, qubit2],
|
5705
5733
|
(),
|
5706
5734
|
)
|
@@ -5716,7 +5744,7 @@ class QuantumCircuit:
|
|
5716
5744
|
Returns:
|
5717
5745
|
A handle to the instructions created.
|
5718
5746
|
"""
|
5719
|
-
return self._append_standard_gate(StandardGate.
|
5747
|
+
return self._append_standard_gate(StandardGate.ISwap, [qubit1, qubit2], ())
|
5720
5748
|
|
5721
5749
|
def cswap(
|
5722
5750
|
self,
|
@@ -5745,7 +5773,7 @@ class QuantumCircuit:
|
|
5745
5773
|
# if the control state is |1> use the fast Rust version of the gate
|
5746
5774
|
if ctrl_state is None or ctrl_state in ["1", 1]:
|
5747
5775
|
return self._append_standard_gate(
|
5748
|
-
StandardGate.
|
5776
|
+
StandardGate.CSwap,
|
5749
5777
|
[control_qubit, target_qubit1, target_qubit2],
|
5750
5778
|
(),
|
5751
5779
|
label=label,
|
@@ -5771,7 +5799,7 @@ class QuantumCircuit:
|
|
5771
5799
|
Returns:
|
5772
5800
|
A handle to the instructions created.
|
5773
5801
|
"""
|
5774
|
-
return self._append_standard_gate(StandardGate.
|
5802
|
+
return self._append_standard_gate(StandardGate.SX, [qubit], ())
|
5775
5803
|
|
5776
5804
|
def sxdg(self, qubit: QubitSpecifier) -> InstructionSet:
|
5777
5805
|
"""Apply :class:`~qiskit.circuit.library.SXdgGate`.
|
@@ -5784,7 +5812,7 @@ class QuantumCircuit:
|
|
5784
5812
|
Returns:
|
5785
5813
|
A handle to the instructions created.
|
5786
5814
|
"""
|
5787
|
-
return self._append_standard_gate(StandardGate.
|
5815
|
+
return self._append_standard_gate(StandardGate.SXdg, [qubit], ())
|
5788
5816
|
|
5789
5817
|
def csx(
|
5790
5818
|
self,
|
@@ -5811,7 +5839,7 @@ class QuantumCircuit:
|
|
5811
5839
|
# if the control state is |1> use the fast Rust version of the gate
|
5812
5840
|
if ctrl_state is None or ctrl_state in ["1", 1]:
|
5813
5841
|
return self._append_standard_gate(
|
5814
|
-
StandardGate.
|
5842
|
+
StandardGate.CSX, [control_qubit, target_qubit], (), label=label
|
5815
5843
|
)
|
5816
5844
|
|
5817
5845
|
from .library.standard_gates.sx import CSXGate
|
@@ -5834,7 +5862,7 @@ class QuantumCircuit:
|
|
5834
5862
|
Returns:
|
5835
5863
|
A handle to the instructions created.
|
5836
5864
|
"""
|
5837
|
-
return self._append_standard_gate(StandardGate.
|
5865
|
+
return self._append_standard_gate(StandardGate.T, [qubit], ())
|
5838
5866
|
|
5839
5867
|
def tdg(self, qubit: QubitSpecifier) -> InstructionSet:
|
5840
5868
|
"""Apply :class:`~qiskit.circuit.library.TdgGate`.
|
@@ -5847,7 +5875,7 @@ class QuantumCircuit:
|
|
5847
5875
|
Returns:
|
5848
5876
|
A handle to the instructions created.
|
5849
5877
|
"""
|
5850
|
-
return self._append_standard_gate(StandardGate.
|
5878
|
+
return self._append_standard_gate(StandardGate.Tdg, [qubit], ())
|
5851
5879
|
|
5852
5880
|
def u(
|
5853
5881
|
self,
|
@@ -5869,7 +5897,7 @@ class QuantumCircuit:
|
|
5869
5897
|
Returns:
|
5870
5898
|
A handle to the instructions created.
|
5871
5899
|
"""
|
5872
|
-
return self._append_standard_gate(StandardGate.
|
5900
|
+
return self._append_standard_gate(StandardGate.U, [qubit], [theta, phi, lam])
|
5873
5901
|
|
5874
5902
|
def cu(
|
5875
5903
|
self,
|
@@ -5904,7 +5932,7 @@ class QuantumCircuit:
|
|
5904
5932
|
# if the control state is |1> use the fast Rust version of the gate
|
5905
5933
|
if ctrl_state is None or ctrl_state in ["1", 1]:
|
5906
5934
|
return self._append_standard_gate(
|
5907
|
-
StandardGate.
|
5935
|
+
StandardGate.CU,
|
5908
5936
|
[control_qubit, target_qubit],
|
5909
5937
|
[theta, phi, lam, gamma],
|
5910
5938
|
label=label,
|
@@ -5931,7 +5959,7 @@ class QuantumCircuit:
|
|
5931
5959
|
Returns:
|
5932
5960
|
A handle to the instructions created.
|
5933
5961
|
"""
|
5934
|
-
return self._append_standard_gate(StandardGate.
|
5962
|
+
return self._append_standard_gate(StandardGate.X, [qubit], (), label=label)
|
5935
5963
|
|
5936
5964
|
def cx(
|
5937
5965
|
self,
|
@@ -5958,7 +5986,7 @@ class QuantumCircuit:
|
|
5958
5986
|
# if the control state is |1> use the fast Rust version of the gate
|
5959
5987
|
if ctrl_state is None or ctrl_state in ["1", 1]:
|
5960
5988
|
return self._append_standard_gate(
|
5961
|
-
StandardGate.
|
5989
|
+
StandardGate.CX,
|
5962
5990
|
[control_qubit, target_qubit],
|
5963
5991
|
(),
|
5964
5992
|
label=label,
|
@@ -5985,7 +6013,7 @@ class QuantumCircuit:
|
|
5985
6013
|
Returns:
|
5986
6014
|
A handle to the instructions created.
|
5987
6015
|
"""
|
5988
|
-
return self._append_standard_gate(StandardGate.
|
6016
|
+
return self._append_standard_gate(StandardGate.DCX, [qubit1, qubit2], ())
|
5989
6017
|
|
5990
6018
|
def ccx(
|
5991
6019
|
self,
|
@@ -6012,7 +6040,7 @@ class QuantumCircuit:
|
|
6012
6040
|
# if the control state is |11> use the fast Rust version of the gate
|
6013
6041
|
if ctrl_state is None or ctrl_state in ["11", 3]:
|
6014
6042
|
return self._append_standard_gate(
|
6015
|
-
StandardGate.
|
6043
|
+
StandardGate.CCX,
|
6016
6044
|
[control_qubit1, control_qubit2, target_qubit],
|
6017
6045
|
(),
|
6018
6046
|
)
|
@@ -6026,12 +6054,21 @@ class QuantumCircuit:
|
|
6026
6054
|
copy=False,
|
6027
6055
|
)
|
6028
6056
|
|
6057
|
+
@deprecate_arg(
|
6058
|
+
name="mode",
|
6059
|
+
since="2.1",
|
6060
|
+
additional_msg=(
|
6061
|
+
"Instead, add a generic MCXGate to the circuit and specify the synthesis method "
|
6062
|
+
"via the ``hls_config`` in the transpilation. Alternatively, specific decompositions "
|
6063
|
+
"are available at https://qisk.it/mcx."
|
6064
|
+
),
|
6065
|
+
)
|
6029
6066
|
def mcx(
|
6030
6067
|
self,
|
6031
6068
|
control_qubits: Sequence[QubitSpecifier],
|
6032
6069
|
target_qubit: QubitSpecifier,
|
6033
6070
|
ancilla_qubits: QubitSpecifier | Sequence[QubitSpecifier] | None = None,
|
6034
|
-
mode: str =
|
6071
|
+
mode: str | None = None,
|
6035
6072
|
ctrl_state: str | int | None = None,
|
6036
6073
|
) -> InstructionSet:
|
6037
6074
|
"""Apply :class:`~qiskit.circuit.library.MCXGate`.
|
@@ -6067,46 +6104,62 @@ class QuantumCircuit:
|
|
6067
6104
|
num_ctrl_qubits = len(control_qubits)
|
6068
6105
|
|
6069
6106
|
available_implementations = {
|
6070
|
-
"noancilla"
|
6071
|
-
"recursion"
|
6072
|
-
"v-chain"
|
6073
|
-
"v-chain-dirty"
|
6074
|
-
|
6075
|
-
"
|
6076
|
-
"basic"
|
6077
|
-
"basic-dirty-ancilla": MCXVChain(
|
6078
|
-
num_ctrl_qubits, dirty_ancillas=True, ctrl_state=ctrl_state
|
6079
|
-
),
|
6107
|
+
"noancilla",
|
6108
|
+
"recursion",
|
6109
|
+
"v-chain",
|
6110
|
+
"v-chain-dirty",
|
6111
|
+
"advanced",
|
6112
|
+
"basic",
|
6113
|
+
"basic-dirty-ancilla",
|
6080
6114
|
}
|
6081
6115
|
|
6082
6116
|
# check ancilla input
|
6083
6117
|
if ancilla_qubits:
|
6084
6118
|
_ = self._qbit_argument_conversion(ancilla_qubits)
|
6085
6119
|
|
6086
|
-
|
6087
|
-
gate =
|
6088
|
-
|
6089
|
-
|
6120
|
+
if mode is None:
|
6121
|
+
gate = MCXGate(num_ctrl_qubits, ctrl_state=ctrl_state)
|
6122
|
+
elif mode in available_implementations:
|
6123
|
+
if mode == "noancilla":
|
6124
|
+
gate = MCXGate(num_ctrl_qubits, ctrl_state=ctrl_state)
|
6125
|
+
elif mode in ["recursion", "advanced"]:
|
6126
|
+
gate = MCXRecursive(num_ctrl_qubits, ctrl_state=ctrl_state)
|
6127
|
+
elif mode in ["v-chain", "basic"]:
|
6128
|
+
gate = MCXVChain(num_ctrl_qubits, False, ctrl_state=ctrl_state)
|
6129
|
+
elif mode in ["v-chain-dirty", "basic-dirty-ancilla"]:
|
6130
|
+
gate = MCXVChain(num_ctrl_qubits, dirty_ancillas=True, ctrl_state=ctrl_state)
|
6131
|
+
else:
|
6132
|
+
raise ValueError("unreachable.")
|
6133
|
+
# else is unreachable, we exhausted all options
|
6134
|
+
else:
|
6090
6135
|
raise ValueError(
|
6091
|
-
f"Unsupported mode ({mode}) selected, choose one of {
|
6092
|
-
)
|
6093
|
-
|
6094
|
-
if hasattr(gate, "num_ancilla_qubits") and gate.num_ancilla_qubits > 0:
|
6095
|
-
required = gate.num_ancilla_qubits
|
6096
|
-
if ancilla_qubits is None:
|
6097
|
-
raise AttributeError(f"No ancillas provided, but {required} are needed!")
|
6098
|
-
|
6099
|
-
# convert ancilla qubits to a list if they were passed as int or qubit
|
6100
|
-
if not hasattr(ancilla_qubits, "__len__"):
|
6101
|
-
ancilla_qubits = [ancilla_qubits]
|
6136
|
+
f"Unsupported mode ({mode}) selected, choose one of {available_implementations}"
|
6137
|
+
)
|
6102
6138
|
|
6103
|
-
|
6104
|
-
actually = len(ancilla_qubits)
|
6105
|
-
raise ValueError(f"At least {required} ancillas required, but {actually} given.")
|
6106
|
-
# size down if too many ancillas were provided
|
6107
|
-
ancilla_qubits = ancilla_qubits[:required]
|
6108
|
-
else:
|
6139
|
+
if mode is None or not hasattr(gate, "num_ancilla_qubits"):
|
6109
6140
|
ancilla_qubits = []
|
6141
|
+
else:
|
6142
|
+
with warnings.catch_warnings():
|
6143
|
+
warnings.filterwarnings("ignore", category=DeprecationWarning, module="qiskit")
|
6144
|
+
required = gate.num_ancilla_qubits
|
6145
|
+
|
6146
|
+
if required > 0:
|
6147
|
+
if ancilla_qubits is None:
|
6148
|
+
raise AttributeError(f"No ancillas provided, but {required} are needed!")
|
6149
|
+
|
6150
|
+
# convert ancilla qubits to a list if they were passed as int or qubit
|
6151
|
+
if not hasattr(ancilla_qubits, "__len__"):
|
6152
|
+
ancilla_qubits = [ancilla_qubits]
|
6153
|
+
|
6154
|
+
if len(ancilla_qubits) < required:
|
6155
|
+
actually = len(ancilla_qubits)
|
6156
|
+
raise ValueError(
|
6157
|
+
f"At least {required} ancillas required, but {actually} given."
|
6158
|
+
)
|
6159
|
+
# size down if too many ancillas were provided
|
6160
|
+
ancilla_qubits = ancilla_qubits[:required]
|
6161
|
+
else:
|
6162
|
+
ancilla_qubits = []
|
6110
6163
|
|
6111
6164
|
return self.append(gate, control_qubits[:] + [target_qubit] + ancilla_qubits[:], [])
|
6112
6165
|
|
@@ -6121,7 +6174,7 @@ class QuantumCircuit:
|
|
6121
6174
|
Returns:
|
6122
6175
|
A handle to the instructions created.
|
6123
6176
|
"""
|
6124
|
-
return self._append_standard_gate(StandardGate.
|
6177
|
+
return self._append_standard_gate(StandardGate.Y, [qubit], ())
|
6125
6178
|
|
6126
6179
|
def cy(
|
6127
6180
|
self,
|
@@ -6148,7 +6201,7 @@ class QuantumCircuit:
|
|
6148
6201
|
# if the control state is |1> use the fast Rust version of the gate
|
6149
6202
|
if ctrl_state is None or ctrl_state in ["1", 1]:
|
6150
6203
|
return self._append_standard_gate(
|
6151
|
-
StandardGate.
|
6204
|
+
StandardGate.CY,
|
6152
6205
|
[control_qubit, target_qubit],
|
6153
6206
|
(),
|
6154
6207
|
label=label,
|
@@ -6174,7 +6227,7 @@ class QuantumCircuit:
|
|
6174
6227
|
Returns:
|
6175
6228
|
A handle to the instructions created.
|
6176
6229
|
"""
|
6177
|
-
return self._append_standard_gate(StandardGate.
|
6230
|
+
return self._append_standard_gate(StandardGate.Z, [qubit], ())
|
6178
6231
|
|
6179
6232
|
def cz(
|
6180
6233
|
self,
|
@@ -6201,7 +6254,7 @@ class QuantumCircuit:
|
|
6201
6254
|
# if the control state is |1> use the fast Rust version of the gate
|
6202
6255
|
if ctrl_state is None or ctrl_state in ["1", 1]:
|
6203
6256
|
return self._append_standard_gate(
|
6204
|
-
StandardGate.
|
6257
|
+
StandardGate.CZ, [control_qubit, target_qubit], (), label=label
|
6205
6258
|
)
|
6206
6259
|
|
6207
6260
|
from .library.standard_gates.z import CZGate
|
@@ -6240,7 +6293,7 @@ class QuantumCircuit:
|
|
6240
6293
|
# if the control state is |11> use the fast Rust version of the gate
|
6241
6294
|
if ctrl_state is None or ctrl_state in ["11", 3]:
|
6242
6295
|
return self._append_standard_gate(
|
6243
|
-
StandardGate.
|
6296
|
+
StandardGate.CCZ,
|
6244
6297
|
[control_qubit1, control_qubit2, target_qubit],
|
6245
6298
|
(),
|
6246
6299
|
label=label,
|
@@ -6663,16 +6716,15 @@ class QuantumCircuit:
|
|
6663
6716
|
|
6664
6717
|
def box(
|
6665
6718
|
self,
|
6666
|
-
|
6667
|
-
# allow `annotations` to be passed as the positional argument in the context-manager form.
|
6668
|
-
body: QuantumCircuit | None = None,
|
6719
|
+
body_or_annotations: QuantumCircuit | typing.Iterable[Annotation] = ...,
|
6669
6720
|
/,
|
6670
6721
|
qubits: Sequence[QubitSpecifier] | None = None,
|
6671
6722
|
clbits: Sequence[ClbitSpecifier] | None = None,
|
6672
6723
|
*,
|
6673
6724
|
label: str | None = None,
|
6674
6725
|
duration: None = None,
|
6675
|
-
unit: Literal["dt", "s", "ms", "us", "ns", "ps"] =
|
6726
|
+
unit: Literal["dt", "s", "ms", "us", "ns", "ps", "expr"] | None = None,
|
6727
|
+
annotations: typing.Iterable[Annotation] = ...,
|
6676
6728
|
):
|
6677
6729
|
"""Create a ``box`` of operations on this circuit that are treated atomically in the greater
|
6678
6730
|
context.
|
@@ -6701,13 +6753,16 @@ class QuantumCircuit:
|
|
6701
6753
|
|
6702
6754
|
.. code-block:: python
|
6703
6755
|
|
6704
|
-
from qiskit.circuit import QuantumCircuit
|
6756
|
+
from qiskit.circuit import QuantumCircuit, Annotation
|
6757
|
+
|
6758
|
+
class MyAnnotation(Annotation):
|
6759
|
+
namespace = "my.namespace"
|
6705
6760
|
|
6706
6761
|
qc = QuantumCircuit(9)
|
6707
6762
|
with qc.box():
|
6708
6763
|
qc.cz(0, 1)
|
6709
6764
|
qc.cz(2, 3)
|
6710
|
-
with qc.box():
|
6765
|
+
with qc.box([MyAnnotation()]):
|
6711
6766
|
qc.cz(4, 5)
|
6712
6767
|
qc.cz(6, 7)
|
6713
6768
|
qc.noop(8)
|
@@ -6735,8 +6790,11 @@ class QuantumCircuit:
|
|
6735
6790
|
qc.box(body_1, [4, 5, 6, 7, 8], [])
|
6736
6791
|
|
6737
6792
|
Args:
|
6738
|
-
|
6739
|
-
|
6793
|
+
body_or_annotations: the first positional argument is unnamed. If a
|
6794
|
+
:class:`QuantumCircuit` is passed positionally, it is immediately used as the body
|
6795
|
+
of the box, and ``qubits`` and ``clbits`` must also be specified. If not given, or
|
6796
|
+
if given an iterable of :class:`.Annotation` objects, the context-manager form of
|
6797
|
+
this method is triggered.
|
6740
6798
|
qubits: the qubits to apply the :class:`.BoxOp` to, in the explicit form.
|
6741
6799
|
clbits: the qubits to apply the :class:`.BoxOp` to, in the explicit form.
|
6742
6800
|
label: an optional string label for the instruction.
|
@@ -6744,23 +6802,35 @@ class QuantumCircuit:
|
|
6744
6802
|
constrained to schedule the contained scope to match a given duration, including
|
6745
6803
|
delay insertion if required.
|
6746
6804
|
unit: the unit of the ``duration``.
|
6805
|
+
annotations: any :class:`.Annotation` objects the box should have. When this method is
|
6806
|
+
used in context-manager form, this argument can instead be passed as the only
|
6807
|
+
positional argument.
|
6747
6808
|
"""
|
6748
|
-
if isinstance(
|
6809
|
+
if isinstance(body_or_annotations, QuantumCircuit):
|
6749
6810
|
# Explicit-body form.
|
6811
|
+
body = body_or_annotations
|
6750
6812
|
if qubits is None or clbits is None:
|
6751
6813
|
raise CircuitError("When using 'box' with a body, you must pass qubits and clbits.")
|
6814
|
+
if annotations is Ellipsis:
|
6815
|
+
annotations = []
|
6752
6816
|
return self.append(
|
6753
|
-
BoxOp(body, duration=duration, unit=unit, label=label),
|
6817
|
+
BoxOp(body, duration=duration, unit=unit, label=label, annotations=annotations),
|
6754
6818
|
qubits,
|
6755
6819
|
clbits,
|
6756
6820
|
copy=False,
|
6757
6821
|
)
|
6822
|
+
if body_or_annotations is ...:
|
6823
|
+
annotations = () if annotations is ... else annotations
|
6824
|
+
elif annotations is not ...:
|
6825
|
+
raise TypeError("QuantumCircuit.box() got multiple values for argument 'annotations'")
|
6826
|
+
else:
|
6827
|
+
annotations = body_or_annotations
|
6758
6828
|
# Context-manager form.
|
6759
6829
|
if qubits is not None or clbits is not None:
|
6760
6830
|
raise CircuitError(
|
6761
6831
|
"When using 'box' as a context manager, you cannot pass qubits or clbits."
|
6762
6832
|
)
|
6763
|
-
return BoxContext(self, duration=duration, unit=unit, label=label)
|
6833
|
+
return BoxContext(self, duration=duration, unit=unit, label=label, annotations=annotations)
|
6764
6834
|
|
6765
6835
|
@typing.overload
|
6766
6836
|
def while_loop(
|