Skip to content

Add Mirror RB experiment #842

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

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
b493b29
add mirror RB experiment and analysis files
albertzhu01 Jul 11, 2022
11b8af2
edit appropriate mirrorRB-relevant files for PR
albertzhu01 Jul 11, 2022
f3121eb
update docstrings
albertzhu01 Jul 11, 2022
b4e6072
delete commented series code
albertzhu01 Jul 11, 2022
aef0379
fix pygsti version
albertzhu01 Jul 12, 2022
933bc7b
remove outcomes setting
albertzhu01 Jul 12, 2022
094ebd0
remove prints and add paper ref
paco-ri Jul 12, 2022
0e1ec4d
remove prints and add paper ref
paco-ri Jul 12, 2022
f28cdb7
move coupling map outside loop, delete elements_without_inv and int_c…
albertzhu01 Jul 12, 2022
281b777
Merge branch 'main' of https://github.com/albertzhu01/qiskit-experiments
albertzhu01 Jul 12, 2022
9a4602a
reformat files with black and lint
albertzhu01 Jul 12, 2022
1c9b350
cleaned RB tutorial
paco-ri Jul 12, 2022
66c6f3e
cleaned RB tutorial
paco-ri Jul 12, 2022
374fc2e
moved Clifford sampling in edgegrab algo
paco-ri Jul 12, 2022
34e2cb7
use full connectivity for coupling map if coupling map is not provided
albertzhu01 Aug 8, 2022
fefc4ba
resolved some merge conflits
paco-ri Aug 31, 2022
b8ab48d
changed AnalysisResult imports
paco-ri Sep 1, 2022
5cd64e5
edited BitGenerator and SeedSequence imports
paco-ri Sep 7, 2022
b43325a
removed MirrorRBPyGSTi from library init file
paco-ri Sep 7, 2022
f172c9b
fix full connectivity map generation code
albertzhu01 Oct 31, 2022
d0feba2
remove MirrorRBPyGSTi from mirror_rb_experiment.py, rb tutorial, and …
albertzhu01 Oct 31, 2022
d069f5d
fix oupling map full connectivity generation and update aer imports i…
albertzhu01 Nov 1, 2022
6846e12
fix merge conflicts with upstream main branch
albertzhu01 Nov 3, 2022
ddfcbaf
reformat imports (temporarily) to pass lint with merged code from ups…
albertzhu01 Nov 3, 2022
1124ea8
merged main
coruscating Dec 12, 2022
057de84
merged main branch
coruscating Jan 31, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [3.7, 3.8, 3.9, "3.10"]
python-version: [3.7, 3.8, 3.9, "3.10", "3.11"]
os: ["ubuntu-latest", "macOS-latest", "windows-latest"]
steps:
- name: Print Concurrency Group
Expand Down
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ ignore-mixin-members=yes
# (useful for modules/projects where namespaces are manipulated during runtime
# and thus existing member attributes cannot be deduced by static analysis. It
# supports qualified module names, as well as Unix pattern matching.
ignored-modules=matplotlib.cm,numpy.random,retworkx
ignored-modules=matplotlib.cm,numpy.random,rustworkx

