Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: PEP 503/625 compatibility and Windows MPI tests #530

Draft
wants to merge 16 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/beta-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [macos-13, ubuntu-latest, windows-latest] # TODO: Unpin mac version when cvxopt or Python 3.8 dropped
python-version: [3.8, 3.9, '3.10', '3.11']
os: [macos-latest, ubuntu-latest, windows-latest]
python-version: [3.9, '3.10', '3.11', '3.12']
use-cython: ['true', 'false']
uses: ./.github/workflows/reuseable-main.yml
name: Run pyGSTi tests
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest] # No Mac
python-version: [3.8, 3.9, '3.10', '3.11']
python-version: [3.9, '3.10', '3.11', '3.12']
use-cython: ['true', 'false']
uses: ./.github/workflows/reuseable-main.yml
name: Run pyGSTi tests
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/feature-branches.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ jobs:
strategy:
# fail-fast: true is OK here
matrix:
os: [ubuntu-latest, windows-latest] # No Mac
python-version: [3.8, '3.11'] # Only extremal Python versions
os: [macos-latest, ubuntu-latest, windows-latest] # TEMP: Try latest mac again # No Mac
python-version: [3.9, '3.12'] # Only extremal Python versions
uses: ./.github/workflows/reuseable-main.yml
name: Run pyGSTi tests
with:
os: ${{ matrix.os }}
python-version: ${{ matrix.python-version }}
use-cython: 'true' # Only test environment with Cython
run-unit-tests: 'true'
run-extra-tests: 'false' # No integration tests
run-notebook-tests: 'false' # No notebook tests
run-extra-tests: 'true' # No integration tests # TEMP: Try integration tests
run-notebook-tests: 'true' # No notebook tests # TEMP: Try notebook tests



Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/reuseable-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,19 @@ jobs:
runs-on: ${{ inputs.os }}
steps:
- uses: actions/checkout@v4
- name: Set up installation environment (Linux and Windows)
if: ${{ inputs.os != 'macos-13' }}
- name: Set up installation environment (Linux)
if: ${{ inputs.os == 'ubuntu-latest' }}
run: |
./.github/ci-scripts/before_install.sh
- name: Set up installation environment (MacOS)
if: ${{ inputs.os == 'macos-13' }}
if: ${{ inputs.os == 'macos-latest' }}
run: |
./.github/ci-scripts/before_install_macos.sh
- name: Set up MPI (Windows)
if: ${{ inputs.os == 'windows-latest' }}
uses: mpi4py/setup-mpi@v1
with:
mpi: intelmpi
- name: Set up Python ${{ inputs.python-version }}
uses: actions/setup-python@v5
with:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ In particular, there are a number of characterization protocols currently implem

PyGSTi is designed with a modular structure so as to be highly customizable
and easily integrated to new or existing python software. It runs using
python 3.8 or higher. To faclilitate integration with software for running
python 3.9 or higher. To faclilitate integration with software for running
cloud-QIP experiments, pyGSTi `Circuit` objects can be converted to IBM's
**OpenQASM** and Rigetti Quantum Computing's **Quil** circuit description languages.

Expand Down
4 changes: 2 additions & 2 deletions pygsti/baseobjs/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ def __new__(cls, name, state_space_labels=None, time=None, args=None):

#print(" -> preproc with name=", name, "sslbls=", state_space_labels, "t=", time, "args=", args)
if state_space_labels is None or state_space_labels in ((), (None,)):
if args:
if args is not None:
return LabelTupWithArgs.init(name, (), time, args) # just use empty sslbls
else:
return LabelStr.init(name, time)

else:
if args: return LabelTupWithArgs.init(name, state_space_labels, time, args)
if args is not None: return LabelTupWithArgs.init(name, state_space_labels, time, args)
else:
if time == 0.0:
return LabelTup.init(name, state_space_labels)
Expand Down
2 changes: 1 addition & 1 deletion pygsti/evotypes/chp/povmreps.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def _run_chp_ops(self, chp_ops):

