qiskit 2.0.3__cp39-abi3-macosx_11_0_arm64.whl → 2.1.0__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.
Files changed (180) hide show
  1. qiskit/VERSION.txt +1 -1
  2. qiskit/__init__.py +19 -1
  3. qiskit/_accelerate.abi3.so +0 -0
  4. qiskit/circuit/__init__.py +104 -20
  5. qiskit/circuit/_add_control.py +57 -31
  6. qiskit/circuit/_classical_resource_map.py +4 -0
  7. qiskit/circuit/annotation.py +504 -0
  8. qiskit/circuit/classical/expr/__init__.py +1 -1
  9. qiskit/circuit/classical/expr/expr.py +104 -446
  10. qiskit/circuit/classical/expr/visitors.py +6 -0
  11. qiskit/circuit/classical/types/types.py +7 -130
  12. qiskit/circuit/controlflow/box.py +32 -7
  13. qiskit/circuit/delay.py +11 -9
  14. qiskit/circuit/library/arithmetic/adders/adder.py +4 -4
  15. qiskit/circuit/library/arithmetic/multipliers/multiplier.py +2 -2
  16. qiskit/circuit/library/arithmetic/piecewise_chebyshev.py +8 -4
  17. qiskit/circuit/library/arithmetic/piecewise_linear_pauli_rotations.py +23 -15
  18. qiskit/circuit/library/arithmetic/piecewise_polynomial_pauli_rotations.py +22 -14
  19. qiskit/circuit/library/arithmetic/quadratic_form.py +6 -0
  20. qiskit/circuit/library/arithmetic/weighted_adder.py +43 -24
  21. qiskit/circuit/library/basis_change/qft.py +2 -2
  22. qiskit/circuit/library/blueprintcircuit.py +6 -0
  23. qiskit/circuit/library/boolean_logic/inner_product.py +2 -2
  24. qiskit/circuit/library/boolean_logic/quantum_and.py +2 -2
  25. qiskit/circuit/library/boolean_logic/quantum_or.py +3 -3
  26. qiskit/circuit/library/boolean_logic/quantum_xor.py +2 -2
  27. qiskit/circuit/library/data_preparation/_z_feature_map.py +2 -2
  28. qiskit/circuit/library/data_preparation/_zz_feature_map.py +2 -2
  29. qiskit/circuit/library/data_preparation/pauli_feature_map.py +2 -2
  30. qiskit/circuit/library/fourier_checking.py +2 -2
  31. qiskit/circuit/library/generalized_gates/diagonal.py +5 -1
  32. qiskit/circuit/library/generalized_gates/gms.py +5 -1
  33. qiskit/circuit/library/generalized_gates/linear_function.py +2 -2
  34. qiskit/circuit/library/generalized_gates/permutation.py +5 -1
  35. qiskit/circuit/library/generalized_gates/uc.py +1 -1
  36. qiskit/circuit/library/generalized_gates/unitary.py +21 -2
  37. qiskit/circuit/library/graph_state.py +2 -2
  38. qiskit/circuit/library/grover_operator.py +2 -2
  39. qiskit/circuit/library/hidden_linear_function.py +2 -2
  40. qiskit/circuit/library/iqp.py +2 -2
  41. qiskit/circuit/library/n_local/efficient_su2.py +2 -2
  42. qiskit/circuit/library/n_local/evolved_operator_ansatz.py +1 -1
  43. qiskit/circuit/library/n_local/excitation_preserving.py +7 -9
  44. qiskit/circuit/library/n_local/n_local.py +4 -3
  45. qiskit/circuit/library/n_local/pauli_two_design.py +2 -2
  46. qiskit/circuit/library/n_local/real_amplitudes.py +2 -2
  47. qiskit/circuit/library/n_local/two_local.py +2 -2
  48. qiskit/circuit/library/overlap.py +2 -2
  49. qiskit/circuit/library/pauli_evolution.py +3 -2
  50. qiskit/circuit/library/phase_estimation.py +2 -2
  51. qiskit/circuit/library/standard_gates/dcx.py +11 -12
  52. qiskit/circuit/library/standard_gates/ecr.py +21 -24
  53. qiskit/circuit/library/standard_gates/equivalence_library.py +232 -96
  54. qiskit/circuit/library/standard_gates/global_phase.py +5 -6
  55. qiskit/circuit/library/standard_gates/h.py +22 -45
  56. qiskit/circuit/library/standard_gates/i.py +1 -1
  57. qiskit/circuit/library/standard_gates/iswap.py +13 -31
  58. qiskit/circuit/library/standard_gates/p.py +19 -26
  59. qiskit/circuit/library/standard_gates/r.py +11 -17
  60. qiskit/circuit/library/standard_gates/rx.py +21 -45
  61. qiskit/circuit/library/standard_gates/rxx.py +7 -22
  62. qiskit/circuit/library/standard_gates/ry.py +21 -39
  63. qiskit/circuit/library/standard_gates/ryy.py +13 -28
  64. qiskit/circuit/library/standard_gates/rz.py +18 -35
  65. qiskit/circuit/library/standard_gates/rzx.py +7 -22
  66. qiskit/circuit/library/standard_gates/rzz.py +7 -19
  67. qiskit/circuit/library/standard_gates/s.py +44 -39
  68. qiskit/circuit/library/standard_gates/swap.py +25 -38
  69. qiskit/circuit/library/standard_gates/sx.py +34 -41
  70. qiskit/circuit/library/standard_gates/t.py +18 -27
  71. qiskit/circuit/library/standard_gates/u.py +8 -24
  72. qiskit/circuit/library/standard_gates/u1.py +28 -52
  73. qiskit/circuit/library/standard_gates/u2.py +9 -9
  74. qiskit/circuit/library/standard_gates/u3.py +24 -40
  75. qiskit/circuit/library/standard_gates/x.py +190 -336
  76. qiskit/circuit/library/standard_gates/xx_minus_yy.py +12 -50
  77. qiskit/circuit/library/standard_gates/xx_plus_yy.py +13 -52
  78. qiskit/circuit/library/standard_gates/y.py +19 -23
  79. qiskit/circuit/library/standard_gates/z.py +31 -38
  80. qiskit/circuit/parameter.py +14 -5
  81. qiskit/circuit/parameterexpression.py +109 -75
  82. qiskit/circuit/quantumcircuit.py +172 -99
  83. qiskit/circuit/quantumcircuitdata.py +1 -0
  84. qiskit/circuit/random/__init__.py +37 -2
  85. qiskit/circuit/random/utils.py +445 -56
  86. qiskit/circuit/tools/pi_check.py +5 -13
  87. qiskit/compiler/transpiler.py +1 -1
  88. qiskit/converters/circuit_to_instruction.py +2 -2
  89. qiskit/dagcircuit/dagnode.py +8 -3
  90. qiskit/primitives/__init__.py +2 -2
  91. qiskit/primitives/base/base_estimator.py +2 -2
  92. qiskit/primitives/containers/data_bin.py +0 -3
  93. qiskit/primitives/containers/observables_array.py +192 -108
  94. qiskit/primitives/primitive_job.py +29 -10
  95. qiskit/providers/fake_provider/generic_backend_v2.py +2 -0
  96. qiskit/qasm3/__init__.py +106 -12
  97. qiskit/qasm3/ast.py +15 -1
  98. qiskit/qasm3/exporter.py +59 -36
  99. qiskit/qasm3/printer.py +12 -0
  100. qiskit/qpy/__init__.py +182 -6
  101. qiskit/qpy/binary_io/circuits.py +256 -24
  102. qiskit/qpy/binary_io/parse_sympy_repr.py +5 -0
  103. qiskit/qpy/binary_io/schedules.py +12 -32
  104. qiskit/qpy/binary_io/value.py +36 -18
  105. qiskit/qpy/common.py +11 -3
  106. qiskit/qpy/formats.py +17 -1
  107. qiskit/qpy/interface.py +52 -12
  108. qiskit/qpy/type_keys.py +7 -1
  109. qiskit/quantum_info/__init__.py +10 -0
  110. qiskit/quantum_info/operators/__init__.py +1 -0
  111. qiskit/quantum_info/operators/symplectic/__init__.py +1 -0
  112. qiskit/quantum_info/operators/symplectic/clifford_circuits.py +26 -0
  113. qiskit/quantum_info/operators/symplectic/pauli.py +2 -2
  114. qiskit/result/sampled_expval.py +3 -1
  115. qiskit/synthesis/__init__.py +10 -0
  116. qiskit/synthesis/arithmetic/__init__.py +1 -1
  117. qiskit/synthesis/arithmetic/adders/__init__.py +1 -0
  118. qiskit/synthesis/arithmetic/adders/draper_qft_adder.py +6 -2
  119. qiskit/synthesis/arithmetic/adders/rv_ripple_carry_adder.py +156 -0
  120. qiskit/synthesis/discrete_basis/generate_basis_approximations.py +14 -126
  121. qiskit/synthesis/discrete_basis/solovay_kitaev.py +161 -121
  122. qiskit/synthesis/evolution/lie_trotter.py +10 -7
  123. qiskit/synthesis/evolution/product_formula.py +10 -7
  124. qiskit/synthesis/evolution/qdrift.py +10 -7
  125. qiskit/synthesis/evolution/suzuki_trotter.py +10 -7
  126. qiskit/synthesis/multi_controlled/__init__.py +4 -0
  127. qiskit/synthesis/multi_controlled/mcx_synthesis.py +402 -178
  128. qiskit/synthesis/multi_controlled/multi_control_rotation_gates.py +14 -15
  129. qiskit/synthesis/qft/qft_decompose_lnn.py +7 -25
  130. qiskit/synthesis/unitary/qsd.py +80 -9
  131. qiskit/transpiler/__init__.py +10 -3
  132. qiskit/transpiler/instruction_durations.py +2 -20
  133. qiskit/transpiler/passes/__init__.py +5 -2
  134. qiskit/transpiler/passes/layout/dense_layout.py +26 -6
  135. qiskit/transpiler/passes/layout/disjoint_utils.py +1 -166
  136. qiskit/transpiler/passes/layout/sabre_layout.py +22 -3
  137. qiskit/transpiler/passes/layout/sabre_pre_layout.py +1 -1
  138. qiskit/transpiler/passes/layout/vf2_layout.py +49 -13
  139. qiskit/transpiler/passes/layout/vf2_utils.py +10 -0
  140. qiskit/transpiler/passes/optimization/__init__.py +1 -1
  141. qiskit/transpiler/passes/optimization/optimize_1q_decomposition.py +2 -1
  142. qiskit/transpiler/passes/optimization/optimize_clifford_t.py +68 -0
  143. qiskit/transpiler/passes/optimization/template_matching/template_substitution.py +3 -9
  144. qiskit/transpiler/passes/routing/sabre_swap.py +4 -2
  145. qiskit/transpiler/passes/routing/star_prerouting.py +106 -81
  146. qiskit/transpiler/passes/scheduling/__init__.py +1 -1
  147. qiskit/transpiler/passes/scheduling/alignments/check_durations.py +1 -1
  148. qiskit/transpiler/passes/scheduling/padding/__init__.py +1 -0
  149. qiskit/transpiler/passes/scheduling/padding/context_aware_dynamical_decoupling.py +876 -0
  150. qiskit/transpiler/passes/synthesis/__init__.py +1 -0
  151. qiskit/transpiler/passes/synthesis/clifford_unitary_synth_plugin.py +123 -0
  152. qiskit/transpiler/passes/synthesis/hls_plugins.py +494 -93
  153. qiskit/transpiler/passes/synthesis/plugin.py +4 -0
  154. qiskit/transpiler/passes/synthesis/solovay_kitaev_synthesis.py +27 -22
  155. qiskit/transpiler/passmanager_config.py +3 -0
  156. qiskit/transpiler/preset_passmanagers/builtin_plugins.py +149 -28
  157. qiskit/transpiler/preset_passmanagers/common.py +101 -0
  158. qiskit/transpiler/preset_passmanagers/generate_preset_pass_manager.py +6 -0
  159. qiskit/transpiler/preset_passmanagers/level3.py +2 -2
  160. qiskit/transpiler/target.py +15 -2
  161. qiskit/utils/optionals.py +6 -5
  162. qiskit/visualization/circuit/_utils.py +5 -3
  163. qiskit/visualization/circuit/latex.py +9 -2
  164. qiskit/visualization/circuit/matplotlib.py +26 -4
  165. qiskit/visualization/circuit/qcstyle.py +9 -157
  166. qiskit/visualization/dag/__init__.py +13 -0
  167. qiskit/visualization/dag/dagstyle.py +103 -0
  168. qiskit/visualization/dag/styles/__init__.py +13 -0
  169. qiskit/visualization/dag/styles/color.json +10 -0
  170. qiskit/visualization/dag/styles/plain.json +5 -0
  171. qiskit/visualization/dag_visualization.py +169 -98
  172. qiskit/visualization/style.py +223 -0
  173. {qiskit-2.0.3.dist-info → qiskit-2.1.0.dist-info}/METADATA +7 -6
  174. {qiskit-2.0.3.dist-info → qiskit-2.1.0.dist-info}/RECORD +178 -169
  175. {qiskit-2.0.3.dist-info → qiskit-2.1.0.dist-info}/entry_points.txt +6 -0
  176. qiskit/synthesis/discrete_basis/commutator_decompose.py +0 -265
  177. qiskit/synthesis/discrete_basis/gate_sequence.py +0 -421
  178. {qiskit-2.0.3.dist-info → qiskit-2.1.0.dist-info}/WHEEL +0 -0
  179. {qiskit-2.0.3.dist-info → qiskit-2.1.0.dist-info}/licenses/LICENSE.txt +0 -0
  180. {qiskit-2.0.3.dist-info → qiskit-2.1.0.dist-info}/top_level.txt +0 -0
