From f61c5cc97afec147cf012565c70e662de76da83a Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Thu, 3 Oct 2024 23:07:32 -0700 Subject: [PATCH 01/14] Copy pylint_copyright_checker plugin from cirq --- dev_tools/pylint_copyright_checker.py | 117 ++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 dev_tools/pylint_copyright_checker.py diff --git a/dev_tools/pylint_copyright_checker.py b/dev_tools/pylint_copyright_checker.py new file mode 100644 index 00000000..0a5c69e2 --- /dev/null +++ b/dev_tools/pylint_copyright_checker.py @@ -0,0 +1,117 @@ +# Copyright 2021 The Cirq Developers +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. + +from __future__ import annotations + +from typing import TYPE_CHECKING + +from astroid import nodes +from pylint.checkers import BaseRawFileChecker + +if TYPE_CHECKING: + from pylint.lint import PyLinter + + +class CopyrightChecker(BaseRawFileChecker): + """Check for the copyright notices at the beginning of a Python source file. + + This checker can be disabled by putting `# pylint: disable=wrong-or-nonexistent-copyright-notice` + at the beginning of a file. + """ + + name = "copyright-notice" + msgs = { + "R0001": ( + "Missing or wrong copyright notice", + "wrong-or-nonexistent-copyright-notice", + "Consider putting a correct copyright notice at the beginning of a file.", + ) + } + options = () + + def process_module(self, node: nodes.Module) -> None: + """Check whether the copyright notice is correctly placed in the source file of a module. + + Compare the first lines of a source file against the standard copyright notice (i.e., the + `golden` variable below). Suffix whitespace (including newline symbols) is not considered + during the comparison. Pylint will report a message if the copyright notice is not + correctly placed. + + Args: + node: the module to be checked. + """ + # Exit if the checker is disabled in the source file. + if not self.linter.is_message_enabled("wrong-or-nonexistent-copyright-notice"): + return + golden = [ + b'# Copyright 20XX The Cirq Developers', + b'#', + b'# Licensed under the Apache License, Version 2.0 (the "License");', + b'# you may not use this file except in compliance with the License.', + b'# You may obtain a copy of the License at', + b'#', + b'# https://www.apache.org/licenses/LICENSE-2.0', + b'#', + b'# Unless required by applicable law or agreed to in writing, software', + b'# distributed under the License is distributed on an "AS IS" BASIS,', + b'# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.', + b'# See the License for the specific language governing permissions and', + b'# limitations under the License.', + ] + with node.stream() as stream: + + def skip_shebang(stream): + """Skip shebang line if present, and blank lines between shebang and content.""" + lines = iter(enumerate(stream)) + try: + lineno, line = next(lines) + except StopIteration: + return + if line.startswith(b'#!'): + # skip shebang and blank lines + for lineno, line in lines: + if line.strip(): + yield lineno, line + break + else: + # no shebang + yield lineno, line + yield from lines + + for expected_line, (i, (lineno, line)) in zip(golden, enumerate(skip_shebang(stream))): + for expected_char, (colno, char) in zip(expected_line, enumerate(line)): + # The text needs to be same as the template except for the year. + if expected_char != char and not (i == 0 and 14 <= colno <= 15): + self.add_message( + "wrong-or-nonexistent-copyright-notice", + line=lineno + 1, + col_offset=colno, + ) + return + # The line cannot be shorter than the template or contain extra text. + if len(line) < len(expected_line) or line[len(expected_line) :].strip() != b'': + self.add_message( + "wrong-or-nonexistent-copyright-notice", + line=lineno + 1, + col_offset=min(len(line), len(expected_line)), + ) + return + + +def register(linter: PyLinter): + """Register this checker to pylint. + + The registration is done automatically if this file is in $PYTHONPATH. + """ + linter.register_checker(CopyrightChecker(linter)) From 718df8631125c516f012b0f224b4e6762df55991 Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Thu, 3 Oct 2024 23:43:17 -0700 Subject: [PATCH 02/14] pylint_copyright_checker - update expected copyright text --- dev_tools/pylint_copyright_checker.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev_tools/pylint_copyright_checker.py b/dev_tools/pylint_copyright_checker.py index 0a5c69e2..91b45609 100644 --- a/dev_tools/pylint_copyright_checker.py +++ b/dev_tools/pylint_copyright_checker.py @@ -1,4 +1,4 @@ -# Copyright 2021 The Cirq Developers +# Copyright 2024 The Unitary Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -55,7 +55,7 @@ def process_module(self, node: nodes.Module) -> None: if not self.linter.is_message_enabled("wrong-or-nonexistent-copyright-notice"): return golden = [ - b'# Copyright 20XX The Cirq Developers', + b'# Copyright 20XX The Unitary Authors', b'#', b'# Licensed under the Apache License, Version 2.0 (the "License");', b'# you may not use this file except in compliance with the License.', From 506b42088bb8faa6dcee9f7d2d8c08521e9a2a6d Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Thu, 3 Oct 2024 23:08:40 -0700 Subject: [PATCH 03/14] Use the same pylint configuration as in cirq --- dev_tools/.pylintrc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dev_tools/.pylintrc b/dev_tools/.pylintrc index 638ba3e6..40fcdd44 100644 --- a/dev_tools/.pylintrc +++ b/dev_tools/.pylintrc @@ -2,7 +2,6 @@ load-plugins=pylint.extensions.docstyle,pylint.extensions.docparams,pylint_copyright_checker max-line-length=88 disable=all -#ignore-paths=cirq-google/cirq_google/cloud/.* ignore-patterns=.*_pb2\.py output-format=colorized score=no @@ -15,11 +14,13 @@ enable= bad-reversed-sequence, bad-super-call, consider-merging-isinstance, + consider-using-f-string, continue-in-finally, dangerous-default-value, docstyle, duplicate-argument-name, expression-not-assigned, + f-string-without-interpolation, function-redefined, inconsistent-mro, init-is-generator, @@ -53,6 +54,7 @@ enable= unused-variable, unused-wildcard-import, wildcard-import, + wrong-or-nonexistent-copyright-notice, wrong-import-order, wrong-import-position, yield-outside-function From 526edeb4ebce0b38bf06d9177f4cdd31f684c79e Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Thu, 3 Oct 2024 23:23:55 -0700 Subject: [PATCH 04/14] pylint - fix unused-import --- examples/fox_in_a_hole/fox_in_a_hole_test.py | 2 -- examples/quantum_chinese_chess/board_test.py | 3 +-- examples/quantum_chinese_chess/chess.py | 2 +- examples/quantum_chinese_chess/move.py | 3 ++- examples/quantum_chinese_chess/move_test.py | 6 ------ examples/quantum_chinese_chess/piece.py | 2 +- examples/quantum_chinese_chess/test_utils.py | 2 +- examples/quantum_rpg/bb84.py | 5 +++-- examples/quantum_rpg/encounter.py | 1 - examples/quantum_rpg/encounter_test.py | 1 - .../final_state_preparation/classical_frontier.py | 2 -- examples/quantum_rpg/game_state.py | 1 - examples/quantum_rpg/main_loop.py | 4 +--- examples/quantum_rpg/main_loop_test.py | 2 +- examples/quantum_rpg/npcs.py | 2 +- examples/quantum_rpg/npcs_test.py | 2 -- examples/quantum_rpg/qaracter.py | 4 ++-- examples/quantum_rpg/world_test.py | 1 - examples/quantum_rpg/xp_utils.py | 2 -- examples/tic_tac_toe/tic_tac_split.py | 4 ++-- examples/tic_tac_toe/tic_tac_toe.py | 2 +- examples/tic_tac_toe/tic_tac_toe_test.py | 2 +- unitary/alpha/quantum_world.py | 2 +- unitary/alpha/qubit_effects.py | 6 ++---- unitary/alpha/qudit_effects.py | 4 ---- unitary/quantum_chess/ascii_board.py | 2 +- unitary/quantum_chess/circuit_transformer.py | 2 +- unitary/quantum_chess/controlled_iswap.py | 2 +- 28 files changed, 24 insertions(+), 49 deletions(-) diff --git a/examples/fox_in_a_hole/fox_in_a_hole_test.py b/examples/fox_in_a_hole/fox_in_a_hole_test.py index d61937f1..7dd76ee1 100644 --- a/examples/fox_in_a_hole/fox_in_a_hole_test.py +++ b/examples/fox_in_a_hole/fox_in_a_hole_test.py @@ -14,8 +14,6 @@ """Tests for ClassicalGame and QuantumGame classes.""" -import pytest - from . import fox_in_a_hole as fh diff --git a/examples/quantum_chinese_chess/board_test.py b/examples/quantum_chinese_chess/board_test.py index 93649056..dee04ca7 100644 --- a/examples/quantum_chinese_chess/board_test.py +++ b/examples/quantum_chinese_chess/board_test.py @@ -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. -# + from .enums import ( Language, Color, @@ -25,7 +25,6 @@ locations_to_bitboard, assert_samples_in, assert_sample_distribution, - get_board_probability_distribution, set_board, ) from unitary import alpha diff --git a/examples/quantum_chinese_chess/chess.py b/examples/quantum_chinese_chess/chess.py index 34543f6e..37cc2067 100644 --- a/examples/quantum_chinese_chess/chess.py +++ b/examples/quantum_chinese_chess/chess.py @@ -11,6 +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. + from typing import Tuple, List from .board import Board from .enums import ( @@ -31,7 +32,6 @@ MergeSlide, CannonFire, ) -import readline # List of acceptable commands. _HELP_TEXT = """ diff --git a/examples/quantum_chinese_chess/move.py b/examples/quantum_chinese_chess/move.py index 6f602612..7ce2b8e8 100644 --- a/examples/quantum_chinese_chess/move.py +++ b/examples/quantum_chinese_chess/move.py @@ -11,7 +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. -from typing import Optional, List, Tuple, Iterator + +from typing import Optional, List, Iterator import cirq from unitary import alpha from unitary.alpha.quantum_effect import QuantumEffect diff --git a/examples/quantum_chinese_chess/move_test.py b/examples/quantum_chinese_chess/move_test.py index 27e38273..8a798991 100644 --- a/examples/quantum_chinese_chess/move_test.py +++ b/examples/quantum_chinese_chess/move_test.py @@ -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. -from typing import List -import pytest from unitary import alpha from .move import * @@ -22,7 +20,6 @@ from .enums import ( MoveType, MoveVariant, - SquareState, Type, Color, ) @@ -30,11 +27,8 @@ locations_to_bitboard, assert_samples_in, assert_sample_distribution, - assert_this_or_that, - assert_prob_about, assert_fifty_fifty, get_board_probability_distribution, - print_samples, set_board, ) diff --git a/examples/quantum_chinese_chess/piece.py b/examples/quantum_chinese_chess/piece.py index 801a0c75..dba50eeb 100644 --- a/examples/quantum_chinese_chess/piece.py +++ b/examples/quantum_chinese_chess/piece.py @@ -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. -from typing import Optional + from unitary.alpha import QuantumObject from .enums import ( SquareState, diff --git a/examples/quantum_chinese_chess/test_utils.py b/examples/quantum_chinese_chess/test_utils.py index a4033a58..e495d890 100644 --- a/examples/quantum_chinese_chess/test_utils.py +++ b/examples/quantum_chinese_chess/test_utils.py @@ -11,12 +11,12 @@ # 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. + from typing import List, Dict from collections import defaultdict from scipy.stats import chisquare from unitary import alpha -from unitary.alpha import QuantumObject, QuantumWorld from .enums import SquareState, Type, Color from .board import Board diff --git a/examples/quantum_rpg/bb84.py b/examples/quantum_rpg/bb84.py index adb6d6c1..89398c17 100644 --- a/examples/quantum_rpg/bb84.py +++ b/examples/quantum_rpg/bb84.py @@ -11,13 +11,14 @@ # 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. + from typing import Tuple import random import re from .game_state import GameState -from .item import EXAMINE, TALK, Item -from .world import Direction, Location +from .item import EXAMINE, Item +from .world import Direction _WORDS = [ diff --git a/examples/quantum_rpg/encounter.py b/examples/quantum_rpg/encounter.py index 04680222..b4285be3 100644 --- a/examples/quantum_rpg/encounter.py +++ b/examples/quantum_rpg/encounter.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import io from typing import Optional, Sequence import random diff --git a/examples/quantum_rpg/encounter_test.py b/examples/quantum_rpg/encounter_test.py index 0d647db8..13a83644 100644 --- a/examples/quantum_rpg/encounter_test.py +++ b/examples/quantum_rpg/encounter_test.py @@ -16,7 +16,6 @@ import unitary.alpha as alpha -from . import battle from . import classes from . import encounter from . import game_state diff --git a/examples/quantum_rpg/final_state_preparation/classical_frontier.py b/examples/quantum_rpg/final_state_preparation/classical_frontier.py index ae33ea6e..9a903d64 100644 --- a/examples/quantum_rpg/final_state_preparation/classical_frontier.py +++ b/examples/quantum_rpg/final_state_preparation/classical_frontier.py @@ -11,10 +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. -import unitary.alpha as alpha from ..classes import Engineer -from ..encounter import Encounter from ..exceptions import UntimelyDeathException from ..game_state import GameState from .monsters import ( diff --git a/examples/quantum_rpg/game_state.py b/examples/quantum_rpg/game_state.py index 2f04fabe..4e1f0988 100644 --- a/examples/quantum_rpg/game_state.py +++ b/examples/quantum_rpg/game_state.py @@ -14,7 +14,6 @@ from typing import Dict, List, Optional, Sequence, TextIO -import io import sys from . import input_helpers diff --git a/examples/quantum_rpg/main_loop.py b/examples/quantum_rpg/main_loop.py index 66be33ea..affd8128 100644 --- a/examples/quantum_rpg/main_loop.py +++ b/examples/quantum_rpg/main_loop.py @@ -13,10 +13,8 @@ # limitations under the License. import enum -import io -import sys import textwrap -from typing import List, Optional, Sequence +from typing import Optional, Sequence from . import ascii_art from . import battle diff --git a/examples/quantum_rpg/main_loop_test.py b/examples/quantum_rpg/main_loop_test.py index 869f76ab..3367bd75 100644 --- a/examples/quantum_rpg/main_loop_test.py +++ b/examples/quantum_rpg/main_loop_test.py @@ -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. -import copy + import io from typing import cast diff --git a/examples/quantum_rpg/npcs.py b/examples/quantum_rpg/npcs.py index ac0c2701..d1f3bb82 100644 --- a/examples/quantum_rpg/npcs.py +++ b/examples/quantum_rpg/npcs.py @@ -11,13 +11,13 @@ # 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. + from typing import cast, List import random import unitary.alpha as alpha -from . import enums from . import qaracter diff --git a/examples/quantum_rpg/npcs_test.py b/examples/quantum_rpg/npcs_test.py index 1ae3014a..bc2ddc41 100644 --- a/examples/quantum_rpg/npcs_test.py +++ b/examples/quantum_rpg/npcs_test.py @@ -12,8 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unitary.alpha as alpha - from . import battle from . import classes from . import enums diff --git a/examples/quantum_rpg/qaracter.py b/examples/quantum_rpg/qaracter.py index 17cb86b8..cb9513d2 100644 --- a/examples/quantum_rpg/qaracter.py +++ b/examples/quantum_rpg/qaracter.py @@ -11,9 +11,9 @@ # 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. -from typing import cast, Callable, Dict, List, Optional, Union + +from typing import cast, Dict, List, Optional, Union import inspect -import random import sys import cirq diff --git a/examples/quantum_rpg/world_test.py b/examples/quantum_rpg/world_test.py index b51a706a..e09ae9a9 100644 --- a/examples/quantum_rpg/world_test.py +++ b/examples/quantum_rpg/world_test.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from . import item from . import world diff --git a/examples/quantum_rpg/xp_utils.py b/examples/quantum_rpg/xp_utils.py index c5a6674e..f60da96b 100644 --- a/examples/quantum_rpg/xp_utils.py +++ b/examples/quantum_rpg/xp_utils.py @@ -14,9 +14,7 @@ from typing import List, Optional, Sequence -import io import random -import sys import unitary.alpha as alpha diff --git a/examples/tic_tac_toe/tic_tac_split.py b/examples/tic_tac_toe/tic_tac_split.py index c5e452bc..fb8b3486 100644 --- a/examples/tic_tac_toe/tic_tac_split.py +++ b/examples/tic_tac_toe/tic_tac_split.py @@ -11,13 +11,13 @@ # 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. -# + from typing import Optional import numpy as np import cirq -from unitary.alpha import QuantumEffect, QuantumObject +from unitary.alpha import QuantumEffect from unitary.alpha.qudit_gates import QuditXGate, QuditISwapPowGate from .enums import TicTacSquare, TicTacRules diff --git a/examples/tic_tac_toe/tic_tac_toe.py b/examples/tic_tac_toe/tic_tac_toe.py index d483b057..57f41645 100644 --- a/examples/tic_tac_toe/tic_tac_toe.py +++ b/examples/tic_tac_toe/tic_tac_toe.py @@ -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. -import io + import sys from typing import Dict, List, TextIO diff --git a/examples/tic_tac_toe/tic_tac_toe_test.py b/examples/tic_tac_toe/tic_tac_toe_test.py index 05c9efd4..8da73774 100644 --- a/examples/tic_tac_toe/tic_tac_toe_test.py +++ b/examples/tic_tac_toe/tic_tac_toe_test.py @@ -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. -import os + import pytest import io from unittest.mock import MagicMock diff --git a/unitary/alpha/quantum_world.py b/unitary/alpha/quantum_world.py index 6235b908..889a9b70 100644 --- a/unitary/alpha/quantum_world.py +++ b/unitary/alpha/quantum_world.py @@ -11,6 +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. + import copy import enum from typing import cast, Dict, Iterable, List, Optional, Sequence, Set, Tuple, Union @@ -20,7 +21,6 @@ from unitary.alpha.sparse_vector_simulator import PostSelectOperation, SparseSimulator from unitary.alpha.qudit_state_transform import qudit_to_qubit_unitary, num_bits import numpy as np -import itertools class QuantumWorld: diff --git a/unitary/alpha/qubit_effects.py b/unitary/alpha/qubit_effects.py index f786046b..b3345f18 100644 --- a/unitary/alpha/qubit_effects.py +++ b/unitary/alpha/qubit_effects.py @@ -11,10 +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. -# -from typing import Iterator, Optional, Sequence, Union -import abc -import enum + +from typing import Optional import cirq diff --git a/unitary/alpha/qudit_effects.py b/unitary/alpha/qudit_effects.py index a8c29e1c..ca139605 100644 --- a/unitary/alpha/qudit_effects.py +++ b/unitary/alpha/qudit_effects.py @@ -11,10 +11,6 @@ # 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. -# -from typing import Iterator, Optional, Sequence, Union -import abc -import enum import cirq diff --git a/unitary/quantum_chess/ascii_board.py b/unitary/quantum_chess/ascii_board.py index a7ca483f..163f6edd 100644 --- a/unitary/quantum_chess/ascii_board.py +++ b/unitary/quantum_chess/ascii_board.py @@ -13,7 +13,7 @@ # limitations under the License. import math -from typing import Optional, Sequence +from typing import Sequence import unitary.quantum_chess.bit_utils as bu import unitary.quantum_chess.constants as c diff --git a/unitary/quantum_chess/circuit_transformer.py b/unitary/quantum_chess/circuit_transformer.py index 08cb78f7..5fd58938 100644 --- a/unitary/quantum_chess/circuit_transformer.py +++ b/unitary/quantum_chess/circuit_transformer.py @@ -11,11 +11,11 @@ # 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. + import copy from typing import Dict, Iterable, List, Optional, Sequence, Set import cirq -import cirq_google as cg import unitary.quantum_chess.controlled_iswap as controlled_iswap import unitary.quantum_chess.initial_mapping_utils as imu diff --git a/unitary/quantum_chess/controlled_iswap.py b/unitary/quantum_chess/controlled_iswap.py index 3ff5e950..11b256d6 100644 --- a/unitary/quantum_chess/controlled_iswap.py +++ b/unitary/quantum_chess/controlled_iswap.py @@ -11,10 +11,10 @@ # 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. + from typing import Sequence, Union, Optional import cirq -import cirq_google as cg import numpy as np from cirq.transformers.analytical_decompositions.two_qubit_to_fsim import ( _decompose_xx_yy_into_two_fsims_ignoring_single_qubit_ops, From 016a344915867cb643dcd793d81c7b3e72ba4f70 Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Thu, 3 Oct 2024 23:34:33 -0700 Subject: [PATCH 05/14] pylint - fix wrong-import-order --- examples/fox_in_a_hole/fox_in_a_hole.py | 5 +++-- examples/quantum_chinese_chess/board.py | 5 ++++- examples/quantum_chinese_chess/board_test.py | 5 +++-- examples/quantum_chinese_chess/chess_test.py | 7 +++++-- .../final_state_preparation/final_state_world_test.py | 4 +++- examples/tic_tac_toe/tic_tac_toe_test.py | 3 ++- unitary/alpha/quantum_world.py | 3 ++- unitary/alpha/quokka_sampler.py | 4 ++-- unitary/quantum_chess/controlled_iswap_test.py | 4 +++- .../experiments/circuit_transform_benchmark.py | 11 ++++++----- unitary/quantum_chess/initial_mapping_utils_test.py | 3 ++- unitary/quantum_chess/move.py | 4 +++- unitary/quantum_chess/pauli_decomposition.py | 6 ++++-- unitary/quantum_chess/pauli_decomposition_test.py | 6 ++++-- unitary/quantum_chess/swap_updater_test.py | 2 +- 15 files changed, 47 insertions(+), 25 deletions(-) diff --git a/examples/fox_in_a_hole/fox_in_a_hole.py b/examples/fox_in_a_hole/fox_in_a_hole.py index ff92687f..517943c6 100644 --- a/examples/fox_in_a_hole/fox_in_a_hole.py +++ b/examples/fox_in_a_hole/fox_in_a_hole.py @@ -15,12 +15,13 @@ """Classical and quantum Fox-in-a-hole game.""" import abc +import argparse import sys import enum -import numpy as np -import argparse from typing import Optional +import numpy as np + from unitary.alpha import ( QuantumObject, QuantumWorld, diff --git a/examples/quantum_chinese_chess/board.py b/examples/quantum_chinese_chess/board.py index 87170f9a..2946e153 100644 --- a/examples/quantum_chinese_chess/board.py +++ b/examples/quantum_chinese_chess/board.py @@ -11,8 +11,11 @@ # 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. -import numpy as np + from typing import List, Tuple + +import numpy as np + import unitary.alpha as alpha from .enums import ( SquareState, diff --git a/examples/quantum_chinese_chess/board_test.py b/examples/quantum_chinese_chess/board_test.py index dee04ca7..f6dad82f 100644 --- a/examples/quantum_chinese_chess/board_test.py +++ b/examples/quantum_chinese_chess/board_test.py @@ -12,6 +12,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +import re + +from unitary import alpha from .enums import ( Language, Color, @@ -27,8 +30,6 @@ assert_sample_distribution, set_board, ) -from unitary import alpha -import re def test_init_with_default_fen(): diff --git a/examples/quantum_chinese_chess/chess_test.py b/examples/quantum_chinese_chess/chess_test.py index 50f08c30..c3423d57 100644 --- a/examples/quantum_chinese_chess/chess_test.py +++ b/examples/quantum_chinese_chess/chess_test.py @@ -11,16 +11,19 @@ # 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. -import pytest + import io import sys + +import pytest + +from unitary import alpha from .test_utils import ( set_board, assert_sample_distribution, locations_to_bitboard, assert_samples_in, ) -from unitary import alpha from .chess import QuantumChineseChess from .piece import Piece from .enums import ( diff --git a/examples/quantum_rpg/final_state_preparation/final_state_world_test.py b/examples/quantum_rpg/final_state_preparation/final_state_world_test.py index f24dc634..e7d8ef5c 100644 --- a/examples/quantum_rpg/final_state_preparation/final_state_world_test.py +++ b/examples/quantum_rpg/final_state_preparation/final_state_world_test.py @@ -12,9 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. """Various consistency checks to make sure the world is correctly built.""" -import pytest + import io +import pytest + from .. import classes from .. import exceptions from .. import game_state diff --git a/examples/tic_tac_toe/tic_tac_toe_test.py b/examples/tic_tac_toe/tic_tac_toe_test.py index 8da73774..b2d45bc8 100644 --- a/examples/tic_tac_toe/tic_tac_toe_test.py +++ b/examples/tic_tac_toe/tic_tac_toe_test.py @@ -12,10 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -import pytest import io from unittest.mock import MagicMock +import pytest + from . import enums from . import tic_tac_toe diff --git a/unitary/alpha/quantum_world.py b/unitary/alpha/quantum_world.py index 889a9b70..8053dfbd 100644 --- a/unitary/alpha/quantum_world.py +++ b/unitary/alpha/quantum_world.py @@ -15,12 +15,13 @@ import copy import enum from typing import cast, Dict, Iterable, List, Optional, Sequence, Set, Tuple, Union + import cirq +import numpy as np from unitary.alpha.quantum_object import QuantumObject from unitary.alpha.sparse_vector_simulator import PostSelectOperation, SparseSimulator from unitary.alpha.qudit_state_transform import qudit_to_qubit_unitary, num_bits -import numpy as np class QuantumWorld: diff --git a/unitary/alpha/quokka_sampler.py b/unitary/alpha/quokka_sampler.py index 0222e66c..fcf09fd3 100644 --- a/unitary/alpha/quokka_sampler.py +++ b/unitary/alpha/quokka_sampler.py @@ -13,12 +13,12 @@ # limitations under the License. """Simulation using a "Quokka" device.""" -from typing import Any, Callable, Dict, Optional, Sequence +import json import warnings +from typing import Any, Callable, Dict, Optional, Sequence import cirq import numpy as np -import json _REQUEST_ENDPOINT = "http://{}.quokkacomputing.com/qsim/qasm" _DEFAULT_QUOKKA_NAME = "quokka1" diff --git a/unitary/quantum_chess/controlled_iswap_test.py b/unitary/quantum_chess/controlled_iswap_test.py index 0c8c4200..56bb8414 100644 --- a/unitary/quantum_chess/controlled_iswap_test.py +++ b/unitary/quantum_chess/controlled_iswap_test.py @@ -11,10 +11,12 @@ # 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. + import cirq -import unitary.quantum_chess.controlled_iswap as controlled_iswap import numpy as np +import unitary.quantum_chess.controlled_iswap as controlled_iswap + def test_controlled_iswap(): qubits = cirq.LineQubit.range(3) diff --git a/unitary/quantum_chess/experiments/circuit_transform_benchmark.py b/unitary/quantum_chess/experiments/circuit_transform_benchmark.py index 152deaeb..875214f9 100644 --- a/unitary/quantum_chess/experiments/circuit_transform_benchmark.py +++ b/unitary/quantum_chess/experiments/circuit_transform_benchmark.py @@ -43,16 +43,17 @@ directory (https://github.com/quantumlib/ReCirq/issues/163). """ -import cirq -import cirq_google as cg import cProfile import pstats import sys +from timeit import default_timer as timer +from typing import List -import unitary.quantum_chess.circuit_transformer as ct +import cirq +import cirq_google as cg from cirq.contrib.qasm_import import circuit_from_qasm -from typing import List -from timeit import default_timer as timer + +import unitary.quantum_chess.circuit_transformer as ct def print_stats(time_sec: float, circuit: cirq.Circuit) -> None: diff --git a/unitary/quantum_chess/initial_mapping_utils_test.py b/unitary/quantum_chess/initial_mapping_utils_test.py index bee64019..6f6c8e12 100644 --- a/unitary/quantum_chess/initial_mapping_utils_test.py +++ b/unitary/quantum_chess/initial_mapping_utils_test.py @@ -11,11 +11,12 @@ # 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. -import pytest + from collections import deque import cirq import cirq_google as cg +import pytest import unitary.quantum_chess.initial_mapping_utils as imu diff --git a/unitary/quantum_chess/move.py b/unitary/quantum_chess/move.py index d140a495..9fa5af23 100644 --- a/unitary/quantum_chess/move.py +++ b/unitary/quantum_chess/move.py @@ -11,9 +11,11 @@ # 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. + +from typing import Optional + from unitary.quantum_chess import constants import unitary.quantum_chess.enums as enums -from typing import Optional _ORD_A = ord("a") diff --git a/unitary/quantum_chess/pauli_decomposition.py b/unitary/quantum_chess/pauli_decomposition.py index 90a49193..61774e43 100644 --- a/unitary/quantum_chess/pauli_decomposition.py +++ b/unitary/quantum_chess/pauli_decomposition.py @@ -14,12 +14,14 @@ """ Utility functions used for decomposing the given measurement matrix into a PauliSum. """ -import cirq + import itertools import functools +from typing import List + +import cirq import numpy as np from scipy.linalg import kron -from typing import List def kron_product(matrices: np.ndarray) -> np.ndarray: diff --git a/unitary/quantum_chess/pauli_decomposition_test.py b/unitary/quantum_chess/pauli_decomposition_test.py index 2ad03086..156dafe1 100644 --- a/unitary/quantum_chess/pauli_decomposition_test.py +++ b/unitary/quantum_chess/pauli_decomposition_test.py @@ -11,10 +11,12 @@ # 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. -import pytest + +import re + import cirq import numpy as np -import re +import pytest from unitary.quantum_chess.pauli_decomposition import pauli_decomposition diff --git a/unitary/quantum_chess/swap_updater_test.py b/unitary/quantum_chess/swap_updater_test.py index 658860d9..0e062406 100644 --- a/unitary/quantum_chess/swap_updater_test.py +++ b/unitary/quantum_chess/swap_updater_test.py @@ -15,10 +15,10 @@ import pytest import cirq import cirq_google as cg +import numpy as np from unitary.quantum_chess.swap_updater import SwapUpdater, generate_decomposed_swap import unitary.quantum_chess.quantum_moves as qm -import numpy as np # Logical qubits q0 - q5. q = list(cirq.NamedQubit(f"q{i}") for i in range(6)) From a158b613138e7a30f46056c7d2b97e1a23bb3a17 Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Fri, 4 Oct 2024 00:01:10 -0700 Subject: [PATCH 06/14] pylint - fix wrong-or-nonexistent-copyright-notice --- dev_tools/check_notebooks.py | 2 +- dev_tools/write-ci-requirements.py | 2 +- examples/quantum_chinese_chess/__init__.py | 2 +- examples/quantum_chinese_chess/enums.py | 3 ++- examples/quantum_chinese_chess/enums_test.py | 3 ++- examples/quantum_chinese_chess/piece_test.py | 2 +- examples/quantum_chinese_chess/test_utils.py | 2 +- examples/quantum_rpg/__init__.py | 2 +- examples/quantum_rpg/ascii_art.py | 14 ++++++++++++++ examples/quantum_rpg/battle.py | 3 ++- examples/quantum_rpg/battle_test.py | 2 +- examples/quantum_rpg/bb84.py | 2 +- examples/quantum_rpg/bb84_test.py | 3 ++- examples/quantum_rpg/classes.py | 2 +- examples/quantum_rpg/classes_test.py | 2 +- examples/quantum_rpg/encounter.py | 2 +- examples/quantum_rpg/encounter_test.py | 2 +- examples/quantum_rpg/enums.py | 2 +- examples/quantum_rpg/exceptions.py | 3 ++- .../final_state_preparation/__init__.py | 2 +- .../final_state_preparation/classical_frontier.py | 2 +- .../final_state_preparation/final_state_world.py | 3 ++- .../final_state_world_test.py | 3 ++- .../final_state_preparation/hadamard_hills.py | 3 ++- .../final_state_preparation/monsters.py | 3 ++- .../final_state_preparation/oxtail_university.py | 3 ++- .../final_state_preparation/quantum_perimeter.py | 14 ++++++++++++++ examples/quantum_rpg/game_state.py | 2 +- examples/quantum_rpg/game_state_test.py | 2 +- examples/quantum_rpg/input_helpers.py | 14 ++++++++++++++ examples/quantum_rpg/input_helpers_test.py | 14 ++++++++++++++ examples/quantum_rpg/item.py | 14 ++++++++++++++ examples/quantum_rpg/item_test.py | 14 ++++++++++++++ examples/quantum_rpg/main_loop.py | 2 +- examples/quantum_rpg/main_loop_test.py | 2 +- examples/quantum_rpg/npcs.py | 2 +- examples/quantum_rpg/npcs_test.py | 2 +- examples/quantum_rpg/qaracter.py | 2 +- examples/quantum_rpg/qaracter_test.py | 2 +- examples/quantum_rpg/world.py | 2 +- examples/quantum_rpg/world_test.py | 2 +- examples/quantum_rpg/xp_utils.py | 2 +- examples/quantum_rpg/xp_utils_test.py | 2 +- examples/tic_tac_toe/enums.py | 2 +- examples/tic_tac_toe/tic_tac_split_test.py | 2 +- setup.py | 2 +- unitary/__init__.py | 2 +- unitary/_version.py | 2 +- unitary/alpha/__init__.py | 1 - unitary/alpha/quantum_effect.py | 2 +- unitary/alpha/quantum_effect_test.py | 2 +- unitary/alpha/quantum_object_test.py | 2 +- unitary/alpha/quantum_world_test.py | 2 +- unitary/alpha/qubit_effects_test.py | 1 - unitary/alpha/qudit_effects_test.py | 2 +- unitary/alpha/qudit_gates.py | 2 -- unitary/alpha/qudit_gates_test.py | 2 +- unitary/alpha/qudit_state_transform.py | 2 +- unitary/alpha/qudit_state_transform_test.py | 2 +- unitary/alpha/quokka_sampler.py | 3 ++- unitary/alpha/quokka_sampler_test.py | 2 +- unitary/alpha/sparse_vector_simulator.py | 2 +- unitary/alpha/sparse_vector_simulator_test.py | 2 +- unitary/engine_utils.py | 2 +- unitary/engine_utils_test.py | 2 +- unitary/quantum_chess/__init__.py | 2 +- unitary/quantum_chess/ascii_board.py | 2 +- unitary/quantum_chess/ascii_board_test.py | 2 +- unitary/quantum_chess/bit_utils.py | 3 ++- unitary/quantum_chess/bit_utils_test.py | 3 ++- unitary/quantum_chess/caching_utils.py | 2 +- unitary/quantum_chess/circuit_transformer.py | 2 +- unitary/quantum_chess/circuit_transformer_test.py | 3 ++- unitary/quantum_chess/constants.py | 3 ++- unitary/quantum_chess/controlled_iswap.py | 2 +- unitary/quantum_chess/controlled_iswap_test.py | 2 +- unitary/quantum_chess/enums.py | 3 ++- unitary/quantum_chess/experiments/__init__.py | 2 +- unitary/quantum_chess/experiments/batch_moves.py | 2 +- .../experiments/circuit_transform_benchmark.py | 2 +- .../quantum_chess/experiments/interactive_board.py | 2 +- unitary/quantum_chess/initial_mapping_utils.py | 3 ++- .../quantum_chess/initial_mapping_utils_test.py | 2 +- unitary/quantum_chess/mcpe_utils.py | 3 ++- unitary/quantum_chess/mcpe_utils_test.py | 2 +- unitary/quantum_chess/move.py | 2 +- unitary/quantum_chess/move_test.py | 3 ++- unitary/quantum_chess/pauli_decomposition.py | 3 ++- unitary/quantum_chess/pauli_decomposition_test.py | 2 +- unitary/quantum_chess/puzzles_test.py | 3 ++- unitary/quantum_chess/quantum_board.py | 3 ++- unitary/quantum_chess/quantum_board_test.py | 3 ++- unitary/quantum_chess/quantum_moves.py | 3 ++- unitary/quantum_chess/quantum_moves_test.py | 3 ++- unitary/quantum_chess/readout_tester.py | 4 ++-- unitary/quantum_chess/readout_tester_test.py | 5 ++--- unitary/quantum_chess/swap_updater.py | 3 ++- unitary/quantum_chess/swap_updater_test.py | 2 +- unitary/quantum_chess/test_utils.py | 3 ++- 99 files changed, 203 insertions(+), 97 deletions(-) diff --git a/dev_tools/check_notebooks.py b/dev_tools/check_notebooks.py index 835ac4a2..8d233069 100644 --- a/dev_tools/check_notebooks.py +++ b/dev_tools/check_notebooks.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/dev_tools/write-ci-requirements.py b/dev_tools/write-ci-requirements.py index bedd1ca4..c9754e95 100644 --- a/dev_tools/write-ci-requirements.py +++ b/dev_tools/write-ci-requirements.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/examples/quantum_chinese_chess/__init__.py b/examples/quantum_chinese_chess/__init__.py index 4d904923..4cce2e5f 100644 --- a/examples/quantum_chinese_chess/__init__.py +++ b/examples/quantum_chinese_chess/__init__.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/examples/quantum_chinese_chess/enums.py b/examples/quantum_chinese_chess/enums.py index 1f01c4a5..43afd53b 100644 --- a/examples/quantum_chinese_chess/enums.py +++ b/examples/quantum_chinese_chess/enums.py @@ -4,13 +4,14 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # 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. + import enum from typing import Optional diff --git a/examples/quantum_chinese_chess/enums_test.py b/examples/quantum_chinese_chess/enums_test.py index 2dd047d4..827cb28b 100644 --- a/examples/quantum_chinese_chess/enums_test.py +++ b/examples/quantum_chinese_chess/enums_test.py @@ -4,13 +4,14 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # 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. + from .enums import Type, Color, Language diff --git a/examples/quantum_chinese_chess/piece_test.py b/examples/quantum_chinese_chess/piece_test.py index e5a94139..90caf3dc 100644 --- a/examples/quantum_chinese_chess/piece_test.py +++ b/examples/quantum_chinese_chess/piece_test.py @@ -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. -# + from unitary.alpha import QuantumWorld from .enums import ( diff --git a/examples/quantum_chinese_chess/test_utils.py b/examples/quantum_chinese_chess/test_utils.py index e495d890..413dfe2c 100644 --- a/examples/quantum_chinese_chess/test_utils.py +++ b/examples/quantum_chinese_chess/test_utils.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/examples/quantum_rpg/__init__.py b/examples/quantum_rpg/__init__.py index c6935cb0..7590488a 100644 --- a/examples/quantum_rpg/__init__.py +++ b/examples/quantum_rpg/__init__.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/examples/quantum_rpg/ascii_art.py b/examples/quantum_rpg/ascii_art.py index 08eef985..cf052958 100644 --- a/examples/quantum_rpg/ascii_art.py +++ b/examples/quantum_rpg/ascii_art.py @@ -1,3 +1,17 @@ +# Copyright 2023 The Unitary Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. + """ASCII art and other large text constants.""" # ASCII art generated with font diff --git a/examples/quantum_rpg/battle.py b/examples/quantum_rpg/battle.py index 8dbcdd63..4dd6b8e3 100644 --- a/examples/quantum_rpg/battle.py +++ b/examples/quantum_rpg/battle.py @@ -4,13 +4,14 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # 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. + import enum from typing import List, Optional, Set diff --git a/examples/quantum_rpg/battle_test.py b/examples/quantum_rpg/battle_test.py index 59be39fa..315ec529 100644 --- a/examples/quantum_rpg/battle_test.py +++ b/examples/quantum_rpg/battle_test.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/examples/quantum_rpg/bb84.py b/examples/quantum_rpg/bb84.py index 89398c17..31891bab 100644 --- a/examples/quantum_rpg/bb84.py +++ b/examples/quantum_rpg/bb84.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/examples/quantum_rpg/bb84_test.py b/examples/quantum_rpg/bb84_test.py index e9eee03d..fb4b62e0 100644 --- a/examples/quantum_rpg/bb84_test.py +++ b/examples/quantum_rpg/bb84_test.py @@ -4,13 +4,14 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # 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. + from typing import cast import io diff --git a/examples/quantum_rpg/classes.py b/examples/quantum_rpg/classes.py index 10015536..d10e8b60 100644 --- a/examples/quantum_rpg/classes.py +++ b/examples/quantum_rpg/classes.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/examples/quantum_rpg/classes_test.py b/examples/quantum_rpg/classes_test.py index 0a461efb..834d1a96 100644 --- a/examples/quantum_rpg/classes_test.py +++ b/examples/quantum_rpg/classes_test.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/examples/quantum_rpg/encounter.py b/examples/quantum_rpg/encounter.py index b4285be3..cda6fdbc 100644 --- a/examples/quantum_rpg/encounter.py +++ b/examples/quantum_rpg/encounter.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/examples/quantum_rpg/encounter_test.py b/examples/quantum_rpg/encounter_test.py index 13a83644..786319d7 100644 --- a/examples/quantum_rpg/encounter_test.py +++ b/examples/quantum_rpg/encounter_test.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/examples/quantum_rpg/enums.py b/examples/quantum_rpg/enums.py index 6f4a86bf..2c859d45 100644 --- a/examples/quantum_rpg/enums.py +++ b/examples/quantum_rpg/enums.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/examples/quantum_rpg/exceptions.py b/examples/quantum_rpg/exceptions.py index 1359ac16..002ea1d5 100644 --- a/examples/quantum_rpg/exceptions.py +++ b/examples/quantum_rpg/exceptions.py @@ -4,13 +4,14 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # 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. + """Exceptions used in Quantum RPG.""" diff --git a/examples/quantum_rpg/final_state_preparation/__init__.py b/examples/quantum_rpg/final_state_preparation/__init__.py index 501ce45c..2f493751 100644 --- a/examples/quantum_rpg/final_state_preparation/__init__.py +++ b/examples/quantum_rpg/final_state_preparation/__init__.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/examples/quantum_rpg/final_state_preparation/classical_frontier.py b/examples/quantum_rpg/final_state_preparation/classical_frontier.py index 9a903d64..59922cd1 100644 --- a/examples/quantum_rpg/final_state_preparation/classical_frontier.py +++ b/examples/quantum_rpg/final_state_preparation/classical_frontier.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/examples/quantum_rpg/final_state_preparation/final_state_world.py b/examples/quantum_rpg/final_state_preparation/final_state_world.py index 2c9e65f5..00cb6e42 100644 --- a/examples/quantum_rpg/final_state_preparation/final_state_world.py +++ b/examples/quantum_rpg/final_state_preparation/final_state_world.py @@ -4,13 +4,14 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # 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. + """Module to combine all the zones of the RPG world into one list.""" from . import classical_frontier diff --git a/examples/quantum_rpg/final_state_preparation/final_state_world_test.py b/examples/quantum_rpg/final_state_preparation/final_state_world_test.py index e7d8ef5c..e1d72eb9 100644 --- a/examples/quantum_rpg/final_state_preparation/final_state_world_test.py +++ b/examples/quantum_rpg/final_state_preparation/final_state_world_test.py @@ -4,13 +4,14 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # 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. + """Various consistency checks to make sure the world is correctly built.""" import io diff --git a/examples/quantum_rpg/final_state_preparation/hadamard_hills.py b/examples/quantum_rpg/final_state_preparation/hadamard_hills.py index 2f3dcf5d..7b927c78 100644 --- a/examples/quantum_rpg/final_state_preparation/hadamard_hills.py +++ b/examples/quantum_rpg/final_state_preparation/hadamard_hills.py @@ -4,13 +4,14 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # 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. + import unitary.alpha as alpha from ..bb84 import ALICE, BOB, DOOR diff --git a/examples/quantum_rpg/final_state_preparation/monsters.py b/examples/quantum_rpg/final_state_preparation/monsters.py index 3a30ad4d..ac34898f 100644 --- a/examples/quantum_rpg/final_state_preparation/monsters.py +++ b/examples/quantum_rpg/final_state_preparation/monsters.py @@ -4,13 +4,14 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # 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. + import unitary.alpha as alpha from ..encounter import Encounter diff --git a/examples/quantum_rpg/final_state_preparation/oxtail_university.py b/examples/quantum_rpg/final_state_preparation/oxtail_university.py index dab84240..b5d7c386 100644 --- a/examples/quantum_rpg/final_state_preparation/oxtail_university.py +++ b/examples/quantum_rpg/final_state_preparation/oxtail_university.py @@ -4,13 +4,14 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # 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. + import unitary.alpha as alpha from ..classes import Engineer diff --git a/examples/quantum_rpg/final_state_preparation/quantum_perimeter.py b/examples/quantum_rpg/final_state_preparation/quantum_perimeter.py index f62e1605..c22856c8 100644 --- a/examples/quantum_rpg/final_state_preparation/quantum_perimeter.py +++ b/examples/quantum_rpg/final_state_preparation/quantum_perimeter.py @@ -1,3 +1,17 @@ +# Copyright 2023 The Unitary Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. + from ..item import EXAMINE, Item from ..world import Direction, Location diff --git a/examples/quantum_rpg/game_state.py b/examples/quantum_rpg/game_state.py index 4e1f0988..9c31011b 100644 --- a/examples/quantum_rpg/game_state.py +++ b/examples/quantum_rpg/game_state.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/examples/quantum_rpg/game_state_test.py b/examples/quantum_rpg/game_state_test.py index b744e161..276caa41 100644 --- a/examples/quantum_rpg/game_state_test.py +++ b/examples/quantum_rpg/game_state_test.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/examples/quantum_rpg/input_helpers.py b/examples/quantum_rpg/input_helpers.py index 6f3f5829..61a0df8b 100644 --- a/examples/quantum_rpg/input_helpers.py +++ b/examples/quantum_rpg/input_helpers.py @@ -1,3 +1,17 @@ +# Copyright 2023 The Unitary Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. + """Functions for safe and user-friendly input.""" from typing import Callable, Optional, Sequence, TextIO, Union diff --git a/examples/quantum_rpg/input_helpers_test.py b/examples/quantum_rpg/input_helpers_test.py index 549f62e8..3b5d63a6 100644 --- a/examples/quantum_rpg/input_helpers_test.py +++ b/examples/quantum_rpg/input_helpers_test.py @@ -1,3 +1,17 @@ +# Copyright 2023 The Unitary Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. + import io import pytest diff --git a/examples/quantum_rpg/item.py b/examples/quantum_rpg/item.py index 860a5319..254c0683 100644 --- a/examples/quantum_rpg/item.py +++ b/examples/quantum_rpg/item.py @@ -1,3 +1,17 @@ +# Copyright 2023 The Unitary Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. + import re from typing import Any, Callable, Optional, Sequence, Tuple, Union diff --git a/examples/quantum_rpg/item_test.py b/examples/quantum_rpg/item_test.py index 72960176..62a39708 100644 --- a/examples/quantum_rpg/item_test.py +++ b/examples/quantum_rpg/item_test.py @@ -1,3 +1,17 @@ +# Copyright 2023 The Unitary Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. + import re from . import item diff --git a/examples/quantum_rpg/main_loop.py b/examples/quantum_rpg/main_loop.py index affd8128..63b87aef 100644 --- a/examples/quantum_rpg/main_loop.py +++ b/examples/quantum_rpg/main_loop.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/examples/quantum_rpg/main_loop_test.py b/examples/quantum_rpg/main_loop_test.py index 3367bd75..493b5c06 100644 --- a/examples/quantum_rpg/main_loop_test.py +++ b/examples/quantum_rpg/main_loop_test.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/examples/quantum_rpg/npcs.py b/examples/quantum_rpg/npcs.py index d1f3bb82..c339dc78 100644 --- a/examples/quantum_rpg/npcs.py +++ b/examples/quantum_rpg/npcs.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/examples/quantum_rpg/npcs_test.py b/examples/quantum_rpg/npcs_test.py index bc2ddc41..9e8388d7 100644 --- a/examples/quantum_rpg/npcs_test.py +++ b/examples/quantum_rpg/npcs_test.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/examples/quantum_rpg/qaracter.py b/examples/quantum_rpg/qaracter.py index cb9513d2..bed2a5c0 100644 --- a/examples/quantum_rpg/qaracter.py +++ b/examples/quantum_rpg/qaracter.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/examples/quantum_rpg/qaracter_test.py b/examples/quantum_rpg/qaracter_test.py index 5e9c0737..0561c0eb 100644 --- a/examples/quantum_rpg/qaracter_test.py +++ b/examples/quantum_rpg/qaracter_test.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/examples/quantum_rpg/world.py b/examples/quantum_rpg/world.py index 47d9d0a4..efa8b9d2 100644 --- a/examples/quantum_rpg/world.py +++ b/examples/quantum_rpg/world.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/examples/quantum_rpg/world_test.py b/examples/quantum_rpg/world_test.py index e09ae9a9..78b7cdb4 100644 --- a/examples/quantum_rpg/world_test.py +++ b/examples/quantum_rpg/world_test.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/examples/quantum_rpg/xp_utils.py b/examples/quantum_rpg/xp_utils.py index f60da96b..bfa78a16 100644 --- a/examples/quantum_rpg/xp_utils.py +++ b/examples/quantum_rpg/xp_utils.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/examples/quantum_rpg/xp_utils_test.py b/examples/quantum_rpg/xp_utils_test.py index 79672d43..143cb2f8 100644 --- a/examples/quantum_rpg/xp_utils_test.py +++ b/examples/quantum_rpg/xp_utils_test.py @@ -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. -# + import io import cirq diff --git a/examples/tic_tac_toe/enums.py b/examples/tic_tac_toe/enums.py index 43c1a863..89d13006 100644 --- a/examples/tic_tac_toe/enums.py +++ b/examples/tic_tac_toe/enums.py @@ -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. -# + from typing import Union import enum diff --git a/examples/tic_tac_toe/tic_tac_split_test.py b/examples/tic_tac_toe/tic_tac_split_test.py index 6a6c2640..498f6d1e 100644 --- a/examples/tic_tac_toe/tic_tac_split_test.py +++ b/examples/tic_tac_toe/tic_tac_split_test.py @@ -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. -# + import pytest import cirq diff --git a/setup.py b/setup.py index 605b2157..dfd6dfb3 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -# Copyright 2020 Google +# Copyright 2020 The Unitary Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/unitary/__init__.py b/unitary/__init__.py index a6ce2123..36c9d6d5 100644 --- a/unitary/__init__.py +++ b/unitary/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2020 Google +# Copyright 2020 The Unitary Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/unitary/_version.py b/unitary/_version.py index 94f4928f..46049a69 100644 --- a/unitary/_version.py +++ b/unitary/_version.py @@ -1,4 +1,4 @@ -# Copyright 2020 Google +# Copyright 2020 The Unitary Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/unitary/alpha/__init__.py b/unitary/alpha/__init__.py index 472a0c71..92513493 100644 --- a/unitary/alpha/__init__.py +++ b/unitary/alpha/__init__.py @@ -11,7 +11,6 @@ # 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. -# from unitary.alpha.qudit_state_transform import ( qubit_to_qudit_state, diff --git a/unitary/alpha/quantum_effect.py b/unitary/alpha/quantum_effect.py index 3259080c..374ca8e2 100644 --- a/unitary/alpha/quantum_effect.py +++ b/unitary/alpha/quantum_effect.py @@ -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. -# + from typing import Iterator, Optional, Sequence, Union, TYPE_CHECKING import abc import enum diff --git a/unitary/alpha/quantum_effect_test.py b/unitary/alpha/quantum_effect_test.py index 04044e57..e3b21e5f 100644 --- a/unitary/alpha/quantum_effect_test.py +++ b/unitary/alpha/quantum_effect_test.py @@ -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. -# + import pytest import cirq diff --git a/unitary/alpha/quantum_object_test.py b/unitary/alpha/quantum_object_test.py index 2b06c859..55525275 100644 --- a/unitary/alpha/quantum_object_test.py +++ b/unitary/alpha/quantum_object_test.py @@ -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. -# + import enum import pytest diff --git a/unitary/alpha/quantum_world_test.py b/unitary/alpha/quantum_world_test.py index f8880c9d..fc40d128 100644 --- a/unitary/alpha/quantum_world_test.py +++ b/unitary/alpha/quantum_world_test.py @@ -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. -# + import enum import pytest diff --git a/unitary/alpha/qubit_effects_test.py b/unitary/alpha/qubit_effects_test.py index 90d627e1..19572c05 100644 --- a/unitary/alpha/qubit_effects_test.py +++ b/unitary/alpha/qubit_effects_test.py @@ -11,7 +11,6 @@ # 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. -# import enum import pytest diff --git a/unitary/alpha/qudit_effects_test.py b/unitary/alpha/qudit_effects_test.py index c2c3d8a2..2033153c 100644 --- a/unitary/alpha/qudit_effects_test.py +++ b/unitary/alpha/qudit_effects_test.py @@ -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. -# + import enum import pytest diff --git a/unitary/alpha/qudit_gates.py b/unitary/alpha/qudit_gates.py index 7cb581ee..1c26711a 100644 --- a/unitary/alpha/qudit_gates.py +++ b/unitary/alpha/qudit_gates.py @@ -11,8 +11,6 @@ # 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. -# - from typing import List, Dict, Optional, Tuple diff --git a/unitary/alpha/qudit_gates_test.py b/unitary/alpha/qudit_gates_test.py index 50ae6d09..843b376b 100644 --- a/unitary/alpha/qudit_gates_test.py +++ b/unitary/alpha/qudit_gates_test.py @@ -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. -# + import pytest import numpy as np import cirq diff --git a/unitary/alpha/qudit_state_transform.py b/unitary/alpha/qudit_state_transform.py index 7bafdf8a..abccc4d9 100644 --- a/unitary/alpha/qudit_state_transform.py +++ b/unitary/alpha/qudit_state_transform.py @@ -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. -# + import itertools import numpy as np diff --git a/unitary/alpha/qudit_state_transform_test.py b/unitary/alpha/qudit_state_transform_test.py index bfe57602..5afcbb0b 100644 --- a/unitary/alpha/qudit_state_transform_test.py +++ b/unitary/alpha/qudit_state_transform_test.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/unitary/alpha/quokka_sampler.py b/unitary/alpha/quokka_sampler.py index fcf09fd3..c5c9cfc2 100644 --- a/unitary/alpha/quokka_sampler.py +++ b/unitary/alpha/quokka_sampler.py @@ -4,13 +4,14 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # 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. + """Simulation using a "Quokka" device.""" import json diff --git a/unitary/alpha/quokka_sampler_test.py b/unitary/alpha/quokka_sampler_test.py index f4f81763..ebc7ad92 100644 --- a/unitary/alpha/quokka_sampler_test.py +++ b/unitary/alpha/quokka_sampler_test.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/unitary/alpha/sparse_vector_simulator.py b/unitary/alpha/sparse_vector_simulator.py index 9a0d9d66..2f495d34 100644 --- a/unitary/alpha/sparse_vector_simulator.py +++ b/unitary/alpha/sparse_vector_simulator.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/unitary/alpha/sparse_vector_simulator_test.py b/unitary/alpha/sparse_vector_simulator_test.py index 391f2114..2104905e 100644 --- a/unitary/alpha/sparse_vector_simulator_test.py +++ b/unitary/alpha/sparse_vector_simulator_test.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/unitary/engine_utils.py b/unitary/engine_utils.py index 5b78ee07..290a2df6 100644 --- a/unitary/engine_utils.py +++ b/unitary/engine_utils.py @@ -1,4 +1,4 @@ -# Copyright 2020 Google +# Copyright 2020 The Unitary Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/unitary/engine_utils_test.py b/unitary/engine_utils_test.py index 4af3083f..67c12838 100644 --- a/unitary/engine_utils_test.py +++ b/unitary/engine_utils_test.py @@ -1,4 +1,4 @@ -# Copyright 2020 Google +# Copyright 2020 The Unitary Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/unitary/quantum_chess/__init__.py b/unitary/quantum_chess/__init__.py index d0feedfc..35cd321d 100644 --- a/unitary/quantum_chess/__init__.py +++ b/unitary/quantum_chess/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2020 Google +# Copyright 2020 The Unitary Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/unitary/quantum_chess/ascii_board.py b/unitary/quantum_chess/ascii_board.py index 163f6edd..674a0f02 100644 --- a/unitary/quantum_chess/ascii_board.py +++ b/unitary/quantum_chess/ascii_board.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/unitary/quantum_chess/ascii_board_test.py b/unitary/quantum_chess/ascii_board_test.py index 46436ba9..7c43ad0b 100644 --- a/unitary/quantum_chess/ascii_board_test.py +++ b/unitary/quantum_chess/ascii_board_test.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/unitary/quantum_chess/bit_utils.py b/unitary/quantum_chess/bit_utils.py index 7eb5731c..3d064be3 100644 --- a/unitary/quantum_chess/bit_utils.py +++ b/unitary/quantum_chess/bit_utils.py @@ -1,4 +1,4 @@ -# Copyright 2020 Google +# Copyright 2020 The Unitary Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +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. + """ Utilities for converting to and from bit boards. """ diff --git a/unitary/quantum_chess/bit_utils_test.py b/unitary/quantum_chess/bit_utils_test.py index 317d6fbe..cc556fb1 100644 --- a/unitary/quantum_chess/bit_utils_test.py +++ b/unitary/quantum_chess/bit_utils_test.py @@ -1,4 +1,4 @@ -# Copyright 2020 Google +# Copyright 2020 The Unitary Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +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. + import cirq import unitary.quantum_chess.bit_utils as u diff --git a/unitary/quantum_chess/caching_utils.py b/unitary/quantum_chess/caching_utils.py index ea71ec0c..bf9237d4 100644 --- a/unitary/quantum_chess/caching_utils.py +++ b/unitary/quantum_chess/caching_utils.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/unitary/quantum_chess/circuit_transformer.py b/unitary/quantum_chess/circuit_transformer.py index 5fd58938..8dcfa412 100644 --- a/unitary/quantum_chess/circuit_transformer.py +++ b/unitary/quantum_chess/circuit_transformer.py @@ -1,4 +1,4 @@ -# Copyright 2020 Google +# Copyright 2020 The Unitary Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/unitary/quantum_chess/circuit_transformer_test.py b/unitary/quantum_chess/circuit_transformer_test.py index ef79e093..afd65f92 100644 --- a/unitary/quantum_chess/circuit_transformer_test.py +++ b/unitary/quantum_chess/circuit_transformer_test.py @@ -1,4 +1,4 @@ -# Copyright 2020 Google +# Copyright 2020 The Unitary Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +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. + import pytest import cirq import cirq_google as cg diff --git a/unitary/quantum_chess/constants.py b/unitary/quantum_chess/constants.py index 0ac864dd..ab0f7e02 100644 --- a/unitary/quantum_chess/constants.py +++ b/unitary/quantum_chess/constants.py @@ -1,4 +1,4 @@ -# Copyright 2020 Google +# Copyright 2020 The Unitary Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +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. + import cirq PIECES = { diff --git a/unitary/quantum_chess/controlled_iswap.py b/unitary/quantum_chess/controlled_iswap.py index 11b256d6..a31f13c1 100644 --- a/unitary/quantum_chess/controlled_iswap.py +++ b/unitary/quantum_chess/controlled_iswap.py @@ -1,4 +1,4 @@ -# Copyright 2020 Google +# Copyright 2020 The Unitary Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/unitary/quantum_chess/controlled_iswap_test.py b/unitary/quantum_chess/controlled_iswap_test.py index 56bb8414..aa015d20 100644 --- a/unitary/quantum_chess/controlled_iswap_test.py +++ b/unitary/quantum_chess/controlled_iswap_test.py @@ -1,4 +1,4 @@ -# Copyright 2020 Google +# Copyright 2020 The Unitary Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/unitary/quantum_chess/enums.py b/unitary/quantum_chess/enums.py index 80204e0d..7ec756b6 100644 --- a/unitary/quantum_chess/enums.py +++ b/unitary/quantum_chess/enums.py @@ -1,4 +1,4 @@ -# Copyright 2020 Google +# Copyright 2020 The Unitary Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +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. + import enum diff --git a/unitary/quantum_chess/experiments/__init__.py b/unitary/quantum_chess/experiments/__init__.py index d0feedfc..35cd321d 100644 --- a/unitary/quantum_chess/experiments/__init__.py +++ b/unitary/quantum_chess/experiments/__init__.py @@ -1,4 +1,4 @@ -# Copyright 2020 Google +# Copyright 2020 The Unitary Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/unitary/quantum_chess/experiments/batch_moves.py b/unitary/quantum_chess/experiments/batch_moves.py index 1d8cca63..dd5fd758 100644 --- a/unitary/quantum_chess/experiments/batch_moves.py +++ b/unitary/quantum_chess/experiments/batch_moves.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/unitary/quantum_chess/experiments/circuit_transform_benchmark.py b/unitary/quantum_chess/experiments/circuit_transform_benchmark.py index 875214f9..a507c4d6 100644 --- a/unitary/quantum_chess/experiments/circuit_transform_benchmark.py +++ b/unitary/quantum_chess/experiments/circuit_transform_benchmark.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/unitary/quantum_chess/experiments/interactive_board.py b/unitary/quantum_chess/experiments/interactive_board.py index a3d501cf..1511bd53 100644 --- a/unitary/quantum_chess/experiments/interactive_board.py +++ b/unitary/quantum_chess/experiments/interactive_board.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/unitary/quantum_chess/initial_mapping_utils.py b/unitary/quantum_chess/initial_mapping_utils.py index 138f6927..28c92dcc 100644 --- a/unitary/quantum_chess/initial_mapping_utils.py +++ b/unitary/quantum_chess/initial_mapping_utils.py @@ -1,4 +1,4 @@ -# Copyright 2021 Google +# Copyright 2021 The Unitary Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +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. + import math from collections import defaultdict, deque from typing import Deque, Dict, List, Optional, Tuple, Union, ValuesView diff --git a/unitary/quantum_chess/initial_mapping_utils_test.py b/unitary/quantum_chess/initial_mapping_utils_test.py index 6f6c8e12..27184ba2 100644 --- a/unitary/quantum_chess/initial_mapping_utils_test.py +++ b/unitary/quantum_chess/initial_mapping_utils_test.py @@ -1,4 +1,4 @@ -# Copyright 2020 Google +# Copyright 2020 The Unitary Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/unitary/quantum_chess/mcpe_utils.py b/unitary/quantum_chess/mcpe_utils.py index 31fa9318..c2d3f848 100644 --- a/unitary/quantum_chess/mcpe_utils.py +++ b/unitary/quantum_chess/mcpe_utils.py @@ -1,4 +1,4 @@ -# Copyright 2021 Google +# Copyright 2021 The Unitary Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +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. + """Utilities related to the maximum consecutive positive effect (mcpe) heuristic cost function. diff --git a/unitary/quantum_chess/mcpe_utils_test.py b/unitary/quantum_chess/mcpe_utils_test.py index 35c353c3..7da12cbe 100644 --- a/unitary/quantum_chess/mcpe_utils_test.py +++ b/unitary/quantum_chess/mcpe_utils_test.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/unitary/quantum_chess/move.py b/unitary/quantum_chess/move.py index 9fa5af23..a57af33c 100644 --- a/unitary/quantum_chess/move.py +++ b/unitary/quantum_chess/move.py @@ -1,4 +1,4 @@ -# Copyright 2020 Google +# Copyright 2020 The Unitary Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/unitary/quantum_chess/move_test.py b/unitary/quantum_chess/move_test.py index 33c9a456..33f74616 100644 --- a/unitary/quantum_chess/move_test.py +++ b/unitary/quantum_chess/move_test.py @@ -1,4 +1,4 @@ -# Copyright 2020 Google +# Copyright 2020 The Unitary Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +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. + from unitary.quantum_chess import constants from unitary.quantum_chess.move import Move import unitary.quantum_chess.enums as enums diff --git a/unitary/quantum_chess/pauli_decomposition.py b/unitary/quantum_chess/pauli_decomposition.py index 61774e43..e48573af 100644 --- a/unitary/quantum_chess/pauli_decomposition.py +++ b/unitary/quantum_chess/pauli_decomposition.py @@ -1,4 +1,4 @@ -# Copyright 2021 Google +# Copyright 2021 The Unitary Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +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. + """ Utility functions used for decomposing the given measurement matrix into a PauliSum. """ diff --git a/unitary/quantum_chess/pauli_decomposition_test.py b/unitary/quantum_chess/pauli_decomposition_test.py index 156dafe1..a388f88c 100644 --- a/unitary/quantum_chess/pauli_decomposition_test.py +++ b/unitary/quantum_chess/pauli_decomposition_test.py @@ -1,4 +1,4 @@ -# Copyright 2020 Google +# Copyright 2020 The Unitary Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/unitary/quantum_chess/puzzles_test.py b/unitary/quantum_chess/puzzles_test.py index 6c3eb1ff..c72afe5d 100644 --- a/unitary/quantum_chess/puzzles_test.py +++ b/unitary/quantum_chess/puzzles_test.py @@ -1,4 +1,4 @@ -# Copyright 2020 Google +# Copyright 2020 The Unitary Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +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. + import pytest import unitary.quantum_chess.bit_utils as u diff --git a/unitary/quantum_chess/quantum_board.py b/unitary/quantum_chess/quantum_board.py index 4039e4c0..77f9ae57 100644 --- a/unitary/quantum_chess/quantum_board.py +++ b/unitary/quantum_chess/quantum_board.py @@ -1,4 +1,4 @@ -# Copyright 2020 Google +# Copyright 2020 The Unitary Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +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. + import time from collections import defaultdict from typing import Dict, List, Optional, Sequence, Set, Tuple diff --git a/unitary/quantum_chess/quantum_board_test.py b/unitary/quantum_chess/quantum_board_test.py index 71ad799b..e5e0eb3c 100644 --- a/unitary/quantum_chess/quantum_board_test.py +++ b/unitary/quantum_chess/quantum_board_test.py @@ -1,4 +1,4 @@ -# Copyright 2020 Google +# Copyright 2020 The Unitary Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +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. + import os import random diff --git a/unitary/quantum_chess/quantum_moves.py b/unitary/quantum_chess/quantum_moves.py index 265f300f..8b8b78f4 100644 --- a/unitary/quantum_chess/quantum_moves.py +++ b/unitary/quantum_chess/quantum_moves.py @@ -1,4 +1,4 @@ -# Copyright 2020 Google +# Copyright 2020 The Unitary Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +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. + """Quantum Circuits for common quantum chess moves.""" from typing import Sequence diff --git a/unitary/quantum_chess/quantum_moves_test.py b/unitary/quantum_chess/quantum_moves_test.py index a08517ce..24772591 100644 --- a/unitary/quantum_chess/quantum_moves_test.py +++ b/unitary/quantum_chess/quantum_moves_test.py @@ -1,4 +1,4 @@ -# Copyright 2020 Google +# Copyright 2020 The Unitary Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +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. + import numpy as np import cirq diff --git a/unitary/quantum_chess/readout_tester.py b/unitary/quantum_chess/readout_tester.py index a710ea59..26f3851c 100644 --- a/unitary/quantum_chess/readout_tester.py +++ b/unitary/quantum_chess/readout_tester.py @@ -1,4 +1,4 @@ -# Copyright 2020 Google +# Copyright 2020 The Unitary Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -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. -# + """ Simple sanity test to test readout for device qubits. This will test P11 and P00 for each qubit on the device. diff --git a/unitary/quantum_chess/readout_tester_test.py b/unitary/quantum_chess/readout_tester_test.py index 159cf018..47fc7da8 100644 --- a/unitary/quantum_chess/readout_tester_test.py +++ b/unitary/quantum_chess/readout_tester_test.py @@ -1,4 +1,4 @@ -# Copyright 2020 Google +# Copyright 2020 The Unitary Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -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. -# -# + import cirq import cirq_google as cg diff --git a/unitary/quantum_chess/swap_updater.py b/unitary/quantum_chess/swap_updater.py index 722ba70e..8f450040 100644 --- a/unitary/quantum_chess/swap_updater.py +++ b/unitary/quantum_chess/swap_updater.py @@ -1,4 +1,4 @@ -# Copyright 2021 Google +# Copyright 2021 The Unitary Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +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. + """Implementation of the swap update algorithm described in the paper 'A Dynamic Look-Ahead Heuristic for the Qubit Mapping Problem of NISQ Computers' (https://ieeexplore.ieee.org/abstract/document/8976109). diff --git a/unitary/quantum_chess/swap_updater_test.py b/unitary/quantum_chess/swap_updater_test.py index 0e062406..f5d854fb 100644 --- a/unitary/quantum_chess/swap_updater_test.py +++ b/unitary/quantum_chess/swap_updater_test.py @@ -4,7 +4,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, diff --git a/unitary/quantum_chess/test_utils.py b/unitary/quantum_chess/test_utils.py index 620dcbe6..4f2b03de 100644 --- a/unitary/quantum_chess/test_utils.py +++ b/unitary/quantum_chess/test_utils.py @@ -1,4 +1,4 @@ -# Copyright 2020 Google +# Copyright 2020 The Unitary Authors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -11,6 +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. + from collections import defaultdict from scipy.stats import chisquare From 06240e3c4451c2bf5cc7e09e07c2dd105655dedb Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Fri, 4 Oct 2024 00:09:11 -0700 Subject: [PATCH 07/14] pylint - fix f-string-without-interpolation --- examples/fox_in_a_hole/fox_in_a_hole.py | 10 +++++----- examples/quantum_chinese_chess/chess.py | 2 +- examples/quantum_rpg/bb84.py | 4 ++-- examples/quantum_rpg/bb84_test.py | 2 +- .../final_state_preparation/oxtail_university.py | 2 +- examples/tic_tac_toe/tic_tac_toe.py | 2 +- unitary/quantum_chess/experiments/batch_moves.py | 2 +- unitary/quantum_chess/quantum_board.py | 12 ++++++------ 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/examples/fox_in_a_hole/fox_in_a_hole.py b/examples/fox_in_a_hole/fox_in_a_hole.py index 517943c6..eed1fd53 100644 --- a/examples/fox_in_a_hole/fox_in_a_hole.py +++ b/examples/fox_in_a_hole/fox_in_a_hole.py @@ -358,19 +358,19 @@ def take_random_move(self) -> str: # Initialize game object - print(f"---------------------------------") + print("---------------------------------") if args.is_quantum or (args.qprob is not None and args.qprob > 0.0): game: Game = QuantumGame(qprob=args.qprob, iswap=args.use_iswap) - print(f"Quantum Fox-in-a-hole game.") + print("Quantum Fox-in-a-hole game.") print(f"Probability of quantum move: {game.qprob}.") if args.use_iswap: - print(f"Using iSWAP for moves.") + print("Using iSWAP for moves.") else: - print(f"Using SWAP for moves.") + print("Using SWAP for moves.") else: game = ClassicalGame() print("Classical Fox-in-a-hole game.") - print(f"---------------------------------") + print("---------------------------------") # Run Fox-in-a-hole game.run() diff --git a/examples/quantum_chinese_chess/chess.py b/examples/quantum_chinese_chess/chess.py index 37cc2067..3544379c 100644 --- a/examples/quantum_chinese_chess/chess.py +++ b/examples/quantum_chinese_chess/chess.py @@ -138,7 +138,7 @@ def parse_input_string(str_to_parse: str) -> Tuple[List[str], List[str]]: for location in sources + targets: if location[0].lower() not in "abcdefghi" or not location[1].isdigit(): raise ValueError( - f"Invalid location string. Make sure they are from a0 to i9." + "Invalid location string. Make sure they are from a0 to i9." ) return sources, targets diff --git a/examples/quantum_rpg/bb84.py b/examples/quantum_rpg/bb84.py index 31891bab..3a7578c2 100644 --- a/examples/quantum_rpg/bb84.py +++ b/examples/quantum_rpg/bb84.py @@ -105,7 +105,7 @@ def _view_alice(state: GameState, world): return "The display reads 'Ready to TRANSMIT'" if state.state_dict["astatus"] == "success": return f"The display reads 'Transmission Successful:'\n'{state.state_dict['alice']}'" - return f"The display reads 'Error transmitting data.'" + return "The display reads 'Error transmitting data.'" def _view_bob(state: GameState, world): @@ -115,7 +115,7 @@ def _view_bob(state: GameState, world): return "The display reads 'Ready to Receive'" if state.state_dict["bstatus"] == "success": return f"The display reads 'Received data:'\n'{state.state_dict['bob']}'" - return f"The display reads 'Error receiving data.'" + return "The display reads 'Error receiving data.'" def _power_on_alice(state: GameState, world): diff --git a/examples/quantum_rpg/bb84_test.py b/examples/quantum_rpg/bb84_test.py index fb4b62e0..43ca3360 100644 --- a/examples/quantum_rpg/bb84_test.py +++ b/examples/quantum_rpg/bb84_test.py @@ -166,7 +166,7 @@ def test_alice_bob(): loop.loop() assert ( cast(io.StringIO, state.file).getvalue().replace("\t", " ").strip() - == f""" + == """ Quantum Communication Receiving Facility diff --git a/examples/quantum_rpg/final_state_preparation/oxtail_university.py b/examples/quantum_rpg/final_state_preparation/oxtail_university.py index b5d7c386..1ab3752d 100644 --- a/examples/quantum_rpg/final_state_preparation/oxtail_university.py +++ b/examples/quantum_rpg/final_state_preparation/oxtail_university.py @@ -36,7 +36,7 @@ def _engineer_joins(state: GameState, world) -> str: if len(state.party) > 1: - return f"The engineer reminisces about his former experiment." + return "The engineer reminisces about his former experiment." print( "The engineer looks at the apparatus that dominates the room.", file=state.file ) diff --git a/examples/tic_tac_toe/tic_tac_toe.py b/examples/tic_tac_toe/tic_tac_toe.py index 57f41645..1e420d2f 100644 --- a/examples/tic_tac_toe/tic_tac_toe.py +++ b/examples/tic_tac_toe/tic_tac_toe.py @@ -202,7 +202,7 @@ def move(self, move: str, mark: TicTacSquare) -> TicTacResult: # Check if rules allow quantum moves if self.rules == TicTacRules.CLASSICAL: raise ValueError( - f"Quantum moves are not allowed in a classical TicTacToe" + "Quantum moves are not allowed in a classical TicTacToe" ) # Check if either square is non-empty. Splitting on top of diff --git a/unitary/quantum_chess/experiments/batch_moves.py b/unitary/quantum_chess/experiments/batch_moves.py index dd5fd758..fb0352fe 100644 --- a/unitary/quantum_chess/experiments/batch_moves.py +++ b/unitary/quantum_chess/experiments/batch_moves.py @@ -77,7 +77,7 @@ def main_loop(args): b.load_fen(args.position) else: b.reset() - print(f"Applying moves to board...") + print("Applying moves to board...") apply_moves(b, moves) print(b) diff --git a/unitary/quantum_chess/quantum_board.py b/unitary/quantum_chess/quantum_board.py index 77f9ae57..6434abc6 100644 --- a/unitary/quantum_chess/quantum_board.py +++ b/unitary/quantum_chess/quantum_board.py @@ -942,7 +942,7 @@ def do_move_internal(self, m: move.Move) -> bool: if m.move_type == enums.MoveType.SPLIT_SLIDE: if not m.target2: - raise ValueError(f"Merge slide must have a second source move") + raise ValueError("Merge slide must have a second source move") tbit2 = square_to_bit(m.target2) tqubit2 = bit_to_qubit(tbit2) @@ -1055,7 +1055,7 @@ def do_move_internal(self, m: move.Move) -> bool: if m.move_type == enums.MoveType.MERGE_SLIDE: if not m.source2: - raise ValueError(f"Merge slide must have a second source move") + raise ValueError("Merge slide must have a second source move") sbit2 = square_to_bit(m.source2) squbit2 = bit_to_qubit(sbit2) @@ -1302,7 +1302,7 @@ def do_move_internal(self, m: move.Move) -> bool: if m.move_type == enums.MoveType.SPLIT_JUMP: if not m.target2: - raise ValueError(f"Split jumps must have a second target move") + raise ValueError("Split jumps must have a second target move") tbit2 = square_to_bit(m.target2) tqubit2 = bit_to_qubit(tbit2) is_basic_case = ( @@ -1322,7 +1322,7 @@ def do_move_internal(self, m: move.Move) -> bool: if m.move_type == enums.MoveType.MERGE_JUMP: if not m.source2: - raise ValueError(f"Merge jumps must have a second source move") + raise ValueError("Merge jumps must have a second source move") sbit2 = square_to_bit(m.source2) squbit2 = bit_to_qubit(sbit2) self.add_entangled(squbit, squbit2, tqubit) @@ -1338,7 +1338,7 @@ def do_move_internal(self, m: move.Move) -> bool: rook_sbit = square_to_bit("h8") rook_tbit = square_to_bit("f8") else: - raise ValueError(f"Invalid kingside castling move") + raise ValueError("Invalid kingside castling move") return self._do_noncontrolled_castle( m.move_variant, m.measurement, sbit, tbit, rook_sbit, rook_tbit @@ -1355,7 +1355,7 @@ def do_move_internal(self, m: move.Move) -> bool: rook_tbit = square_to_bit("d8") b_bit = square_to_bit("b8") else: - raise ValueError(f"Invalid queenside castling move") + raise ValueError("Invalid queenside castling move") b_qubit = bit_to_qubit(b_bit) if b_qubit not in self.entangled_squares and not nth_bit_of( From 577cbf304353cd081d6aec251230f9369d503512 Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Fri, 4 Oct 2024 00:16:45 -0700 Subject: [PATCH 08/14] pylint - fix docstring-first-line-empty --- examples/quantum_chinese_chess/board.py | 6 ++---- examples/tic_tac_toe/tic_tac_split.py | 3 +-- examples/tic_tac_toe/tic_tac_toe.py | 15 +++++---------- unitary/alpha/sparse_vector_simulator.py | 1 + unitary/quantum_chess/bit_utils.py | 5 ++--- unitary/quantum_chess/circuit_transformer_test.py | 3 +-- unitary/quantum_chess/experiments/batch_moves.py | 5 ++--- .../experiments/circuit_transform_benchmark.py | 3 +-- .../experiments/interactive_board.py | 4 ++-- unitary/quantum_chess/mcpe_utils.py | 1 + unitary/quantum_chess/move.py | 3 +-- unitary/quantum_chess/pauli_decomposition.py | 4 +--- unitary/quantum_chess/quantum_moves.py | 1 + unitary/quantum_chess/readout_tester.py | 11 ++++++----- unitary/quantum_chess/swap_updater.py | 1 + 15 files changed, 28 insertions(+), 38 deletions(-) diff --git a/examples/quantum_chinese_chess/board.py b/examples/quantum_chinese_chess/board.py index 2946e153..9fea49d6 100644 --- a/examples/quantum_chinese_chess/board.py +++ b/examples/quantum_chinese_chess/board.py @@ -64,8 +64,7 @@ def set_language(self, lang: Language) -> None: @classmethod def from_fen(cls, fen: str = _INITIAL_FEN) -> "Board": - """ - Translates FEN (Forsyth-Edwards Notation) symbols into the whole QuantumWorld board. + """Translates FEN (Forsyth-Edwards Notation) symbols into the whole QuantumWorld board. FEN rule for Chinese Chess could be found at https://www.wxf-xiangqi.org/images/computer-xiangqi/fen-for-xiangqi-chinese-chess.pdf """ chess_board = {} @@ -113,8 +112,7 @@ def to_str( probabilities: List[float] = None, peek_result: List[int] = None, ) -> str: - """ - Print the board into string. + """Print the board into string. Args: terminal: type of the terminal that the game is currently running on; diff --git a/examples/tic_tac_toe/tic_tac_split.py b/examples/tic_tac_toe/tic_tac_split.py index fb8b3486..bd880616 100644 --- a/examples/tic_tac_toe/tic_tac_split.py +++ b/examples/tic_tac_toe/tic_tac_split.py @@ -71,8 +71,7 @@ def _circuit_diagram_info_(self, args): class TicTacSplit(QuantumEffect): - """ - Flips a qubit from |0> to |1> then splits to another square. + """Flips a qubit from |0> to |1> then splits to another square. Depending on the ruleset, the split is done either using a standard sqrt-ISWAP gate, or using the custom QuditSplitGate. """ diff --git a/examples/tic_tac_toe/tic_tac_toe.py b/examples/tic_tac_toe/tic_tac_toe.py index 1e420d2f..00520ec2 100644 --- a/examples/tic_tac_toe/tic_tac_toe.py +++ b/examples/tic_tac_toe/tic_tac_toe.py @@ -260,8 +260,7 @@ def sample(self, count: int = 1) -> List[str]: class GameInterface: - """ - A class that provides a command-line interface to play Quantum Tic Tac Toe. + """A class that provides a command-line interface to play Quantum Tic Tac Toe. Initialize by providing an instance of a TicTacToe game, then call play() to run the game. @@ -281,16 +280,14 @@ def __init__(self, game: TicTacToe, file: TextIO = sys.stdout): self.player_quit = False def get_move(self) -> str: - """ - Gets and returns the player's move. + """Gets and returns the player's move. Basically a wrapper around input to facilitate testing. """ return input(f'Player {self.player} to move ("help" for help): ') def player_move(self) -> None: - """ - Interprets the player's move and takes the appropriate action. + """Interprets the player's move and takes the appropriate action. A move can be a one or two letter string within the set [abcdefghi], in which case this function hands the move off to the TicTacToe instance, @@ -318,8 +315,7 @@ def player_move(self) -> None: self.player = "O" if self.player == "X" else "X" def print_welcome(self) -> str: - """ - Prints the welcome message for the game interface. + """Prints the welcome message for the game interface. """ message = """ Welcome to quantum tic tac toe! @@ -329,8 +325,7 @@ def print_welcome(self) -> str: return message def play(self) -> None: - """ - Run the game loop, requesting player moves, alternating players, until + """Run the game loop, requesting player moves, alternating players, until the TicTacToe instance reports that the game ends with a winner or a tie or one of the players has quit. """ diff --git a/unitary/alpha/sparse_vector_simulator.py b/unitary/alpha/sparse_vector_simulator.py index 2f495d34..1a2d2711 100644 --- a/unitary/alpha/sparse_vector_simulator.py +++ b/unitary/alpha/sparse_vector_simulator.py @@ -20,6 +20,7 @@ Does not work with 3+-state qudits. """ + import cirq import numpy as np diff --git a/unitary/quantum_chess/bit_utils.py b/unitary/quantum_chess/bit_utils.py index 3d064be3..57de0b7a 100644 --- a/unitary/quantum_chess/bit_utils.py +++ b/unitary/quantum_chess/bit_utils.py @@ -12,9 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -""" -Utilities for converting to and from bit boards. -""" +"""Utilities for converting to and from bit boards.""" + from typing import List import cirq diff --git a/unitary/quantum_chess/circuit_transformer_test.py b/unitary/quantum_chess/circuit_transformer_test.py index afd65f92..1a90d55e 100644 --- a/unitary/quantum_chess/circuit_transformer_test.py +++ b/unitary/quantum_chess/circuit_transformer_test.py @@ -51,8 +51,7 @@ def test_qubits_within(device): @pytest.mark.parametrize("device", (cg.Sycamore23, cg.Sycamore)) def test_edges_within(device): - """ - The circuit looks like: + """The circuit looks like: a1 --- a4 --- a3 --- a2 d1 | | | diff --git a/unitary/quantum_chess/experiments/batch_moves.py b/unitary/quantum_chess/experiments/batch_moves.py index fb0352fe..a20add91 100644 --- a/unitary/quantum_chess/experiments/batch_moves.py +++ b/unitary/quantum_chess/experiments/batch_moves.py @@ -12,9 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -""" -Runs a series of moves on a quantum chess board then displays the -result. +"""Runs a series of moves on a quantum chess board then displays the result. Run with: python -m unitary.quantum_chess.experiments.batch_moves \ @@ -32,6 +30,7 @@ FEN is a initial position in chess FEN notation. Optional. Default is the normal classical chess starting position. """ + import argparse from typing import List diff --git a/unitary/quantum_chess/experiments/circuit_transform_benchmark.py b/unitary/quantum_chess/experiments/circuit_transform_benchmark.py index a507c4d6..f54bf563 100644 --- a/unitary/quantum_chess/experiments/circuit_transform_benchmark.py +++ b/unitary/quantum_chess/experiments/circuit_transform_benchmark.py @@ -12,8 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -""" -Benchmarking tool for logical-to-hardware circuit transformations. +"""Benchmarking tool for logical-to-hardware circuit transformations. To run this: python unitary/quantum_chess/experiments/circuit_transform_benchmark.py \ diff --git a/unitary/quantum_chess/experiments/interactive_board.py b/unitary/quantum_chess/experiments/interactive_board.py index 1511bd53..4e086a00 100644 --- a/unitary/quantum_chess/experiments/interactive_board.py +++ b/unitary/quantum_chess/experiments/interactive_board.py @@ -12,8 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -""" -Interactive ascii-based quantum chess game. +"""Interactive ascii-based quantum chess game. Run with: @@ -50,6 +49,7 @@ The interactive board uses a simulator with an unconstrained device. """ + import argparse import sys diff --git a/unitary/quantum_chess/mcpe_utils.py b/unitary/quantum_chess/mcpe_utils.py index c2d3f848..882cd412 100644 --- a/unitary/quantum_chess/mcpe_utils.py +++ b/unitary/quantum_chess/mcpe_utils.py @@ -20,6 +20,7 @@ NISQ Computers' (https://ieeexplore.ieee.org/abstract/document/8976109). """ + from collections import defaultdict, deque from typing import Callable, Dict, Iterable, Set, Tuple diff --git a/unitary/quantum_chess/move.py b/unitary/quantum_chess/move.py index a57af33c..3dd7c0cb 100644 --- a/unitary/quantum_chess/move.py +++ b/unitary/quantum_chess/move.py @@ -177,8 +177,7 @@ def has_measurement(self) -> bool: return self.measurement is not None def to_string(self, include_type=False) -> str: - """ - Constructs the string representation of this move object. + """Constructs the string representation of this move object. By default, only returns the move source(s), target(s), and measurement if present. diff --git a/unitary/quantum_chess/pauli_decomposition.py b/unitary/quantum_chess/pauli_decomposition.py index e48573af..74d18621 100644 --- a/unitary/quantum_chess/pauli_decomposition.py +++ b/unitary/quantum_chess/pauli_decomposition.py @@ -12,9 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -""" -Utility functions used for decomposing the given measurement matrix into a PauliSum. -""" +"""Utility functions used for decomposing the given measurement matrix into a PauliSum.""" import itertools import functools diff --git a/unitary/quantum_chess/quantum_moves.py b/unitary/quantum_chess/quantum_moves.py index 8b8b78f4..759d73fd 100644 --- a/unitary/quantum_chess/quantum_moves.py +++ b/unitary/quantum_chess/quantum_moves.py @@ -13,6 +13,7 @@ # limitations under the License. """Quantum Circuits for common quantum chess moves.""" + from typing import Sequence import cirq diff --git a/unitary/quantum_chess/readout_tester.py b/unitary/quantum_chess/readout_tester.py index 26f3851c..321b489d 100644 --- a/unitary/quantum_chess/readout_tester.py +++ b/unitary/quantum_chess/readout_tester.py @@ -12,13 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. -""" - Simple sanity test to test readout for device qubits. - This will test P11 and P00 for each qubit on the device. +"""Simple sanity test to test readout for device qubits. + +This will test P11 and P00 for each qubit on the device. - See https://www.twitch.tv/anna_chess/video/824369168 - at 1h:17m to see how this can affect live demos. +See https://www.twitch.tv/anna_chess/video/824369168 +at 1h:17m to see how this can affect live demos. """ + from typing import Dict import cirq diff --git a/unitary/quantum_chess/swap_updater.py b/unitary/quantum_chess/swap_updater.py index 8f450040..a836f0b8 100644 --- a/unitary/quantum_chess/swap_updater.py +++ b/unitary/quantum_chess/swap_updater.py @@ -18,6 +18,7 @@ This transforms circuits by adding additional SWAP gates to ensure that all operations are on adjacent qubits. """ + from collections import deque from typing import ( Callable, From 140bc142e61b7f2fac310299ea3ce6583c98570b Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Fri, 4 Oct 2024 00:24:45 -0700 Subject: [PATCH 09/14] pylint - fix singleton-comparison --- examples/quantum_chinese_chess/board_test.py | 6 +++--- examples/quantum_chinese_chess/chess_test.py | 4 ++-- examples/quantum_chinese_chess/enums_test.py | 2 +- examples/quantum_chinese_chess/move_test.py | 16 ++++++++-------- examples/quantum_chinese_chess/piece_test.py | 2 +- unitary/alpha/quantum_world_test.py | 2 +- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/examples/quantum_chinese_chess/board_test.py b/examples/quantum_chinese_chess/board_test.py index f6dad82f..317c719e 100644 --- a/examples/quantum_chinese_chess/board_test.py +++ b/examples/quantum_chinese_chess/board_test.py @@ -170,16 +170,16 @@ def test_flying_general_check_classical_cases(): board = Board.from_fen() # If they are in different columns, the check fails. board.king_locations = ["d0", "e9"] - assert board.flying_general_check() == False + assert not board.flying_general_check() # If there are classical pieces between two KINGs, the check fails. board.king_locations = ["e0", "e9"] - assert board.flying_general_check() == False + assert not board.flying_general_check() # If there are no pieces between two KINGs, the check successes. board.board["e3"].reset() board.board["e6"].reset() - assert board.flying_general_check() == True + assert board.flying_general_check() def test_flying_general_check_quantum_cases(): diff --git a/examples/quantum_chinese_chess/chess_test.py b/examples/quantum_chinese_chess/chess_test.py index c3423d57..c59b08c1 100644 --- a/examples/quantum_chinese_chess/chess_test.py +++ b/examples/quantum_chinese_chess/chess_test.py @@ -386,12 +386,12 @@ def test_update_board_by_sampling(monkeypatch): game.update_board_by_sampling() assert board["a0"].type_ == Type.EMPTY assert board["a0"].color == Color.NA - assert board["a0"].is_entangled == False + assert not board["a0"].is_entangled board["a1"].is_entangled = True # Verify that the method would set a1 to classically occupied. game.update_board_by_sampling() - assert board["a1"].is_entangled == False + assert not board["a1"].is_entangled def test_undo_single_effect_per_move(monkeypatch): diff --git a/examples/quantum_chinese_chess/enums_test.py b/examples/quantum_chinese_chess/enums_test.py index 827cb28b..03bea06d 100644 --- a/examples/quantum_chinese_chess/enums_test.py +++ b/examples/quantum_chinese_chess/enums_test.py @@ -21,7 +21,7 @@ def test_type_of(): assert Type.type_of("k") == Type.KING assert Type.type_of("K") == Type.KING assert Type.type_of("ยท") == Type.EMPTY - assert Type.type_of("b") == None + assert Type.type_of("b") is None def test_symbol(): diff --git a/examples/quantum_chinese_chess/move_test.py b/examples/quantum_chinese_chess/move_test.py index 8a798991..af5c882b 100644 --- a/examples/quantum_chinese_chess/move_test.py +++ b/examples/quantum_chinese_chess/move_test.py @@ -80,7 +80,7 @@ def test_move_type(): move_type=MoveType.MERGE_JUMP, move_variant=MoveVariant.CAPTURE, ) - assert move1.is_split_move() == False + assert not move1.is_split_move() assert move1.is_merge_move() move2 = Move( @@ -91,7 +91,7 @@ def test_move_type(): move_variant=MoveVariant.BASIC, ) assert move2.is_split_move() - assert move2.is_merge_move() == False + assert not move2.is_merge_move() move3 = Move( world["a1"], @@ -99,8 +99,8 @@ def test_move_type(): move_type=MoveType.SLIDE, move_variant=MoveVariant.CAPTURE, ) - assert move3.is_split_move() == False - assert move3.is_merge_move() == False + assert not move3.is_split_move() + assert not move3.is_merge_move() def test_to_str(): @@ -275,10 +275,10 @@ def test_split_jump_classical_source(): assert_fifty_fifty(board_probabilities, locations_to_bitboard(["a3"])) assert world["a2"].type_ == Type.ROOK assert world["a2"].color == Color.RED - assert world["a2"].is_entangled == True + assert world["a2"].is_entangled assert world["a3"].type_ == Type.ROOK assert world["a3"].color == Color.RED - assert world["a3"].is_entangled == True + assert world["a3"].is_entangled def test_split_jump_quantum_source(): @@ -295,8 +295,8 @@ def test_split_jump_quantum_source(): locations_to_bitboard(["a5"]): 0.25, }, ) - assert world["a4"].is_entangled == True - assert world["a5"].is_entangled == True + assert world["a4"].is_entangled + assert world["a5"].is_entangled def test_merge_jump_perfect_merge(): diff --git a/examples/quantum_chinese_chess/piece_test.py b/examples/quantum_chinese_chess/piece_test.py index 90caf3dc..5be46ee5 100644 --- a/examples/quantum_chinese_chess/piece_test.py +++ b/examples/quantum_chinese_chess/piece_test.py @@ -58,7 +58,7 @@ def test_reset(): p0.reset() assert p0.type_ == Type.EMPTY assert p0.color == Color.NA - assert p0.is_entangled == False + assert not p0.is_entangled p0.reset(p1) assert p0.type_ == p1.type_ diff --git a/unitary/alpha/quantum_world_test.py b/unitary/alpha/quantum_world_test.py index fc40d128..bab88672 100644 --- a/unitary/alpha/quantum_world_test.py +++ b/unitary/alpha/quantum_world_test.py @@ -51,7 +51,7 @@ def test_get_object_by_name(compile_to_qubits): board = alpha.QuantumWorld([light, light2], compile_to_qubits=compile_to_qubits) assert board.get_object_by_name("test") == light assert board.get_object_by_name("test2") == light2 - assert board.get_object_by_name("test3") == None + assert board.get_object_by_name("test3") is None assert board["test"] == light assert board["test2"] == light2 with pytest.raises(KeyError): From 08b0c80f9f02fcf10d21bb793f5ab9f748c847c0 Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Fri, 4 Oct 2024 10:46:26 -0700 Subject: [PATCH 10/14] Make it explicit we use black default 88 character line length --- pyproject.toml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 pyproject.toml diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..e7528acd --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,3 @@ +[tool.black] +line-length = 88 +target_version = ['py310', 'py311', 'py312'] From 5795ac6960cf9c063bf890434909d844cfd05034 Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Fri, 4 Oct 2024 11:11:05 -0700 Subject: [PATCH 11/14] CI - use the latest pylint for lint checking --- .github/workflows/pylint.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 84a101e8..d8a0da8b 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -12,9 +12,8 @@ jobs: python-version: '3.12' architecture: 'x64' - name: Install Pylint - # TODO: #210 - install the latest pylint below run: | python -m pip install --upgrade pip - pip install 'pylint<3' + pip install pylint - name: Pylint check run: dev_tools/pylint From 148fcbb1adeb266b0435c1d69f9ef016edc3c853 Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Fri, 4 Oct 2024 11:12:33 -0700 Subject: [PATCH 12/14] CI - convert pylint to soft check --- .github/workflows/pylint.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index d8a0da8b..f789707a 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -16,4 +16,9 @@ jobs: python -m pip install --upgrade pip pip install pylint - name: Pylint check - run: dev_tools/pylint + # TODO: #210 - convert to hard check when lint is picked up + run: | + dev_tools/pylint || ( + echo "pylint check failed. The error is temporarily ignored." + echo "See https://github.com/quantumlib/unitary/issues/210" + ) From 0985873025063c1c5ed499b6ffd3337215d3aa83 Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Mon, 7 Oct 2024 10:28:52 -0700 Subject: [PATCH 13/14] Revert "CI - convert pylint to soft check" This reverts commit 148fcbb1adeb266b0435c1d69f9ef016edc3c853. --- .github/workflows/pylint.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index f789707a..d8a0da8b 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -16,9 +16,4 @@ jobs: python -m pip install --upgrade pip pip install pylint - name: Pylint check - # TODO: #210 - convert to hard check when lint is picked up - run: | - dev_tools/pylint || ( - echo "pylint check failed. The error is temporarily ignored." - echo "See https://github.com/quantumlib/unitary/issues/210" - ) + run: dev_tools/pylint From 391c95dbf484661904c40179f158e44c51164907 Mon Sep 17 00:00:00 2001 From: Pavol Juhas Date: Mon, 7 Oct 2024 10:31:05 -0700 Subject: [PATCH 14/14] Temporarily deactivate rules that fail in pylint-3 --- dev_tools/.pylintrc | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/dev_tools/.pylintrc b/dev_tools/.pylintrc index 40fcdd44..3e375048 100644 --- a/dev_tools/.pylintrc +++ b/dev_tools/.pylintrc @@ -7,53 +7,53 @@ output-format=colorized score=no reports=no enable= - anomalous-backslash-in-string, + # anomalous-backslash-in-string, # TODO: #210 - enable and fix assert-on-tuple, bad-indentation, bad-option-value, bad-reversed-sequence, bad-super-call, consider-merging-isinstance, - consider-using-f-string, + # consider-using-f-string, # TODO: #210 - enable and fix continue-in-finally, - dangerous-default-value, + # dangerous-default-value, # TODO: #210 - enable and fix docstyle, duplicate-argument-name, - expression-not-assigned, + # expression-not-assigned, # TODO: #210 - enable and fix f-string-without-interpolation, - function-redefined, + # function-redefined, # TODO: #210 - enable and fix inconsistent-mro, init-is-generator, - line-too-long, + # line-too-long, # TODO: #210 - enable and fix lost-exception, missing-kwoa, - missing-param-doc, + # missing-param-doc, # TODO: #210 - enable and fix missing-raises-doc, mixed-line-endings, - no-value-for-parameter, + # no-value-for-parameter, # TODO: #210 - enable and fix nonexistent-operator, not-in-loop, - pointless-statement, - redefined-builtin, + # pointless-statement, # TODO: #210 - enable and fix + # redefined-builtin, # TODO: #210 - enable and fix return-arg-in-generator, return-in-init, return-outside-function, simplifiable-if-statement, singleton-comparison, syntax-error, - too-many-function-args, + # too-many-function-args, # TODO: #210 - enable and fix trailing-whitespace, undefined-variable, - unexpected-keyword-arg, + # unexpected-keyword-arg, # TODO: #210 - enable and fix unhashable-dict-key, - unnecessary-pass, + # unnecessary-pass, # TODO: #210 - enable and fix unreachable, unrecognized-inline-option, unused-import, unnecessary-semicolon, - unused-variable, - unused-wildcard-import, - wildcard-import, + # unused-variable, # TODO: #210 - enable and fix + # unused-wildcard-import, # TODO: #210 - enable and fix + # wildcard-import, # TODO: #210 - enable and fix wrong-or-nonexistent-copyright-notice, wrong-import-order, wrong-import-position,