qiskit 1.3.0rc2__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.
Files changed (93) hide show
  1. qiskit/VERSION.txt +1 -1
  2. qiskit/_accelerate.pyd +0 -0
  3. qiskit/circuit/__init__.py +2 -0
  4. qiskit/circuit/add_control.py +110 -92
  5. qiskit/circuit/controlledgate.py +2 -0
  6. qiskit/circuit/library/__init__.py +1 -0
  7. qiskit/circuit/library/arithmetic/adders/adder.py +25 -0
  8. qiskit/circuit/library/arithmetic/adders/cdkm_ripple_carry_adder.py +1 -1
  9. qiskit/circuit/library/arithmetic/adders/draper_qft_adder.py +1 -1
  10. qiskit/circuit/library/arithmetic/adders/vbe_ripple_carry_adder.py +1 -1
  11. qiskit/circuit/library/arithmetic/multipliers/multiplier.py +9 -0
  12. qiskit/circuit/library/arithmetic/piecewise_chebyshev.py +1 -0
  13. qiskit/circuit/library/basis_change/qft.py +3 -0
  14. qiskit/circuit/library/boolean_logic/inner_product.py +2 -0
  15. qiskit/circuit/library/boolean_logic/quantum_and.py +4 -0
  16. qiskit/circuit/library/boolean_logic/quantum_or.py +4 -0
  17. qiskit/circuit/library/boolean_logic/quantum_xor.py +2 -0
  18. qiskit/circuit/library/fourier_checking.py +2 -0
  19. qiskit/circuit/library/generalized_gates/gms.py +1 -0
  20. qiskit/circuit/library/generalized_gates/gr.py +4 -0
  21. qiskit/circuit/library/generalized_gates/mcmt.py +1 -0
  22. qiskit/circuit/library/generalized_gates/permutation.py +5 -1
  23. qiskit/circuit/library/generalized_gates/unitary.py +1 -1
  24. qiskit/circuit/library/graph_state.py +2 -0
  25. qiskit/circuit/library/grover_operator.py +7 -3
  26. qiskit/circuit/library/hidden_linear_function.py +2 -0
  27. qiskit/circuit/library/iqp.py +5 -0
  28. qiskit/circuit/library/n_local/efficient_su2.py +7 -2
  29. qiskit/circuit/library/n_local/evolved_operator_ansatz.py +3 -0
  30. qiskit/circuit/library/n_local/excitation_preserving.py +14 -8
  31. qiskit/circuit/library/n_local/n_local.py +10 -5
  32. qiskit/circuit/library/n_local/pauli_two_design.py +5 -2
  33. qiskit/circuit/library/n_local/qaoa_ansatz.py +1 -0
  34. qiskit/circuit/library/n_local/real_amplitudes.py +10 -4
  35. qiskit/circuit/library/overlap.py +1 -0
  36. qiskit/circuit/library/phase_estimation.py +2 -0
  37. qiskit/circuit/library/quantum_volume.py +3 -0
  38. qiskit/circuit/operation.py +1 -0
  39. qiskit/circuit/parameter.py +1 -0
  40. qiskit/circuit/parameterexpression.py +1 -1
  41. qiskit/circuit/quantumcircuit.py +13 -19
  42. qiskit/circuit/random/utils.py +2 -0
  43. qiskit/converters/dag_to_circuit.py +1 -0
  44. qiskit/primitives/statevector_estimator.py +1 -0
  45. qiskit/providers/fake_provider/__init__.py +1 -0
  46. qiskit/pulse/builder.py +8 -0
  47. qiskit/pulse/library/symbolic_pulses.py +1 -0
  48. qiskit/qasm2/export.py +2 -2
  49. qiskit/qasm3/__init__.py +1 -0
  50. qiskit/qasm3/exporter.py +6 -3
  51. qiskit/qpy/__init__.py +5 -5
  52. qiskit/quantum_info/operators/channel/chi.py +9 -9
  53. qiskit/quantum_info/operators/channel/choi.py +9 -9
  54. qiskit/quantum_info/operators/channel/ptm.py +9 -9
  55. qiskit/quantum_info/operators/channel/quantum_channel.py +3 -3
  56. qiskit/quantum_info/operators/channel/stinespring.py +9 -9
  57. qiskit/quantum_info/operators/channel/superop.py +5 -9
  58. qiskit/quantum_info/operators/symplectic/pauli_list.py +8 -8
  59. qiskit/quantum_info/operators/symplectic/sparse_pauli_op.py +10 -1
  60. qiskit/quantum_info/states/densitymatrix.py +17 -15
  61. qiskit/quantum_info/states/stabilizerstate.py +7 -6
  62. qiskit/quantum_info/states/statevector.py +15 -6
  63. qiskit/synthesis/arithmetic/multipliers/hrs_cumulative_multiplier.py +1 -0
  64. qiskit/synthesis/arithmetic/multipliers/rg_qft_multiplier.py +1 -0
  65. qiskit/synthesis/evolution/product_formula.py +0 -6
  66. qiskit/synthesis/evolution/suzuki_trotter.py +22 -5
  67. qiskit/transpiler/__init__.py +22 -1
  68. qiskit/transpiler/layout.py +3 -0
  69. qiskit/transpiler/passes/basis/decompose.py +24 -4
  70. qiskit/transpiler/passes/optimization/inverse_cancellation.py +2 -0
  71. qiskit/transpiler/passes/routing/star_prerouting.py +1 -0
  72. qiskit/transpiler/passes/scheduling/dynamical_decoupling.py +1 -0
  73. qiskit/transpiler/passes/scheduling/padding/dynamical_decoupling.py +1 -0
  74. qiskit/transpiler/passes/synthesis/hls_plugins.py +137 -30
  75. qiskit/transpiler/passes/utils/filter_op_nodes.py +2 -1
  76. qiskit/transpiler/passes/utils/remove_barriers.py +1 -0
  77. qiskit/transpiler/preset_passmanagers/__init__.py +5 -5
  78. qiskit/transpiler/preset_passmanagers/builtin_plugins.py +19 -22
  79. qiskit/transpiler/target.py +1 -1
  80. qiskit/visualization/__init__.py +6 -0
  81. qiskit/visualization/circuit/circuit_visualization.py +1 -0
  82. qiskit/visualization/counts_visualization.py +2 -0
  83. qiskit/visualization/dag_visualization.py +1 -0
  84. qiskit/visualization/gate_map.py +7 -3
  85. qiskit/visualization/pulse_v2/interface.py +4 -1
  86. qiskit/visualization/state_visualization.py +13 -2
  87. qiskit/visualization/timeline/interface.py +6 -3
  88. {qiskit-1.3.0rc2.dist-info → qiskit-1.3.2.dist-info}/METADATA +26 -26
  89. {qiskit-1.3.0rc2.dist-info → qiskit-1.3.2.dist-info}/RECORD +93 -93
  90. {qiskit-1.3.0rc2.dist-info → qiskit-1.3.2.dist-info}/WHEEL +1 -1
  91. {qiskit-1.3.0rc2.dist-info → qiskit-1.3.2.dist-info}/entry_points.txt +1 -1
  92. {qiskit-1.3.0rc2.dist-info → qiskit-1.3.2.dist-info}/LICENSE.txt +0 -0
  93. {qiskit-1.3.0rc2.dist-info → qiskit-1.3.2.dist-info}/top_level.txt +0 -0