@@ -27,7 +27,8 @@ from qiskit.circuit.measure import Measure
27
27
  from qiskit.circuit.tools.pi_check import pi_check
28
28
 
29
29
 
30
- from .qcstyle import load_style
30
+ from qiskit.visualization.style import load_style
31
+ from qiskit.visualization.circuit.qcstyle import MPLDefaultStyle, MPLStyleDict
31
32
  from ._utils import (
32
33
  get_gate_ctrl_text,
33
34
  get_param_str,
@@ -151,7 +152,13 @@ class QCircuitImage:
151
152
  self._wire_map = get_wire_map(circuit, qubits + clbits, self._cregbundle)
152
153
  self._img_width = len(self._wire_map)
153
154
 
154
- self._style, _ = load_style(style)
155
+ self._style, _ = load_style(
156
+ style,
157
+ style_dict=MPLStyleDict,
158
+ default_style=MPLDefaultStyle(),
159
+ user_config_opt="circuit_mpl_style",
160
+ user_config_path_opt="circuit_mpl_style_path",
161
+ )
155
162
 
156
163
  def latex(self):
157
164
  """Return LaTeX string representation of circuit."""
@@ -55,7 +55,8 @@ from qiskit.qasm3.printer import BasicPrinter
55
55
  from qiskit.circuit.tools.pi_check import pi_check
56
56
  from qiskit.utils import optionals as _optionals
57
57
 
58
- from .qcstyle import load_style
58
+ from qiskit.visualization.style import load_style
59
+ from qiskit.visualization.circuit.qcstyle import MPLDefaultStyle, MPLStyleDict
59
60
  from ._utils import (
60
61
  get_gate_ctrl_text,
61
62
  get_param_str,
@@ -266,7 +267,13 @@ class MatplotlibDrawer:
266
267
  glob_data["patches_mod"] = patches
267
268
  plt_mod = plt
268
269
 
269
- self._style, def_font_ratio = load_style(self._style)
270
+ self._style, def_font_ratio = load_style(
271
+ self._style,
272
+ style_dict=MPLStyleDict,
273
+ default_style=MPLDefaultStyle(),
274
+ user_config_opt="circuit_mpl_style",
275
+ user_config_path_opt="circuit_mpl_style_path",
276
+ )
270
277
 
271
278
  # If font/subfont ratio changes from default, have to scale width calculations for
272
279
  # subfont. Font change is auto scaled in the mpl_figure.set_size_inches call in draw()
@@ -608,6 +615,10 @@ class MatplotlibDrawer:
608
615
  for width, layer_num, flow_parent in flow_widths.values():
609
616
  if layer_num != -1 and flow_parent == flow_drawer._flow_parent:
610
617
  raw_gate_width += width
618
+ # This is necessary to prevent 1 being added to the width of a
619
+ # BoxOp in layer_widths at the end of this method
620
+ if isinstance(node.op, BoxOp):
621
+ raw_gate_width -= 0.001
611
622
 
612
623
  # Need extra incr of 1.0 for else and case boxes
613
624
  gate_width += raw_gate_width + (1.0 if circ_num > 0 else 0.0)
@@ -740,7 +751,13 @@ class MatplotlibDrawer:
740
751
  # increment by if/switch width. If more cases increment by width of previous cases.
741
752
  if flow_parent is not None:
742
753
  node_data[node].inside_flow = True
743
- node_data[node].x_index = node_data[flow_parent].x_index + curr_x_index + 1
754
+ # front_space provides a space for 'If', 'While', etc. which is not
755
+ # necessary for a BoxOp
756
+ front_space = 0 if isinstance(flow_parent.op, BoxOp) else 1
757
+ node_data[node].x_index = (
758
+ node_data[flow_parent].x_index + curr_x_index + front_space
759
+ )
760
+
744
761
  # If an else or case
745
762
  if node_data[node].circ_num > 0:
746
763
  for width in node_data[flow_parent].width[: node_data[node].circ_num]:
@@ -1548,7 +1565,9 @@ class MatplotlibDrawer:
1548
1565
  ypos = min(y[1] for y in xy)
1549
1566
  ypos_max = max(y[1] for y in xy)
1550
1567
 
1551
- if_width = node_data[node].width[0] + WID
1568
+ # If a BoxOp, bring the right side back tight against the gates to allow for
1569
+ # better spacing
1570
+ if_width = node_data[node].width[0] + (WID if not isinstance(node.op, BoxOp) else -0.19)
1552
1571
  box_width = if_width
1553
1572
  # Add the else and case widths to the if_width
1554
1573
  for ewidth in node_data[node].width[1:]:
@@ -1598,6 +1617,9 @@ class MatplotlibDrawer:
1598
1617
  expr_spacer = 0.0
1599
1618
  empty_default_spacer = 0.3 if len(node.op.blocks[-1]) == 0 else 0.0
1600
1619
  elif isinstance(node.op, BoxOp):
1620
+ # Move the X start position back for a BoxOp, since there is no
1621
+ # leading text. This tightens the BoxOp with other ops.
1622
+ xpos -= 0.15
1601
1623
  op_spacer = 0.0
1602
1624
  expr_spacer = 0.0
1603
1625
  empty_default_spacer = 0.0
@@ -15,15 +15,12 @@
15
15
  from __future__ import annotations
16
16
 
17
17
  import json
18
- import os
19
- from typing import Any
20
18
  from pathlib import Path
21
- from warnings import warn
22
19
 
23
- from qiskit import user_config
20
+ from qiskit.visualization.style import StyleDict, DefaultStyle
24
21
 
25
22
 
26
- class StyleDict(dict):
23
+ class MPLStyleDict(StyleDict):
27
24
  """A dictionary for matplotlib styles.
28
25
 
29
26
  Defines additional abbreviations for key accesses, such as allowing
@@ -70,40 +67,10 @@ class StyleDict(dict):
70
67
  "dispcol": "displaycolor",
71
68
  }
72
69
 
73
- def __setitem__(self, key: Any, value: Any) -> None:
74
- # allow using field abbreviations
75
- if key in self.ABBREVIATIONS:
76
- key = self.ABBREVIATIONS[key]
70
+ NESTED_ATTRS = {"displaycolor", "displaytext"}
77
71
 
78
- if key not in self.VALID_FIELDS:
79
- warn(
80
- f"style option ({key}) is not supported",
81
- UserWarning,
82
- 2,
83
- )
84
- return super().__setitem__(key, value)
85
72
 
86
- def __getitem__(self, key: Any) -> Any:
87
- # allow using field abbreviations
88
- if key in self.ABBREVIATIONS:
89
- key = self.ABBREVIATIONS[key]
90
-
91
- return super().__getitem__(key)
92
-
93
- def update(self, other):
94
- # the attributes "displaycolor" and "displaytext" are dictionaries
95
- # themselves, therefore we need to propagate the update down to them
96
- nested_attrs = {"displaycolor", "displaytext"}
97
- for attr in nested_attrs.intersection(other.keys()):
98
- if attr in self.keys():
99
- self[attr].update(other[attr])
100
- else:
101
- self[attr] = other[attr]
102
-
103
- super().update((key, value) for key, value in other.items() if key not in nested_attrs)
104
-
105
-
106
- class DefaultStyle:
73
+ class MPLDefaultStyle(DefaultStyle):
107
74
  """Creates a Default Style dictionary
108
75
 
109
76
  The style dict contains numerous options that define the style of the
@@ -150,129 +117,14 @@ class DefaultStyle:
150
117
  which allows for custom colors for user-created gates.
151
118
  """
152
119
 
120
+ DEFAULT_STYLE_NAME = "iqp"
121
+ DEFAULT_STYLE_PATH = Path(__file__).parent / "styles"
122
+
153
123
  def __init__(self):
154
- default_style_dict = "iqp.json"
155
- path = Path(__file__).parent / "styles" / default_style_dict
124
+ path = self.DEFAULT_STYLE_PATH / Path(self.DEFAULT_STYLE_NAME).with_suffix(".json")
156
125
 
157
126
  with open(path, "r") as infile:
158
127
  default_style = json.load(infile)
159
128
 
160
129
  # set shortcuts, such as "ec" for "edgecolor"
161
- self.style = StyleDict(**default_style)
162
-
163
-
164
- def load_style(style: dict | str | None) -> tuple[StyleDict, float]:
165
- """Utility function to load style from json files.
166
-
167
- Args:
168
- style: Depending on the type, this acts differently:
169
-
170
- * If a string, it can specify a supported style name (such
171
- as "iqp" or "clifford"). It can also specify the name of
172
- a custom color scheme stored as JSON file. This JSON file
173
- _must_ specify a complete set of colors.
174
- * If a dictionary, it may specify the style name via a
175
- ``{"name": "<desired style>"}`` entry. If this is not given,
176
- the default style will be used. The remaining entries in the
177
- dictionary can be used to override certain specs.
178
- E.g. ``{"name": "iqp", "ec": "#FF0000"}`` will use the ``"iqp"``
179
- color scheme but set the edgecolor to red.
180
-
181
- Returns:
182
- A tuple containing the style as dictionary and the default font ratio.
183
- """
184
-
185
- # if the style is not given, try to load the configured default (if set),
186
- # or use the default style
187
- config = user_config.get_config()
188
- if style is None:
189
- if config:
190
- style = config.get("circuit_mpl_style", "default")
191
- else:
192
- style = "default"
193
-
194
- # determine the style name which could also be inside a dictionary, like
195
- # style={"name": "clifford", <other settings...>}
196
- if isinstance(style, dict):
197
- style_name = style.get("name", "default")
198
- elif isinstance(style, str):
199
- if style.endswith(".json"):
200
- style_name = style[:-5]
201
- else:
202
- style_name = style
203
- else:
204
- warn(
205
- f'Unsupported style parameter "{style}" of type {type(style)}. '
206
- "Will use the default style.",
207
- UserWarning,
208
- 2,
209
- )
210
- style_name = "default"
211
-
212
- if style_name in ["iqp", "default"]:
213
- current_style = DefaultStyle().style
214
- else:
215
- # Search for file in 'styles' dir, then config_path, and finally the current directory
216
- style_name = style_name + ".json"
217
- style_paths = []
218
-
219
- default_path = Path(__file__).parent / "styles" / style_name
220
- style_paths.append(default_path)
221
-
222
- # check configured paths, if there are any
223
- if config:
224
- config_path = config.get("circuit_mpl_style_path", "")
225
- if config_path:
226
- for path in config_path:
227
- style_paths.append(Path(path) / style_name)
228
-
229
- # check current directory
230
- cwd_path = Path("") / style_name
231
- style_paths.append(cwd_path)
232
-
233
- for path in style_paths:
234
- # expand ~ to the user directory and check if the file exists
235
- exp_user = path.expanduser()
236
- if os.path.isfile(exp_user):
237
- try:
238
- with open(exp_user) as infile:
239
- json_style = json.load(infile)
240
-
241
- current_style = StyleDict(json_style)
242
- break
243
- except json.JSONDecodeError as err:
244
- warn(
245
- f"Could not decode JSON in file '{path}': {str(err)}. "
246
- "Will use default style.",
247
- UserWarning,
248
- 2,
249
- )
250
- break
251
- except (OSError, FileNotFoundError):
252
- warn(
253
- f"Error loading JSON file '{path}'. Will use default style.",
254
- UserWarning,
255
- 2,
256
- )
257
- break
258
- else:
259
- warn(
260
- f"Style JSON file '{style_name}' not found in any of these locations: "
261
- f"{', '.join(map(str, style_paths))}. "
262
- "Will use default style.",
263
- UserWarning,
264
- 2,
265
- )
266
- current_style = DefaultStyle().style
267
-
268
- # if the style is a dictionary, update the defaults with the new values
269
- # this _needs_ to happen after loading by name to cover cases like
270
- # style = {"name": "bw", "edgecolor": "#FF0000"}
271
- if isinstance(style, dict):
272
- current_style.update(style)
273
-
274
- # this is the default font ratio
275
- # if the font- or subfont-sizes are changed, the new size is based on this ratio
276
- def_font_ratio = 13 / 8
277
-
278
- return current_style, def_font_ratio
130
+ self.style = MPLStyleDict(**default_style)
@@ -0,0 +1,13 @@
1
+ # This code is part of Qiskit.
2
+ #
3
+ # (C) Copyright IBM 2025.
4
+ #
5
+ # This code is licensed under the Apache License, Version 2.0. You may
6
+ # obtain a copy of this license in the LICENSE.txt file in the root directory
7
+ # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
8
+ #
9
+ # Any modifications or derivative works of this code must retain this
10
+ # copyright notice, and modified files need to carry a notice indicating
11
+ # that they have been altered from the originals.
12
+
13
+ """Empty init for data directory."""
@@ -0,0 +1,103 @@
1
+ # This code is part of Qiskit.
2
+ #
3
+ # (C) Copyright IBM 2025.
4
+ #
5
+ # This code is licensed under the Apache License, Version 2.0. You may
6
+ # obtain a copy of this license in the LICENSE.txt file in the root directory
7
+ # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
8
+ #
9
+ # Any modifications or derivative works of this code must retain this
10
+ # copyright notice, and modified files need to carry a notice indicating
11
+ # that they have been altered from the originals.
12
+
13
+ """Matplotlib circuit visualization style."""
14
+
15
+ from __future__ import annotations
16
+
17
+ import json
18
+ from pathlib import Path
19
+ from qiskit.visualization.circuit.qcstyle import StyleDict, DefaultStyle
20
+
21
+
22
+ class DAGStyleDict(StyleDict):
23
+ """A dictionary for graphviz styles.
24
+
25
+ Defines additional abbreviations for key accesses, such as allowing
26
+ ``"ec"`` instead of writing ``"edgecolor"``.
27
+ """
28
+
29
+ VALID_FIELDS = {
30
+ "name",
31
+ "fontsize",
32
+ "bgcolor",
33
+ "dpi",
34
+ "pad",
35
+ "nodecolor",
36
+ "inputnodecolor",
37
+ "inputnodefontcolor",
38
+ "outputnodecolor",
39
+ "outputnodefontcolor",
40
+ "opnodecolor",
41
+ "opnodefontcolor",
42
+ "edgecolor",
43
+ "qubitedgecolor",
44
+ "clbitedgecolor",
45
+ }
46
+
47
+ ABBREVIATIONS = {
48
+ "nc": "nodecolor",
49
+ "ic": "inputnodecolor",
50
+ "if": "inputnodefontcolor",
51
+ "oc": "outputnodecolor",
52
+ "of": "outputnodefontcolor",
53
+ "opc": "opnodecolor",
54
+ "opf": "opnodefontcolor",
55
+ "ec": "edgecolor",
56
+ "qec": "qubitedgecolor",
57
+ "clc": "clbitedgecolor",
58
+ }
59
+
60
+
61
+ class DAGDefaultStyle(DefaultStyle):
62
+ """Creates a Default Style dictionary
63
+
64
+ The style dict contains numerous options that define the style of the
65
+ output circuit visualization. The style dict is used by the `graphviz`
66
+ output. The options available in the style dict are defined below:
67
+
68
+ Attributes:
69
+ name (str): The name of the style.
70
+ fontsize (str): The font size to use for text.
71
+ bgcolor (str): The color name to use for the background ('red', 'green', etc.).
72
+ nodecolor (str): The color to use for all nodes.
73
+ dpi (int): The DPI to use for the output image.
74
+ pad (int): A number to adjust padding around output
75
+ graph.
76
+ inputnodecolor (str): The color to use for incoming wire nodes. Overrides
77
+ nodecolor for those nodes.
78
+ inputnodefontcolor (str): The font color to use for incoming wire nodes.
79
+ Overrides nodecolor for those nodes.
80
+ outputnodecolor (str): The color to use for output wire nodes. Overrides
81
+ nodecolor for those nodes.
82
+ outputnodefontcolor (str): The font color to use for output wire nodes.
83
+ Overrides nodecolor for those nodes.
84
+ opnodecolor (str): The color to use for Instruction nodes. Overrides
85
+ nodecolor for those nodes.
86
+ opnodefontcolor (str): The font color to use for Instruction nodes.
87
+ Overrides nodecolor for those nodes.
88
+
89
+ qubitedgecolor (str): The edge color for qubits. Overrides edgecolor for these edges.
90
+ clbitedgecolor (str): The edge color for clbits. Overrides edgecolor for these edges.
91
+ """
92
+
93
+ DEFAULT_STYLE_NAME = "plain"
94
+ DEFAULT_STYLE_PATH = Path(__file__).parent / "styles"
95
+
96
+ def __init__(self):
97
+ path = self.DEFAULT_STYLE_PATH / Path(self.DEFAULT_STYLE_NAME).with_suffix(".json")
98
+
99
+ with open(path, "r") as infile:
100
+ default_style = json.load(infile)
101
+
102
+ # set shortcuts, such as "ec" for "edgecolor"
103
+ self.style = DAGStyleDict(**default_style)
@@ -0,0 +1,13 @@
1
+ # This code is part of Qiskit.
2
+ #
3
+ # (C) Copyright IBM 2025.
4
+ #
5
+ # This code is licensed under the Apache License, Version 2.0. You may
6
+ # obtain a copy of this license in the LICENSE.txt file in the root directory
7
+ # of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
8
+ #
9
+ # Any modifications or derivative works of this code must retain this
10
+ # copyright notice, and modified files need to carry a notice indicating
11
+ # that they have been altered from the originals.
12
+
13
+ """Empty init for data directory."""
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "color",
3
+ "inputnodecolor": "green",
4
+ "outputnodecolor": "red",
5
+ "opnodecolor": "lightblue",
6
+ "barriercolor": "grey",
7
+ "directivecolor": "red",
8
+ "conditioncolor": "green",
9
+ "measurecolor": "white"
10
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "plain",
3
+ "nodecolor": "white",
4
+ "edgecolor": "black"
5
+ }