# List of class names for which member attributes should not be checked (useful
# for classes with dynamically set attributes). This supports the use of
Expand Down
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include LICENSE.txt
include requirements.txt
include qiskit_experiments/VERSION.txt
include qiskit_experiments/library/randomized_benchmarking/data/*.npz
exclude qiskit_experiments/library/randomized_benchmarking/data/generate_clifford_data.py
99 changes: 99 additions & 0 deletions docs/_ext/autodoc_visualization.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2021, 2023.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.

"""
Documentation extension for visualization classes.
"""

from typing import Any

from docs._ext.custom_styles.styles import VisualizationDocstring
from qiskit.exceptions import QiskitError
from qiskit_experiments.visualization import BasePlotter, BaseDrawer
from sphinx.application import Sphinx
from sphinx.ext.autodoc import ClassDocumenter


class VisualizationDocumenter(ClassDocumenter):
"""Sphinx extension for the custom documentation of the standard visualization classes."""

objtype = "visualization" # Must be overwritten by subclasses.
directivetype = "class"
priority = 10 + ClassDocumenter.priority
option_spec = dict(ClassDocumenter.option_spec)

def add_content(self, more_content: Any, no_docstring: bool = False) -> None:
sourcename = self.get_sourcename()
try:
class_doc, init_doc = self.get_doc()
except ValueError:
raise QiskitError(
f"Documentation of {self.name} doesn't match with the expected format."
"Please run sphinx build without using the visualization template."
)

# format visualization class documentation into the visualization style
class_doc_parser = VisualizationDocstring(
target_cls=self.object,
docstring_lines=class_doc,
config=self.env.app.config,
indent=self.content_indent,
)

# write introduction
for i, line in enumerate(self.process_doc(class_doc_parser.generate_class_docs())):
self.add_line(line, sourcename, i)
self.add_line("", sourcename)

# write init method documentation
self.add_line(".. rubric:: Initialization", sourcename)
self.add_line("", sourcename)
for i, line in enumerate(self.process_doc([init_doc])):
self.add_line(line, sourcename, i)
self.add_line("", sourcename)

# method and attributes
if more_content:
for line, src in zip(more_content.data, more_content.items):
self.add_line(line, src[0], src[1])


class PlotterDocumenter(VisualizationDocumenter):
"""Sphinx extension for the custom documentation of plotter classes."""

objtype = "plotter"

@classmethod
def can_document_member(cls, member: Any, membername: str, isattr: bool, parent: Any) -> bool:
return isinstance(member, BasePlotter)


class DrawerDocumenter(VisualizationDocumenter):
"""Sphinx extension for the custom documentation of drawer classes."""

objtype = "drawer"

@classmethod
def can_document_member(cls, member: Any, membername: str, isattr: bool, parent: Any) -> bool:
return isinstance(member, BaseDrawer)


def setup(app: Sphinx):
# Add plotter documenter
existing_documenter = app.registry.documenters.get(PlotterDocumenter.objtype)
if existing_documenter is None or not issubclass(existing_documenter, PlotterDocumenter):
app.add_autodocumenter(PlotterDocumenter, override=True)

# Add drawer documenter
existing_documenter = app.registry.documenters.get(DrawerDocumenter.objtype)
if existing_documenter is None or not issubclass(existing_documenter, DrawerDocumenter):
app.add_autodocumenter(DrawerDocumenter, override=True)
2 changes: 2 additions & 0 deletions docs/_ext/autoref.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class WebSite(Directive):
.. ref_website:: qiskit-experiments, https://github.com/Qiskit/qiskit-experiments

"""

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes to this file look unnecessary; please revert them if so.

required_arguments = 1
optional_arguments = 0
final_argument_whitespace = True
Expand Down Expand Up @@ -67,6 +68,7 @@ class Arxiv(Directive):
If an article is not found, no journal information will be shown.

"""

required_arguments = 2
optional_arguments = 0
final_argument_whitespace = False
Expand Down
34 changes: 33 additions & 1 deletion docs/_ext/custom_styles/formatter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2021.
# (C) Copyright IBM 2021, 2023.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand Down Expand Up @@ -215,3 +215,35 @@ def format_fit_parameters(self, lines: List[str]) -> List[str]:
format_lines.append("")

return format_lines

class VisualizationSectionFormatter(DocstringSectionFormatter):
"""Formatter for visualization classes."""

@_check_no_indent
def format_opts(self, lines: List[str]) -> List[str]:
"""Format options section."""

format_lines = [
".. rubric:: Options",
"",
"The following can be set using :meth:`set_options`.",
"",
]
format_lines.extend(lines)
format_lines.append("")

return format_lines

@_check_no_indent
def format_figure_opts(self, lines: List[str]) -> List[str]:
"""Format figure options section."""
format_lines = [
".. rubric:: Figure Options",
"",
"The following can be set using :meth:`set_figure_options`.",
"",
]
format_lines.extend(lines)
format_lines.append("")

return format_lines
86 changes: 85 additions & 1 deletion docs/_ext/custom_styles/styles.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2021.
# (C) Copyright IBM 2021, 2023.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand All @@ -21,12 +21,14 @@

from qiskit_experiments.framework.base_analysis import BaseAnalysis
from qiskit_experiments.framework.base_experiment import BaseExperiment
from qiskit_experiments.visualization import BaseDrawer, BasePlotter
from sphinx.config import Config as SphinxConfig

from .formatter import (
ExperimentSectionFormatter,
AnalysisSectionFormatter,
DocstringSectionFormatter,
VisualizationSectionFormatter,
)
from .section_parsers import load_standard_section, load_fit_parameters
from .utils import (
Expand Down Expand Up @@ -310,3 +312,85 @@ def _extra_sections(self, sectioned_docstring: Dict[str, List[str]]):
option_desc.append("No option available for this analysis.")

sectioned_docstring["analysis_opts"] = option_desc


class VisualizationDocstring(QiskitExperimentDocstring):
"""Documentation parser for visualization classes' introductions."""

__sections__ = {
"header": load_standard_section,
"warning": load_standard_section,
"overview": load_standard_section,
"reference": load_standard_section,
"tutorial": load_standard_section,
"opts": None, # For standard options
"figure_opts": None, # For figure options
"example": load_standard_section,
"note": load_standard_section,
"see_also": load_standard_section,
}

__formatter__ = VisualizationSectionFormatter

def __init__(
self,
target_cls: Union[BaseDrawer, BasePlotter],
docstring_lines: Union[str, List[str]],
config: SphinxConfig,
indent: str = "",
):
"""Create new parser and parse formatted docstring."""
super().__init__(target_cls, docstring_lines, config, indent)

def _extra_sections(self, sectioned_docstring: Dict[str, List[str]]):
"""Generate extra sections."""
# add options
option_desc = []
figure_option_desc = []

docs_config = copy.copy(self._config)
docs_config.napoleon_custom_sections = [
("options", "args"),
("figure options", "args"),
]

# Generate options docs
option = _generate_options_documentation(
current_class=self._target_cls,
method_name="_default_options",
config=docs_config,
indent=self._indent,
)
if option:
option_desc.extend(option)
option_desc.append("")
option_desc.extend(
_format_default_options(
defaults=self._target_cls._default_options().__dict__,
indent=self._indent,
)
)
else:
option_desc.append("No options available.")

# Generate figure options docs
figure_option = _generate_options_documentation(
current_class=self._target_cls,
method_name="_default_figure_options",
config=docs_config,
indent=self._indent,
)
if figure_option:
figure_option_desc.extend(figure_option)
figure_option_desc.append("")
figure_option_desc.extend(
_format_default_options(
defaults=self._target_cls._default_figure_options().__dict__,
indent=self._indent,
)
)
else:
figure_option_desc.append("No figure options available.")

sectioned_docstring["opts"] = option_desc
sectioned_docstring["figure_opts"] = figure_option_desc
49 changes: 49 additions & 0 deletions docs/_templates/autosummary/drawer.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{% if referencefile %}
.. include:: {{ referencefile }}
{% endif %}

{{ objname }}
{{ underline }}

.. currentmodule:: {{ module }}

.. autodrawer:: {{ objname }}
:no-members:
:no-inherited-members:
:no-special-members:

{% block attributes_summary %}
{% if attributes %}

.. rubric:: Attributes

.. autosummary::
:toctree: ../stubs/
{% for item in all_attributes %}
{%- if not item.startswith('_') %}
{{ name }}.{{ item }}
{%- endif -%}
{%- endfor %}
{% endif %}
{% endblock %}

{% block methods_summary %}
{% if methods %}

.. rubric:: Methods

.. autosummary::
:toctree: ../stubs/
{% for item in all_methods %}
{%- if not item.startswith('_') or item in ['__call__', '__mul__', '__getitem__', '__len__'] %}
{{ name }}.{{ item }}
{%- endif -%}
{%- endfor %}
{% for item in inherited_members %}
{%- if item in ['__call__', '__mul__', '__getitem__', '__len__'] %}
{{ name }}.{{ item }}
{%- endif -%}
{%- endfor %}

{% endif %}
{% endblock %}
50 changes: 50 additions & 0 deletions docs/_templates/autosummary/plotter.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{% if referencefile %}
.. include:: {{ referencefile }}
{% endif %}

{{ objname }}
{{ underline }}

.. currentmodule:: {{ module }}

.. autoplotter:: {{ objname }}
:no-members:
:no-inherited-members:
:no-special-members:

{% block attributes_summary %}
{% if attributes %}

.. rubric:: Attributes

.. autosummary::
:toctree: ../stubs/
{% for item in all_attributes %}
{%- if not item.startswith('_') %}
{{ name }}.{{ item }}
{%- endif -%}
{%- endfor %}
{% endif %}
{% endblock %}

{% block methods_summary %}
{% if methods %}

.. rubric:: Methods

.. autosummary::
:toctree: ../stubs/

{% for item in all_methods %}
{%- if not item.startswith('_') or item in ['__call__', '__mul__', '__getitem__', '__len__'] %}
{{ name }}.{{ item }}
{%- endif -%}
{%- endfor %}
{% for item in inherited_members %}
{%- if item in ['__call__', '__mul__', '__getitem__', '__len__'] %}
{{ name }}.{{ item }}
{%- endif -%}
{%- endfor %}

{% endif %}
{% endblock %}
Loading