qiskit/qpy/__init__.py CHANGED
@@ -447,10 +447,10 @@ characters:
447
447
  * - ``u``
448
448
  - substitution
449
449
 
450
- If the type value is ``f`` ,``c`` or ``i``, the corresponding ``lhs`` or `rhs``
450
+ If the type value is ``f``, ``c``, or ``i``, the corresponding ``lhs`` or ``rhs``
451
451
  field widths are 128 bits each. In the case of floats, the literal value is encoded as a double
452
452
  with 0 padding, while complex numbers are encoded as real part followed by imaginary part,
453
- taking up 64 bits each. For ``i`, the value is encoded as a 64 bit signed integer with 0 padding
453
+ taking up 64 bits each. For ``i``, the value is encoded as a 64 bit signed integer with 0 padding
454
454
  for the full 128 bit width. ``n`` is used to represent a ``None`` and typically isn't directly used
455
455
  as it indicates an argument that's not used. For ``p`` the data is the UUID for the
456
456
  :class:`.Parameter` which can be looked up in the symbol map described in the
@@ -546,7 +546,7 @@ Type code Meaning
546
546
  Changes to EXPR_VAR
547
547
  ~~~~~~~~~~~~~~~~~~~
548
548
 
549
- The EXPR_VAR variable has gained a new type code and payload, in addition to the pre-existing ones:
549
+ The ``EXPR_VAR`` variable has gained a new type code and payload, in addition to the pre-existing ones:
550
550
 
