Skip to content

Commit

Permalink
Fix version parsing issue in bloch.py. (Qiskit#12928)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinhartman authored Aug 12, 2024
1 parent fb9c0db commit 61adcf9
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion qiskit/visualization/bloch.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

import math
import os
import re
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
Expand All @@ -60,6 +61,47 @@
from .utils import matplotlib_close_if_inline


# This version pattern is taken from the pypa packaging project:
# https://github.com/pypa/packaging/blob/21.3/packaging/version.py#L223-L254
# which is dual licensed Apache 2.0 and BSD see the source for the original
# authors and other details
VERSION_PATTERN = (
"^"
+ r"""
v?
(?:
(?:(?P<epoch>[0-9]+)!)? # epoch
(?P<release>[0-9]+(?:\.[0-9]+)*) # release segment
(?P<pre> # pre-release
[-_\.]?
(?P<pre_l>(a|b|c|rc|alpha|beta|pre|preview))
[-_\.]?
(?P<pre_n>[0-9]+)?
)?
(?P<post> # post release
(?:-(?P<post_n1>[0-9]+))
|
(?:
[-_\.]?
(?P<post_l>post|rev|r)
[-_\.]?
(?P<post_n2>[0-9]+)?
)
)?
(?P<dev> # dev release
[-_\.]?
(?P<dev_l>dev)
[-_\.]?
(?P<dev_n>[0-9]+)?
)?
)
(?:\+(?P<local>[a-z0-9]+(?:[-_\.][a-z0-9]+)*))? # local version
"""
+ "$"
)
VERSION_PATTERN_REGEX = re.compile(VERSION_PATTERN, re.VERBOSE | re.IGNORECASE)


class Arrow3D(Patch3D, FancyArrowPatch):
"""Makes a fancy arrow"""

Expand Down Expand Up @@ -419,7 +461,8 @@ def render(self, title=""):
self.fig = plt.figure(figsize=self.figsize)

if not self._ext_axes:
if tuple(int(x) for x in matplotlib.__version__.split(".")) >= (3, 4, 0):
version_match = VERSION_PATTERN_REGEX.search(matplotlib.__version__)
if tuple(int(x) for x in version_match.group("release").split(".")) >= (3, 4, 0):
self.axes = Axes3D(
self.fig, azim=self.view[0], elev=self.view[1], auto_add_to_figure=False
)
Expand Down

0 comments on commit 61adcf9

Please sign in to comment.