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

Increase scope of docformatter and black [unitaryhack] #79

Merged
merged 21 commits into from
Jun 7, 2022
Merged
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
5 changes: 4 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
* Added tests for `EGraph` plots. [#60](https://github.com/XanaduAI/flamingpy/pull/60)
* Added `.gitattributes` to the repository, so git automatically handles consistent `eol`'s for all commits and contributors across different operating systems. [#78](https://github.com/XanaduAI/flamingpy/pull/78)
* Added `fig, ax` returns for the draw methods in `utils/viz.py` and some additional tests. [#55](https://github.com/XanaduAI/flamingpy/pull/55)
* Increased the scope of `docformatter` to all `.py` files in the repository. [#79](https://github.com/XanaduAI/flamingpy/pull/79)
* Increased the scope of `black` formatter to include documentation files. [#79](https://github.com/XanaduAI/flamingpy/pull/79)

### Documentation changes

* Mention the new graph state functions from `flamingpy.utils.graph_states` in the `run_graph_states.py` tutorial. [#68](https://github.com/XanaduAI/flamingpy/pull/68)
* Typo fix and minor README change. [#70](https://github.com/XanaduAI/flamingpy/pull/80)

Expand All @@ -22,7 +25,7 @@

This release contains contributions from (in alphabetical order):

[Joost Bus](https://github.com/soosub), [Sebastián Duque Mesa](https://github.com/sduquemesa), [Luis Mantilla](https://github.com/BestQuark), Nariman Saadatmand
[Joost Bus](https://github.com/soosub), [Sebastián Duque Mesa](https://github.com/sduquemesa), [Luis Mantilla](https://github.com/BestQuark), Nariman Saadatmand, [WingCode](https://github.com/WingCode)

See full commit details ...

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/format.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- uses: actions/checkout@v2

- name: Run black
run: python -m black -l 100 tests flamingpy --check
run: python -m black -l 100 tests flamingpy doc --check

- name: Run docformatter
run: python -m docformatter --check flamingpy/*/*.py
run: python -m docformatter -r --check .
9 changes: 4 additions & 5 deletions doc/_ext/edit_on_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@


def get_github_url(app, view, path):
"""A function to generate github url based on __app__, __view__,
and __path__ inputs.
"""
"""A function to generate github url based on __app__, __view__, and
__path__ inputs."""
return "https://github.com/{project}/{view}/{branch}/{path}".format(
project=app.config.edit_on_github_project,
view=view,
Expand All @@ -36,7 +35,7 @@ def get_github_url(app, view, path):


def html_page_context(app, pagename, templatename, context, doctree):
"""A function to set html page context and return warnings as needed"""
"""A function to set html page context and return warnings as needed."""
if templatename != "page.html":
return

Expand All @@ -56,7 +55,7 @@ def html_page_context(app, pagename, templatename, context, doctree):


def setup(app):
"""A handy function to set up edit_on_github links"""
"""A handy function to set up edit_on_github links."""
app.add_config_value("edit_on_github_project", "", True)
app.add_config_value("edit_on_github_branch", "master", True)
app.connect("html-page-context", html_page_context)
6 changes: 2 additions & 4 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
# This file does only contain a selection of the most common options. For a
# full list see the documentation:
# http://www.sphinx-doc.org/en/master/config
"""
flamingpy configuration file for the Sphinx documentation builder.
"""
"""flamingpy configuration file for the Sphinx documentation builder."""
import os
import sys
import re
Expand All @@ -28,7 +26,7 @@


class Mock(MagicMock):
"""An auxiliary class to create mocked modules"""
"""An auxiliary class to create mocked modules."""

__name__ = "foo"

Expand Down
4 changes: 1 addition & 3 deletions doc/tutorials/run_error_correction.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
"""
.. _run-error-correction:
""".. _run-error-correction:

A complete round of error correction
====================================

"""


Expand Down
4 changes: 1 addition & 3 deletions doc/tutorials/run_graph_states.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
"""
.. _graph-states-tutorial:
""".. _graph-states-tutorial:

Graph States
============

"""


Expand Down
2 changes: 1 addition & 1 deletion flamingpy/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
"""Version number (major.minor.patch[label])"""


__version__ = "0.8.2a5.dev5"
__version__ = "0.8.2a5.dev6"
2 changes: 1 addition & 1 deletion flamingpy/examples/surface_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def illustrate_surface_code(d, boundaries, err, polarity, stabilizer_inds=None,
# Instantiate a surface code.
RHG_code = SurfaceCode(d, ec=err, boundaries=boundaries, polarity=polarity)
RHG_lattice = RHG_code.graph
RHG_fig, RHG_ax = RHG_code.draw()
_, RHG_ax = RHG_code.draw()

# Check edges between boundaries for periodic boundary conditions.
if boundaries == "periodic":
Expand Down
3 changes: 2 additions & 1 deletion flamingpy/simulations.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def ec_mc_trial(
weight_options,
rng=default_rng(),
):
"""Runs a single trial of Monte Carlo simulations of error-correction for the given code."""
"""Runs a single trial of Monte Carlo simulations of error-correction for
the given code."""
if passive_objects is not None:
reduce_macro_and_simulate(*passive_objects, p_swap, delta, rng)
else:
Expand Down
11 changes: 6 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""setup.py instructions for FlamingPy installation from Source
"""
"""setup.py instructions for FlamingPy installation from Source."""

# pylint: disable=too-few-public-methods

Expand All @@ -36,7 +35,7 @@


class BinaryDistribution(dist.Distribution):
"""A class to define Binary Distribution objects"""
"""A class to define Binary Distribution objects."""

def has_ext_modules(foo):
"""Check for external modules."""
Expand Down Expand Up @@ -159,8 +158,10 @@ def build_extension(self, ext):
"thewalrus>=0.19.0",
]

description = ("FlamingPy is a cross-platform Python library with a variety of backends for "
"efficient simulations of error correction in fault-tolerant quantum computers.")
description = (
"FlamingPy is a cross-platform Python library with a variety of backends for "
"efficient simulations of error correction in fault-tolerant quantum computers."
)

setup(
name="flamingpy",
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Default parameters, environment variables, fixtures, and shared objects
the unit tests and manual checks."""
"""Default parameters, environment variables, fixtures, and shared objects the
unit tests and manual checks."""
import os
import pytest

Expand Down
1 change: 0 additions & 1 deletion tests/unit/test_benchmarks_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
# pylint: disable=import-outside-toplevel,unused-import

import pytest
from flamingpy.codes import alternating_polarity


@pytest.mark.parametrize("noise", ["cv", "dv"])
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/test_iid_noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ def test_full_noise():

def test_finite_prob_noise():
"""Check that all bit values are either 0 or 1 when the error probability
is between 0 and 1.
"""
is between 0 and 1."""
code = SurfaceCode(3)
for prob in [0.1, 0.5, 0.9]:
noise = IidNoise(code, prob)
Expand All @@ -51,8 +50,8 @@ def test_finite_prob_noise():


def test_decoding():
"""Check that we can use the correct function to decode the code
after applying iid noise."""
"""Check that we can use the correct function to decode the code after
applying iid noise."""
code = SurfaceCode(3)
noise = IidNoise(code, 0.1)
noise.apply_noise()
Expand All @@ -61,7 +60,8 @@ def test_decoding():

@pytest.mark.parametrize("prob", [-0.1, 1.1])
def test_warning(prob):
"""Test that a warning is raised when the probability is not between 0 and 1."""
"""Test that a warning is raised when the probability is not between 0 and
1."""

code = SurfaceCode(3)
with pytest.raises(Exception) as exc:
Expand Down
4 changes: 1 addition & 3 deletions tests/unit/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Unit tests for flamingpy top _init_.py functions.
"""
"""Unit tests for flamingpy top _init_.py functions."""

# pylint: disable=protected-access

Expand Down
3 changes: 2 additions & 1 deletion tests/unit/test_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def test_matching_has_same_weight(matching_graphs):

@pytest.fixture(scope="module", params=it.product(matching_graph_types, distances))
def code_matching_graphs(request):
"""Return a matching graph type built from a surface code with given distance.
"""Return a matching graph type built from a surface code with given
distance.

Also return the corresponding NxMatchingGraph for comparison.
"""
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/test_stabilizer_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Unit tests for StablizerGraph classes in stab_graph.py.
"""Unit tests for StablizerGraph classes in stab_graph.py.

The networkx implementation is used as a reference.
"""
Expand Down
30 changes: 12 additions & 18 deletions tests/unit/test_uf_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,8 @@ def enc_state(request):

@pytest.fixture(scope="module", params=code_params)
def enc_state_swap_list(request):
"""
In this function, lattice is generated based on a list of psqueezed states,
which are generated randomly.
"""
"""In this function, lattice is generated based on a list of psqueezed
states, which are generated randomly."""
distance, ec, boundaries, delta = request.param

if boundaries == "periodic":
Expand Down Expand Up @@ -172,7 +170,7 @@ def test_support(self, enc_state_swap_list):
assert support.status[frozenset((edge[0], edge[1]))] == "grown"

def test_support_value(self, enc_state_swap_list):
"""Test Support function assignments"""
"""Test Support function assignments."""
CV_decoder(enc_state_swap_list[0])
assign_weights(enc_state_swap_list[0], "UF")

Expand Down Expand Up @@ -230,7 +228,7 @@ def test_boundary(self, enc_state):


class TestUnionFindFunctions:
"""Test function members of UnionFind decoder"""
"""Test function members of UnionFind decoder."""

def test_union(self):
"""Test the union of trees."""
Expand Down Expand Up @@ -338,10 +336,11 @@ def test_initialize_cluster_trees(self, enc_state):


class PeelingDecoder:
"""A class to host methods for testing peeling decoder assignments"""
"""A class to host methods for testing peeling decoder assignments."""

def test_peeling(self):
"""Test the peeling decoder for the surface code with periodic boundary conditions."""
"""Test the peeling decoder for the surface code with periodic boundary
conditions."""
# Test 1: Check if the peeling decoder works fine for one even cluster
spanning_forest = rx.PyGraph()

Expand Down Expand Up @@ -443,9 +442,8 @@ def test_uf_erasure(self, enc_state_swap_list):
assert set(enc_state_swap_list[2]) == set(erased_qubits)

def test_assign_weight_UF(self):
"""
Testing the different types of weights and number of weight levels in
different weighted UF decoders in UFdecoder.py
"""Testing the different types of weights and number of weight levels
in different weighted UF decoders in UFdecoder.py.

The graph considered is
(0,0,0) A'p' -
Expand All @@ -457,10 +455,8 @@ def test_assign_weight_UF(self):
"""

class MinimalCode:
"""
A class similar to SurfaceCode class but only with
attributes that are required for the testing.
"""
"""A class similar to SurfaceCode class but only with attributes
that are required for the testing."""

def __init__(self, G, synd_coords):
self.graph = G
Expand Down Expand Up @@ -505,9 +501,7 @@ def __init__(self, G, synd_coords):
assert G.nodes[(6, 3, 2)]["weight"] == 2

def test_UF(self):
"""
Testing the UFdecoder
"""
"""Testing the UFdecoder."""
syndrome_dict = {1: 1, 2: 0, 3: 1, 4: 0, 5: 0, 6: 1, 7: 1, 8: 0, 9: 0}
syndrome_nodes = []
for i in range(len(syndrome_dict)):
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/test_utils_graphstates.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
""""Unit tests for the utils.graph_states module"""
""""Unit tests for the utils.graph_states module."""
import pytest
from flamingpy.utils import graph_states

Expand All @@ -28,7 +28,7 @@ def test_star_graph():


def test_star_graph_inputs():
"""Check that invalid inputs in star_graph raise a warning"""
"""Check that invalid inputs in star_graph raise a warning."""
n = 0
with pytest.raises(Exception) as e:
graph_states.star_graph(n)
Expand Down Expand Up @@ -56,7 +56,7 @@ def test_complete_graph():


def test_complete_graph_inputs():
"""Check that invalid inputs in complete_graph raise a warning"""
"""Check that invalid inputs in complete_graph raise a warning."""
n = 0
with pytest.raises(Exception) as e:
graph_states.complete_graph(n)
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/test_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
""""Unit tests for functions in the viz module."""

import math
from datetime import datetime

import numpy as np
from numpy.random import default_rng as rng
Expand Down