551
551
  =========================== ========= ============================================================
552
552
  Python class Type code Payload
@@ -693,9 +693,9 @@ Each of these are described in the following table:
693
693
  ====================== ========= ======================================================= ========
694
694
  Qiskit class Type code Payload Children
695
695
  ====================== ========= ======================================================= ========
696
- :class:`~.expr.Var` ``x`` One EXPR_VAR. 0
696
+ :class:`~.expr.Var` ``x`` One ``EXPR_VAR``. 0
697
697
 
698
- :class:`~.expr.Value` ``v`` One EXPR_VALUE. 0
698
+ :class:`~.expr.Value` ``v`` One ``EXPR_VALUE``. 0
699
699
 
700
700
  :class:`~.expr.Cast` ``c`` One ``_Bool`` that corresponds to the value of 1
701
701
  ``implicit``.
@@ -18,6 +18,8 @@ Chi-matrix representation of a Quantum Channel.
18
18
  from __future__ import annotations
19
19
  import copy as _copy
20
20
  import math
21
+ from typing import TYPE_CHECKING
22
+
21
23
  import numpy as np
22
24
 
23
25
  from qiskit import _numpy_compat
@@ -31,6 +33,9 @@ from qiskit.quantum_info.operators.channel.transformations import _to_chi
31
33
  from qiskit.quantum_info.operators.mixins import generate_apidocs
32
34
  from qiskit.quantum_info.operators.base_operator import BaseOperator
33
35
 
36
+ if TYPE_CHECKING:
37
+ from qiskit import circuit
38
+
34
39
 
35
40
  class Chi(QuantumChannel):
36
41
  r"""Pauli basis Chi-matrix representation of a quantum channel.
@@ -59,21 +64,16 @@ class Chi(QuantumChannel):
59
64
 
60
65
  def __init__(
61
66
  self,
62
- data: QuantumCircuit | Instruction | BaseOperator | np.ndarray,
67
+ data: QuantumCircuit | circuit.instruction.Instruction | BaseOperator | np.ndarray,
63
68
  input_dims: int | tuple | None = None,
64
69
  output_dims: int | tuple | None = None,
65
70
  ):
66
71
  """Initialize a quantum channel Chi-matrix operator.
67
72
 
68
73
  Args:
69
- data (QuantumCircuit or
70
- Instruction or
71
- BaseOperator or
72
- matrix): data to initialize superoperator.
73
- input_dims (tuple): the input subsystem dimensions.
74
- [Default: None]
75
- output_dims (tuple): the output subsystem dimensions.
76
- [Default: None]
74
+ data: data to initialize superoperator.
75
+ input_dims: the input subsystem dimensions.
76
+ output_dims: the output subsystem dimensions.
77
77
 
78
78
  Raises:
79
79
  QiskitError: if input data is not an N-qubit channel or
@@ -18,6 +18,8 @@ Choi-matrix representation of a Quantum Channel.
18
18
  from __future__ import annotations
19
19
  import copy as _copy
20
20
  import math
21
+ from typing import TYPE_CHECKING
22
+
21
23
  import numpy as np
22
24
 
23
25
  from qiskit import _numpy_compat
@@ -32,6 +34,9 @@ from qiskit.quantum_info.operators.channel.transformations import _bipartite_ten
32
34
  from qiskit.quantum_info.operators.mixins import generate_apidocs
33
35
  from qiskit.quantum_info.operators.base_operator import BaseOperator