# Extract outputs
#print("CHP program out (debug): ", out.decode('utf-8'))
pattern = _re.compile('Outcome of measuring qubit (\d+): (\d)( ?\S*)')
pattern = _re.compile(r'Outcome of measuring qubit (\d+): (\d)( ?\S*)')
matched_values = [] # elements = (qubit_index, outcome, '(random)' or '') tuples
for match in pattern.finditer(out.decode('utf-8')):
matched_values.append((int(match.group(1)), match.group(2), match.group(3)))
Expand Down
4 changes: 2 additions & 2 deletions pygsti/report/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def _no_format(x, specs):
ebstring='%s <span class="errorbar">&plusmn; %s</span>',
nmebstring='%s <span class="nmerrorbar">&plusmn; %s</span>')
NormalLatex = _Formatter(latex,
ebstring='$ \\begin{array}{c} %s \\\\ \pm %s \\end{array} $') # nmebstring will match
ebstring='$ \\begin{array}{c} %s \\\\ \\pm %s \\end{array} $') # nmebstring will match

# Normal replacements
format_dict['Normal'] = {
Expand Down Expand Up @@ -186,7 +186,7 @@ def special_convert_latex(x, specs):

format_dict['Vec'] = {
'html': NormalHTML,
'latex': _Formatter(latex, ebstring='%s $\pm$ %s'),
'latex': _Formatter(latex, ebstring='%s $\\pm$ %s'),
'python': _no_format}

format_dict['Circuit'] = {
Expand Down
10 changes: 5 additions & 5 deletions pygsti/report/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ def vector(v, specs):
lines.append(value(el, specs, mathmode=True))
if specs['brackets']:
return "$ \\begin{pmatrix}\n" + \
" \\\\ \n".join(lines) + "\n \end{pmatrix} $\n"
" \\\\ \n".join(lines) + "\n \\end{pmatrix} $\n"
else:
return "$ \\begin{pmatrix}\n" + \
" \\\\ \n".join(lines) + "\n \end{pmatrix} $\n"
" \\\\ \n".join(lines) + "\n \\end{pmatrix} $\n"


def matrix(m, specs):
Expand All @@ -177,18 +177,18 @@ def matrix(m, specs):
fontsize = specs['fontsize']

if fontsize is not None:
prefix += "\\fontsize{%f}{%f}\selectfont " % (fontsize, fontsize * 1.2)
prefix += "\\fontsize{%f}{%f}\\selectfont " % (fontsize, fontsize * 1.2)

for r in range(m.shape[0]):
lines.append(" & ".join(
[value(el, specs, mathmode=True) for el in m[r, :]]))

if specs['brackets']:
return prefix + "$ \\begin{pmatrix}\n" + \
" \\\\ \n".join(lines) + "\n \end{pmatrix} $\n"
" \\\\ \n".join(lines) + "\n \\end{pmatrix} $\n"
else:
return prefix + "$ \\begin{pmatrix}\n" + \
" \\\\ \n".join(lines) + "\n \end{pmatrix} $\n"
" \\\\ \n".join(lines) + "\n \\end{pmatrix} $\n"


def value(el, specs, mathmode=False):
Expand Down
22 changes: 11 additions & 11 deletions pygsti/report/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ def table(custom_headings, col_headings_formatted, rows, spec):
and "latex" in custom_headings:
latex = custom_headings['latex']
else:
latex = "\\begin{%s}[l]{%s}\n\hline\n" % \
latex = "\\begin{%s}[l]{%s}\n\\hline\n" % \
(table, "|c" * len(col_headings_formatted) + "|")
latex += ("%s \\\\ \hline\n"
latex += ("%s \\\\ \\hline\n"
% (" & ".join(col_headings_formatted)))

for formatted_rowData in rows:
Expand Down Expand Up @@ -82,9 +82,9 @@ def table(custom_headings, col_headings_formatted, rows, spec):
# latex += "\cline{%d-%d} "%(lineStart,col-1)
# latex += "\n"
#else:
latex += " \\\\ \hline\n"
latex += " \\\\ \\hline\n"

latex += "\end{%s}\n" % table
latex += "\\end{%s}\n" % table
return {'latex': latex}


Expand Down Expand Up @@ -129,7 +129,7 @@ def list(l, specs):
latex string for l.
"""
return "\\begin{tabular}{c}\n" + \
" \\\\ \n".join(l) + "\n \end{tabular}\n"
" \\\\ \n".join(l) + "\n \\end{tabular}\n"


def vector(v, specs):
Expand All @@ -154,10 +154,10 @@ def vector(v, specs):
lines.append(value(el, specs, mathmode=True))
if specs['brackets']:
return "\\ensuremath{ \\begin{pmatrix}\n" + \
" \\\\ \n".join(lines) + "\n \end{pmatrix} }\n"
" \\\\ \n".join(lines) + "\n \\end{pmatrix} }\n"
else:
return "\\ensuremath{ \\begin{pmatrix}\n" + \
" \\\\ \n".join(lines) + "\n \end{pmatrix} }\n"
" \\\\ \n".join(lines) + "\n \\end{pmatrix} }\n"


def matrix(m, specs):
Expand All @@ -182,18 +182,18 @@ def matrix(m, specs):
fontsize = specs['fontsize']

if fontsize is not None:
prefix += "\\fontsize{%f}{%f}\selectfont " % (fontsize, fontsize * 1.2)
prefix += "\\fontsize{%f}{%f}\\selectfont " % (fontsize, fontsize * 1.2)

for r in range(m.shape[0]):
lines.append(" & ".join(
[value(el, specs, mathmode=True) for el in m[r, :]]))

if specs['brackets']:
return prefix + "\\ensuremath{ \\begin{pmatrix}\n" + \
" \\\\ \n".join(lines) + "\n \end{pmatrix} }\n"
" \\\\ \n".join(lines) + "\n \\end{pmatrix} }\n"
else:
return prefix + "\\ensuremath{ \\begin{pmatrix}\n" + \
" \\\\ \n".join(lines) + "\n \end{pmatrix} }\n"
" \\\\ \n".join(lines) + "\n \\end{pmatrix} }\n"


def value(el, specs, mathmode=False):
Expand Down Expand Up @@ -304,5 +304,5 @@ def escaped(txt, specs):
-------
string
"""
ret = txt.replace("_", "\_")
ret = txt.replace("_", r"\_")
return ret
4 changes: 2 additions & 2 deletions pygsti/report/reportables.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
used primarily in reports, so we refer to these quantities as
"reportables".
"""
import pkgutil
import importlib
import warnings as _warnings

import numpy as _np
Expand All @@ -32,7 +32,7 @@
from pygsti.models.explicitmodel import ExplicitOpModel as _ExplicitOpModel


_CVXPY_AVAILABLE = pkgutil.find_loader('cvxpy') is not None
_CVXPY_AVAILABLE = importlib.util.find_spec('cvxpy') is not None

FINITE_DIFF_EPS = 1e-7

Expand Down
38 changes: 19 additions & 19 deletions pygsti/report/workspacetables.py
Original file line number Diff line number Diff line change
Expand Up @@ -2213,10 +2213,10 @@ def _create(self, model, confidence_region_info, show_axis_angle_err_bars):
formatters = [None] * nCols

table = "tabular"
latex_head = "\\begin{%s}[l]{%s}\n\hline\n" % (table, "|c" * nCols + "|")
latex_head = "\\begin{%s}[l]{%s}\n\\hline\n" % (table, "|c" * nCols + "|")
latex_head += "\\multirow{2}{*}{Gate} & \\multirow{2}{*}{Angle} & " + \
"\\multicolumn{%d}{c|}{Angle between Rotation Axes} \\\\ \cline{3-%d}\n" % (len(opLabels), nCols)
latex_head += " & & %s \\\\ \hline\n" % (" & ".join(map(str, opLabels)))
"\\multicolumn{%d}{c|}{Angle between Rotation Axes} \\\\ \\cline{3-%d}\n" % (len(opLabels), nCols)
latex_head += " & & %s \\\\ \\hline\n" % (" & ".join(map(str, opLabels)))

table = _ReportTable(colHeadings, formatters,
custom_header={'latex': latex_head}, confidence_region_info=confidence_region_info)
Expand Down Expand Up @@ -2834,8 +2834,8 @@ def _create(self, xs, circuits_by_x, model_by_x, dataset, objfn_builder, x_label
if objfn_builder == "chi2" or (isinstance(objfn_builder, _objfns.ObjectiveFunctionBuilder)
and objfn_builder.cls_to_build == _objfns.Chi2Function):
colHeadings = {
'latex': (x_label, '$\\chi^2$', '$k$', '$\\chi^2-k$', '$\sqrt{2k}$',
'$N_\\sigma$', '$N_s$', '$N_p$', 'Rating'),
'latex': (x_label, r'$\chi^2$', '$k$', r'$\chi^2-k$', r'$\sqrt{2k}$',
r'$N_\sigma$', '$N_s$', '$N_p$', 'Rating'),
'html': (x_label, '&chi;<sup>2</sup>', 'k', '&chi;<sup>2</sup>-k',
'&radic;<span style="text-decoration:overline;">2k</span>',
'N<sub>sigma</sub>', 'N<sub>s</sub>', 'N<sub>p</sub>', 'Rating'),
Expand All @@ -2845,8 +2845,8 @@ def _create(self, xs, circuits_by_x, model_by_x, dataset, objfn_builder, x_label
elif objfn_builder == "logl" or (isinstance(objfn_builder, _objfns.ObjectiveFunctionBuilder)
and objfn_builder.cls_to_build == _objfns.PoissonPicDeltaLogLFunction):
colHeadings = {
'latex': (x_label, '$2\Delta\\log(\\mathcal{L})$', '$k$', '$2\Delta\\log(\\mathcal{L})-k$',
'$\sqrt{2k}$', '$N_\\sigma$', '$N_s$', '$N_p$', 'Rating'),
'latex': (x_label, r'$2\Delta\log(\mathcal{L})$', '$k$', r'$2\Delta\log(\mathcal{L})-k$',
r'$\sqrt{2k}$', r'$N_\sigma$', '$N_s$', '$N_p$', 'Rating'),
'html': (x_label, '2&Delta;(log L)', 'k', '2&Delta;(log L)-k',
'&radic;<span style="text-decoration:overline;">2k</span>',
'N<sub>sigma</sub>', 'N<sub>s</sub>', 'N<sub>p</sub>', 'Rating'),
Expand Down Expand Up @@ -2948,9 +2948,9 @@ def _create(self, circuit_lists, titles, num_cols, common_title):
else:
table = "tabular"
colHeadings = ('\\#',) + tuple(titles)
latex_head = "\\begin{%s}[l]{%s}\n\hline\n" % (table, "|c" * len(colHeadings) + "|")
latex_head += " & \multicolumn{%d}{c|}{%s} \\\\ \hline\n" % (len(colHeadings) - 1, common_title)
latex_head += "%s \\\\ \hline\n" % (" & ".join(colHeadings))
latex_head = "\\begin{%s}[l]{%s}\n\\hline\n" % (table, "|c" * len(colHeadings) + "|")
latex_head += " & \\multicolumn{%d}{c|}{%s} \\\\ \\hline\n" % (len(colHeadings) - 1, common_title)
latex_head += "%s \\\\ \\hline\n" % (" & ".join(colHeadings))

colHeadings = ('#',) + tuple(titles)
html_head = '<table class="%(tableclass)s" id="%(tableid)s" ><thead>'
Expand Down Expand Up @@ -3149,9 +3149,9 @@ def _create(self, metric, models, target_models, titles,
#html_head += "</thead><tbody>"

if table_title:
latex_head = "\\begin{tabular}[l]{%s}\n\hline\n" % ("|c" * nCols + "|")
latex_head += "\\multicolumn{%d}{c|}{%s} \\\\ \cline{1-%d}\n" % (nCols, table_title, nCols)
latex_head += " & ".join(colHeadings) + "\\\\ \hline\n"
latex_head = "\\begin{tabular}[l]{%s}\n\\hline\n" % ("|c" * nCols + "|")
latex_head += "\\multicolumn{%d}{c|}{%s} \\\\ \\cline{1-%d}\n" % (nCols, table_title, nCols)
latex_head += " & ".join(colHeadings) + "\\\\ \\hline\n"

html_head = '<table class="%(tableclass)s" id="%(tableid)s" ><thead>'
html_head += '<tr><th colspan="%d">%s</th></tr>\n' % (nCols, table_title)
Expand Down Expand Up @@ -3406,8 +3406,8 @@ def _create(self, model, params_dict):
formatters = ('Bold', 'Bold')

#custom latex header for maximum width imposed on 2nd col
latex_head = "\\begin{tabular}[l]{|c|p{3in}|}\n\hline\n"
latex_head += "\\textbf{Quantity} & \\textbf{Value} \\\\ \hline\n"
latex_head = "\\begin{tabular}[l]{|c|p{3in}|}\n\\hline\n"
latex_head += "\\textbf{Quantity} & \\textbf{Value} \\\\ \\hline\n"
table = _ReportTable(colHeadings, formatters,
custom_header={'latex': latex_head})

Expand Down Expand Up @@ -3513,8 +3513,8 @@ def _get_package_version(module_name):
formatters = ('Bold', 'Bold')

#custom latex header for maximum width imposed on 2nd col
latex_head = "\\begin{tabular}[l]{|c|p{3in}|}\n\hline\n"
latex_head += "\\textbf{Quantity} & \\textbf{Value} \\\\ \hline\n"
latex_head = "\\begin{tabular}[l]{|c|p{3in}|}\n\\hline\n"
latex_head += "\\textbf{Quantity} & \\textbf{Value} \\\\ \\hline\n"
table = _ReportTable(colHeadings, formatters,
custom_header={'latex': latex_head})

Expand Down Expand Up @@ -3583,8 +3583,8 @@ def _create(self, profiler, sort_by):
formatters = ('Bold', 'Bold')

#custom latex header for maximum width imposed on 2nd col
latex_head = "\\begin{tabular}[l]{|c|p{3in}|}\n\hline\n"
latex_head += "\\textbf{Label} & \\textbf{Time} (sec) \\\\ \hline\n"
latex_head = "\\begin{tabular}[l]{|c|p{3in}|}\n\\hline\n"
latex_head += "\\textbf{Label} & \\textbf{Time} (sec) \\\\ \\hline\n"
table = _ReportTable(colHeadings, formatters,
custom_header={'latex': latex_head})

Expand Down
2 changes: 1 addition & 1 deletion pygsti/tools/optools.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ def unitarity(a, mx_basis="gm"):
noise" NJP 17 113020 (2015). The unitarity is given by (Prop 1 in Wallman
et al):

`u(a) = Tr( A_u^{\dagger} A_u ) / (d^2 - 1)`,
`u(a) = Tr( A_u^{\\dagger} A_u ) / (d^2 - 1)`,

where A_u is the unital submatrix of a, and d is the dimension of
the Hilbert space. When a is written in any basis for which the
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def build_extensions(self):

def setup_with_extensions(extensions=None):
setup(
name='pyGSTi',
name='pygsti',
use_scm_version=custom_version,
cmdclass={'build_ext': build_ext_compiler_check},
description='A python implementation of Gate Set Tomography',
Expand Down Expand Up @@ -277,10 +277,10 @@ def setup_with_extensions(extensions=None):
'networkx'
],
extras_require=extras,
python_requires='>=3.8',
python_requires='>=3.9',
platforms=["any"],
url='http://www.pygsti.info',
download_url='https://github.com/pyGSTio/pyGSTi/tarball/master',
download_url='https://github.com/sandialabs/pyGSTi/tarball/master',
keywords=[
'pygsti',
'tomography',
Expand Down
2 changes: 1 addition & 1 deletion test/test_packages/extras/test_interpygate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
_comm = MPI.COMM_WORLD
_rank = _comm.Get_rank()
_size = _comm.Get_size()
except (ImportError, RuntimeError):
except ImportError: # Reverted RuntimeError to cause Windows runners to break
_comm = None
_rank = 0
_size = 1
Expand Down
Loading
Loading