Skip to content

Commit

Permalink
Make all mpl styles json loads and update visualization code and docs (
Browse files Browse the repository at this point in the history
…#5223)

* Convert default in qcstyle to dict

* Convert styles to all dict and begin file loads

* Created bw and iqx json files, styles dir, and cleanup

* Finish json load and cleanup

* Consolidate json load and remove copy in qcstyle

* Update docs and cleanup style dict

* Update docs and adjust barrier and measure

* Fixing doc strings

* Docstrings

* Set up path for styles json and added tests

* Testing paths

* Update docs, use warn in user_config, and new test

* Finalize drawer docstrings

* Lint

* More lint

* QC doc fix

* QC doc fix2

* QC doc fix3

* QC doc fix4

* Updated partial_layout.png reference image

* Doc updates, path delimeter, and mpl changes

* Lint

* Docstring fix

* Release note

* Subfont fix, bad style var warn, and for-else

* Fix italic c

* Fix path and bw.png

* Debug path in binder

* Debug2

* Debug3

* Debug4

* Update path

* Update path pkgutil

* Update2

* Use exists

* Listdir

* Listdir minus 1

* install locally

* Cleanup and return to sanity

* Lint

* Doc error

* Fix style selection

* new refs

* debug

* edit

* install style jsons

* remove debuging print

* references!

Co-authored-by: Luciano Bello <luciano.bello@ibm.com>
  • Loading branch information
enavarro51 and Luciano Bello authored Oct 29, 2020
1 parent c7c19a0 commit 8c40b02
Show file tree
Hide file tree
Showing 22 changed files with 1,828 additions and 1,140 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ include qiskit/schemas/*.json
include qiskit/VERSION.txt
include qiskit/transpiler/passes/routing/cython/stochastic_swap/*.pyx
include qiskit/transpiler/passes/routing/cython/stochastic_swap/*.pxd
include qiskit/visualization/styles/*.json
recursive-include qiskit/test/mock/backends *.json

# Include the tests files.
Expand Down
1 change: 1 addition & 0 deletions postBuild
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# - pillow: for image comparison
# - appmode: jupyter extension for executing the notebook
pip install matplotlib pylatexenc pillow appmode
pip install .

# Activation of appmode extension
jupyter nbextension enable --py --sys-prefix appmode
Expand Down
313 changes: 172 additions & 141 deletions qiskit/circuit/quantumcircuit.py

Large diffs are not rendered by default.

35 changes: 27 additions & 8 deletions qiskit/user_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import configparser
import os
from warnings import warn

from qiskit import exceptions

Expand All @@ -29,14 +30,17 @@ class UserConfig:
[default]
circuit_drawer = mpl
circuit_mpl_style = default
circuit_mpl_style_path = ~/.qiskit:<default location>
transpile_optimization_level = 1
suppress_packaging_warnings = False
"""
def __init__(self, filename=None):
"""Create a UserConfig
Args:
filename (str): The path to the user config file. If one isn't
specified ~/.qiskit/settings.conf is used.
specified, ~/.qiskit/settings.conf is used.
"""
if filename is None:
self.filename = DEFAULT_FILENAME
Expand All @@ -60,21 +64,35 @@ def read_config_file(self):
'latex_source', 'auto']:
raise exceptions.QiskitUserConfigError(
"%s is not a valid circuit drawer backend. Must be "
"either 'text', 'mpl', 'latex', 'auto', or "
"'latex_source'"
"either 'text', 'mpl', 'latex', 'latex_source', or "
"'auto'."
% circuit_drawer)
self.settings['circuit_drawer'] = circuit_drawer

# Parse circuit_mpl_style
circuit_mpl_style = self.config_parser.get('default',
'circuit_mpl_style',
fallback=None)
if circuit_mpl_style:
if circuit_mpl_style not in ['default', 'iqx', 'bw']:
raise exceptions.QiskitUserConfigError(
"%s is not a valid mpl circuit style. Must be "
"either 'default', 'iqx', or bw'"
% circuit_mpl_style)
if not isinstance(circuit_mpl_style, str):
warn("%s is not a valid mpl circuit style. Must be "
"a text string. Will not load style."
% circuit_mpl_style, UserWarning, 2)
self.settings['circuit_mpl_style'] = circuit_mpl_style

# Parse circuit_mpl_style_path
circuit_mpl_style_path = self.config_parser.get('default',
'circuit_mpl_style_path',
fallback=None)
if circuit_mpl_style_path:
cpath_list = circuit_mpl_style_path.split(':')
for path in cpath_list:
if not os.path.exists(os.path.expanduser(path)):
warn("%s is not a valid circuit mpl style path."
" Correct the path in ~/.qiskit/settings.conf."
% path, UserWarning, 2)
self.settings['circuit_mpl_style_path'] = cpath_list

# Parse transpile_optimization_level
transpile_optimization_level = self.config_parser.getint(
'default', 'transpile_optimization_level', fallback=-1)
Expand All @@ -86,6 +104,7 @@ def read_config_file(self):
"0, 1, 2, or 3.")
self.settings['transpile_optimization_level'] = (
transpile_optimization_level)

# Parse package warnings
package_warnings = self.config_parser.getboolean(
'default', 'suppress_packaging_warnings', fallback=False)
Expand Down
2 changes: 1 addition & 1 deletion qiskit/visualization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
plot_state_qsphere)
from qiskit.visualization.transition_visualization import visualize_transition

from .circuit_visualization import circuit_drawer, qx_color_scheme
from .circuit_visualization import circuit_drawer
from .dag_visualization import dag_drawer
from .exceptions import VisualizationError
from .gate_map import plot_gate_map, plot_circuit_layout, plot_error_map
Expand Down
Loading

0 comments on commit 8c40b02

Please sign in to comment.