34
36
 
37
+ if TYPE_CHECKING:
38
+ from qiskit import circuit
39
+
35
40
 
36
41
  class Choi(QuantumChannel):
37
42
  r"""Choi-matrix representation of a Quantum Channel.
@@ -64,21 +69,16 @@ class Choi(QuantumChannel):
64
69
 
65
70
  def __init__(
66
71
  self,
67
- data: QuantumCircuit | Instruction | BaseOperator | np.ndarray,
72
+ data: QuantumCircuit | circuit.instruction.Instruction | BaseOperator | np.ndarray,
68
73
  input_dims: int | tuple | None = None,
69
74
  output_dims: int | tuple | None = None,
70
75
  ):
71
76
  """Initialize a quantum channel Choi matrix operator.
72
77
 
73
78
  Args:
74
- data (QuantumCircuit or
75
- Instruction or
76
- BaseOperator or
77
- matrix): data to initialize superoperator.
78
- input_dims (tuple): the input subsystem dimensions.
79
- [Default: None]
80
- output_dims (tuple): the output subsystem dimensions.
81
- [Default: None]
79
+ data: data to initialize superoperator.
80
+ input_dims: the input subsystem dimensions.
81
+ output_dims: the output subsystem dimensions.
82
82
 
83
83
  Raises:
84
84
  QiskitError: if input data cannot be initialized as a
@@ -18,6 +18,8 @@ Pauli Transfer Matrix (PTM) representation of a Quantum Channel.
18
18
  from __future__ import annotations
19
19
  import copy as _copy
20
20
  import math
21
+ from typing import TYPE_CHECKING
22
+
21
23
  import numpy as np
22
24
 
23
25
  from qiskit import _numpy_compat
@@ -30,6 +32,9 @@ from qiskit.quantum_info.operators.channel.transformations import _to_ptm
30
32
  from qiskit.quantum_info.operators.mixins import generate_apidocs
31
33
  from qiskit.quantum_info.operators.base_operator import BaseOperator
32
34
 
35
+ if TYPE_CHECKING:
36
+ from qiskit import circuit
37
+
33
38
 
34
39
  class PTM(QuantumChannel):
35
40
  r"""Pauli Transfer Matrix (PTM) representation of a Quantum Channel.
@@ -67,21 +72,16 @@ class PTM(QuantumChannel):
67
72
 
68
73
  def __init__(
69
74
  self,
70
- data: QuantumCircuit | Instruction | BaseOperator | np.ndarray,
75
+ data: QuantumCircuit | circuit.instruction.Instruction | BaseOperator | np.ndarray,
71
76
  input_dims: int | tuple | None = None,
72
77
  output_dims: int | tuple | None = None,
73
78
  ):
74
79
  """Initialize a PTM quantum channel operator.
75
80
 
76
81
  Args:
77
- data (QuantumCircuit or
78
- Instruction or
79
- BaseOperator or
80
- matrix): data to initialize superoperator.
81
- input_dims (tuple): the input subsystem dimensions.
82
- [Default: None]
83
- output_dims (tuple): the output subsystem dimensions.
84
- [Default: None]
82
+ data: data to initialize superoperator.
83
+ input_dims: the input subsystem dimensions.
84
+ output_dims: the output subsystem dimensions.
85
85
 
86
86
  Raises:
87
87
  QiskitError: if input data is not an N-qubit channel or
@@ -53,9 +53,9 @@ class QuantumChannel(LinearOp):
53
53
  """Initialize a quantum channel Superoperator operator.
54
54
 
55
55
  Args:
56
- data (array or list): quantum channel data array.
57
- op_shape (OpShape): the operator shape of the channel.
58
- num_qubits (int): the number of qubits if the channel is N-qubit.
56
+ data: quantum channel data array.
57
+ op_shape: the operator shape of the channel.
58
+ num_qubits: the number of qubits if the channel is N-qubit.
59
59
 
60
60
  Raises:
61
61
  QiskitError: if arguments are invalid.
@@ -17,6 +17,8 @@ from __future__ import annotations
17
17
  import copy
18
18
  import math
19
19
  from numbers import Number
20
+ from typing import TYPE_CHECKING
21
+
20
22
  import numpy as np
21
23
 
22
24
  from qiskit.circuit.quantumcircuit import QuantumCircuit
@@ -32,6 +34,9 @@ from qiskit.quantum_info.operators.channel.transformations import _to_stinesprin
32
34
  from qiskit.quantum_info.operators.mixins import generate_apidocs
33
35
  from qiskit.quantum_info.operators.base_operator import BaseOperator
34
36
 
37
+ if TYPE_CHECKING:
38
+ from qiskit import circuit
39
+
35
40
 
36
41
  class Stinespring(QuantumChannel):
37
42
  r"""Stinespring representation of a quantum channel.
