qiskit 1.3.1__cp39-abi3-win32.whl → 1.3.2__cp39-abi3-win32.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- qiskit/VERSION.txt +1 -1
- qiskit/_accelerate.pyd +0 -0
- qiskit/circuit/__init__.py +2 -0
- qiskit/circuit/controlledgate.py +2 -0
- qiskit/circuit/library/__init__.py +1 -0
- qiskit/circuit/library/arithmetic/piecewise_chebyshev.py +1 -0
- qiskit/circuit/library/basis_change/qft.py +3 -0
- qiskit/circuit/library/boolean_logic/inner_product.py +2 -0
- qiskit/circuit/library/boolean_logic/quantum_and.py +4 -0
- qiskit/circuit/library/boolean_logic/quantum_or.py +4 -0
- qiskit/circuit/library/boolean_logic/quantum_xor.py +2 -0
- qiskit/circuit/library/fourier_checking.py +2 -0
- qiskit/circuit/library/generalized_gates/gms.py +1 -0
- qiskit/circuit/library/generalized_gates/gr.py +4 -0
- qiskit/circuit/library/generalized_gates/mcmt.py +1 -0
- qiskit/circuit/library/generalized_gates/permutation.py +5 -1
- qiskit/circuit/library/generalized_gates/unitary.py +1 -1
- qiskit/circuit/library/graph_state.py +2 -0
- qiskit/circuit/library/grover_operator.py +7 -3
- qiskit/circuit/library/hidden_linear_function.py +2 -0
- qiskit/circuit/library/iqp.py +5 -0
- qiskit/circuit/library/n_local/efficient_su2.py +7 -2
- qiskit/circuit/library/n_local/evolved_operator_ansatz.py +3 -0
- qiskit/circuit/library/n_local/excitation_preserving.py +14 -8
- qiskit/circuit/library/n_local/n_local.py +10 -5
- qiskit/circuit/library/n_local/pauli_two_design.py +5 -2
- qiskit/circuit/library/n_local/qaoa_ansatz.py +1 -0
- qiskit/circuit/library/n_local/real_amplitudes.py +10 -4
- qiskit/circuit/library/overlap.py +1 -0
- qiskit/circuit/library/phase_estimation.py +2 -0
- qiskit/circuit/library/quantum_volume.py +3 -0
- qiskit/circuit/operation.py +1 -0
- qiskit/circuit/parameter.py +1 -0
- qiskit/circuit/parameterexpression.py +1 -1
- qiskit/circuit/quantumcircuit.py +13 -19
- qiskit/circuit/random/utils.py +2 -0
- qiskit/converters/dag_to_circuit.py +1 -0
- qiskit/primitives/statevector_estimator.py +1 -0
- qiskit/providers/fake_provider/__init__.py +1 -0
- qiskit/pulse/builder.py +8 -0
- qiskit/pulse/library/symbolic_pulses.py +1 -0
- qiskit/qasm2/export.py +2 -2
- qiskit/qasm3/__init__.py +1 -0
- qiskit/qasm3/exporter.py +6 -3
- qiskit/quantum_info/operators/symplectic/pauli_list.py +8 -8
- qiskit/quantum_info/operators/symplectic/sparse_pauli_op.py +10 -1
- qiskit/quantum_info/states/statevector.py +1 -0
- qiskit/synthesis/arithmetic/multipliers/hrs_cumulative_multiplier.py +1 -0
- qiskit/synthesis/arithmetic/multipliers/rg_qft_multiplier.py +1 -0
- qiskit/synthesis/evolution/product_formula.py +0 -6
- qiskit/synthesis/evolution/suzuki_trotter.py +22 -5
- qiskit/transpiler/__init__.py +22 -1
- qiskit/transpiler/layout.py +3 -0
- qiskit/transpiler/passes/routing/star_prerouting.py +1 -0
- qiskit/transpiler/passes/scheduling/dynamical_decoupling.py +1 -0
- qiskit/transpiler/passes/scheduling/padding/dynamical_decoupling.py +1 -0
- qiskit/transpiler/passes/synthesis/hls_plugins.py +48 -9
- qiskit/transpiler/passes/utils/filter_op_nodes.py +2 -1
- qiskit/transpiler/passes/utils/remove_barriers.py +1 -0
- qiskit/transpiler/preset_passmanagers/__init__.py +5 -5
- qiskit/transpiler/preset_passmanagers/builtin_plugins.py +19 -22
- qiskit/transpiler/target.py +1 -1
- qiskit/visualization/__init__.py +6 -0
- qiskit/visualization/circuit/circuit_visualization.py +1 -0
- qiskit/visualization/counts_visualization.py +2 -0
- qiskit/visualization/dag_visualization.py +1 -0
- qiskit/visualization/gate_map.py +7 -3
- qiskit/visualization/pulse_v2/interface.py +4 -1
- qiskit/visualization/state_visualization.py +13 -2
- qiskit/visualization/timeline/interface.py +6 -3
- {qiskit-1.3.1.dist-info → qiskit-1.3.2.dist-info}/METADATA +17 -17
- {qiskit-1.3.1.dist-info → qiskit-1.3.2.dist-info}/RECORD +76 -76
- {qiskit-1.3.1.dist-info → qiskit-1.3.2.dist-info}/WHEEL +1 -1
- {qiskit-1.3.1.dist-info → qiskit-1.3.2.dist-info}/LICENSE.txt +0 -0
- {qiskit-1.3.1.dist-info → qiskit-1.3.2.dist-info}/entry_points.txt +0 -0
- {qiskit-1.3.1.dist-info → qiskit-1.3.2.dist-info}/top_level.txt +0 -0
@@ -76,6 +76,7 @@ class PhaseEstimation(QuantumCircuit):
|
|
76
76
|
|
77
77
|
Reference Circuit:
|
78
78
|
.. plot::
|
79
|
+
:alt: Diagram illustrating the previously described circuit.
|
79
80
|
|
80
81
|
from qiskit.circuit import QuantumCircuit
|
81
82
|
from qiskit.circuit.library import PhaseEstimation
|
@@ -131,6 +132,7 @@ def phase_estimation(
|
|
131
132
|
**Reference Circuit:**
|
132
133
|
|
133
134
|
.. plot::
|
135
|
+
:alt: Circuit diagram output by the previous code.
|
134
136
|
:include-source:
|
135
137
|
|
136
138
|
from qiskit.circuit import QuantumCircuit
|
@@ -35,6 +35,7 @@ class QuantumVolume(QuantumCircuit):
|
|
35
35
|
**Reference Circuit:**
|
36
36
|
|
37
37
|
.. plot::
|
38
|
+
:alt: Diagram illustrating the previously described circuit.
|
38
39
|
|
39
40
|
from qiskit.circuit.library import QuantumVolume
|
40
41
|
circuit = QuantumVolume(5, 6, seed=10)
|
@@ -43,6 +44,7 @@ class QuantumVolume(QuantumCircuit):
|
|
43
44
|
**Expanded Circuit:**
|
44
45
|
|
45
46
|
.. plot::
|
47
|
+
:alt: Diagram illustrating the previously described circuit.
|
46
48
|
|
47
49
|
from qiskit.circuit.library import QuantumVolume
|
48
50
|
from qiskit.visualization.library import _generate_circuit_library_visualization
|
@@ -150,6 +152,7 @@ def quantum_volume(
|
|
150
152
|
**Reference Circuit:**
|
151
153
|
|
152
154
|
.. plot::
|
155
|
+
:alt: Diagram illustrating the previously described circuit.
|
153
156
|
|
154
157
|
from qiskit.circuit.library import quantum_volume
|
155
158
|
circuit = quantum_volume(5, 6, seed=10)
|
qiskit/circuit/operation.py
CHANGED
qiskit/circuit/parameter.py
CHANGED
@@ -340,7 +340,7 @@ class ParameterExpression:
|
|
340
340
|
either a constant or a second ParameterExpression.
|
341
341
|
|
342
342
|
Args:
|
343
|
-
operation:
|
343
|
+
operation: An operator, such as add, sub, mul, and truediv.
|
344
344
|
other: The second argument to be used with self in operation.
|
345
345
|
reflected: Optional - The default ordering is "self operator other".
|
346
346
|
If reflected is True, this is switched to "other operator self".
|
qiskit/circuit/quantumcircuit.py
CHANGED
@@ -835,6 +835,7 @@ class QuantumCircuit:
|
|
835
835
|
Consider the following circuit:
|
836
836
|
|
837
837
|
.. plot::
|
838
|
+
:alt: Circuit diagram output by the previous code.
|
838
839
|
:include-source:
|
839
840
|
|
840
841
|
from qiskit import QuantumCircuit
|
@@ -887,25 +888,6 @@ class QuantumCircuit:
|
|
887
888
|
|
888
889
|
assert qc.size() == 19
|
889
890
|
|
890
|
-
A particularly important circuit property is known as the circuit :meth:`depth`. The depth
|
891
|
-
of a quantum circuit is a measure of how many "layers" of quantum gates, executed in
|
892
|
-
parallel, it takes to complete the computation defined by the circuit. Because quantum
|
893
|
-
gates take time to implement, the depth of a circuit roughly corresponds to the amount of
|
894
|
-
time it takes the quantum computer to execute the circuit. Thus, the depth of a circuit
|
895
|
-
is one important quantity used to measure if a quantum circuit can be run on a device.
|
896
|
-
|
897
|
-
The depth of a quantum circuit has a mathematical definition as the longest path in a
|
898
|
-
directed acyclic graph (DAG). However, such a definition is a bit hard to grasp, even for
|
899
|
-
experts. Fortunately, the depth of a circuit can be easily understood by anyone familiar
|
900
|
-
with playing `Tetris <https://en.wikipedia.org/wiki/Tetris>`_. Lets see how to compute this
|
901
|
-
graphically:
|
902
|
-
|
903
|
-
.. image:: /source_images/depth.gif
|
904
|
-
|
905
|
-
We can verify our graphical result using :meth:`QuantumCircuit.depth`::
|
906
|
-
|
907
|
-
assert qc.depth() == 9
|
908
|
-
|
909
891
|
.. automethod:: count_ops
|
910
892
|
.. automethod:: depth
|
911
893
|
.. automethod:: get_instructions
|
@@ -2169,6 +2151,7 @@ class QuantumCircuit:
|
|
2169
2151
|
Examples:
|
2170
2152
|
|
2171
2153
|
.. plot::
|
2154
|
+
:alt: Circuit diagram output by the previous code.
|
2172
2155
|
:include-source:
|
2173
2156
|
|
2174
2157
|
from qiskit import QuantumCircuit
|
@@ -3425,6 +3408,7 @@ class QuantumCircuit:
|
|
3425
3408
|
|
3426
3409
|
Example:
|
3427
3410
|
.. plot::
|
3411
|
+
:alt: Circuit diagram output by the previous code.
|
3428
3412
|
:include-source:
|
3429
3413
|
|
3430
3414
|
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
|
@@ -3484,6 +3468,14 @@ class QuantumCircuit:
|
|
3484
3468
|
) -> int:
|
3485
3469
|
"""Return circuit depth (i.e., length of critical path).
|
3486
3470
|
|
3471
|
+
The depth of a quantum circuit is a measure of how many
|
3472
|
+
"layers" of quantum gates, executed in parallel, it takes to
|
3473
|
+
complete the computation defined by the circuit. Because
|
3474
|
+
quantum gates take time to implement, the depth of a circuit
|
3475
|
+
roughly corresponds to the amount of time it takes the quantum
|
3476
|
+
computer to execute the circuit.
|
3477
|
+
|
3478
|
+
|
3487
3479
|
.. warning::
|
3488
3480
|
This operation is not well defined if the circuit contains control-flow operations.
|
3489
3481
|
|
@@ -4306,6 +4298,7 @@ class QuantumCircuit:
|
|
4306
4298
|
Create a parameterized circuit and assign the parameters in-place.
|
4307
4299
|
|
4308
4300
|
.. plot::
|
4301
|
+
:alt: Circuit diagram output by the previous code.
|
4309
4302
|
:include-source:
|
4310
4303
|
|
4311
4304
|
from qiskit.circuit import QuantumCircuit, Parameter
|
@@ -4321,6 +4314,7 @@ class QuantumCircuit:
|
|
4321
4314
|
Bind the values out-of-place by list and get a copy of the original circuit.
|
4322
4315
|
|
4323
4316
|
.. plot::
|
4317
|
+
:alt: Circuit diagram output by the previous code.
|
4324
4318
|
:include-source:
|
4325
4319
|
|
4326
4320
|
from qiskit.circuit import QuantumCircuit, ParameterVector
|
qiskit/circuit/random/utils.py
CHANGED
@@ -37,6 +37,7 @@ def random_circuit(
|
|
37
37
|
from the set of standard gates in :mod:`qiskit.circuit.library.standard_gates`. For example:
|
38
38
|
|
39
39
|
.. plot::
|
40
|
+
:alt: Circuit diagram output by the previous code.
|
40
41
|
:include-source:
|
41
42
|
|
42
43
|
from qiskit.circuit.random import random_circuit
|
@@ -295,6 +296,7 @@ def random_clifford_circuit(num_qubits, num_gates, gates="all", seed=None):
|
|
295
296
|
gates from the set of standard gates in :mod:`qiskit.circuit.library.standard_gates`. For example:
|
296
297
|
|
297
298
|
.. plot::
|
299
|
+
:alt: Circuit diagram output by the previous code.
|
298
300
|
:include-source:
|
299
301
|
|
300
302
|
from qiskit.circuit.random import random_clifford_circuit
|
qiskit/pulse/builder.py
CHANGED
@@ -39,6 +39,7 @@ execution. For example, to play a series of pulses on channels is as simple as:
|
|
39
39
|
|
40
40
|
|
41
41
|
.. plot::
|
42
|
+
:alt: Output from the previous code.
|
42
43
|
:include-source:
|
43
44
|
|
44
45
|
from qiskit import pulse
|
@@ -61,6 +62,7 @@ statements. For example, below we write a simple program that :func:`play`\s
|
|
61
62
|
a pulse:
|
62
63
|
|
63
64
|
.. plot::
|
65
|
+
:alt: Output from the previous code.
|
64
66
|
:include-source:
|
65
67
|
|
66
68
|
from qiskit import pulse
|
@@ -90,6 +92,7 @@ state we prepared. This program which mixes circuits and pulses will be
|
|
90
92
|
automatically lowered to be run as a pulse program:
|
91
93
|
|
92
94
|
.. plot::
|
95
|
+
:alt: Output from the previous code.
|
93
96
|
:include-source:
|
94
97
|
|
95
98
|
from math import pi
|
@@ -273,6 +276,7 @@ Instructions
|
|
273
276
|
Pulse instructions are available within the builder interface. Here's an example:
|
274
277
|
|
275
278
|
.. plot::
|
279
|
+
:alt: Output from the previous code.
|
276
280
|
:include-source:
|
277
281
|
|
278
282
|
from qiskit import pulse
|
@@ -321,6 +325,7 @@ example an alignment context like :func:`align_right` may
|
|
321
325
|
be used to align all pulses as late as possible in a pulse program.
|
322
326
|
|
323
327
|
.. plot::
|
328
|
+
:alt: Output from the previous code.
|
324
329
|
:include-source:
|
325
330
|
|
326
331
|
from qiskit import pulse
|
@@ -1165,6 +1170,7 @@ def align_equispaced(duration: int | ParameterExpression) -> Generator[None, Non
|
|
1165
1170
|
Examples:
|
1166
1171
|
|
1167
1172
|
.. plot::
|
1173
|
+
:alt: Output from the previous code.
|
1168
1174
|
:include-source:
|
1169
1175
|
|
1170
1176
|
from qiskit import pulse
|
@@ -1219,6 +1225,7 @@ def align_func(
|
|
1219
1225
|
Examples:
|
1220
1226
|
|
1221
1227
|
.. plot::
|
1228
|
+
:alt: Output from the previous code.
|
1222
1229
|
:include-source:
|
1223
1230
|
|
1224
1231
|
import numpy as np
|
@@ -2043,6 +2050,7 @@ def macro(func: Callable):
|
|
2043
2050
|
Examples:
|
2044
2051
|
|
2045
2052
|
.. plot::
|
2053
|
+
:alt: Output from the previous code.
|
2046
2054
|
:include-source:
|
2047
2055
|
|
2048
2056
|
from qiskit import pulse
|
qiskit/qasm2/export.py
CHANGED
@@ -314,8 +314,8 @@ def _define_custom_operation(operation, gates_to_define):
|
|
314
314
|
# definition, but still continue to return the given object as the call-site object.
|
315
315
|
if operation.base_class in known_good_parameterized:
|
316
316
|
parameterized_operation = type(operation)(*_FIXED_PARAMETERS[: len(operation.params)])
|
317
|
-
elif hasattr(operation, "
|
318
|
-
new_op = operation.
|
317
|
+
elif hasattr(operation, "_qasm_decomposition"):
|
318
|
+
new_op = operation._qasm_decomposition()
|
319
319
|
parameterized_operation = operation = new_op.copy(name=_escape_name(new_op.name, "gate_"))
|
320
320
|
else:
|
321
321
|
parameterized_operation = operation
|
qiskit/qasm3/__init__.py
CHANGED
qiskit/qasm3/exporter.py
CHANGED
@@ -1180,13 +1180,16 @@ class QASM3Builder:
|
|
1180
1180
|
|
1181
1181
|
This will also push the gate into the symbol table (if required), including recursively
|
1182
1182
|
defining the gate blocks."""
|
1183
|
-
|
1183
|
+
operation = instruction.operation
|
1184
|
+
if hasattr(operation, "_qasm_decomposition"):
|
1185
|
+
operation = operation._qasm_decomposition()
|
1186
|
+
ident = self.symbols.get_gate(operation)
|
1184
1187
|
if ident is None:
|
1185
|
-
ident = self.define_gate(
|
1188
|
+
ident = self.define_gate(operation)
|
1186
1189
|
qubits = [self._lookup_bit(qubit) for qubit in instruction.qubits]
|
1187
1190
|
parameters = [
|
1188
1191
|
ast.StringifyAndPray(self._rebind_scoped_parameters(param))
|
1189
|
-
for param in
|
1192
|
+
for param in operation.params
|
1190
1193
|
]
|
1191
1194
|
if not self.disable_constants:
|
1192
1195
|
for parameter in parameters:
|
@@ -445,16 +445,14 @@ class PauliList(BasePauli, LinearMixin, GroupMixin):
|
|
445
445
|
f"Index {ind} is greater than number of qubits"
|
446
446
|
f" in the PauliList ({self.num_qubits})"
|
447
447
|
)
|
448
|
-
if len(value) ==
|
449
|
-
# Pad blocks to correct size
|
450
|
-
value_x = np.vstack(size * [value.x])
|
451
|
-
value_z = np.vstack(size * [value.z])
|
452
|
-
value_phase = np.vstack(size * [value.phase])
|
453
|
-
elif len(value) == size:
|
448
|
+
if len(value) == size:
|
454
449
|
# Blocks are already correct size
|
455
450
|
value_x = value.x
|
456
451
|
value_z = value.z
|
457
|
-
|
452
|
+
elif len(value) == 1:
|
453
|
+
# Pad blocks to correct size
|
454
|
+
value_x = np.vstack(size * [value.x])
|
455
|
+
value_z = np.vstack(size * [value.z])
|
458
456
|
else:
|
459
457
|
# Blocks are incorrect size
|
460
458
|
raise QiskitError(
|
@@ -465,7 +463,7 @@ class PauliList(BasePauli, LinearMixin, GroupMixin):
|
|
465
463
|
# Build new array by blocks
|
466
464
|
z = np.hstack([self.z[:, :ind], value_z, self.z[:, ind:]])
|
467
465
|
x = np.hstack([self.x[:, :ind], value_x, self.x[:, ind:]])
|
468
|
-
phase = self.phase +
|
466
|
+
phase = self.phase + value.phase
|
469
467
|
|
470
468
|
return PauliList.from_symplectic(z, x, phase)
|
471
469
|
|
@@ -1121,6 +1119,8 @@ class PauliList(BasePauli, LinearMixin, GroupMixin):
|
|
1121
1119
|
Returns:
|
1122
1120
|
PauliList: the constructed PauliList.
|
1123
1121
|
"""
|
1122
|
+
if isinstance(phase, np.ndarray) and np.ndim(phase) > 1:
|
1123
|
+
raise ValueError(f"phase should be at most 1D but has {np.ndim(phase)} dimensions.")
|
1124
1124
|
base_z, base_x, base_phase = cls._from_array(z, x, phase)
|
1125
1125
|
return cls(BasePauli(base_z, base_x, base_phase))
|
1126
1126
|
|
@@ -165,7 +165,16 @@ class SparsePauliOp(LinearOp):
|
|
165
165
|
# move the phase of `pauli_list` to `self._coeffs`
|
166
166
|
phase = pauli_list._phase
|
167
167
|
count_y = pauli_list._count_y()
|
168
|
-
|
168
|
+
|
169
|
+
# Compute exponentiation via integer arithmetic and lookup table to avoid
|
170
|
+
# floating point errors
|
171
|
+
exponent = (phase - count_y) % 4
|
172
|
+
lookup = np.array([1 + 0j, -1j, -1 + 0j, 1j], dtype=coeffs.dtype)
|
173
|
+
|
174
|
+
vals = lookup[exponent]
|
175
|
+
self._coeffs = vals * coeffs
|
176
|
+
|
177
|
+
# Update pauli_list phase
|
169
178
|
pauli_list._phase = np.mod(count_y, 4)
|
170
179
|
self._pauli_list = pauli_list
|
171
180
|
|
@@ -27,6 +27,7 @@ def multiplier_cumulative_h18(
|
|
27
27
|
performs a non-modular multiplication on two 3-qubit sized registers is:
|
28
28
|
|
29
29
|
.. plot::
|
30
|
+
:alt: Circuit diagram output by the previous code.
|
30
31
|
:include-source:
|
31
32
|
|
32
33
|
from qiskit.synthesis.arithmetic import multiplier_cumulative_h18
|
@@ -191,12 +191,6 @@ class ProductFormula(EvolutionSynthesis):
|
|
191
191
|
"preserve_order": self.preserve_order,
|
192
192
|
}
|
193
193
|
|
194
|
-
def _normalize_coefficients(
|
195
|
-
self, paulis: list[str | list[int], float | complex | ParameterExpression]
|
196
|
-
) -> list[str | list[int] | ParameterValueType]:
|
197
|
-
"""Ensure the coefficients are real (or parameter expressions)."""
|
198
|
-
return [[(op, qubits, real_or_fail(coeff)) for op, qubits, coeff in ops] for ops in paulis]
|
199
|
-
|
200
194
|
def _custom_evolution(self, num_qubits, pauli_rotations):
|
201
195
|
"""Implement the evolution for the non-standard path.
|
202
196
|
|
@@ -18,7 +18,9 @@ import inspect
|
|
18
18
|
import typing
|
19
19
|
from collections.abc import Callable
|
20
20
|
from itertools import chain
|
21
|
+
import numpy as np
|
21
22
|
|
23
|
+
from qiskit.circuit.parameterexpression import ParameterExpression
|
22
24
|
from qiskit.circuit.quantumcircuit import QuantumCircuit
|
23
25
|
from qiskit.quantum_info.operators import SparsePauliOp, Pauli
|
24
26
|
from qiskit.utils.deprecation import deprecate_arg
|
@@ -138,7 +140,7 @@ class SuzukiTrotter(ProductFormula):
|
|
138
140
|
|
139
141
|
.. code-block:: text
|
140
142
|
|
141
|
-
("X", [0], t), ("ZZ", [0, 1], 2t), ("X", [0],
|
143
|
+
("X", [0], t), ("ZZ", [0, 1], 2t), ("X", [0], t)
|
142
144
|
|
143
145
|
Note that the rotation angle contains a factor of 2, such that that evolution
|
144
146
|
of a Pauli :math:`P` over time :math:`t`, which is :math:`e^{itP}`, is represented
|
@@ -157,7 +159,10 @@ class SuzukiTrotter(ProductFormula):
|
|
157
159
|
time = evolution.time
|
158
160
|
|
159
161
|
def to_sparse_list(operator):
|
160
|
-
paulis =
|
162
|
+
paulis = [
|
163
|
+
(pauli, indices, real_or_fail(coeff) * time * 2 / self.reps)
|
164
|
+
for pauli, indices, coeff in operator.to_sparse_list()
|
165
|
+
]
|
161
166
|
if not self.preserve_order:
|
162
167
|
return reorder_paulis(paulis)
|
163
168
|
|
@@ -171,9 +176,6 @@ class SuzukiTrotter(ProductFormula):
|
|
171
176
|
# here would be the location to do so.
|
172
177
|
non_commuting = [[op] for op in to_sparse_list(operators)]
|
173
178
|
|
174
|
-
# normalize coefficients, i.e. ensure they are float or ParameterExpression
|
175
|
-
non_commuting = self._normalize_coefficients(non_commuting)
|
176
|
-
|
177
179
|
# we're already done here since Lie Trotter does not do any operator repetition
|
178
180
|
product_formula = self._recurse(self.order, non_commuting)
|
179
181
|
flattened = self.reps * list(chain.from_iterable(product_formula))
|
@@ -213,3 +215,18 @@ class SuzukiTrotter(ProductFormula):
|
|
213
215
|
],
|
214
216
|
)
|
215
217
|
return outer + inner + outer
|
218
|
+
|
219
|
+
|
220
|
+
def real_or_fail(value, tol=100):
|
221
|
+
"""Return real if close, otherwise fail. Unbound parameters are left unchanged.
|
222
|
+
|
223
|
+
Based on NumPy's ``real_if_close``, i.e. ``tol`` is in terms of machine precision for float.
|
224
|
+
"""
|
225
|
+
if isinstance(value, ParameterExpression):
|
226
|
+
return value
|
227
|
+
|
228
|
+
abstol = tol * np.finfo(float).eps
|
229
|
+
if abs(np.imag(value)) < abstol:
|
230
|
+
return np.real(value)
|
231
|
+
|
232
|
+
raise ValueError(f"Encountered complex value {value}, but expected real.")
|
qiskit/transpiler/__init__.py
CHANGED
@@ -33,6 +33,8 @@ branches, and other complex behaviors. That being said, the standard
|
|
33
33
|
compilation flow follows the structure given below:
|
34
34
|
|
35
35
|
.. image:: /source_images/transpiling_core_steps.png
|
36
|
+
:alt: The transpilation process takes the input circuit, applies the transpilation \
|
37
|
+
passes, then produces the output circuit.
|
36
38
|
|
37
39
|
.. raw:: html
|
38
40
|
|
@@ -331,7 +333,8 @@ example 3 qubit :class:`~.Target` above:
|
|
331
333
|
|
332
334
|
.. plot::
|
333
335
|
:include-source:
|
334
|
-
|
336
|
+
:alt: Output from the previous code.
|
337
|
+
|
335
338
|
from qiskit.circuit import Parameter, Measure
|
336
339
|
from qiskit.transpiler import Target, InstructionProperties
|
337
340
|
from qiskit.circuit.library import UGate, RZGate, RXGate, RYGate, CXGate, CZGate
|
@@ -390,6 +393,7 @@ see the individual connectivity, you can pass the operation name to
|
|
390
393
|
:meth:`.CouplingMap.build_coupling_map`:
|
391
394
|
|
392
395
|
.. plot::
|
396
|
+
:alt: Output from the previous code.
|
393
397
|
:include-source:
|
394
398
|
|
395
399
|
from qiskit.circuit import Parameter, Measure
|
@@ -445,6 +449,7 @@ see the individual connectivity, you can pass the operation name to
|
|
445
449
|
target.build_coupling_map('cx').draw()
|
446
450
|
|
447
451
|
.. plot::
|
452
|
+
:alt: Output from the previous code.
|
448
453
|
:include-source:
|
449
454
|
|
450
455
|
from qiskit.circuit import Parameter, Measure
|
@@ -532,6 +537,7 @@ Every quantum circuit run on the target device must be expressed using only thes
|
|
532
537
|
For example, to run a simple phase estimation circuit:
|
533
538
|
|
534
539
|
.. plot::
|
540
|
+
:alt: Circuit diagram output by the previous code.
|
535
541
|
:include-source:
|
536
542
|
|
537
543
|
import numpy as np
|
@@ -557,6 +563,7 @@ the target IBM Quantum device (the :class:`~.GenericBackendV2` class generates
|
|
557
563
|
a fake backend with a specified number of qubits for test purposes):
|
558
564
|
|
559
565
|
.. plot::
|
566
|
+
:alt: Circuit diagram output by the previous code.
|
560
567
|
:include-source:
|
561
568
|
|
562
569
|
from qiskit import transpile
|
@@ -608,6 +615,7 @@ It is important to highlight two special cases:
|
|
608
615
|
['id', 'rz', 'sx', 'x', 'cx', 'measure', 'delay']
|
609
616
|
|
610
617
|
.. plot:
|
618
|
+
:alt: Circuit diagram output by the previous code.
|
611
619
|
:include-source:
|
612
620
|
|
613
621
|
from qiskit.circuit import QuantumCircuit
|
@@ -628,6 +636,7 @@ It is important to highlight two special cases:
|
|
628
636
|
this gate must be decomposed. This decomposition is quite costly:
|
629
637
|
|
630
638
|
.. plot::
|
639
|
+
:alt: Circuit diagram output by the previous code.
|
631
640
|
:include-source:
|
632
641
|
|
633
642
|
from qiskit.circuit import QuantumCircuit
|
@@ -653,6 +662,7 @@ qubits used in computations. We need to be able to map these virtual qubits in
|
|
653
662
|
manner to the "physical" qubits in an actual quantum device.
|
654
663
|
|
655
664
|
.. image:: /source_images/mapping.png
|
665
|
+
:alt: Diagram illustrating how virtual qubits are mapped to physical qubits.
|
656
666
|
|
657
667
|
|
658
668
|
By default, qiskit will do this mapping for you. The choice of mapping depends on the
|
@@ -700,6 +710,7 @@ and we can view this layout selection graphically using
|
|
700
710
|
:func:`qiskit.visualization.plot_circuit_layout`:
|
701
711
|
|
702
712
|
.. plot::
|
713
|
+
:alt: Circuit diagram output by the previous code.
|
703
714
|
:include-source:
|
704
715
|
|
705
716
|
from qiskit import QuantumCircuit, transpile
|
@@ -718,6 +729,7 @@ and we can view this layout selection graphically using
|
|
718
729
|
- **Layout Using Optimization Level 0**
|
719
730
|
|
720
731
|
.. plot::
|
732
|
+
:alt: Output from the previous code.
|
721
733
|
:include-source:
|
722
734
|
|
723
735
|
from qiskit import QuantumCircuit, transpile
|
@@ -737,6 +749,7 @@ and we can view this layout selection graphically using
|
|
737
749
|
- **Layout Using Optimization Level 3**
|
738
750
|
|
739
751
|
.. plot::
|
752
|
+
:alt: Output from the previous code.
|
740
753
|
:include-source:
|
741
754
|
|
742
755
|
from qiskit import QuantumCircuit, transpile
|
@@ -760,6 +773,7 @@ keyword argument, where the index labels the virtual qubit in the circuit and th
|
|
760
773
|
corresponding value is the label for the physical qubit to map onto:
|
761
774
|
|
762
775
|
.. plot::
|
776
|
+
:alt: Output from the previous code.
|
763
777
|
:include-source:
|
764
778
|
|
765
779
|
from qiskit import QuantumCircuit, transpile
|
@@ -807,6 +821,7 @@ In order to highlight this, we run a GHZ circuit 100 times, using a "bad" (disco
|
|
807
821
|
``initial_layout`` in a heavy hex coupling map:
|
808
822
|
|
809
823
|
.. plot::
|
824
|
+
:alt: Diagram illustrating the previously described circuit.
|
810
825
|
|
811
826
|
from qiskit import QuantumCircuit, transpile
|
812
827
|
|
@@ -816,6 +831,7 @@ In order to highlight this, we run a GHZ circuit 100 times, using a "bad" (disco
|
|
816
831
|
ghz.draw(output='mpl')
|
817
832
|
|
818
833
|
.. plot::
|
834
|
+
:alt: Output from the previous code.
|
819
835
|
:include-source:
|
820
836
|
|
821
837
|
import matplotlib.pyplot as plt
|
@@ -888,6 +904,7 @@ setting the optimization level higher:
|
|
888
904
|
|
889
905
|
|
890
906
|
.. plot::
|
907
|
+
:alt: Diagram illustrating the previously described circuit.
|
891
908
|
|
892
909
|
import matplotlib.pyplot as plt
|
893
910
|
from qiskit import QuantumCircuit, transpile
|
@@ -900,6 +917,7 @@ setting the optimization level higher:
|
|
900
917
|
ghz.draw(output='mpl')
|
901
918
|
|
902
919
|
.. plot::
|
920
|
+
:alt: Output from the previous code.
|
903
921
|
:include-source:
|
904
922
|
|
905
923
|
import matplotlib.pyplot as plt
|
@@ -946,6 +964,7 @@ for idle time on the qubits between the execution of instructions. For example,
|
|
946
964
|
circuit such as:
|
947
965
|
|
948
966
|
.. plot::
|
967
|
+
:alt: Diagram illustrating the previously described circuit.
|
949
968
|
|
950
969
|
from qiskit import QuantumCircuit
|
951
970
|
|
@@ -957,6 +976,7 @@ circuit such as:
|
|
957
976
|
we can then call :func:`~.transpile` on it with ``scheduling_method`` set:
|
958
977
|
|
959
978
|
.. plot::
|
979
|
+
:alt: Circuit diagram output by the previous code.
|
960
980
|
:include-source:
|
961
981
|
|
962
982
|
from qiskit import QuantumCircuit, transpile
|
@@ -976,6 +996,7 @@ account for idle time on each qubit. To get a better idea of the timing of the c
|
|
976
996
|
also look at it with the :func:`.timeline.draw` function:
|
977
997
|
|
978
998
|
.. plot::
|
999
|
+
:alt: Output from circuit timeline drawer.
|
979
1000
|
|
980
1001
|
from qiskit.visualization.timeline import draw as timeline_draw
|
981
1002
|
|
qiskit/transpiler/layout.py
CHANGED
@@ -455,6 +455,7 @@ class TranspileLayout:
|
|
455
455
|
let the input circuit be:
|
456
456
|
|
457
457
|
.. plot::
|
458
|
+
:alt: Circuit diagram output by the previous code.
|
458
459
|
:include-source:
|
459
460
|
|
460
461
|
from qiskit.circuit import QuantumCircuit, QuantumRegister
|
@@ -470,6 +471,7 @@ class TranspileLayout:
|
|
470
471
|
Suppose that during the layout stage the transpiler reorders the qubits to be:
|
471
472
|
|
472
473
|
.. plot::
|
474
|
+
:alt: Circuit diagram output by the previous code.
|
473
475
|
:include-source:
|
474
476
|
|
475
477
|
from qiskit import QuantumCircuit
|
@@ -498,6 +500,7 @@ class TranspileLayout:
|
|
498
500
|
becomes:
|
499
501
|
|
500
502
|
.. plot::
|
503
|
+
:alt: Circuit diagram output by the previous code.
|
501
504
|
:include-source:
|
502
505
|
|
503
506
|
from qiskit import QuantumCircuit
|