@@ -64,21 +69,16 @@ class Stinespring(QuantumChannel):
64
69
 
65
70
  def __init__(
66
71
  self,
67
- data: QuantumCircuit | Instruction | BaseOperator | np.ndarray,
72
+ data: QuantumCircuit | circuit.instruction.Instruction | BaseOperator | np.ndarray,
68
73
  input_dims: int | tuple | None = None,
69
74
  output_dims: int | tuple | None = None,
70
75
  ):
71
76
  """Initialize a quantum channel Stinespring operator.
72
77
 
73
78
  Args:
74
- data (QuantumCircuit or
75
- Instruction or
76
- BaseOperator or
77
- matrix): data to initialize superoperator.
78
- input_dims (tuple): the input subsystem dimensions.
79
- [Default: None]
80
- output_dims (tuple): the output subsystem dimensions.
81
- [Default: None]
79
+ data: data to initialize superoperator.
80
+ input_dims: the input subsystem dimensions.
81
+ output_dims: the output subsystem dimensions.
82
82
 
83
83
  Raises:
84
84
  QiskitError: if input data cannot be initialized as a
@@ -33,6 +33,7 @@ from qiskit.quantum_info.operators.op_shape import OpShape
33
33
  from qiskit.quantum_info.operators.operator import Operator
34
34
 
35
35
  if TYPE_CHECKING:
36
+ from qiskit import circuit
36
37
  from qiskit.quantum_info.states.densitymatrix import DensityMatrix
37
38
  from qiskit.quantum_info.states.statevector import Statevector
38
39
 
@@ -62,21 +63,16 @@ class SuperOp(QuantumChannel):
62
63
 
63
64
  def __init__(
64
65
  self,
65
- data: QuantumCircuit | Instruction | BaseOperator | np.ndarray,
66
+ data: QuantumCircuit | circuit.instruction.Instruction | BaseOperator | np.ndarray,
66
67
  input_dims: tuple | None = None,
67
68
  output_dims: tuple | None = None,
68
69
  ):
69
70
  """Initialize a quantum channel Superoperator operator.
70
71
 
71
72
  Args:
72
- data (QuantumCircuit or
73
- Instruction or
74
- BaseOperator or
75
- matrix): data to initialize superoperator.
76
- input_dims (tuple): the input subsystem dimensions.
77
- [Default: None]
78
- output_dims (tuple): the output subsystem dimensions.
79
- [Default: None]
73
+ data: data to initialize superoperator.
74
+ input_dims: the input subsystem dimensions.
75
+ output_dims: the output subsystem dimensions.
80
76
 
81
77
  Raises:
82
78
  QiskitError: if input data cannot be initialized as a
@@ -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) == 1:
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
- value_phase = value.phase
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 + value_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
- self._coeffs = np.asarray((-1j) ** (phase - count_y) * coeffs, dtype=coeffs.dtype)
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
 
@@ -17,6 +17,8 @@ DensityMatrix quantum state class.
17
17
  from __future__ import annotations
18
18
  import copy as _copy
19
19
  from numbers import Number
20
+ from typing import TYPE_CHECKING
21
+
20
22
  import numpy as np
21
23
 
22
24
  from qiskit import _numpy_compat
@@ -37,27 +39,27 @@ from qiskit.quantum_info.operators.channel.superop import SuperOp
37
39
  from qiskit._accelerate.pauli_expval import density_expval_pauli_no_x, density_expval_pauli_with_x
38
40
  from qiskit.quantum_info.states.statevector import Statevector
39
41
 
42
+ if TYPE_CHECKING:
43
+ from qiskit import circuit
44
+
40
45
 
41
46
  class DensityMatrix(QuantumState, TolerancesMixin):
42
47
  """DensityMatrix class"""
43
48
 
44
49
  def __init__(
45
50
  self,
46
- data: np.ndarray | list | QuantumCircuit | Instruction | QuantumState,
51
+ data: np.ndarray | list | QuantumCircuit | circuit.instruction.Instruction | QuantumState,
47
52
  dims: int | tuple | list | None = None,
48
53
  ):
49
54
  """Initialize a density matrix object.
50
55
 
51
56
  Args:
52
- data (np.ndarray or list or matrix_like or QuantumCircuit or
53
- qiskit.circuit.Instruction):
54
- A statevector, quantum instruction or an object with a ``to_operator`` or
57
+ data: A statevector, quantum instruction or an object with a ``to_operator`` or
55
58
  ``to_matrix`` method from which the density matrix can be constructed.
56
59
  If a vector the density matrix is constructed as the projector of that vector.
57
60
  If a quantum instruction, the density matrix is constructed by assuming all
58
61
  qubits are initialized in the zero state.
59
- dims (int or tuple or list): Optional. The subsystem dimension
60
- of the state (See additional information).
62
+ dims: The subsystem dimension of the state (See additional information).
61
63
 
62
64
  Raises:
63
65
  QiskitError: if input data is not valid.
@@ -303,19 +305,17 @@ class DensityMatrix(QuantumState, TolerancesMixin):
303
305
 
304
306
  def evolve(
305
307
  self,
306
- other: Operator | QuantumChannel | Instruction | QuantumCircuit,
308
+ other: Operator | QuantumChannel | circuit.instruction.Instruction | QuantumCircuit,
307
309
  qargs: list[int] | None = None,
308
310
  ) -> DensityMatrix:
309
311
  """Evolve a quantum state by an operator.
310
312
 
311
313
  Args:
312
- other (Operator or QuantumChannel
313
- or Instruction or Circuit): The operator to evolve by.
314
- qargs (list): a list of QuantumState subsystem positions to apply
315
- the operator on.
314
+ other: The operator to evolve by.
315
+ qargs: a list of QuantumState subsystem positions to apply the operator on.
316
316
 
317
317
  Returns:
318
- DensityMatrix: the output density matrix.
318
+ The output density matrix.
319
319
 
320
320
  Raises:
321
321
  QiskitError: if the operator dimension does not match the
@@ -598,7 +598,9 @@ class DensityMatrix(QuantumState, TolerancesMixin):
598
598
  return DensityMatrix(state, dims=dims)
599
599
 
600
600
  @classmethod
601
- def from_instruction(cls, instruction: Instruction | QuantumCircuit) -> DensityMatrix:
601
+ def from_instruction(
602
+ cls, instruction: circuit.instruction.Instruction | QuantumCircuit
603
+ ) -> DensityMatrix:
602
604
  """Return the output density matrix of an instruction.
603
605
 
604
606
  The statevector is initialized in the state :math:`|{0,\\ldots,0}\\rangle` of
@@ -606,10 +608,10 @@ class DensityMatrix(QuantumState, TolerancesMixin):
606
608
  by the input instruction, and the output statevector returned.
607
609
 
608
610
  Args:
609
- instruction (qiskit.circuit.Instruction or QuantumCircuit): instruction or circuit
611
+ instruction: instruction or circuit
610
612
 
611
613
  Returns:
612
- DensityMatrix: the final density matrix.
614
+ The final density matrix.
613
615
 
614
616
  Raises:
615
617
  QiskitError: if the instruction contains invalid instructions for
@@ -17,6 +17,7 @@ Stabilizer state class.
17
17
  from __future__ import annotations
18
18
 
19
19
  from collections.abc import Collection
20
+ from typing import TYPE_CHECKING
20
21
 
21
22
  import numpy as np
22
23
 
@@ -28,6 +29,9 @@ from qiskit.quantum_info.operators.symplectic.clifford_circuits import _append_x
28
29
  from qiskit.quantum_info.states.quantum_state import QuantumState
29
30
  from qiskit.circuit import QuantumCircuit, Instruction
30
31
 
32
+ if TYPE_CHECKING:
33
+ from qiskit import circuit
34
+
31
35
 
32
36
  class StabilizerState(QuantumState):
33
37
  """StabilizerState class.
@@ -79,17 +83,14 @@ class StabilizerState(QuantumState):
79
83
 
80
84
  def __init__(
81
85
  self,
82
- data: StabilizerState | Clifford | Pauli | QuantumCircuit | Instruction,
86
+ data: StabilizerState | Clifford | Pauli | QuantumCircuit | circuit.instruction.Instruction,
83
87
  validate: bool = True,
84
88
  ):
85
89
  """Initialize a StabilizerState object.
86
90
 
87
91
  Args:
88
- data (StabilizerState or Clifford or Pauli or QuantumCircuit or
89
- qiskit.circuit.Instruction):
90
- Data from which the stabilizer state can be constructed.
91
- validate (boolean): validate that the stabilizer state data is
92
- a valid Clifford.
92
+ data: Data from which the stabilizer state can be constructed.
93
+ validate: validate that the stabilizer state data is a valid Clifford.
93
94
  """
94
95
 
95
96
  # Initialize from another StabilizerState
@@ -18,6 +18,7 @@ import copy as _copy
18
18
  import math
19
19
  import re
20
20
  from numbers import Number
21
+ from typing import TYPE_CHECKING
21
22
 
22
23
  import numpy as np
23
24
 
@@ -37,27 +38,34 @@ from qiskit._accelerate.pauli_expval import (
37
38
  expval_pauli_with_x,
38
39
  )
39
40
 
41
+ if TYPE_CHECKING:
42
+ from qiskit import circuit
43
+
40
44
 
41
45
  class Statevector(QuantumState, TolerancesMixin):
42
46
  """Statevector class"""
43
47
 
44
48
  def __init__(
45
49
  self,
46
- data: np.ndarray | list | Statevector | Operator | QuantumCircuit | Instruction,
50
+ data: (
51
+ np.ndarray
52
+ | list
53
+ | Statevector
54
+ | Operator
55
+ | QuantumCircuit
56
+ | circuit.instruction.Instruction
57
+ ),
47
58
  dims: int | tuple | list | None = None,
48
59
  ):
49
60
  """Initialize a statevector object.
50
61
 
51
62
  Args:
52
- data (np.array or list or Statevector or Operator or QuantumCircuit or
53
- qiskit.circuit.Instruction):
54
- Data from which the statevector can be constructed. This can be either a complex
63
+ data: Data from which the statevector can be constructed. This can be either a complex
55
64
  vector, another statevector, a ``Operator`` with only one column or a
56
65
  ``QuantumCircuit`` or ``Instruction``. If the data is a circuit or instruction,
57
66
  the statevector is constructed by assuming that all qubits are initialized to the
58
67
  zero state.
59
- dims (int or tuple or list): Optional. The subsystem dimension of
60
- the state (See additional information).
68
+ dims: The subsystem dimension of the state (See additional information).
61
69
 
62
70
  Raises:
63
71
  QiskitError: if input data is not valid.
@@ -173,6 +181,7 @@ class Statevector(QuantumState, TolerancesMixin):
173
181
  Plot one of the Bell states
174
182
 
175
183
  .. plot::
184
+ :alt: Output from the previous code.
176
185
  :include-source:
177
186
 
178
187
  from numpy import sqrt
@@ -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
@@ -35,6 +35,7 @@ def multiplier_qft_r17(
35
35
  For example, on 3 state qubits, a full multiplier is given by:
36
36
 
37
37
  .. plot::
38
+ :alt: Circuit diagram output by the previous code.
38
39
  :include-source:
39
40
 
40
41
  from qiskit.synthesis.arithmetic import multiplier_qft_r17
@@ -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], 2)
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 = (time * (2 / self.reps) * operator).to_sparse_list()
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.")